Commit 17c59756b85a41b5f45353ac9b7b0906cad4bb1b
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,8 +52,8 @@ type | ||
| 52 | procedure SetRowBase(AValue: integer); | 52 | procedure SetRowBase(AValue: integer); |
| 53 | private | 53 | private |
| 54 | function AskQuestion(AQuestion:string):UTF8string; | 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 | procedure DisableConfirmationButton; | 57 | procedure DisableConfirmationButton; |
| 58 | procedure CleanMatrix(AEnabled : Boolean); | 58 | procedure CleanMatrix(AEnabled : Boolean); |
| 59 | procedure NextConditionSetup(S : string); | 59 | procedure NextConditionSetup(S : string); |
| @@ -120,7 +120,7 @@ const | @@ -120,7 +120,7 @@ const | ||
| 120 | 120 | ||
| 121 | implementation | 121 | implementation |
| 122 | 122 | ||
| 123 | -uses ButtonPanel,Controls,ExtCtrls,StdCtrls,LazUTF8, Forms, strutils | 123 | +uses ButtonPanel,Controls,ExtCtrls,StdCtrls,LazUTF8, Forms, Dialogs, strutils |
| 124 | , zhelpers | 124 | , zhelpers |
| 125 | , form_matrixgame | 125 | , form_matrixgame |
| 126 | , presentation_classes | 126 | , presentation_classes |
| @@ -247,17 +247,10 @@ begin | @@ -247,17 +247,10 @@ begin | ||
| 247 | // wait some time, we just sent a message earlier | 247 | // wait some time, we just sent a message earlier |
| 248 | Sleep(5); | 248 | Sleep(5); |
| 249 | 249 | ||
| 250 | + // gui setup | ||
| 250 | // enable matrix grid for the first player | 251 | // enable matrix grid for the first player |
| 251 | FZMQActor.SendMessage([K_START]); | 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 | // points | 254 | // points |
| 262 | //FormMatrixGame.GBIndividualAB.Visible := FExperiment.ABPoints; | 255 | //FormMatrixGame.GBIndividualAB.Visible := FExperiment.ABPoints; |
| 263 | //FormMatrixGame.GBIndividual.Visible:= not FormMatrixGame.GBIndividualAB.Visible; | 256 | //FormMatrixGame.GBIndividual.Visible:= not FormMatrixGame.GBIndividualAB.Visible; |
| @@ -283,8 +276,14 @@ begin | @@ -283,8 +276,14 @@ begin | ||
| 283 | // wait for players | 276 | // wait for players |
| 284 | end; | 277 | end; |
| 285 | 278 | ||
| 279 | +procedure TGameControl.Start; | ||
| 280 | +begin | ||
| 281 | + // check if experiment is running | ||
| 282 | +end; | ||
| 283 | + | ||
| 286 | procedure TGameControl.Pause; | 284 | procedure TGameControl.Pause; |
| 287 | begin | 285 | begin |
| 286 | + //FExperiment.State:=xsPaused; | ||
| 288 | // save to file | 287 | // save to file |
| 289 | 288 | ||
| 290 | // inform players | 289 | // inform players |
| @@ -292,6 +291,7 @@ end; | @@ -292,6 +291,7 @@ end; | ||
| 292 | 291 | ||
| 293 | procedure TGameControl.Resume; | 292 | procedure TGameControl.Resume; |
| 294 | begin | 293 | begin |
| 294 | + //FExperiment.State:=xsRunning; | ||
| 295 | // load from file | 295 | // load from file |
| 296 | 296 | ||
| 297 | // wait for players | 297 | // wait for players |
| @@ -299,6 +299,8 @@ end; | @@ -299,6 +299,8 @@ end; | ||
| 299 | 299 | ||
| 300 | procedure TGameControl.Stop; | 300 | procedure TGameControl.Stop; |
| 301 | begin | 301 | begin |
| 302 | + // Pause | ||
| 303 | + | ||
| 302 | // cleaning | 304 | // cleaning |
| 303 | end; | 305 | end; |
| 304 | 306 | ||
| @@ -457,41 +459,46 @@ var | @@ -457,41 +459,46 @@ var | ||
| 457 | begin | 459 | begin |
| 458 | Prompt:=TForm.CreateNew(nil); | 460 | Prompt:=TForm.CreateNew(nil); |
| 459 | try | 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 | finally | 496 | finally |
| 490 | Prompt.Free; | 497 | Prompt.Free; |
| 491 | end; | 498 | end; |
| 492 | end; | 499 | end; |
| 493 | 500 | ||
| 494 | -procedure TGameControl.ShowPopUp(AText: string); | 501 | +procedure TGameControl.ShowPopUp(AText: string; AInterval: integer); |
| 495 | var PopUpPos : TPoint; | 502 | var PopUpPos : TPoint; |
| 496 | begin | 503 | begin |
| 497 | PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110; | 504 | PopUpPos.X := FormMatrixGame.GBIndividualAB.Left-110; |
| @@ -501,15 +508,19 @@ begin | @@ -501,15 +508,19 @@ begin | ||
| 501 | FormMatrixGame.PopupNotifier.Text:=AText; | 508 | FormMatrixGame.PopupNotifier.Text:=AText; |
| 502 | FormMatrixGame.PopupNotifier.ShowAtPos(PopUpPos.X,PopUpPos.Y); | 509 | FormMatrixGame.PopupNotifier.ShowAtPos(PopUpPos.X,PopUpPos.Y); |
| 503 | FormMatrixGame.Timer.OnTimer:=@FormMatrixGame.TimerTimer; | 510 | FormMatrixGame.Timer.OnTimer:=@FormMatrixGame.TimerTimer; |
| 511 | + FormMatrixGame.Timer.Interval:=AInterval; | ||
| 504 | FormMatrixGame.Timer.Enabled:=True; | 512 | FormMatrixGame.Timer.Enabled:=True; |
| 505 | end; | 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 | var | 517 | var |
| 509 | LConsequence : TConsequence; | 518 | LConsequence : TConsequence; |
| 510 | begin | 519 | begin |
| 520 | + Result := ''; | ||
| 511 | LConsequence := TConsequence.Create(nil,S); | 521 | LConsequence := TConsequence.Create(nil,S); |
| 512 | - LConsequence.GenerateMessage(ForGroup); | 522 | + Result := LConsequence.GenerateMessage(ForGroup); |
| 523 | + if ShowPopUp then | ||
| 513 | LConsequence.PresentMessage(FormMatrixGame.GBIndividualAB); | 524 | LConsequence.PresentMessage(FormMatrixGame.GBIndividualAB); |
| 514 | case FActor of | 525 | case FActor of |
| 515 | gaPlayer: | 526 | gaPlayer: |
| @@ -981,20 +992,24 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); | @@ -981,20 +992,24 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); | ||
| 981 | var | 992 | var |
| 982 | i : integer; | 993 | i : integer; |
| 983 | MID : string; | 994 | MID : string; |
| 995 | + LQConsequence : string; | ||
| 984 | begin | 996 | begin |
| 985 | if AMessage[2] <> #27 then | 997 | if AMessage[2] <> #27 then |
| 986 | begin | 998 | begin |
| 987 | if AMessage.Count > 1 then | 999 | if AMessage.Count > 1 then |
| 988 | begin | 1000 | begin |
| 1001 | + // present only one popup with all messages | ||
| 1002 | + LQConsequence := ''; | ||
| 989 | for i := 3 to AMessage.Count -1 do | 1003 | for i := 3 to AMessage.Count -1 do |
| 990 | begin | 1004 | begin |
| 991 | MID := ExtractDelimited(1,AMessage[i],['+']); | 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 | {$IFDEF DEBUG} | 1008 | {$IFDEF DEBUG} |
| 995 | WriteLn('A Prompt consequence should have shown.'); | 1009 | WriteLn('A Prompt consequence should have shown.'); |
| 996 | {$ENDIF} | 1010 | {$ENDIF} |
| 997 | end; | 1011 | end; |
| 1012 | + ShowPopUp(LQConsequence); | ||
| 998 | end; | 1013 | end; |
| 999 | ResumeNextTurn; | 1014 | ResumeNextTurn; |
| 1000 | if AMessage[2] <> #32 then | 1015 | if AMessage[2] <> #32 then |
| @@ -1007,7 +1022,7 @@ begin | @@ -1007,7 +1022,7 @@ begin | ||
| 1007 | if MHas(K_ARRIVED) then ReceiveActor; | 1022 | if MHas(K_ARRIVED) then ReceiveActor; |
| 1008 | if MHas(K_CHAT_M) then ReceiveChat; | 1023 | if MHas(K_CHAT_M) then ReceiveChat; |
| 1009 | if MHas(K_CHOICE) then ReceiveChoice; | 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 | if MHas(K_START) then NotifyPlayers; | 1026 | if MHas(K_START) then NotifyPlayers; |
| 1012 | if MHas(K_QUESTION) then ShowQuestion; | 1027 | if MHas(K_QUESTION) then ShowQuestion; |
| 1013 | if MHas(K_MOVQUEUE) then MovePlayerQueue; | 1028 | if MHas(K_MOVQUEUE) then MovePlayerQueue; |
| @@ -1166,17 +1181,17 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | @@ -1166,17 +1181,17 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | ||
| 1166 | ARequest.Append(LEndGeneration); // 9, #32 resume, else NextGeneration = PlayerToKick AID | 1181 | ARequest.Append(LEndGeneration); // 9, #32 resume, else NextGeneration = PlayerToKick AID |
| 1167 | LEndCondition := ShouldEndCondition; | 1182 | LEndCondition := ShouldEndCondition; |
| 1168 | if IsLastCondition and LEndCondition then // 10 | 1183 | if IsLastCondition and LEndCondition then // 10 |
| 1169 | - // end experiment envelop | 1184 | + // end experiment envelop item |
| 1170 | ARequest.Append(#27) | 1185 | ARequest.Append(#27) |
| 1171 | else | 1186 | else |
| 1172 | if LEndCondition then | 1187 | if LEndCondition then |
| 1173 | begin | 1188 | begin |
| 1174 | FExperiment.NextCondition; | 1189 | FExperiment.NextCondition; |
| 1175 | - // end condition envelop | 1190 | + // end condition envelop item |
| 1176 | ARequest.Append(FExperiment.CurrentConditionAsString); | 1191 | ARequest.Append(FExperiment.CurrentConditionAsString); |
| 1177 | end | 1192 | end |
| 1178 | else | 1193 | else |
| 1179 | - // do nothing envelop | 1194 | + // do nothing envelop item |
| 1180 | ARequest.Append(#32); | 1195 | ARequest.Append(#32); |
| 1181 | end; | 1196 | end; |
| 1182 | end; | 1197 | end; |
| @@ -1231,10 +1246,12 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | @@ -1231,10 +1246,12 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | ||
| 1231 | begin | 1246 | begin |
| 1232 | P := FExperiment.PlayerFromID[ARequest[0]]; | 1247 | P := FExperiment.PlayerFromID[ARequest[0]]; |
| 1233 | ARequest[2] := K_RESUME+K_ARRIVED; | 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 | S := FExperiment.PlayerAsString[P]; | 1256 | S := FExperiment.PlayerAsString[P]; |
| 1240 | ARequest.Append(S); // 3 | 1257 | ARequest.Append(S); // 3 |
| @@ -1242,10 +1259,13 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | @@ -1242,10 +1259,13 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | ||
| 1242 | end; | 1259 | end; |
| 1243 | 1260 | ||
| 1244 | begin | 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 | end; | 1269 | end; |
| 1250 | 1270 | ||
| 1251 | // Here FActor is garanted to be a TZMQPlayer, replying by: | 1271 | // Here FActor is garanted to be a TZMQPlayer, replying by: |
| @@ -1286,7 +1306,8 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); | @@ -1286,7 +1306,8 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); | ||
| 1286 | else | 1306 | else |
| 1287 | begin | 1307 | begin |
| 1288 | {$IFDEF DEBUG} | 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 | {$ENDIF} | 1311 | {$ENDIF} |
| 1291 | end; | 1312 | end; |
| 1292 | end; | 1313 | end; |