Commit 17c59756b85a41b5f45353ac9b7b0906cad4bb1b

Authored by Carlos Picanco
1 parent 269dad49
Exists in master

allow custom nicnames when changing generations and refactoring

- requires testing
- also change time interval of showpopup procedure
Showing 1 changed file with 78 additions and 57 deletions   Show diff stats
units/game_control.pas
... ... @@ -52,8 +52,8 @@ type
52 52 procedure SetRowBase(AValue: integer);
53 53 private
54 54 function AskQuestion(AQuestion:string):UTF8string;
55   - procedure ShowPopUp(AText:string);
56   - procedure ShowConsequenceMessage(AID,S:string;ForGroup:Boolean);
  55 + function ShowConsequence(AID,S:string;ForGroup:Boolean;ShowPopUp : Boolean = True) : string;
  56 + procedure ShowPopUp(AText:string;AInterval : integer = 5000);
57 57 procedure DisableConfirmationButton;
58 58 procedure CleanMatrix(AEnabled : Boolean);
59 59 procedure NextConditionSetup(S : string);
... ... @@ -120,7 +120,7 @@ const
120 120  
121 121 implementation
122 122  
123   -uses ButtonPanel,Controls,ExtCtrls,StdCtrls,LazUTF8, Forms, strutils
  123 +uses ButtonPanel,Controls,ExtCtrls,StdCtrls,LazUTF8, Forms, Dialogs, strutils
124 124 , zhelpers
125 125 , form_matrixgame
126 126 , presentation_classes
... ... @@ -247,17 +247,10 @@ begin
247 247 // wait some time, we just sent a message earlier
248 248 Sleep(5);
249 249  
  250 + // gui setup
250 251 // enable matrix grid for the first player
251 252 FZMQActor.SendMessage([K_START]);
252 253  
253   - //
254   - Start;
255   -end;
256   -
257   -procedure TGameControl.Start;
258   -begin
259   - // basic gui setup
260   -
261 254 // points
262 255 //FormMatrixGame.GBIndividualAB.Visible := FExperiment.ABPoints;
263 256 //FormMatrixGame.GBIndividual.Visible:= not FormMatrixGame.GBIndividualAB.Visible;
... ... @@ -283,8 +276,14 @@ begin
283 276 // wait for players
284 277 end;
285 278  
  279 +procedure TGameControl.Start;
  280 +begin
  281 + // check if experiment is running
  282 +end;
  283 +
286 284 procedure TGameControl.Pause;
287 285 begin
  286 + //FExperiment.State:=xsPaused;
288 287 // save to file
289 288  
290 289 // inform players
... ... @@ -292,6 +291,7 @@ end;
292 291  
293 292 procedure TGameControl.Resume;
294 293 begin
  294 + //FExperiment.State:=xsRunning;
295 295 // load from file
296 296  
297 297 // wait for players
... ... @@ -299,6 +299,8 @@ end;
299 299  
300 300 procedure TGameControl.Stop;
301 301 begin
  302 + // Pause
  303 +
302 304 // cleaning
303 305 end;
304 306  
... ... @@ -457,41 +459,46 @@ var
457 459 begin
458 460 Prompt:=TForm.CreateNew(nil);
459 461 try
460   - with Prompt do begin
461   - BorderStyle:=bsNone;
462   - Position:=poScreenCenter;
463   - ButtonPanel:=TButtonPanel.Create(Prompt);
464   - with ButtonPanel do begin
465   - ButtonOrder:=boCloseOKCancel;
466   - OKButton.Caption:='Sim';
467   - CancelButton.Caption:='Não';
468   - ShowButtons:=[pbOK, pbCancel];
469   - ShowBevel:=True;
470   - ShowGlyphs:=[];
471   - Parent:=Prompt;
472   - end;
473   - LabelQuestion:=TLabel.Create(Prompt);
474   - with LabelQuestion do begin
475   - Align:=alClient;
476   - Caption:= AQuestion;
477   - Alignment := taCenter;
478   - Anchors := [akLeft,akRight];
479   - Layout := tlCenter;
480   - WordWrap := True;
481   - Parent:=Prompt;
482   - end;
  462 + with Prompt do
  463 + begin
  464 + BorderStyle:=bsNone;
  465 + Position:=poScreenCenter;
  466 + ButtonPanel:=TButtonPanel.Create(Prompt);
  467 + with ButtonPanel do
  468 + begin
  469 + ButtonOrder:=boCloseOKCancel;
  470 + OKButton.Caption:='Sim';
  471 + CancelButton.Caption:='Não';
  472 + ShowButtons:=[pbOK, pbCancel];
  473 + ShowBevel:=True;
  474 + ShowGlyphs:=[];
  475 + Parent:=Prompt;
  476 + end;
483 477  
484   - mr:=ShowModal;
485   - if mr = mrOK then
486   - Result := 'S'
487   - else Result := 'N';
488   - end;
  478 + LabelQuestion:=TLabel.Create(Prompt);
  479 + with LabelQuestion do
  480 + begin
  481 + Align:=alClient;
  482 + Caption:= AQuestion;
  483 + Alignment := taCenter;
  484 + Anchors := [akLeft,akRight];
  485 + Layout := tlCenter;
  486 + WordWrap := True;
  487 + Parent:=Prompt;
  488 + end;
  489 +
  490 + mr:=ShowModal;
  491 + if mr = mrOK then
  492 + Result := 'S'
  493 + else
  494 + Result := 'N';
  495 + end;
489 496 finally
490 497 Prompt.Free;
491 498 end;
492 499 end;
493 500  
494   -procedure TGameControl.ShowPopUp(AText: string);
  501 +procedure TGameControl.ShowPopUp(AText: string; AInterval: integer);
495 502 var PopUpPos : TPoint;
496 503 begin
497 504 PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110;
... ... @@ -501,15 +508,19 @@ begin
501 508 FormMatrixGame.PopupNotifier.Text:=AText;
502 509 FormMatrixGame.PopupNotifier.ShowAtPos(PopUpPos.X,PopUpPos.Y);
503 510 FormMatrixGame.Timer.OnTimer:=@FormMatrixGame.TimerTimer;
  511 + FormMatrixGame.Timer.Interval:=AInterval;
504 512 FormMatrixGame.Timer.Enabled:=True;
505 513 end;
506 514  
507   -procedure TGameControl.ShowConsequenceMessage(AID, S: string; ForGroup: Boolean);
  515 +function TGameControl.ShowConsequence(AID, S: string;
  516 + ForGroup: Boolean; ShowPopUp: Boolean):string;
508 517 var
509 518 LConsequence : TConsequence;
510 519 begin
  520 + Result := '';
511 521 LConsequence := TConsequence.Create(nil,S);
512   - LConsequence.GenerateMessage(ForGroup);
  522 + Result := LConsequence.GenerateMessage(ForGroup);
  523 + if ShowPopUp then
513 524 LConsequence.PresentMessage(FormMatrixGame.GBIndividualAB);
514 525 case FActor of
515 526 gaPlayer:
... ... @@ -981,20 +992,24 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList);
981 992 var
982 993 i : integer;
983 994 MID : string;
  995 + LQConsequence : string;
984 996 begin
985 997 if AMessage[2] <> #27 then
986 998 begin
987 999 if AMessage.Count > 1 then
988 1000 begin
  1001 + // present only one popup with all messages
  1002 + LQConsequence := '';
989 1003 for i := 3 to AMessage.Count -1 do
990 1004 begin
991 1005 MID := ExtractDelimited(1,AMessage[i],['+']);
992   - ShowConsequenceMessage(MID, ExtractDelimited(2,AMessage[i],['+']),MID = 'M');
993   - // TODO: QMESSAGE present only one message with all information...
  1006 + LQConsequence += ShowConsequence(MID, ExtractDelimited(2,AMessage[i],['+']),MID = 'M',False)+' ';
  1007 +
994 1008 {$IFDEF DEBUG}
995 1009 WriteLn('A Prompt consequence should have shown.');
996 1010 {$ENDIF}
997 1011 end;
  1012 + ShowPopUp(LQConsequence);
998 1013 end;
999 1014 ResumeNextTurn;
1000 1015 if AMessage[2] <> #32 then
... ... @@ -1007,7 +1022,7 @@ begin
1007 1022 if MHas(K_ARRIVED) then ReceiveActor;
1008 1023 if MHas(K_CHAT_M) then ReceiveChat;
1009 1024 if MHas(K_CHOICE) then ReceiveChoice;
1010   - if MHas(K_MESSAGE) then ShowConsequenceMessage(AMessage[1],AMessage[2],StrToBool(AMessage[3]));
  1025 + if MHas(K_MESSAGE) then ShowConsequence(AMessage[1],AMessage[2],StrToBool(AMessage[3]));
1011 1026 if MHas(K_START) then NotifyPlayers;
1012 1027 if MHas(K_QUESTION) then ShowQuestion;
1013 1028 if MHas(K_MOVQUEUE) then MovePlayerQueue;
... ... @@ -1166,17 +1181,17 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
1166 1181 ARequest.Append(LEndGeneration); // 9, #32 resume, else NextGeneration = PlayerToKick AID
1167 1182 LEndCondition := ShouldEndCondition;
1168 1183 if IsLastCondition and LEndCondition then // 10
1169   - // end experiment envelop
  1184 + // end experiment envelop item
1170 1185 ARequest.Append(#27)
1171 1186 else
1172 1187 if LEndCondition then
1173 1188 begin
1174 1189 FExperiment.NextCondition;
1175   - // end condition envelop
  1190 + // end condition envelop item
1176 1191 ARequest.Append(FExperiment.CurrentConditionAsString);
1177 1192 end
1178 1193 else
1179   - // do nothing envelop
  1194 + // do nothing envelop item
1180 1195 ARequest.Append(#32);
1181 1196 end;
1182 1197 end;
... ... @@ -1231,10 +1246,12 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
1231 1246 begin
1232 1247 P := FExperiment.PlayerFromID[ARequest[0]];
1233 1248 ARequest[2] := K_RESUME+K_ARRIVED;
1234   - if AskQuestion(
1235   - 'Um novo participante entrou no lugar do participante mais antigo. Criar um novo apelido para o novo participante?'
1236   - ) = 'S' then
1237   - P.Nicname := GenResourceName(-1);
  1249 + P.Nicname := InputBox
  1250 + (
  1251 + 'Mudança de geração',
  1252 + 'Um novo participante entrou no lugar do participante mais antigo.Qual o apelido do novo participante?',
  1253 + GenResourceName(-1)
  1254 + );
1238 1255  
1239 1256 S := FExperiment.PlayerAsString[P];
1240 1257 ARequest.Append(S); // 3
... ... @@ -1242,10 +1259,13 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList);
1242 1259 end;
1243 1260  
1244 1261 begin
1245   - if MHas(K_LOGIN) then ReplyLoginRequest;
1246   - if MHas(K_RESUME) then ReplyResume;
1247   - if MHas(K_CHOICE) then ValidateChoice;
1248   - if MHas(K_QUESTION) then ValidateQuestionResponse;
  1262 + if FExperiment.State = xsRunning then
  1263 + begin
  1264 + if MHas(K_LOGIN) then ReplyLoginRequest;
  1265 + if MHas(K_RESUME) then ReplyResume;
  1266 + if MHas(K_CHOICE) then ValidateChoice;
  1267 + if MHas(K_QUESTION) then ValidateQuestionResponse;
  1268 + end;
1249 1269 end;
1250 1270  
1251 1271 // Here FActor is garanted to be a TZMQPlayer, replying by:
... ... @@ -1286,7 +1306,8 @@ procedure TGameControl.ReceiveReply(AReply: TStringList);
1286 1306 else
1287 1307 begin
1288 1308 {$IFDEF DEBUG}
1289   - WriteLn(Self.ID +' sent but' + AReply[0] +' received. <<<<<<<<<<<<<<<<<<<<<<< This must not occur >>>>>>>>>>>>>>>>>>>>>>>>>>');
  1309 + WriteLn(Self.ID + ' sent but' + AReply[0] +
  1310 + ' received. <<<<<<<<<<<<<<<<<<<<<<< This must never occur >>>>>>>>>>>>>>>>>>>>>>>>>>');
1290 1311 {$ENDIF}
1291 1312 end;
1292 1313 end;
... ...