Commit 10aade720c4232e9fe85b917cc534a783ab23189

Authored by Carlos Picanco
1 parent 17c83cac
Exists in master

gui incremental work

.gitignore
1 1 */backup/*
2 2 id
3 3 /P*/*
4   -*.zip
5 4 \ No newline at end of file
  5 +*.zip
  6 +*.ini
6 7 \ No newline at end of file
... ...
experiment_designer/form_main.lfm
1 1 object FormDesigner: TFormDesigner
2   - Left = 180
  2 + Left = 469
3 3 Height = 635
4   - Top = 54
  4 + Top = 57
5 5 Width = 656
6 6 HorzScrollBar.Page = 387
7 7 VertScrollBar.Page = 482
... ... @@ -12,7 +12,8 @@ object FormDesigner: TFormDesigner
12 12 Menu = MainMenu1
13 13 OnCreate = FormCreate
14 14 OnDestroy = FormDestroy
15   - SessionProperties = 'Caption;ComboCurrentCondition.ItemIndex;ComboCurrentCondition.Items;ComboCurrentContingency.ItemIndex;ComboCurrentContingency.Items;Height;Left;PageControl.TabIndex;Top;Width;WindowState;LabelIf.Caption'
  15 + SessionProperties = 'Caption;ComboCurrentCondition.ItemIndex;ComboCurrentCondition.Items;ComboCurrentContingency.ItemIndex;ComboCurrentContingency.Items;Height;LabelIf.Caption;Left;PageControl.TabIndex;Top;Width;WindowState;ComboCurrentCondition.Text;ComboCurrentContingency.Text'
  16 + ShowHint = True
16 17 LCLVersion = '1.6.2.0'
17 18 object PageControl: TPageControl
18 19 Left = 0
... ... @@ -559,6 +560,7 @@ object FormDesigner: TFormDesigner
559 560 Top = 10
560 561 Width = 650
561 562 ItemHeight = 0
  563 + OnChange = ComboCurrentContingencyChange
562 564 Style = csDropDownList
563 565 TabOrder = 0
564 566 end
... ... @@ -590,6 +592,7 @@ object FormDesigner: TFormDesigner
590 592 Top = 0
591 593 Width = 163
592 594 Caption = 'Remover'
  595 + OnClick = BtnRemoveContingencyClick
593 596 TabOrder = 1
594 597 end
595 598 object BtnReorderContingency: TButton
... ... @@ -623,6 +626,7 @@ object FormDesigner: TFormDesigner
623 626 Height = 25
624 627 Top = 119
625 628 Width = 650
  629 + OnEditingDone = EditContingencyNameEditingDone
626 630 TabOrder = 3
627 631 end
628 632 object RGContingencyStyle: TRadioGroup
... ... @@ -735,6 +739,7 @@ object FormDesigner: TFormDesigner
735 739 Top = 15
736 740 Width = 154
737 741 ItemHeight = 0
  742 + OnChange = CBPointsTypeChange
738 743 Style = csDropDownList
739 744 TabOrder = 4
740 745 end
... ... @@ -782,10 +787,11 @@ object FormDesigner: TFormDesigner
782 787 object EditMessSufix: TEdit
783 788 Left = 392
784 789 Height = 27
  790 + Hint = 'singular|plural'
785 791 Top = 15
786 792 Width = 134
787 793 TabOrder = 1
788   - Text = 'ponto.'
  794 + Text = 'ponto.|pontos.'
789 795 end
790 796 object LabelC5: TLabel
791 797 Left = 526
... ...
experiment_designer/form_main.pas
... ... @@ -96,15 +96,19 @@ type
96 96 procedure BtnAppendCondClick(Sender: TObject);
97 97 procedure BtnAppendContingencyClick(Sender: TObject);
98 98 procedure BtnRemoveCondClick(Sender: TObject);
  99 + procedure BtnRemoveContingencyClick(Sender: TObject);
  100 + procedure CBPointsTypeChange(Sender: TObject);
99 101 procedure CGQuestionItemClick(Sender: TObject; Index: integer);
100 102 procedure CheckBoxBroadcastChange(Sender: TObject);
101 103 procedure CheckBoxIsMetaChange(Sender: TObject);
  104 + procedure CheckBoxColorsRowsChange(Sender: TObject);
102 105 procedure CheckBoxShouldAskQuestionChange(Sender: TObject);
103 106 procedure ChkCleanDotsChange(Sender: TObject);
104 107 procedure ChkDotsChange(Sender: TObject);
105 108 procedure ComboCurrentConditionChange(Sender: TObject);
106   - procedure EditConditionNameChange(Sender: TObject);
  109 + procedure ComboCurrentContingencyChange(Sender: TObject);
107 110 procedure EditConditionNameEditingDone(Sender: TObject);
  111 + procedure EditContingencyNameEditingDone(Sender: TObject);
108 112 procedure EditQuestionChange(Sender: TObject);
109 113 procedure EditQuestionEditingDone(Sender: TObject);
110 114 procedure FormCreate(Sender: TObject);
... ... @@ -135,8 +139,9 @@ type
135 139 procedure SaveSectionExperiment;
136 140 procedure SaveSectionCondition(LS: string);
137 141 procedure SaveContingency(LS, LC: string);
  142 + procedure EraseContingency(LS, LC : string);
138 143 private
139   - function GetLC(IsMeta:Boolean):string;
  144 + function GetLC(IsMeta:Boolean; MustIncrement:Boolean=True):string;
140 145 function GetConsequenceStyle: string;
141 146 function GetContingencyCriteria: string;
142 147 function GetEndCriteriaPorcentage: string;
... ... @@ -147,6 +152,8 @@ type
147 152 procedure SetCGQuestion(AQuestionStyle: string);
148 153 procedure SetRGEndCriteriaStyle(AStyle: string);
149 154 procedure SetContingencyCriteria(S: string);
  155 + procedure SetConsequenceStyle(S:string);
  156 + procedure SetContingencyStyle(S:string);
150 157 public
151 158 { public declarations }
152 159 end;
... ... @@ -374,20 +381,14 @@ begin
374 381  
375 382 if ComboCurrentCondition.ItemIndex <> -1 then
376 383 begin
377   - LS := SEC_CONDITION + IntToStr(ComboCurrentCondition.ItemIndex + 1);
  384 + LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
378 385 LoadSectionCondition(LS);
379 386 if ComboCurrentContingency.ItemIndex <> -1 then
380   - begin
381   - LC := Delimited(1, ComboCurrentContingency.Items[ComboCurrentContingency.ItemIndex]);
382   - LoadContingency(LS, LC);
383   - end;
  387 + begin
  388 + LC := ExtractDelimited(1, ComboCurrentContingency.Text,['|']);
  389 + LoadContingency(LS, LC);
  390 + end;
384 391 end;
385   - //if NamesOnly then
386   - // begin
387   - // ListBoxConditions.Items.Append(LS+'|'+EditConditionName.Text);
388   - // ComboCurrentCondition.Items.Append(LS+'|'+EditConditionName.Text);
389   - // Exit;
390   - // end;
391 392 end;
392 393  
393 394 procedure TFormDesigner.SaveExperiment;
... ... @@ -397,11 +398,11 @@ begin
397 398 SaveSectionExperiment;
398 399 if ComboCurrentCondition.ItemIndex <> -1 then
399 400 begin
400   - LS := SEC_CONDITION + IntToStr(ComboCurrentCondition.ItemIndex + 1);
  401 + LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
401 402 SaveSectionCondition(LS);
402 403 if ComboCurrentContingency.ItemIndex <> -1 then
403 404 begin
404   - LC := Delimited(1, ComboCurrentContingency.Items[ComboCurrentContingency.ItemIndex]);
  405 + LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
405 406 SaveContingency(LS, LC);
406 407 end;
407 408 end;
... ... @@ -500,18 +501,18 @@ var
500 501 begin
501 502 for i := 0 to GBContingencyRows.ComponentCount - 1 do
502 503 case GBContingencyRows.Components[i].Name of
503   - 'Chk1': TCheckBox(GBContingencyColors.Components[i]).Checked := grOne in GR;
504   - 'Chk2': TCheckBox(GBContingencyColors.Components[i]).Checked := grTwo in GR;
505   - 'Chk3': TCheckBox(GBContingencyColors.Components[i]).Checked := grThree in GR;
506   - 'Chk4': TCheckBox(GBContingencyColors.Components[i]).Checked := grFour in GR;
507   - 'Chk5': TCheckBox(GBContingencyColors.Components[i]).Checked := grFive in GR;
508   - 'Chk6': TCheckBox(GBContingencyColors.Components[i]).Checked := grSix in GR;
509   - 'Chk7': TCheckBox(GBContingencyColors.Components[i]).Checked := grSeven in GR;
510   - 'Chk8': TCheckBox(GBContingencyColors.Components[i]).Checked := grEight in GR;
511   - 'Chk9': TCheckBox(GBContingencyColors.Components[i]).Checked := grNine in GR;
512   - 'Chk10': TCheckBox(GBContingencyColors.Components[i]).Checked := grTen in GR;
513   - 'ChkEven': TCheckBox(GBContingencyColors.Components[i]).Checked := grEven in GR;
514   - 'ChkOdd': TCheckBox(GBContingencyColors.Components[i]).Checked := grOdd in GR;
  504 + 'Chk1': TCheckBox(GBContingencyRows.Components[i]).Checked := grOne in GR;
  505 + 'Chk2': TCheckBox(GBContingencyRows.Components[i]).Checked := grTwo in GR;
  506 + 'Chk3': TCheckBox(GBContingencyRows.Components[i]).Checked := grThree in GR;
  507 + 'Chk4': TCheckBox(GBContingencyRows.Components[i]).Checked := grFour in GR;
  508 + 'Chk5': TCheckBox(GBContingencyRows.Components[i]).Checked := grFive in GR;
  509 + 'Chk6': TCheckBox(GBContingencyRows.Components[i]).Checked := grSix in GR;
  510 + 'Chk7': TCheckBox(GBContingencyRows.Components[i]).Checked := grSeven in GR;
  511 + 'Chk8': TCheckBox(GBContingencyRows.Components[i]).Checked := grEight in GR;
  512 + 'Chk9': TCheckBox(GBContingencyRows.Components[i]).Checked := grNine in GR;
  513 + 'Chk10': TCheckBox(GBContingencyRows.Components[i]).Checked := grTen in GR;
  514 + 'ChkEven': TCheckBox(GBContingencyRows.Components[i]).Checked := grEven in GR;
  515 + 'ChkOdd': TCheckBox(GBContingencyRows.Components[i]).Checked := grOdd in GR;
515 516 end;
516 517 end;
517 518  
... ... @@ -528,7 +529,7 @@ var
528 529 'ChkR': TCheckBox(GBContingencyColors.Components[i]).Checked := gcRed in GC;
529 530 'ChkM': TCheckBox(GBContingencyColors.Components[i]).Checked := gcMagenta in GC;
530 531 'ChkB': TCheckBox(GBContingencyColors.Components[i]).Checked := gcBlue in GC;
531   - 'ChkG': TCheckBox(GBContingencyColors.Components[i]).Checked := gcDiff in GC;
  532 + 'ChkG': TCheckBox(GBContingencyColors.Components[i]).Checked := gcGreen in GC;
532 533 end;
533 534 end;
534 535  
... ... @@ -561,6 +562,49 @@ begin
561 562 end;
562 563 end;
563 564  
  565 +procedure TFormDesigner.SetConsequenceStyle(S: string);
  566 +var
  567 + CS : TConsequenceStyle;
  568 + //LVariation : integer;
  569 + SCode,
  570 + SPoints : string;
  571 + LPoints : integer;
  572 +begin
  573 + SPoints := ExtractDelimited(1,S,['|']);
  574 + LPoints := StrToInt(ExtractDelimited(1,SPoints,[',']));
  575 + //LVariation := StrToInt(ExtractDelimited(2,SPoints,[',']));
  576 + SpinEditContingencyPoints.Value := LPoints;
  577 +
  578 + SCode := ExtractDelimited(2,S,['|']);
  579 + CS := GetConsequenceStylesFromString(SCode);
  580 + case RGPoints.ItemIndex of
  581 + 0: { A & B }
  582 + begin
  583 + if gscA in CS then CBPointsType.ItemIndex := 0;
  584 + if gscB in CS then CBPointsType.ItemIndex := 1;
  585 + if gscG in CS then CBPointsType.ItemIndex := 2;
  586 + end;
  587 + 1: { I }
  588 + begin
  589 + if gscI in CS then CBPointsType.ItemIndex := 0;
  590 + if gscG in CS then CBPointsType.ItemIndex := 1;
  591 + end;
  592 + end;
  593 + CBPointsType.Text := CBPointsType.Items[CBPointsType.ItemIndex];
  594 + CheckBoxBroadcast.State := cbUnchecked;
  595 +
  596 + if gscBroadcastMessage in CS then
  597 + CheckBoxBroadcast.State := cbChecked;
  598 +
  599 + if gscMessage in CS then
  600 + CheckBoxBroadcast.State := cbGrayed;
  601 +end;
  602 +
  603 +procedure TFormDesigner.SetContingencyStyle(S: string);
  604 +begin
  605 +
  606 +end;
  607 +
564 608 procedure TFormDesigner.SaveSectionExperiment;
565 609 begin
566 610 with FExperiment do
... ... @@ -620,54 +664,98 @@ procedure TFormDesigner.SaveContingency(LS, LC: string);
620 664 begin
621 665 with FExperiment do
622 666 begin
623   - WriteString(LS, LC + KEY_NAME, EditContingencyName.Text);
  667 + WriteString(LS, LC + KEY_CONT_NAME, EditContingencyName.Text);
624 668 WriteString(LS, LC + KEY_CRITERIA, GetContingencyCriteria);
625 669 WriteString(LS, LC + KEY_CONSEQUE, GetConsequenceStyle);
626   - WriteString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDP,{todo: consequence sufix plural}'');
627   - WriteString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDS, EditMessSufix.Text);
628 670 WriteString(LS, LC + KEY_CONSEQUE_MESSAGE_PREPEND, EditMessPrefix.Text);
  671 + try
  672 + WriteString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDS, ExtractDelimited(1,EditMessSufix.Text,['|']));
  673 + WriteString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDP, ExtractDelimited(2,EditMessSufix.Text,['|']));
  674 + except
  675 + on E: Exception do
  676 + Exit;
  677 + //if E.Message = 'E';
  678 +
  679 + end;
629 680 end;
630 681 end;
631 682  
632   -function TFormDesigner.GetLC(IsMeta: Boolean): string;
  683 +procedure TFormDesigner.EraseContingency(LS, LC: string);
  684 +begin
  685 + with FExperiment do
  686 + begin
  687 + DeleteKey(LS, LC + KEY_CONT_NAME);
  688 + DeleteKey(LS, LC + KEY_CRITERIA);
  689 + DeleteKey(LS, LC + KEY_CONSEQUE);
  690 + DeleteKey(LS, LC + KEY_CONSEQUE_MESSAGE_PREPEND);
  691 + DeleteKey(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDS);
  692 + DeleteKey(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDP);
  693 + end;
  694 +end;
  695 +
  696 +function TFormDesigner.GetLC(IsMeta: Boolean; MustIncrement: Boolean): string;
633 697 var
634 698 LCount,
635 699 i : integer;
636 700 S : string;
637 701 Extension : string;
638   - ContingencyKey : string;
  702 + ContingencyKey: string;
639 703 begin
640 704 if ComboCurrentContingency.Items.Count > 0 then
641   - for i := ComboCurrentContingency.Items.Count-1 downto 0 do
642   - begin
643   - S := ExtractDelimited(1,ComboCurrentContingency.Items[i],['|']);
644   - ContingencyKey := ExtractFileNameWithoutExt(S);
645   -
646   - if IsMeta then
647   - begin
648   - if ContingencyKey = KEY_METACONTINGENCY[16] then
649   - begin
650   - Result := KEY_METACONTINGENCY;
651   - Extension := ExtractFileExt(S);
652   - LCount := StrToInt(Extension);
653   - Inc(LCount);
654   - Result += IntToStr(LCount);
655   - Break;
656   - end;
657   - end
658   - else
659   - begin
660   - if ContingencyKey = KEY_CONTINGENCY[12] then
661   - begin
662   - Result := KEY_CONTINGENCY;
663   - Extension := ExtractFileExt(S);
664   - Lcount := StrToInt(Extension);
665   - Inc(LCount);
666   - Result += IntToStr(LCount);
667   - Break;
668   - end;
669   - end;
670   - end
  705 + begin
  706 + for i := ComboCurrentContingency.Items.Count-1 downto 0 do
  707 + begin
  708 + S := ExtractDelimited(1,ComboCurrentContingency.Items[i],['|']);
  709 + ContingencyKey := ExtractFileNameWithoutExt(S);
  710 +
  711 + if IsMeta then
  712 + begin
  713 + if ContingencyKey = ExtractFileNameWithoutExt(KEY_METACONTINGENCY) then
  714 + begin
  715 + Result := KEY_METACONTINGENCY;
  716 + Extension := ExtractFileExt(S);
  717 + Delete(Extension,1,1);
  718 + LCount := StrToInt(Extension);
  719 + if MustIncrement then
  720 + Inc(LCount);
  721 + Result += IntToStr(LCount);
  722 + Break;
  723 + end
  724 + else
  725 + begin
  726 + if i = 0 then
  727 + begin
  728 + Result := KEY_METACONTINGENCY+'1';
  729 + Exit;
  730 + end;
  731 + Continue;
  732 + end;
  733 + end
  734 + else
  735 + begin
  736 + if ContingencyKey = ExtractFileNameWithoutExt(KEY_CONTINGENCY) then
  737 + begin
  738 + Result := KEY_CONTINGENCY;
  739 + Extension := ExtractFileExt(S);
  740 + Delete(Extension,1,1);
  741 + LCount := StrToInt(Extension);
  742 + if MustIncrement then
  743 + Inc(LCount);
  744 + Result += IntToStr(LCount);
  745 + Break;
  746 + end
  747 + else
  748 + begin
  749 + if i = 0 then
  750 + begin
  751 + Result := KEY_CONTINGENCY+'1';
  752 + Exit;
  753 + end;
  754 + Continue;
  755 + end;
  756 + end;
  757 + end;
  758 + end
671 759 else
672 760 if IsMeta then
673 761 Result := KEY_METACONTINGENCY+'1'
... ... @@ -700,12 +788,84 @@ begin
700 788 cbGrayed: CS -= [gscMessage];
701 789 end;
702 790  
703   - Result := GetConsequenceStylesString(CS);
  791 + Result := IntToStr(SpinEditContingencyPoints.Value)+',0|';
  792 + Result += GetConsequenceStylesString(CS);
704 793 end;
705 794  
706 795 function TFormDesigner.GetContingencyCriteria: string;
707   -begin
  796 +var
  797 + C: TCriteria;
  798 +
  799 + function GetContingencyRows: TGameRows;
  800 + var
  801 + i: integer;
  802 + begin
  803 + Result := [];
  804 + for i := 0 to GBContingencyRows.ComponentCount - 1 do
  805 + case GBContingencyRows.Components[i].Name of
  806 + 'Chk1': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grOne];
  807 + 'Chk2': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grTwo];
  808 + 'Chk3': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grThree];
  809 + 'Chk4': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grFour];
  810 + 'Chk5': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grFive];
  811 + 'Chk6': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grSix];
  812 + 'Chk7': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grSeven];
  813 + 'Chk8': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grEight];
  814 + 'Chk9': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grNine];
  815 + 'Chk10': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grTen];
  816 + 'ChkEven': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grEven];
  817 + 'ChkOdd': if TCheckBox(GBContingencyRows.Components[i]).Checked then Result += [grOdd];
  818 + end;
  819 + end;
  820 +
  821 + function GetContingencyColors: TGameColors;
  822 + var
  823 + i: integer;
  824 + begin
  825 + Result := [];
  826 + for i := 0 to GBContingencyColors.ComponentCount - 1 do
  827 + case GBContingencyColors.Components[i].Name of
  828 + 'ChkEqual': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcEqual];
  829 + 'ChkDiff': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcDiff];
  830 + 'ChkNot': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcNot];
  831 + 'ChkY': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcYellow];
  832 + 'ChkR': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcRed];
  833 + 'ChkM': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcMagenta];
  834 + 'ChkB': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcBlue];
  835 + 'ChkG': if TCheckBox(GBContingencyColors.Components[i]).Checked then Result += [gcGreen];
  836 + end;
  837 + end;
708 838  
  839 +begin
  840 + C.Style := gtNone;
  841 + C.Rows := [];
  842 + C.Colors := [];
  843 + case RGContingencyStyle.ItemIndex of
  844 + 0: { do nothing };
  845 + 1:
  846 + begin
  847 + C.Style := gtRowsOnly;
  848 + C.Rows := GetContingencyRows;
  849 + end;
  850 + 2:
  851 + begin
  852 + C.Style := gtColorsOnly;
  853 + C.Colors := GetContingencyColors;
  854 + end;
  855 + 3:
  856 + begin
  857 + C.Style := gtRowsAndColors;
  858 + C.Rows := GetContingencyRows;
  859 + C.Colors := GetContingencyColors;
  860 + end;
  861 + 4:
  862 + begin
  863 + C.Style := gtRowsOrColors;
  864 + C.Rows := GetContingencyRows;
  865 + C.Colors := GetContingencyColors;
  866 + end;
  867 + end;
  868 + Result := GetCriteriaString(C);
709 869 end;
710 870  
711 871 procedure TFormDesigner.LoadSectionCondition(LS: string);
... ... @@ -737,18 +897,20 @@ end;
737 897  
738 898 procedure TFormDesigner.LoadContingency(LS, LC: string);
739 899 begin
740   - if Pos('Metacontingency', LC) > 0 then
  900 + if Pos(KEY_METACONTINGENCY, LC) > 0 then
741 901 CheckBoxIsMeta.Checked := True
742 902 else
743 903 CheckBoxIsMeta.Checked := False;
744 904  
745 905 with FExperiment do
746 906 if ValueExists(LS, LC + KEY_CONSEQUE) and ValueExists(LS, LC + KEY_CRITERIA) then
747   - begin
748   - EditContingencyName.Text := ReadString(LS, LC + KEY_NAME, '');
749   - SetContingencyCriteria(ReadString(LS, LC + KEY_CRITERIA, ''));
750   - ReadString(LS, LC + KEY_CONSEQUE, '');
751   - end;
  907 + begin
  908 + EditContingencyName.Text := ReadString(LS, LC + KEY_CONT_NAME, '');
  909 + SetContingencyCriteria(ReadString(LS, LC + KEY_CRITERIA, ''));
  910 + SetContingencyStyle(ReadString(LS, LC + KEY_CONSEQUE, ''));
  911 + EditMessPrefix.Text := ReadString(LS, LC + KEY_CONSEQUE_MESSAGE_PREPEND,'');
  912 + EditMessSufix.Text := ReadString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDS,'')+'|'+ReadString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDP,'');
  913 + end;
752 914 end;
753 915  
754 916 function TFormDesigner.GetEndCriteriaPorcentage: string;
... ... @@ -823,9 +985,9 @@ begin
823 985 LoadSectionCondition(SEC_CONDITION + IntToStr(ComboCurrentCondition.ItemIndex + 1));
824 986 end;
825 987  
826   -procedure TFormDesigner.EditConditionNameChange(Sender: TObject);
  988 +procedure TFormDesigner.ComboCurrentContingencyChange(Sender: TObject);
827 989 begin
828   -
  990 + LoadContingency(ExtractDelimited(1,ComboCurrentCondition.Text,['|']),ExtractDelimited(1,ComboCurrentContingency.Text,['|']));
829 991 end;
830 992  
831 993 procedure TFormDesigner.EditConditionNameEditingDone(Sender: TObject);
... ... @@ -843,6 +1005,22 @@ begin
843 1005 end;
844 1006 end;
845 1007  
  1008 +procedure TFormDesigner.EditContingencyNameEditingDone(Sender: TObject);
  1009 +var
  1010 + LS, LC: string;
  1011 +begin
  1012 + with FExperiment do
  1013 + if ComboCurrentContingency.ItemIndex <> -1 then
  1014 + begin
  1015 + LS := SEC_CONDITION+IntToStr(ComboCurrentCondition.ItemIndex+1);
  1016 + LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
  1017 + WriteString(LS, LC+ KEY_CONT_NAME, EditContingencyName.Text);
  1018 + ComboCurrentContingency.Items[ComboCurrentContingency.ItemIndex] :=
  1019 + LC + '|' + EditContingencyName.Text;
  1020 + ListBoxContingencies.Items.Text := ComboCurrentContingency.Items.Text;
  1021 + end;
  1022 +end;
  1023 +
846 1024 procedure TFormDesigner.EditQuestionChange(Sender: TObject);
847 1025 begin
848 1026  
... ... @@ -887,9 +1065,9 @@ var
887 1065 LS, LC : string;
888 1066  
889 1067 begin
890   - i := ComboCurrentContingency.Items.Add('');
891 1068 LS := ExtractDelimited(1,ComboCurrentCondition.Items[ComboCurrentCondition.ItemIndex],['|']);
892 1069 LC := GetLC(CheckBoxIsMeta.Checked);
  1070 + i := ComboCurrentContingency.Items.Add('');
893 1071 ComboCurrentContingency.Items[i] :=
894 1072 LC + '|' + EditContingencyName.Text;
895 1073 ComboCurrentContingency.ItemIndex := i;
... ... @@ -904,27 +1082,30 @@ var
904 1082  
905 1083 procedure Reorder(index : integer);
906 1084 var
907   - j, i: integer;
  1085 + i: integer;
908 1086 Section: TStringList;
909 1087 KeyName,Line,SectionName: string;
910 1088 begin
911 1089 Section := TStringList.Create;
912 1090 with FExperiment do
913 1091 for i := index to ComboCurrentCondition.Items.Count - 1 do
914   - begin
915   - SectionName := ExtractDelimited(1, ComboCurrentCondition.Items[i], ['|']);
916   - ReadSectionValues(SectionName, Section);
917   - EraseSection(SectionName);
918   - SectionName := SEC_CONDITION + IntToStr(i + 1);
919   - for Line in Section do
920   - begin
921   - KeyName := Section.ExtractName(Line);
922   - WriteString(SectionName, KeyName, Section.Values[KeyName]);
923   - end;
924   - Section.Clear;
925   - ComboCurrentCondition.Items[i] :=
926   - SectionName + '|' + ExtractDelimited(2, ComboCurrentCondition.Items[i], ['|']);
927   - end;
  1092 + begin
  1093 + // whatever the section name is, save and erase section
  1094 + SectionName := ExtractDelimited(1, ComboCurrentCondition.Items[i], ['|']);
  1095 + ReadSectionValues(SectionName, Section);
  1096 + EraseSection(SectionName);
  1097 +
  1098 + // then rename and rewrite section
  1099 + SectionName := SEC_CONDITION + IntToStr(i + 1);
  1100 + for Line in Section do
  1101 + begin
  1102 + KeyName := Section.ExtractName(Line);
  1103 + WriteString(SectionName, KeyName, Section.Values[KeyName]);
  1104 + end;
  1105 + Section.Clear;
  1106 + ComboCurrentCondition.Items[i] :=
  1107 + SectionName + '|' + ExtractDelimited(2, ComboCurrentCondition.Items[i], ['|']);
  1108 + end;
928 1109 Section.Free;
929 1110 end;
930 1111  
... ... @@ -942,9 +1123,80 @@ begin
942 1123 else
943 1124 ComboCurrentCondition.ItemIndex := i -1;
944 1125 end;
945   - ListBoxConditions.Items.Text := ComboCurrentCondition.Items.Text;
  1126 + ListBoxContingencies.Items.Text := ComboCurrentCondition.Items.Text;
  1127 +end;
  1128 +
  1129 +procedure TFormDesigner.BtnRemoveContingencyClick(Sender: TObject);
  1130 +var
  1131 + i: integer;
  1132 + MustReorder: boolean;
  1133 +
  1134 + procedure ReadContingencyValuesInSection(LS,LC : string; var Keys : TStringList);
  1135 + begin
  1136 + Keys.BeginUpdate;
  1137 + with FExperiment do
  1138 + begin
  1139 + Keys.Values[LC + KEY_NAME] := ReadString(LS,LC+KEY_NAME,'');
  1140 + Keys.Values[LC + KEY_CRITERIA] := ReadString(LS, LC + KEY_CRITERIA,'');
  1141 + Keys.Values[LC + KEY_CONSEQUE] := ReadString(LS, LC + KEY_CONSEQUE,'');
  1142 + Keys.Values[LC + KEY_CONSEQUE_MESSAGE_PREPEND] := ReadString(LS, LC + KEY_CONSEQUE_MESSAGE_PREPEND,'');
  1143 + Keys.Values[LC + KEY_CONSEQUE_MESSAGE_APPENDS] := ReadString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDS,'');
  1144 + Keys.Values[LC + KEY_CONSEQUE_MESSAGE_APPENDP] := ReadString(LS, LC + KEY_CONSEQUE_MESSAGE_APPENDP,'');
  1145 + end;
  1146 + Keys.EndUpdate;
  1147 + end;
  1148 +
  1149 + procedure Reorder(index : integer);
  1150 + var
  1151 + i: integer;
  1152 + SectionKeys: TStringList;
  1153 + KeyName,Line,SectionName: string;
  1154 + begin
  1155 + SectionKeys := TStringList.Create;
  1156 + with FExperiment do
  1157 + for i := index to ComboCurrentContingency.Items.Count - 1 do
  1158 + begin
  1159 + SectionName := ExtractDelimited(1, ComboCurrentCondition.Items[ComboCurrentCondition.ItemIndex], ['|']);
  1160 + KeyName := ExtractDelimited(1, ComboCurrentContingency.Items[i], ['|']);
  1161 + ReadContingencyValuesInSection(SectionName,KeyName, SectionKeys);
  1162 + EraseContingency(SectionName,KeyName);
  1163 + // todo: contingencies on top, meta on bootom...
  1164 + KeyName := GetLC(ExtractFileNameWithoutExt(KeyName) = ExtractFileNameWithoutExt(KEY_METACONTINGENCY));
  1165 + for Line in SectionKeys do
  1166 + begin
  1167 + KeyName := SectionKeys.ExtractName(Line);
  1168 + WriteString(SectionName, KeyName, SectionKeys.Values[KeyName]);
  1169 + end;
  1170 + SectionKeys.Clear;
  1171 + ComboCurrentContingency.Items[i] :=
  1172 + KeyName + '|' + ExtractDelimited(2, ComboCurrentContingency.Items[i], ['|']);
  1173 + end;
  1174 + SectionKeys.Free;
  1175 + end;
  1176 +
  1177 +begin
  1178 + i := ComboCurrentContingency.ItemIndex;
  1179 + MustReorder := i < ComboCurrentContingency.Items.Count - 1;
  1180 + ComboCurrentContingency.Items.Delete(i);
  1181 + if MustReorder then
  1182 + Reorder(i);
  1183 + case ComboCurrentContingency.Items.Count of
  1184 + 0: {do nothing};
  1185 + 1..MaxInt:
  1186 + if i = 1 then
  1187 + ComboCurrentContingency.ItemIndex := i
  1188 + else
  1189 + ComboCurrentContingency.ItemIndex := i -1;
  1190 + end;
  1191 + ListBoxContingencies.Items.Text := ComboCurrentContingency.Items.Text;
  1192 +end;
  1193 +
  1194 +procedure TFormDesigner.CBPointsTypeChange(Sender: TObject);
  1195 +begin
  1196 +
946 1197 end;
947 1198  
  1199 +
948 1200 procedure TFormDesigner.CGQuestionItemClick(Sender: TObject; Index: integer);
949 1201 var
950 1202 LS: String;
... ... @@ -961,6 +1213,7 @@ procedure TFormDesigner.CheckBoxIsMetaChange(Sender: TObject);
961 1213 var
962 1214 i: integer;
963 1215 CH: TCheckBox;
  1216 + LS,LC : string;
964 1217  
965 1218 procedure CreateChkBox(N, C: string; AOwner: TWinControl);
966 1219 begin
... ... @@ -968,6 +1221,9 @@ var
968 1221 CH.Name := N;
969 1222 CH.Caption := C;
970 1223 CH.Parent := AOwner;
  1224 + CH.ShowHint := True;
  1225 + CH.Hint := C;
  1226 + CH.OnChange := @CheckBoxColorsRowsChange;
971 1227 end;
972 1228  
973 1229 begin
... ... @@ -1002,6 +1258,48 @@ begin
1002 1258 CreateChkBox('ChkG', 'VERDE', GBContingencyColors);
1003 1259 LabelIf.Caption := 'SE O PARTICIPANTE ESCOLHER';
1004 1260 end;
  1261 +
  1262 +
  1263 + if Sender = CheckBoxIsMeta then
  1264 + if ComboCurrentCondition.Items.Count > 0 then
  1265 + if ComboCurrentContingency.Items.Count > 0 then
  1266 + begin
  1267 + LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
  1268 + LC := ExtractDelimited(1, ComboCurrentContingency.Text,['|']);
  1269 + EraseContingency(LS,LC);
  1270 + LC := GetLC(TCheckBox(Sender).Checked,False);
  1271 + SaveContingency(LS,LC);
  1272 + ComboCurrentContingency.Items[ComboCurrentContingency.ItemIndex] := LC +'|'+ EditContingencyName.Text;
  1273 + ListBoxContingencies.Items.Text := ComboCurrentContingency.Items.Text;
  1274 + end;
  1275 +end;
  1276 +
  1277 +procedure TFormDesigner.CheckBoxColorsRowsChange(Sender: TObject);
  1278 +var
  1279 + LS, LC : String;
  1280 +
  1281 + procedure UncheckBox(ACheckBoxName : string);
  1282 + var i : integer;
  1283 + begin
  1284 + for i := 0 to TCheckBox(Sender).Owner.ComponentCount -1 do
  1285 + if TCheckBox(Sender).Owner.Components[i].Name = ACheckBoxName then
  1286 + TCheckBox(TCheckBox(Sender).Owner.Components[i]).Checked := not TCheckBox(Sender).Checked;
  1287 + end;
  1288 +
  1289 +begin
  1290 + LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
  1291 + LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
  1292 + with FExperiment do
  1293 + WriteString(LS, LC + KEY_CRITERIA, GetContingencyCriteria);
  1294 +
  1295 + if TCheckBox(Sender).Name = 'ChkEqual' then
  1296 + if TCheckBox(Sender).Checked then
  1297 + UncheckBox('ChkDiff');
  1298 +
  1299 + if TCheckBox(Sender).Name = 'ChkDiff' then
  1300 + if TCheckBox(Sender).Checked then
  1301 + UncheckBox('ChkEqual');
  1302 +
1005 1303 end;
1006 1304  
1007 1305 end.
... ...
units/game_resources.pas
... ... @@ -70,6 +70,7 @@ resourcestring
70 70 KEY_METACONTINGENCY = 'Metacontingência.';
71 71  
72 72 // ROW,COLOR,OPCODE
  73 + KEY_CONT_NAME = '.Nome';
73 74 KEY_CRITERIA = '.Resposta';
74 75 KEY_CONSEQUE = '.Consequência'; // A,B,G,CSQCODE
75 76 KEY_CONSEQUE_MESSAGE_PREPEND = '.Consequência.Mensagem.Prefixo';
... ...
units/gui_file_methods.pas
... ... @@ -1,15 +0,0 @@
1   -unit gui_file_methods;
2   -
3   -{$mode objfpc}{$H+}
4   -
5   -interface
6   -
7   -uses
8   - Classes, SysUtils, IniFiles;
9   -
10   -
11   -
12   -implementation
13   -
14   -end.
15   -
units/string_methods.pas
... ... @@ -135,6 +135,7 @@ end;
135 135  
136 136 function GetRowString(ARow: TGameRow): string;
137 137 begin
  138 + Result := '';
138 139 case ARow of
139 140 grNone : Result := '0';
140 141 grOne : Result := '1';
... ... @@ -155,7 +156,7 @@ end;
155 156 function GetRowFromString(S: string): TGameRow;
156 157 begin
157 158 case UpperCase(S) of
158   - 'NA', '.' , '0', 'NONE' : Result := grNone;
  159 + 'NA', '.' , '0', 'NONE' : Result := grNone;
159 160 '01', '1', 'UM', 'ONE' : Result := grOne;
160 161 '02', '2', 'DOIS', 'TWO' : Result := grTwo;
161 162 '03', '3', 'TRÊS', 'THREE' : Result := grThree;
... ... @@ -173,6 +174,7 @@ end;
173 174  
174 175 function GetColorString(AColor: TGameColor): string;
175 176 begin
  177 + Result := '';
176 178 case AColor of
177 179 gcNone :Result := 'INDIFERENTE';
178 180 gcYellow :Result := 'AMARELO';
... ... @@ -202,7 +204,6 @@ end;
202 204  
203 205 function GetGamePromptStyleFromString(S: string): TGamePromptStyle;
204 206 begin
205   - // todos,sim,metacontingência,recuperar pontos,
206 207 case UpperCase(S) of
207 208 //'NENHUM','NONE': Result:=[gsNone];
208 209 'TODOS', 'ALL' : Result := gsAll;
... ... @@ -249,6 +250,7 @@ end;
249 250  
250 251 function GetConsequenceStyleString(AStyle: TGameConsequenceStyle): string;
251 252 begin
  253 + Result := '';
252 254 case AStyle of
253 255 gscNone : Result:= 'NADA';
254 256 gscMessage : Result:= 'MENSAGEM' ;
... ... @@ -266,6 +268,7 @@ function GetCriteriaString(ACriteria: TCriteria): string;
266 268 var R : TGameRow;
267 269 C : TGameColor;
268 270 begin
  271 + Result := '';
269 272 for R in ACriteria.Rows do
270 273 Result += GetRowString(R) + VV_SEP;
271 274 Result += '|';
... ...