source: tags/1.3.8/LocalPlayer/Rates.pas

Last change on this file was 684, checked in by chronos, 13 days ago
  • Modified: Improved forms painting if resized to bigger dimensions.
File size: 6.8 KB
Line 
1{$INCLUDE Switches.inc}
2unit Rates;
3
4interface
5
6uses
7 Protocol, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils, Classes, ButtonB,
8 ButtonC,
9 {$IFDEF DPI}Dpi.Graphics, Dpi.Controls, Dpi.Forms{$ELSE}
10 Graphics, Controls, Forms{$ENDIF};
11
12type
13
14 { TRatesDlg }
15
16 TRatesDlg = class(TBufferedDrawDlg)
17 CloseBtn: TButtonB;
18 LuxBtn: TButtonC;
19 ScienceBtn: TButtonC;
20 TaxUpBtn: TButtonC;
21 TaxDownBtn: TButtonC;
22 procedure FormShow(Sender: TObject);
23 procedure CloseBtnClick(Sender: TObject);
24 procedure FormCreate(Sender: TObject);
25 procedure TaxLuxBtnClick(Sender: TObject);
26 protected
27 procedure OffscreenPaint; override;
28 procedure DoOnResize; override;
29 public
30 procedure ShowNewContent(NewMode: TWindowMode);
31 end;
32
33
34implementation
35
36uses
37 ClientTools, Term, Tribes;
38
39{$R *.lfm}
40
41const
42 MessageLineSpacing = 20;
43
44procedure TRatesDlg.FormCreate(Sender: TObject);
45begin
46 TitleHeight := Screen.PrimaryMonitor.Height;
47 InitButtons;
48end;
49
50procedure TRatesDlg.OffscreenPaint;
51var
52 P, X, Y, Current, Max, I: Integer;
53 S, s1: string;
54begin
55 inherited;
56
57 Fill(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
58 (Maintexture.Width - ClientWidth) div 2, (Maintexture.Height - ClientHeight) div 2);
59 Frame(Offscreen.Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
60 Frame(Offscreen.Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
61 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
62 Frame(Offscreen.Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
63 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
64
65 BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture);
66 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
67 S := Phrases.Lookup('TITLE_RATES');
68 RisedTextOut(Offscreen.Canvas,
69 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S);
70
71 if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
72 S := Phrases.Lookup('NORATES')
73 else
74 S := Phrases.Lookup('RATES');
75 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
76 P := Pos('\', S);
77 if P = 0 then
78 RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, S))
79 div 2, 114, S)
80 else
81 begin
82 s1 := Copy(S, 1, P - 1);
83 RisedTextOut(Offscreen.Canvas,
84 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2,
85 114 - MessageLineSpacing div 2, s1);
86 s1 := Copy(S, P + 1, 255);
87 RisedTextOut(Offscreen.Canvas,
88 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2,
89 114 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
90 end;
91 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
92
93 if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
94 begin
95 GlowFrame(Offscreen, ClientWidth div 2 - xSizeBig div 2, 52, xSizeBig,
96 ySizeBig, Tribe[Me].Color);
97 BitBltBitmap(Offscreen, ClientWidth div 2 - xSizeBig div 2, 52,
98 xSizeBig, ySizeBig, BigImp, (woLiberty mod 7) * xSizeBig,
99 (woLiberty div 7 + SystemIconLines) * ySizeBig);
100 end
101 else
102 begin
103 // ImageOp_CBC(Offscreen,Templates,260,40,145,112,36,36,$404000,$8B8BEB);
104
105 S := Phrases.Lookup('SCIENCE');
106 RisedTextOut(Offscreen.Canvas,
107 16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 44, S);
108 S := Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]);
109 RisedTextOut(Offscreen.Canvas,
110 16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 60, S);
111 // PaintProgressBar(Offscreen.Canvas,2,16,81,(100-MyRO.LuxRate-MyRO.TaxRate)*120 div 100,0,120,MainTexture);
112
113 // reverse progress bar for science
114 X := 16;
115 Y := 81;
116 Current := (100 - MyRO.LuxRate - MyRO.TaxRate) * 120 div 100;
117 Max := 120;
118 Frame(Offscreen.Canvas, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000);
119 RFrame(Offscreen.Canvas, X - 2, Y - 2, X + Max + 1, Y + 8,
120 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
121 with Offscreen.Canvas do
122 begin
123 for I := 0 to Current div 8 - 1 do
124 BitBltBitmap(Offscreen, X + Max - 8 - I * 8, Y, 8, 7,
125 HGrSystem.Data, 104, 9 + 8 * 2);
126 BitBltBitmap(Offscreen, X + Max - Current, Y, Current - 8 * (Current div 8), 7,
127 HGrSystem.Data, 104, 9 + 8 * 2);
128 Brush.Color := $000000;
129 FillRect(Rect(X, Y, X + Max - Current, Y + 7));
130 Brush.Style := TBrushStyle.bsClear;
131 end;
132
133 RisedTextOut(Offscreen.Canvas, 16 + 160, 44, Phrases.Lookup('LUX'));
134 S := Format('%d%%', [MyRO.LuxRate]);
135 RisedTextOut(Offscreen.Canvas,
136 16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, S);
137 PaintProgressBar(Offscreen.Canvas, 5, 16 + 160, 81,
138 MyRO.LuxRate * 120 div 100, 0, 120, MainTexture);
139 RFrame(Offscreen.Canvas, ScienceBtn.Left - 1, LuxBtn.Top - 1,
140 LuxBtn.Left + 12, LuxBtn.Top + 12, MainTexture.ColorBevelShade,
141 MainTexture.ColorBevelLight);
142 end;
143
144 DLine(Offscreen.Canvas, 1, ClientWidth - 2, 154, MainTexture.ColorBevelShade,
145 MainTexture.ColorBevelLight);
146 RisedTextOut(Offscreen.Canvas, 16 + 80, 164, Phrases.Lookup('TAXRATE'));
147 S := Format('%d%%', [MyRO.TaxRate]);
148 RisedTextOut(Offscreen.Canvas,
149 16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, S);
150 PaintProgressBar(Offscreen.Canvas, 0, 16 + 80, 201,
151 MyRO.TaxRate * 120 div 100, 0, 120, MainTexture);
152 RFrame(Offscreen.Canvas, TaxUpBtn.Left - 1, TaxUpBtn.Top - 1,
153 TaxUpBtn.Left + 12, TaxDownBtn.Top + 12, MainTexture.ColorBevelShade,
154 MainTexture.ColorBevelLight);
155
156 MarkUsedOffscreen(ClientWidth, ClientHeight);
157end;
158
159procedure TRatesDlg.DoOnResize;
160begin
161 inherited;
162 CloseBtn.Left := Width - 38;
163end;
164
165procedure TRatesDlg.ShowNewContent(NewMode: TWindowMode);
166begin
167 inherited ShowNewContent(NewMode);
168end;
169
170procedure TRatesDlg.FormShow(Sender: TObject);
171begin
172 Caption := Phrases.Lookup('TITLE_RATES');
173 if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
174 begin
175 ScienceBtn.Visible := False;
176 LuxBtn.Visible := False;
177 end
178 else
179 begin
180 ScienceBtn.Visible := True;
181 LuxBtn.Visible := True;
182 end;
183 OffscreenPaint;
184end;
185
186procedure TRatesDlg.CloseBtnClick(Sender: TObject);
187begin
188 Close;
189end;
190
191procedure TRatesDlg.TaxLuxBtnClick(Sender: TObject);
192var
193 NewTax, NewLux: Integer;
194begin
195 NewTax := MyRO.TaxRate div 10;
196 NewLux := MyRO.LuxRate div 10;
197 if Sender = TaxUpBtn then
198 begin
199 if NewTax < 10 then
200 Inc(NewTax);
201 if NewTax + NewLux > 10 then
202 Dec(NewLux);
203 end
204 else if (Sender = TaxDownBtn) and (NewTax > 0) then
205 Dec(NewTax)
206 else if (Sender = ScienceBtn) and (NewLux > 0) then
207 Dec(NewLux)
208 else if (Sender = LuxBtn) and (NewLux + NewTax < 100) then
209 Inc(NewLux);
210 if Server(sSetRates, Me, NewTax + NewLux shl 4, nil^) <> eNotChanged then
211 begin
212 CityOptimizer_BeginOfTurn;
213 SmartUpdateContent;
214 MainScreen.UpdateViews(True);
215 end;
216end;
217
218end.
Note: See TracBrowser for help on using the repository browser.