From 86db5e0bfa0b0663dd0cea29551afb2d260a8a41 Mon Sep 17 00:00:00 2001 From: cpicanco Date: Fri, 9 Dec 2016 12:17:50 -0300 Subject: [PATCH] gui incremental work --- units/game_actors.pas | 2 +- units/game_control.pas | 4 ++-- units/game_file_methods.pas | 46 +++++++--------------------------------------- units/game_resources.pas | 15 +++++++++++---- units/gui_file_methods.pas | 15 +++++++++++++++ units/string_methods.pas | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++----------------- 6 files changed, 86 insertions(+), 63 deletions(-) create mode 100644 units/gui_file_methods.pas diff --git a/units/game_actors.pas b/units/game_actors.pas index 51cb440..a6fc1c3 100644 --- a/units/game_actors.pas +++ b/units/game_actors.pas @@ -594,7 +594,7 @@ begin FMessage := TPopupNotifier.Create(Self); FTimer := TTimer.Create(Self); FTimer.Enabled:=False; - FTimer.Interval:=10000; + FTimer.Interval:=5000; FTimer.OnTimer:=@SelfDestroy; FConsequenceByPlayerID := TStringList.Create; end; diff --git a/units/game_control.pas b/units/game_control.pas index 3f5dfdc..557cdd0 100644 --- a/units/game_control.pas +++ b/units/game_control.pas @@ -988,7 +988,7 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); begin MID := ExtractDelimited(1,AMessage[i],['+']); ShowConsequenceMessage(MID, ExtractDelimited(2,AMessage[i],['+']),MID = 'M'); - + // TODO: QMESSAGE present only one message with all information... {$IFDEF DEBUG} WriteLn('A Prompt consequence should have shown.'); {$ENDIF} @@ -1310,7 +1310,7 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); // The Announcer sends a message, waits interval time until all messages have been sent and then destroys itself. LAnnouncer := TIntervalarAnnouncer.Create(nil); LAnnouncer.OnStart := @FZMQActor.SendMessage; - LAnnouncer.Interval := 500; + LAnnouncer.Interval := 5000; LCount := WordCount(AReply[6],['+']); // individual consequences diff --git a/units/game_file_methods.pas b/units/game_file_methods.pas index 34e5791..6e366e5 100644 --- a/units/game_file_methods.pas +++ b/units/game_file_methods.pas @@ -18,14 +18,7 @@ uses , game_experiment ; -type - { TCIniFile } - - TCIniFile = class (TIniFile) - public - procedure ReadSectionValues(const Section: string; Strings: TStrings); override; - end; function LoadExperimentFromResource(var AExperiment: TExperiment):Boolean; function LoadExperimentFromFile(var AExperiment: TExperiment; AFilename : string):Boolean; procedure SaveExperimentToFile(AExperiment: TExperiment; AFilename : string); @@ -38,7 +31,7 @@ resourcestring implementation -uses LCLIntf, game_resources, game_actors, game_actors_helpers, string_methods, regdata, zhelpers; +uses LCLIntf, game_resources, game_actors, game_actors_helpers, string_methods, regdata; function LoadExperimentFromResource(var AExperiment: TExperiment): Boolean; var @@ -92,7 +85,7 @@ begin Turn.Value:=2; Turn.Random:=False; Cycles.Count:=0; - Cycles.Value:=20; + Cycles.Value:=2; Cycles.Generation:=0; EndCriterium.AbsoluteCycles := 15; EndCriterium.InterlockingPorcentage := 80; @@ -127,7 +120,7 @@ end; function LoadExperimentFromFile(var AExperiment: TExperiment; AFilename: string):Boolean; var - LIniFile : TCIniFile; + LIniFile : TIniFile; //procedure HandleRootPath(var APath : string); //begin @@ -166,7 +159,7 @@ var begin Turn := ReadInteger(LS,KEY_PLAYER_TURN,i); Choice := GetChoiceFromString(ReadString(LS,KEY_PLAYER_CHOICE_LAST,'0,NONE,')); - ID := ReadString(LS,KEY_PLAYER_ID,s_random(20)); + ID := ReadString(LS,KEY_PLAYER_ID,'ID'); Nicname := ReadString(LS,KEY_PLAYER_NICNAME,GenResourceName(i)); Login := ReadString(LS,KEY_PLAYER_LOGIN,'jogador'+IntToStr(i+1)); Password := ReadString(LS,KEY_PLAYER_PASSWORD,'1234'); @@ -267,7 +260,7 @@ begin Result := False; if FileExists(AFileName) then begin - LIniFile:= TCIniFile.Create(AFileName); + LIniFile:= TIniFile.Create(AFileName); with LIniFile do if SectionExists(SEC_EXPERIMENT) then begin @@ -291,13 +284,13 @@ procedure SaveExperimentToFile(AExperiment: TExperiment; AFilename: string); var i,j : Integer; LWriter : TRegData; - LIniFile : TCIniFile; + LIniFile : TIniFile; LC, LCK : string; begin LWriter := TRegData.Create(nil,AFilename); - LIniFile:= TCIniFile.Create(LWriter.FileName); + LIniFile:= TIniFile.Create(LWriter.FileName); LWriter.Free; LIniFile.WriteString(SEC_EXPERIMENT,KEY_RESEARCHER,AExperiment.Researcher); @@ -354,30 +347,5 @@ begin end; end; - -procedure TCIniFile.ReadSectionValues(const Section: string; Strings: TStrings); -var - KeyList: TStringList; - I: Integer; -begin - KeyList := TStringList.Create; - //KeyList.Sorted := False; - KeyList.CaseSensitive := False; - KeyList.Duplicates := dupIgnore; - try - ReadSection(Section, KeyList); - //showmessage(Keylist.Text); - //Strings.BeginUpdate; - //try - for I := 0 to KeyList.Count - 1 do - Strings.Add(KeyList[I] + '=' + ReadString(Section, KeyList[I], '')) - //finally - // Strings.EndUpdate; - //end; - finally - KeyList.Free; - end; -end; - end. diff --git a/units/game_resources.pas b/units/game_resources.pas index c219c0c..43864b6 100644 --- a/units/game_resources.pas +++ b/units/game_resources.pas @@ -24,10 +24,14 @@ resourcestring SEC_EXPERIMENT = 'Experimento'; KEY_NAME = 'Nome'; KEY_AIM = 'Objetivo'; - KEY_RESEARCHER = 'Pesquisador.Responsável'; - KEY_GEN_PLAYER_AS_NEEDED = 'GerarJogadoresAutomaticamente'; + KEY_RESEARCHER = 'Pesquisador.Nome'; + KEY_RESEARCHER_CANCHAT = 'Pesquisador.BatePapo'; + KEY_RESEARCHER_CANPLAY = 'Pesquisador.PodeJogar'; + KEY_GEN_PLAYER_AS_NEEDED = 'Jogadores.GerarAutomaticamente'; + KEY_CHAT_HISTORY_FOR_NEW_PLAYERS = 'Jogadores.Novos.Enviar_Histórico_do_BatePapo'; KEY_CURRENT_CONDITION = 'ComeçarNaCondição'; KEY_MATRIX_TYPE= 'TipoDaMatrix'; + KEY_POINTS_TYPE= 'TipoDePontuação'; SEC_PLAYER = 'Jogador.'; KEY_PLAYER_TEMP = 'Data.X'; @@ -57,13 +61,16 @@ resourcestring //KEY_PROMPT_VALUE = 'Questão.Apresentar'; // BOOL,CSQPROMPTCODE KEY_PROMPT_STYLE = 'Questão.Estilo'; // string KEY_PROMPT_MESSAGE = 'Questão.Mensagem'; // string - KEY_ENDCRITERIA = 'Critério.DeFinalizaçãoDaCondição'; //2,50,10,30, + KEY_ENDCRITERIA = 'Critério_de_Finalização.Estilo'; //2,50,10,30, + KEY_ENDCRITERIA_CYCLES = 'Critério_de_Finalização.Ciclos'; // 20 + KEY_ENDCRITERIA_PORCENTAGE = 'Critério_de_Finalização.Porcentagem'; // 80|10 + KEY_CONTINGENCY = 'Contingência.'; KEY_METACONTINGENCY = 'Metacontingência.'; // ROW,COLOR,OPCODE - KEY_CRITERIA = '.EsquemaDeReforço'; + KEY_CRITERIA = '.Resposta'; KEY_CONSEQUE = '.Consequência'; // A,B,G,CSQCODE KEY_CONSEQUE_MESSAGE_PREPEND = '.Consequência.Mensagem.Prefixo'; KEY_CONSEQUE_MESSAGE_APPENDS = '.Consequência.Mensagem.Sufixo.Singular'; diff --git a/units/gui_file_methods.pas b/units/gui_file_methods.pas new file mode 100644 index 0000000..84d9042 --- /dev/null +++ b/units/gui_file_methods.pas @@ -0,0 +1,15 @@ +unit gui_file_methods; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, IniFiles; + + + +implementation + +end. + diff --git a/units/string_methods.pas b/units/string_methods.pas index cbae7b7..f6ca542 100644 --- a/units/string_methods.pas +++ b/units/string_methods.pas @@ -53,6 +53,9 @@ function GetPointsString(APoints : TPoints) : string; function GetChoiceString(AChoice : TPlayerChoice) : string; function GetChoiceFromString(S:string) : TPlayerChoice; +function GetEndCriteriaLastCyclesFromString(S:string):integer; +function GetEndCriteriaPorcentageFromString(S:string):integer; +function GetEndCriteriaStyleString(AEndCriteriaStyle : TGameEndCondition):string; function GetEndCriteriaString(AEndCriterium:TEndConditionCriterium) : string; function GetEndCriteriaFromString(S:string) : TEndConditionCriterium; @@ -60,6 +63,8 @@ function GetEndCriteriaFromString(S:string) : TEndConditionCriterium; function GetPlayerFromString(s: string): TPlayer; function GetPlayerAsString(P: TPlayer): string; +// gui helpers + implementation uses strutils; @@ -108,11 +113,12 @@ end; function GetPromptStyleFromString(S:string):TPromptStyle; var i : integer; + LCount : integer; begin - // Yes,All,Metacontingency,RecoverLostPoints, Result := []; - for i := 1 to 4 do - Result := Result + [GetGamePromptStyleFromString(ExtractDelimited(i,S,[',']))]; + LCount := WordCount(S,[',']); + for i := 1 to LCount do + Result += [GetGamePromptStyleFromString(ExtractDelimited(i,S,[',']))]; end; function GetAndDelFirstValue(var S: string;Sep:Char=','): string; @@ -204,8 +210,8 @@ begin 'NÃO','NAO','N' : Result := gsNo; 'CONTINGÊNCIA','CONTINGENCIA','CONTINGENCY','OPERANTE', 'OPERANT': Result := gsContingency; 'METACONTINGÊNCIA','METACONTINGENCIA','METACONTINGENCY','META': Result := gsMetacontingency; - 'RECUPERA','RECUPERAR','RECUPERAR PONTOS','RECOVER','RESETAR', 'RESET': Result := gsRevertPoints; - 'TIRAR DE A AO INVES DE B','TIRAR DE A AO INVÉS DE B', 'B as A' : Result := gsBasA; + 'REVERTER','RECUPERA','RECUPERAR','RECUPERAR PONTOS','RECOVER','RESETAR', 'RESET': Result := gsRevertPoints; + 'TIRAR DE A AO INVES DE B','TIRAR DE A AO INVÉS DE B', 'B as A','B->A' : Result := gsBasA; end; end; @@ -216,13 +222,13 @@ begin for Style in AStyle do case Style of //gsNone: Result:= Result+'nenhum'+VV_SEP; - gsAll: Result:= Result+'todos'+VV_SEP; - gsYes: Result:= Result+'s'+VV_SEP; - gsNo: Result:= Result+'n'+VV_SEP; - gsContingency: Result:= Result+'operante'+VV_SEP; - gsMetacontingency: Result:= Result+'meta'+VV_SEP; - gsRevertPoints: Result:= Result+'recupera'+VV_SEP; - gsBasA: Result:= Result+'b as a'+VV_SEP; + gsAll: Result += 'TODOS'+VV_SEP; + gsYes: Result += 'SIM'+VV_SEP; + gsNo: Result += 'NÃO'+VV_SEP; + gsContingency: Result += 'OPERANTE'+VV_SEP; + gsMetacontingency: Result += 'META'+VV_SEP; + gsRevertPoints: Result += 'REVERTER'+VV_SEP; + gsBasA: Result += 'B->A'+VV_SEP; end; end; @@ -372,15 +378,41 @@ begin end; end; +function GetEndCriteriaLastCyclesFromString(S: string): integer; +begin + try + Result := StrToInt(ExtractDelimited(2,S,[','])); + except + On E : Exception do + Result := 0; + end; +end; + +function GetEndCriteriaPorcentageFromString(S: string): integer; +begin + try + Result := StrToInt(ExtractDelimited(1,S,[','])); + except + On E : Exception do + Result := 0; + end; +end; + + +function GetEndCriteriaStyleString(AEndCriteriaStyle: TGameEndCondition): string; +begin + case AEndCriteriaStyle of + gecAbsoluteCycles: Result := 'CICLOS'; + gecInterlockingPorcentage: Result := 'PORCENTAGEM'; + gecWhichComeFirst: Result := 'O QUE OCORRER PRIMEIRO'; + end; +end; + function GetEndCriteriaString(AEndCriterium: TEndConditionCriterium ): string; begin // 2,20,10,10, - case AEndCriterium.Style of - gecAbsoluteCycles: Result := '0'; - gecInterlockingPorcentage: Result := '1'; - gecWhichComeFirst: Result := '2'; - end; + Result := GetEndCriteriaStyleString(AEndCriterium.Style); Result := Result + VV_SEP; Result := Result + IntToStr(AEndCriterium.AbsoluteCycles) + VV_SEP; Result := Result + IntToStr(AEndCriterium.InterlockingPorcentage) + VV_SEP; @@ -489,6 +521,7 @@ begin Result += M[i] + '|'; end; + function GetPlayerFromString(s: string): TPlayer; function RowFromString(S: string): TGameRow; -- libgit2 0.21.2