source: trunk/LocalPlayer/Rates.pas

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