source: tags/1.3.1/LocalPlayer/Rates.pas

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