Changeset 336 for trunk


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.
Location:
trunk
Files:
4 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,
  • trunk/GameServer.pas

    r328 r336  
    1515  FirstBookCompatibleVersion = $010103;
    1616
    17   // notifications
    18   ntCreateWorld = 0;
    19   ntInitModule = $100;
    20   ntInitLocalHuman = $1FF;
    21   ntDLLError = $200;
    22   ntAIError = $2FF;
    23   ntClientError = $300;
    24   ntInitPlayers = $400;
    25   ntDeactivationMissing = $410;
    26   ntSetAIName = $420;
    27   ntException = $500;
    28   ntLoadBegin = $600;
    29   ntLoadState = $601;
    30   ntEndInfo = $6FC;
    31   ntBackOn = $6FD;
    32   ntBackOff = $6FE;
    33   ntLoadError = $6FF;
    34   ntStartDone = $700;
    35   ntStartGo = $701;
    36   ntStartGoRefresh = $702;
    37   ntStartGoRefreshMaps = $703;
    38   ntChangeClient = $800;
    39   ntNextPlayer = $810;
    40   ntDeinitModule = $900;
    41 
    4217  // module flags
    4318  fMultiple = $10000000;
     
    4823
    4924type
    50   TNotifyFunction = procedure(ID: integer);
     25  // notifications
     26  TNotify = (
     27    ntCreateWorld = 0,
     28    ntInitModule = $100,
     29    ntInitLocalHuman = $1FF,
     30    ntDLLError = $200,
     31    ntAIError = $2FF,
     32    ntClientError = $300,
     33    ntInitPlayers = $400,
     34    ntDeactivationMissing = $410,
     35    ntSetAIName = $420,
     36    ntException = $500,
     37    ntLoadBegin = $600,
     38    ntLoadState = $601,
     39    ntEndInfo = $6FC,
     40    ntBackOn = $6FD,
     41    ntBackOff = $6FE,
     42    ntLoadError = $6FF,
     43    ntStartDone = $700,
     44    ntStartGo = $701,
     45    ntStartGoRefresh = $702,
     46    ntStartGoRefreshMaps = $703,
     47    ntChangeClient = $800,
     48    ntNextPlayer = $810,
     49    ntDeinitModule = $900
     50  );
     51
     52  TNotifyFunction = procedure(ID: TNotify; Index: Integer = 0);
    5153
    5254  TBrainType = (btNoTerm, btSuperVirtual, btTerm, btRandom, btAI);
     
    365367    (CCPlayer < 0) then
    366368  begin
    367     Notify(ntDeactivationMissing + p);
     369    Notify(ntDeactivationMissing, p);
    368370    ForceClientDeactivation;
    369371  end
     
    513515    if Kind = btAI then
    514516    begin { get client function }
    515       Notify(ntInitModule + Brains.IndexOf(bix));
     517      Notify(ntInitModule, Brains.IndexOf(bix));
    516518      if Flags and fDotNet > 0 then
    517519        Client := DotNetClient
     
    522524        begin
    523525          Client := nil;
    524           Notify(ntDLLError + Brains.IndexOf(bix));
     526          Notify(ntDLLError, Brains.IndexOf(bix));
    525527        end
    526528        else
     
    528530          Client := GetProcAddress(hm, 'client');
    529531          if @Client = nil then
    530             Notify(ntClientError + Brains.IndexOf(bix));
    531         end
    532       end
     532            Notify(ntClientError, Brains.IndexOf(bix));
     533        end;
     534      end;
    533535    end;
    534536    if @Client <> nil then
     
    545547        DataSize := 0;
    546548      Flags := Flags or InitModuleData.Flags;
    547     end
    548   end
     549    end;
     550  end;
    549551end;
    550552
     
    730732  if bix[0].Kind <> btNoTerm then
    731733    Notify(ntInitLocalHuman);
     734
    732735  BrainUsed := [];
    733736  for p := 0 to nPl - 1 do
     
    955958        else
    956959          NotifyMessage := '';
    957         Notify(ntSetAIName + p1);
    958       end
     960        Notify(ntSetAIName, p1);
     961      end;
    959962  end;
    960963
     
    12781281    end;
    12791282    if not MovieMode then
    1280       Notify(ntLoadState + CL.Progress * 128 div 1000);
     1283      Notify(ntLoadState, CL.Progress * 128 div 1000);
    12811284  end;
    12821285
     
    32503253            begin
    32513254              if Brains[i].Kind = btAI then
    3252                 Notify(ntDeinitModule + i);
     3255                Notify(ntDeinitModule, i);
    32533256              CallClient(i, cBreakGame, nil^);
    32543257            end;
  • trunk/LocalPlayer/NatStat.pas

    r327 r336  
    114114      (hMainTexture - ClientHeight) div 2);
    115115    ImageOp_B(Back, Template, 0, 0, 0, 0, ClientWidth, ClientHeight);
    116   end
     116  end;
    117117end;
    118118
  • trunk/Packages/CevoComponents/DrawDlg.pas

    r313 r336  
    8686procedure TDrawDlg.OnEraseBkgnd(var m: TMessage);
    8787begin
     88  // Full area should be covered by Paint method
    8889end;
    8990
Note: See TracChangeset for help on using the changeset viewer.