Changeset 35
- Timestamp:
- Mar 7, 2014, 11:03:30 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r34 r35 108 108 end 109 109 end 110 object MenuItem10: TMenuItem 111 Caption = 'View' 112 object MenuItem11: TMenuItem 113 Action = AZoomAll 114 end 115 object MenuItem12: TMenuItem 116 Action = AZoomIn 117 end 118 object MenuItem13: TMenuItem 119 Action = AZoomOut 120 end 121 end 110 122 object MenuItem8: TMenuItem 111 123 Caption = 'Tools' … … 121 133 top = 263 122 134 end 135 object ActionList1: TActionList 136 Images = Core.ImageListSmall 137 left = 280 138 top = 152 139 object AZoomIn: TAction 140 Caption = 'Zoom in' 141 OnExecute = AZoomInExecute 142 ShortCut = 16491 143 end 144 object AZoomOut: TAction 145 Caption = 'Zoom out' 146 OnExecute = AZoomOutExecute 147 ShortCut = 16493 148 end 149 object AZoomAll: TAction 150 Caption = 'Zoom all' 151 OnExecute = AZoomAllExecute 152 ShortCut = 16449 153 end 154 end 123 155 end -
trunk/Forms/UFormMain.lrt
r34 r35 2 2 TFORMMAIN.MENUITEM1.CAPTION=Game 3 3 TFORMMAIN.MENUITEM5.CAPTION=- 4 TFORMMAIN.MENUITEM10.CAPTION=View 4 5 TFORMMAIN.MENUITEM8.CAPTION=Tools 6 TFORMMAIN.AZOOMIN.CAPTION=Zoom in 7 TFORMMAIN.AZOOMOUT.CAPTION=Zoom out 8 TFORMMAIN.AZOOMALL.CAPTION=Zoom all -
trunk/Forms/UFormMain.pas
r34 r35 17 17 18 18 TFormMain = class(TForm) 19 AZoomIn: TAction; 20 AZoomAll: TAction; 21 AZoomOut: TAction; 22 ActionList1: TActionList; 19 23 MainMenu1: TMainMenu; 20 24 MenuItem1: TMenuItem; 25 MenuItem10: TMenuItem; 26 MenuItem11: TMenuItem; 27 MenuItem12: TMenuItem; 28 MenuItem13: TMenuItem; 21 29 MenuItem2: TMenuItem; 22 30 MenuItem3: TMenuItem; … … 36 44 ToolButton4: TToolButton; 37 45 ToolButton5: TToolButton; 46 procedure AZoomAllExecute(Sender: TObject); 47 procedure AZoomInExecute(Sender: TObject); 48 procedure AZoomOutExecute(Sender: TObject); 38 49 procedure FormActivate(Sender: TObject); 39 50 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); … … 136 147 end; 137 148 149 procedure TFormMain.AZoomAllExecute(Sender: TObject); 150 var 151 Factor: TFloatPoint; 152 MapRect: TRect; 153 begin 154 with Core.Game, CurrentPlayer, View do begin 155 MapRect := Map.GetPixelRect; 156 Factor := FloatPoint((DestRect.Right - DestRect.Left) / (MapRect.Right - MapRect.Left), 157 (DestRect.Bottom - DestRect.Top) / (MapRect.Bottom - MapRect.Top)); 158 if Factor.X < Factor.Y then Zoom := Factor.X 159 else Zoom := Factor.Y; 160 CenterMap; 161 end; 162 Redraw; 163 end; 164 165 procedure TFormMain.AZoomInExecute(Sender: TObject); 166 begin 167 with Core.Game.CurrentPlayer do begin 168 View.Zoom := View.Zoom * ZoomFactor; 169 end; 170 Redraw; 171 end; 172 173 procedure TFormMain.AZoomOutExecute(Sender: TObject); 174 var 175 D: TPoint; 176 begin 177 with Core.Game.CurrentPlayer do begin 178 //D := Point(Trunc(MousePos.X - View.Left / ViewZoom), 179 // Trunc(MousePos.Y - View.Top / ViewZoom)); 180 View.Zoom := View.Zoom / ZoomFactor; 181 //View := Bounds(Trunc((D.X - MousePos.X) * ViewZoom), 182 // Trunc((D.Y - MousePos.Y) * ViewZoom), 183 // View.Right - View.Left, 184 // View.Bottom - View.Top); 185 end; 186 Redraw; 187 end; 188 138 189 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 139 190 begin … … 172 223 Cell: TCell; 173 224 OldCell: TCell; 225 CellPos: TPoint; 174 226 begin 175 227 if Assigned(Core.Game.CurrentPlayer) then begin … … 195 247 StatusBar1.Panels[0].Text := ''; 196 248 end; 249 CellPos := Core.Game.CurrentPlayer.View.CanvasToCellPos(Point(X, Y)); 250 StatusBar1.Panels[2].Text := 'CellPos: ' + IntToStr(CellPos.X) + ', ' + IntToStr(CellPos.Y); 197 251 if Cell <> OldCell then Redraw; 198 252 end else StatusBar1.Panels[0].Text := ''; … … 213 267 procedure TFormMain.PaintBox1MouseWheelDown(Sender: TObject; 214 268 Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); 215 var 216 D: TPoint; 217 begin 218 with Core.Game.CurrentPlayer do begin 219 //D := Point(Trunc(MousePos.X - View.Left / ViewZoom), 220 // Trunc(MousePos.Y - View.Top / ViewZoom)); 221 View.Zoom := View.Zoom / ZoomFactor; 222 //View := Bounds(Trunc((D.X - MousePos.X) * ViewZoom), 223 // Trunc((D.Y - MousePos.Y) * ViewZoom), 224 // View.Right - View.Left, 225 // View.Bottom - View.Top); 226 end; 227 Redraw; 269 begin 270 AZoomOut.Execute; 228 271 end; 229 272 … … 231 274 MousePos: TPoint; var Handled: Boolean); 232 275 begin 233 with Core.Game.CurrentPlayer do 234 View.Zoom := View.Zoom * ZoomFactor; 235 Redraw; 276 AZoomIn.Execute; 236 277 end; 237 278 -
trunk/Languages/xtactics.cs.po
r34 r35 66 66 msgstr "" 67 67 68 #: tformmain.azoomall.caption 69 msgid "Zoom all" 70 msgstr "" 71 72 #: tformmain.azoomin.caption 73 msgid "Zoom in" 74 msgstr "" 75 76 #: tformmain.azoomout.caption 77 msgid "Zoom out" 78 msgstr "" 79 68 80 #: tformmain.caption 69 81 msgid "xTactics" … … 73 85 msgid "Game" 74 86 msgstr "Hra" 87 88 #: tformmain.menuitem10.caption 89 msgid "View" 90 msgstr "" 75 91 76 92 #: tformmain.menuitem5.caption -
trunk/Languages/xtactics.po
r34 r35 57 57 msgstr "" 58 58 59 #: tformmain.azoomall.caption 60 msgid "Zoom all" 61 msgstr "" 62 63 #: tformmain.azoomin.caption 64 msgid "Zoom in" 65 msgstr "" 66 67 #: tformmain.azoomout.caption 68 msgid "Zoom out" 69 msgstr "" 70 59 71 #: tformmain.caption 60 72 msgid "xTactics" … … 63 75 #: tformmain.menuitem1.caption 64 76 msgid "Game" 77 msgstr "" 78 79 #: tformmain.menuitem10.caption 80 msgid "View" 65 81 msgstr "" 66 82 -
trunk/UGame.pas
r33 r35 66 66 destructor Destroy; override; 67 67 procedure SelectCell(Pos: TPoint; Player: TPlayer); 68 procedure CenterMap; 68 69 function CanvasToCellPos(Pos: TPoint): TPoint; 69 70 function CellToCanvasPos(Pos: TPoint): TPoint; … … 96 97 procedure Grow(APlayer: TPlayer); 97 98 procedure ComputePlayerStats; 98 function GetPixel Size: TPoint;99 function GetPixelRect: TRect; 99 100 property Size: TPoint read FSize write SetSize; 100 101 end; … … 137 138 FCellFrom: TCell; 138 139 FCellTo: TCell; 140 FDestroying: Boolean; 139 141 procedure SetCellFrom(AValue: TCell); 140 142 procedure SetCellTo(AValue: TCell); … … 160 162 FOnWin: TWinEvent; 161 163 FRunning: Boolean; 164 procedure Attack(var AttackPower, DefendPower: Integer); 162 165 procedure MoveAll(Player: TPlayer); 163 166 procedure ClearMovesFromCell(Cell: TCell); … … 195 198 196 199 procedure InitStrings; 200 function FloatPoint(AX, AY: Double): TFloatPoint; 197 201 198 202 … … 295 299 296 300 destructor TMove.Destroy; 301 var 302 LastState: Boolean; 297 303 begin 298 304 CellFrom := nil; 299 305 CellTo := nil; 300 if Assigned(List) then 301 List.Remove(Self); 306 if Assigned(List) then begin 307 // To remove itself from list we need disable owning to not be called twice 308 try 309 LastState := List.OwnsObjects; 310 List.OwnsObjects := False; 311 List.Remove(Self); 312 finally 313 List.OwnsObjects := LastState; 314 end; 315 end; 302 316 inherited Destroy; 303 317 end; … … 306 320 307 321 procedure TView.SetZoom(AValue: Double); 322 var 323 OldSourceRect: TRect; 308 324 begin 309 325 if FZoom = AValue then Exit; 310 326 FZoom := AValue; 311 SourceRect := Bounds(SourceRect.Left, SourceRect.Top, 327 SourceRect := Bounds(Trunc(SourceRect.Left + (SourceRect.Right - SourceRect.Left) div 2 - (DestRect.Right - DestRect.Left) / Zoom / 2), 328 Trunc(SourceRect.Top + (SourceRect.Bottom - SourceRect.Top) div 2 - (DestRect.Bottom - DestRect.Top) / Zoom / 2), 312 329 Trunc((DestRect.Right - DestRect.Left) / Zoom), 313 330 Trunc((DestRect.Bottom - DestRect.Top) / Zoom)); … … 321 338 322 339 procedure TView.SetDestRect(AValue: TRect); 340 var 341 Diff: TPoint; 323 342 begin 324 343 if RectEquals(FDestRect, AValue) then Exit; 344 Diff := Point(Trunc((DestRect.Right - DestRect.Left) / Zoom - (AValue.Right - AValue.Left) / Zoom) div 2, 345 Trunc((DestRect.Bottom - DestRect.Top) / Zoom - (AValue.Bottom - AValue.Top) / Zoom) div 2); 325 346 FDestRect := AValue; 326 SourceRect := Bounds(SourceRect.Left , SourceRect.Top,347 SourceRect := Bounds(SourceRect.Left + Diff.X, SourceRect.Top + Diff.Y, 327 348 Trunc((DestRect.Right - DestRect.Left) / Zoom), 328 349 Trunc((DestRect.Bottom - DestRect.Top) / Zoom)); … … 360 381 constructor TCell.Create; 361 382 begin 383 Player := nil; 362 384 MovesFrom := TObjectList.Create; 363 385 MovesFrom.OwnsObjects := False; … … 499 521 end; 500 522 523 procedure TView.CenterMap; 524 var 525 MapRect: TRect; 526 begin 527 MapRect := Game.Map.GetPixelRect; 528 SourceRect := Bounds(MapRect.Left + (MapRect.Right - MapRect.Left) div 2 - (SourceRect.Right - SourceRect.Left) div 2, 529 MapRect.Top + (MapRect.Bottom - MapRect.Top) div 2 - (SourceRect.Bottom - SourceRect.Top) div 2, 530 SourceRect.Right - SourceRect.Left, 531 SourceRect.Bottom - SourceRect.Top); 532 end; 533 501 534 procedure TPlayer.Paint(PaintBox: TPaintBox); 502 535 begin … … 530 563 { TGame } 531 564 565 procedure TGame.Attack(var AttackPower, DefendPower: Integer); 566 var 567 AttackerRoll: Integer; 568 DefenderRoll: Integer; 569 begin 570 while (AttackPower > 0) and (DefendPower > 0) do begin 571 // Earch side do dice roll and compare result. Defender wins tie 572 AttackerRoll := Random(6); 573 DefenderRoll := Random(6); 574 if AttackerRoll > DefenderRoll then Dec(DefendPower) 575 else Dec(AttackPower); 576 end; 577 end; 578 532 579 procedure TGame.MoveAll(Player: TPlayer); 533 580 var 534 581 I: Integer; 582 Remain: Integer; 583 AttackerPower: Integer; 584 DefenderPower: Integer; 535 585 begin 536 586 I := 0; … … 542 592 CellTo.Power := CellTo.Power + CountOnce; 543 593 end else begin 544 // Fight 545 //NewPower := CellTo.Power - Trunc(CountOnce / CellTo.Power); 546 if CellTo.Power > CountOnce then begin 547 // Defender wins 548 CellTo.Power := CellTo.Power - CountOnce; 549 end else begin 550 // Attacker wins 551 CellTo.Power := CountOnce - CellTo.Power; 594 AttackerPower := CountOnce; 595 DefenderPower := CellTo.Power; 596 Attack(AttackerPower, DefenderPower); 597 if DefenderPower = 0 then begin 598 // Attacker wins with possible loses 599 ClearMovesFromCell(CellTo); 552 600 CellTo.Player := Player; 553 ClearMovesFromCell(CellTo); 554 end; 601 CellTo.Power := AttackerPower; 602 end else 603 if AttackerPower = 0 then begin 604 // Defender wins with possible loses 605 CellTo.Power := DefenderPower; 606 end else 607 raise Exception.Create('Unfinished battle'); 555 608 end; 556 609 CellFrom.Power := CellFrom.Power - CountOnce; … … 764 817 end; 765 818 View.Zoom := 1; 766 // Center board 767 View.SourceRect.TopLeft := Point(Trunc(Map.GetPixelSize.X div 2 - (View.SourceRect.Right - View.SourceRect.Left) div 2 / View.Zoom), 768 Trunc(Map.GetPixelSize.Y div 2 - (View.SourceRect.Bottom - View.SourceRect.Top) div 2 / View.Zoom)); 819 View.CenterMap; 769 820 end; 770 821 CurrentPlayer := TPlayer(Players[0]); … … 873 924 Points: array of TPoint; 874 925 begin 875 with View do begin876 926 CellSize := FloatPoint(DefaultCellSize.X / CellMulX, DefaultCellSize.Y / CellMulY); 877 927 HexSize := FloatPoint(DefaultCellSize.X, DefaultCellSize.Y); … … 885 935 Result.X := Trunc(X * CellSize.X); 886 936 Result.Y := Trunc(Y * CellSize.Y); 887 end;888 937 end; 889 938 … … 1008 1057 Player.TotalCells := Player.TotalCells + 1; 1009 1058 Player.TotalUnits := Player.TotalUnits + Power; 1010 1011 end; 1012 end; 1013 end; 1014 1015 function THexMap.GetPixelSize: TPoint; 1016 begin 1017 Result := Point(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y); 1059 end; 1060 end; 1061 end; 1062 1063 function THexMap.GetPixelRect: TRect; 1064 begin 1065 Result := Bounds(Trunc(-0.5 * DefaultCellSize.X), 1066 Trunc(-0.5 * DefaultCellSize.Y), 1067 Trunc((Size.X + 0.5) * DefaultCellSize.X), 1068 Trunc(((Size.Y + 0.5) * 0.78) * DefaultCellSize.Y)); 1018 1069 end; 1019 1070
Note:
See TracChangeset
for help on using the changeset viewer.