@@ -42,7 +42,7 @@ TViewGame = class(TCastleView)
4242 private
4343 FPreviousRoom: TRoomComponent;
4444 FWeapons: array [0 ..3 ] of TCastleButton;
45- FSkip, FPause: Boolean;
45+ FSkip, FPause, FInternalWeaponSwitch : Boolean;
4646 FPosFrom, FPosTo: TVector2;
4747 FAnimateWeaponTicks, FGameTicks: Integer;
4848 FViewEnd: TCastleView;
@@ -61,6 +61,7 @@ TViewGame = class(TCastleView)
6161 procedure WeaponHint (ADoShow: Boolean; AWeapon: NHeroWeapon = hwNo);
6262 procedure VisualizeTime ();
6363 procedure UpdateRooms ();
64+ procedure WeaponClick (AWeapon: NHeroWeapon; AFromUser: Boolean = False);
6465 private const
6566 TicksToFlyWeapon = 30 ; // animation will last 0.5 seconds (30 ticks * 16 ms)
6667 GameSeconds: array [NDifficulty] of Integer = (240 , 360 , 480 , 600 );
@@ -132,7 +133,7 @@ procedure TViewGame.Start();
132133 FWeapons[1 ] := WeaponPlus;
133134 FWeapons[2 ] := WeaponMinus;
134135 FWeapons[3 ] := WeaponMultiply;
135- WeaponNo.Doclick ();
136+ WeaponNo.DoClick ();
136137 TimerPreEnd.Exists := False;
137138 TimerBlood.Exists := False;
138139 TimerPreEnd.OnTimer := TimerPreEndTick;
@@ -145,7 +146,8 @@ procedure TViewGame.Start();
145146 FGameTicks := GameSeconds[Difficulty()];
146147 VisualizeTime();
147148
148- GroupTowers.ClearControls();
149+ GroupTowers.ClearControls();
150+ GroupTowers.Spacing := (Ord(High(NDifficulty)) - Ord(Difficulty()) - 1 ) * 40 ;
149151 for LTowerIndex := 0 to Pred(Map.Towers.Count) do
150152 begin
151153 LVisualTower := FactoryTower.ComponentLoad(GroupTowers) as TCastleUserInterface;
@@ -196,9 +198,11 @@ procedure TViewGame.ButtonWeaponClick(Sender: TObject);
196198 LIsWeapon := FWeapons[i] = LWeaponButton;
197199 if LIsWeapon then
198200 begin
199- WeaponHint(False);
201+ if not FInternalWeaponSwitch then
202+ WeaponHint(False);
200203 Map.Hero.Weapon := NHeroWeapon(i);
201- WeaponHint(True);
204+ if not FInternalWeaponSwitch then
205+ WeaponHint(True);
202206 end ;
203207 FWeapons[i].Pressed := LIsWeapon or (i = Ord(hwNo));
204208 FWeapons[i].Border.AllSides := IIF(LIsWeapon or (i = Ord(hwNo)), 4 , 0 );
@@ -248,7 +252,7 @@ procedure TViewGame.Update(const SecondsPassed: Single; var HandleInput: boolean
248252 if FAnimateWeaponTicks = 0 then
249253 begin
250254 ImageWeapon.Url := ' ' ;
251- WeaponNo.DoClick( );
255+ WeaponClick(hwNo );
252256 end ;
253257 end ;
254258 if not FPause and (Map.Hero.Weapon <> hwNo) then
@@ -289,19 +293,19 @@ function TViewGame.Press(const Event: TInputPressRelease): Boolean;
289293 repeat
290294 W := (W + 1 ) mod Length(FWeapons);
291295 until FWeapons[W].Enabled;
292- FWeapons[W].DoClick( );
296+ WeaponClick(NHeroWeapon(W), True );
293297 Exit(True); // key was handled
294298 end ;
295299
296300 if Event.Key in [key1, key2, key3, key4] then
297301 begin
298- FWeapons[ Ord(Event.Key) - Ord(key1)].DoClick( );
302+ WeaponClick(NHeroWeapon( Ord(Event.Key) - Ord(key1)), True );
299303 Exit(True); // key was handled
300304 end ;
301305
302306 if Event.Key in [keyNumpad1, keyNumpad2, keyNumpad3, keyNumpad4] then
303307 begin
304- FWeapons[ Ord(Event.Key) - Ord(keyNumpad1)].DoClick( );
308+ WeaponClick(NHeroWeapon( Ord(Event.Key) - Ord(keyNumpad1)), True );
305309 Exit(True); // key was handled
306310 end ;
307311
@@ -442,7 +446,7 @@ procedure TViewGame.TimerBloodTick(ASender: TObject);
442446 FRoomFight.LabelLeft.Caption := Map.Hero.Visual;
443447
444448 if LWeapon = hwNo then
445- WeaponNo.DoClick( );
449+ WeaponClick(hwNo );
446450 // WriteLnLog(Format('T%d S%d L%d L%d', [Map.HeroTowerIndex, Map.HeroStockIndex, Map.LastTower, Map.LastStock]));
447451 if Map.IsFinalRoom(Map.HeroTowerIndex + 1 , Map.HeroStockIndex + 1 ) then
448452 begin
@@ -472,6 +476,7 @@ procedure TViewGame.WeaponHint(ADoShow: Boolean; AWeapon: NHeroWeapon = hwNo);
472476var
473477 LWeapon: NHeroWeapon;
474478begin
479+ TimerHint.ResetNextTimerEvent();
475480 TimerHint.Exists := ADoShow;
476481 if AWeapon = hwNo then
477482 LWeapon := Map.Hero.Weapon
@@ -512,9 +517,16 @@ procedure TViewGame.UpdateRooms();
512517 for LStockIndex := 0 to Pred(Map.Towers[LTowerIndex].Rooms.Count) do
513518 begin
514519 LRoomComponent := LGroupTower.Controls[LStockIndex] as TRoomComponent;
515- LRoomComponent.ControlRoom.Enabled := { Map.IsHeroRoom(LRoomComponent.Tag) or } Map.IsRoomReachable(LTowerIndex, LStockIndex);
520+ LRoomComponent.ControlRoom.Enabled := Map.IsRoomReachable(LTowerIndex, LStockIndex);
516521 end ;
517522 end ;
518523end ;
519524
520- end .
525+ procedure TViewGame.WeaponClick (AWeapon: NHeroWeapon; AFromUser: Boolean = False);
526+ begin
527+ FInternalWeaponSwitch := not AFromUser;
528+ FWeapons[Ord(AWeapon)].DoClick();
529+ FInternalWeaponSwitch := False;
530+ end ;
531+
532+ end .
0 commit comments