Changeset 336 for trunk/Direct.pas


Ignore:
Timestamp:
Mar 31, 2021, 10:49:44 PM (3 years ago)
Author:
chronos
Message:
  • Modify: Change Notify function to have separate enumeration type and integer value. Previously was combined into single integer.
  • Fixed: Paint correctly loading progress dialog on Linux.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Direct.pas

    r190 r336  
    88
    99  LCLIntf, LCLType, {$IFDEF Linux}LMessages, {$ENDIF}Messages, SysUtils, Classes,
    10   Graphics, Controls, Forms, DrawDlg;
     10  Graphics, Controls, Forms, DrawDlg, GameServer;
    1111
    1212const
     
    2323    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    2424  public
    25     procedure DlgNotify(ID: integer);
     25    procedure DlgNotify(ID: TNotify; Index: Integer = 0);
    2626  private
    2727    Info: string;
    28     State: integer;
    29     Gone, Quick: boolean;
     28    State: Integer;
     29    Gone: Boolean;
     30    Quick: Boolean;
    3031    procedure SetInfo(x: string);
    3132    procedure SetState(x: integer);
     
    4243
    4344uses
    44   ScreenTools, Protocol, GameServer, Start, LocalPlayer, NoTerm, Back;
     45  ScreenTools, Protocol, Start, LocalPlayer, NoTerm, Back;
    4546
    4647{$R *.lfm}
    4748
    48 procedure Notify(ID: integer);
    49 begin
    50   DirectDlg.DlgNotify(ID);
    51 end;
    52 
    53 procedure TDirectDlg.DlgNotify(ID: integer);
     49procedure Notify(ID: TNotify; Index: Integer = 0);
     50begin
     51  DirectDlg.DlgNotify(ID, Index);
     52end;
     53
     54procedure TDirectDlg.DlgNotify(ID: TNotify; Index: Integer = 0);
    5455var
    5556//  hMem: Cardinal;
     
    5859begin
    5960  case ID of
    60     ntInitLocalHuman:
    61       begin
    62         SetMainTextureByAge(-1);
    63         State := -1;
    64         Info := Phrases.Lookup('BUSY_MODLH');
    65         Show;
    66         Invalidate;
    67         Update;
    68       end;
    69     ntInitModule .. ntInitModule + maxBrain - 1:
     61    ntInitLocalHuman: begin
     62      SetMainTextureByAge(-1);
     63      State := -1;
     64      Info := Phrases.Lookup('BUSY_MODLH');
     65      Show;
     66      Application.ProcessMessages; // Repaint after show for Linux
     67      Invalidate;
     68      Update;
     69    end;
     70    ntInitModule:
    7071      if visible then
    7172      begin
    72         s := Format(Phrases.Lookup('BUSY_MOD'),
    73           [Brains[ID - ntInitModule].Name]);
     73        s := Format(Phrases.Lookup('BUSY_MOD'), [Brains[Index].Name]);
    7474        while BiColorTextWidth(Canvas, s) + 64 > ClientWidth do
    7575          Delete(s, Length(s), 1);
     
    8282      if visible then
    8383        SetInfo(Phrases.Lookup('BUSY_INIT'));
    84     ntDeactivationMissing .. ntDeactivationMissing + nPl - 1:
    85       SimpleMessage(Format(Phrases.Lookup('MISSDEACT'),
    86         [ID - ntDeactivationMissing]));
    87     ntSetAIName .. ntSetAIName + nPl - 1:
    88       LocalPlayer.SetAIName(ID - ntSetAIName, NotifyMessage);
    89     ntException .. ntException + maxBrain - 1:
    90       PostMessage(Handle, WM_AIEXCEPTION, ID - ntException, 0);
    91     ntLoadBegin:
    92       begin
    93         Info := Phrases.Lookup('BUSY_LOAD');
    94         SetState(0);
    95       end;
    96     ntLoadState .. ntLoadState + 128:
    97       SetState(ID - ntLoadState);
    98     ntDLLError .. ntDLLError + 128:
    99       SimpleMessage(Format(Phrases.Lookup('DLLERROR'),
    100         [Brains[ID - ntDLLError].FileName]));
     84    ntDeactivationMissing:
     85      SimpleMessage(Format(Phrases.Lookup('MISSDEACT'), [Index]));
     86    ntSetAIName:
     87      LocalPlayer.SetAIName(Index, NotifyMessage);
     88    ntException:
     89      PostMessage(Handle, WM_AIEXCEPTION, Index, 0);
     90    ntLoadBegin: begin
     91      Info := Phrases.Lookup('BUSY_LOAD');
     92      SetState(0);
     93    end;
     94    ntLoadState: SetState(Index);
     95    ntDLLError:
     96      SimpleMessage(Format(Phrases.Lookup('DLLERROR'), [Brains[Index].FileName]));
    10197    ntAIError:
    10298      SimpleMessage(Format(Phrases.Lookup('AIERROR'), [NotifyMessage]));
    103     ntClientError .. ntClientError + 128:
     99    ntClientError:
    104100      SimpleMessage(Format(Phrases.Lookup('CLIENTERROR'),
    105         [Brains[ID - ntClientError].FileName]));
    106     ntEndInfo:
    107       begin
    108         Hide;
    109         background.Update;
    110       end;
    111     ntLoadError:
    112       begin
     101        [Brains[Index].FileName]));
     102    ntEndInfo: begin
     103      Hide;
     104      Background.Update;
     105    end;
     106    ntLoadError: begin
    113107(* TODO        if OpenClipboard(Handle) then
    114108        begin // copy file path to clipboard
     
    134128      end;
    135129    ntStartDone:
    136       if not Quick then
    137       begin
     130      if not Quick then begin
    138131        StartDlg.Hide;
    139         background.Update;
     132        Background.Update;
    140133      end;
    141134    ntStartGo, ntStartGoRefresh, ntStartGoRefreshMaps:
    142       if Quick then
    143         Close
    144       else
    145       begin
     135      if Quick then Close
     136      else begin
    146137        if ID = ntStartGoRefresh then
    147138          StartDlg.UpdateFormerGames
     
    150141        StartDlg.Show;
    151142      end;
    152     ntChangeClient:
    153       PostMessage(Handle, WM_CHANGECLIENT, 0, 0);
    154     ntNextPlayer:
    155       PostMessage(Handle, WM_NEXTPLAYER, 0, 0);
    156     ntDeinitModule .. ntDeinitModule + maxBrain - 1:
     143    ntChangeClient: PostMessage(Handle, WM_CHANGECLIENT, 0, 0);
     144    ntNextPlayer: PostMessage(Handle, WM_NEXTPLAYER, 0, 0);
     145    ntDeinitModule:
    157146      begin
    158147        Info := Format(Phrases2.Lookup('BUSY_DEINIT'),
    159           [Brains[ID - ntDeinitModule].Name]);
     148          [Brains[Index].Name]);
    160149        while BiColorTextWidth(Canvas, Info) + 64 > ClientWidth do
    161150          Delete(Info, Length(Info), 1);
     
    165154        Invalidate;
    166155        Update;
    167       end;
    168     ntBackOn:
    169       begin
    170         background.Show;
    171         background.Update;
    172         sleep(50); // prevent flickering
    173       end;
    174     ntBackOff:
    175       background.Close;
     156        Application.ProcessMessages;
     157      end;
     158    ntBackOn: begin
     159      Background.Show;
     160      Background.Update;
     161      Sleep(50); // prevent flickering
     162    end;
     163    ntBackOff: Background.Close;
    176164  end;
    177165end;
     
    179167procedure TDirectDlg.FormCreate(Sender: TObject);
    180168begin
    181   Gone := false;
     169  Gone := False;
    182170  State := -1;
    183171  Info := '';
     
    218206    Application.MessageBox(PChar(Phrases.Lookup('NOAI')), 'C-evo', 0);
    219207    Close;
    220     exit;
     208    Exit;
    221209  end;
    222210  Quick := false;
     
    234222        Quick := true;
    235223        DirectHelp(cHelpOnly);
    236         Close
     224        Close;
    237225      end;
    238226    end
     
    249237  end;
    250238  if not Quick then begin
    251     background.Show;
     239    Background.Show;
    252240    StartDlg.Show;
    253241  end;
     
    294282  Invalidate;
    295283  Update;
     284  Application.ProcessMessages;
    296285end;
    297286
    298287procedure TDirectDlg.SetState(x: integer);
    299288begin
    300   if (x < 0) <> (State < 0) then
    301   begin
     289  if (x < 0) <> (State < 0) then begin
    302290    State := x;
    303291    Invalidate;
    304     Update
     292    Update;
    305293  end
    306   else if x <> State then
    307   begin
     294  else if x <> State then begin
    308295    State := x;
    309296    PaintProgressBar(Canvas, 6, ClientWidth div 2 - 64, 40, State, 128 - State,
Note: See TracChangeset for help on using the changeset viewer.