Changeset 23 for trunk/UFormMain.pas


Ignore:
Timestamp:
Mar 2, 2014, 11:27:14 PM (11 years ago)
Author:
chronos
Message:
  • Modified: Calculation of player visible frame is now handled by TView class.
  • Fixed: Set proper max power on existing player move update.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.pas

    r22 r23  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   UGame, LCLType, Menus, ActnList, types;
     9  UGame, LCLType, Menus, ActnList, ComCtrls, types;
    1010
    1111const
     
    2626    MenuItem7: TMenuItem;
    2727    PaintBox1: TPaintBox;
     28    StatusBar1: TStatusBar;
    2829    Timer1: TTimer;
    2930    procedure FormActivate(Sender: TObject);
     
    6364  UFormNew, UFormMove, UCore;
    6465
     66resourcestring
     67  STurn = 'turn';
     68
    6569{$R *.lfm}
    6670
     
    7175  if Core.Game.Running then
    7276  with Core.Game.CurrentPlayer do begin
    73     ViewSize := Point(PaintBox1.Width, PaintBox1.Height);
     77    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    7478    Paint(PaintBox1);
    7579  end;
     
    8488  if Assigned(Core.Game.CurrentPlayer) then
    8589  with Core.Game.CurrentPlayer do
    86     ViewSize := Point(PaintBox1.Width, PaintBox1.Height);
     90    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    8791  Redraw;
    8892end;
     
    98102    NewCaption := 'xTactics';
    99103    if Assigned(Core.Game.CurrentPlayer) then
    100       NewCaption := Core.Game.CurrentPlayer.Name + ' - turn ' + IntToStr(Core.Game.TurnCounter) + ' - ' + NewCaption;
     104      NewCaption := Core.Game.CurrentPlayer.Name + ' - ' + STurn + ' ' + IntToStr(Core.Game.TurnCounter) + ' - ' + NewCaption;
    101105    Caption := NewCaption;
    102106  end;
     
    134138    if Core.Game.CurrentPlayer.Mode = pmHuman then begin
    135139      StartMousePoint := Point(X, Y);
    136       StartViewPoint := Core.Game.CurrentPlayer.CellPos;
     140      StartViewPoint := Core.Game.CurrentPlayer.View.SourceRect.TopLeft;
    137141      MoveActive := True;
    138142    end;
     
    147151procedure TFormMain.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
    148152  Y: Integer);
    149 begin
    150   if MoveActive then begin
    151     if Core.Game.CurrentPlayer.Mode = pmHuman then begin
    152       Core.Game.CurrentPlayer.CellPos := Point(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / Core.Game.CurrentPlayer.ViewZoom),
    153         Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / Core.Game.CurrentPlayer.ViewZoom));
    154       Redraw;
    155     end;
    156   end;
     153var
     154  Cell: TCell;
     155  OldCell: TCell;
     156begin
     157  if Assigned(Core.Game.CurrentPlayer) then begin
     158    if MoveActive then
     159    with Core.Game.CurrentPlayer do begin
     160      if Mode = pmHuman then begin
     161        View.SourceRect := Bounds(Trunc(StartViewPoint.X + (StartMousePoint.X - X) / View.Zoom),
     162          Trunc(StartViewPoint.Y + (StartMousePoint.Y - Y) / View.Zoom),
     163          View.SourceRect.Right - View.SourceRect.Left,
     164          View.SourceRect.Bottom - View.SourceRect.Top);
     165        Redraw;
     166      end;
     167    end;
     168    Cell := nil;
     169    OldCell := Core.Game.CurrentPlayer.FocusedCell;
     170    with Core.Game do
     171      Cell := Map.PosToCell(CurrentPlayer.View.CanvasToCellPos(Point(X, Y)), CurrentPlayer.View );
     172    if Assigned(Cell) then begin
     173      Core.Game.CurrentPlayer.FocusedCell := Cell;
     174      StatusBar1.Panels[0].Text := '[' + IntToStr(Cell.Pos.X) + ', ' + IntToStr(Cell.Pos.Y) + ']';
     175    end else begin
     176      Core.Game.CurrentPlayer.FocusedCell := nil;
     177      StatusBar1.Panels[0].Text := '';
     178    end;
     179    if Cell <> OldCell then Redraw;
     180  end else StatusBar1.Panels[0].Text := '';
    157181end;
    158182
     
    177201    //D := Point(Trunc(MousePos.X - View.Left / ViewZoom),
    178202    //  Trunc(MousePos.Y - View.Top / ViewZoom));
    179     ViewZoom := ViewZoom / ZoomFactor;
     203    View.Zoom := View.Zoom / ZoomFactor;
    180204    //View := Bounds(Trunc((D.X - MousePos.X) * ViewZoom),
    181205    //  Trunc((D.Y - MousePos.Y) * ViewZoom),
     
    190214begin
    191215  with Core.Game.CurrentPlayer do
    192     ViewZoom := ViewZoom * ZoomFactor;
     216    View.Zoom := View.Zoom * ZoomFactor;
    193217  Redraw;
    194218end;
Note: See TracChangeset for help on using the changeset viewer.