source: tags/1.2.0/LocalPlayer/Rates.pas

Last change on this file was 188, checked in by chronos, 4 years ago
  • Modified: Simplified code by replacing BitBlt which uses always handles by BitBltCanvas which uses directly TCanvas objects. Used default ROP SRCCOPY.
File size: 6.7 KB
Line 
1{$INCLUDE Switches.inc}
2unit Rates;
3
4interface
5
6uses
7 Protocol, ScreenTools, BaseWin, LCLIntf, LCLType,
8
9 SysUtils, Classes, Graphics, Controls, Forms,
10 ButtonB, ButtonC;
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: integer);
26 end;
27
28var
29 RatesDlg: TRatesDlg;
30
31implementation
32
33uses
34 ClientTools, Term, Tribes;
35
36{$R *.lfm}
37
38const
39 MessageLineSpacing = 20;
40
41procedure TRatesDlg.FormCreate(Sender: TObject);
42begin
43 TitleHeight := Screen.Height;
44 InitButtons();
45end;
46
47procedure TRatesDlg.OffscreenPaint;
48var
49 p, x, y, current, max, i: integer;
50 s, s1: string;
51begin
52 if (OffscreenUser <> nil) and (OffscreenUser <> self) then
53 OffscreenUser.Update;
54 // complete working with old owner to prevent rebound
55 OffscreenUser := self;
56
57 Fill(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
58 (wMaintexture - ClientWidth) div 2, (hMaintexture - 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.clBevelLight, MainTexture.clBevelShade);
62 Frame(Offscreen.Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
63 MainTexture.clBevelLight, MainTexture.clBevelShade);
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 BitBltCanvas(Offscreen.Canvas, ClientWidth div 2 - xSizeBig div 2, 52,
98 xSizeBig, ySizeBig, BigImp.Canvas, (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.clBevelShade, MainTexture.clBevelLight);
121 with Offscreen.Canvas do
122 begin
123 for i := 0 to current div 8 - 1 do
124 BitBltCanvas(Offscreen.Canvas, x + max - 8 - i * 8, y, 8, 7,
125 GrExt[HGrSystem].Data.Canvas, 104, 9 + 8 * 2);
126 BitBltCanvas(Offscreen.Canvas, x + max - current, y, current - 8 * (current div 8), 7,
127 GrExt[HGrSystem].Data.Canvas, 104, 9 + 8 * 2);
128 Brush.Color := $000000;
129 FillRect(Rect(x, y, x + max - current, y + 7));
130 Brush.Style := 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.clBevelShade,
141 MainTexture.clBevelLight);
142 end;
143
144 DLine(Offscreen.Canvas, 1, ClientWidth - 2, 154, MainTexture.clBevelShade,
145 MainTexture.clBevelLight);
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.clBevelShade,
154 MainTexture.clBevelLight);
155
156 MarkUsedOffscreen(ClientWidth, ClientHeight);
157end;
158
159procedure TRatesDlg.ShowNewContent(NewMode: integer);
160begin
161 inherited ShowNewContent(NewMode);
162end;
163
164procedure TRatesDlg.FormShow(Sender: TObject);
165begin
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.