Changeset 290


Ignore:
Timestamp:
Mar 25, 2019, 12:51:41 AM (6 years ago)
Author:
chronos
Message:
  • Modified: List and item forms for BuildingKind and Nation converted to generic forms.
Location:
trunk
Files:
4 added
8 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormGameSystem.pas

    r289 r290  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, UGameSystem, UFormUnitKinds, UFormNations, UFormBuildingKinds;
     9  ComCtrls, UGameSystem, UFormUnitKinds,
     10  UFormList;
    1011
    1112type
     
    3738    FGameSystem: TGameSystem;
    3839    FormUnitKinds: TFormUnitKinds;
    39     FormNations: TFormNations;
    40     FormBuildingKinds: TFormBuildingKinds;
     40    FormNations: TFormList;
     41    FormBuildingKinds: TFormList;
    4142    procedure SetGameSystem(AValue: TGameSystem);
    4243  public
     
    9899  FormUnitKinds.Align := alClient;
    99100  FormUnitKinds.Visible := True;
    100   FormNations := TFormNations.Create(nil);
     101  FormNations := TFormList.Create(nil);
    101102  FormNations.ManualDock(TabSheetNations, nil, alClient);
    102103  FormNations.Align := alClient;
    103104  FormNations.Visible := True;
    104   FormBuildingKinds := TFormBuildingKinds.Create(nil);
     105  FormBuildingKinds := TFormList.Create(nil);
    105106  FormBuildingKinds.ManualDock(TabSheetBuildings, nil, alClient);
    106107  FormBuildingKinds.Align := alClient;
     
    126127  if Assigned(FGameSystem) then begin
    127128    FormUnitKinds.UnitKinds := nil;
    128     FormNations.Nations := nil;
    129     FormBuildingKinds.BuildingKinds := nil;
     129    FormNations.List := nil;
     130    FormBuildingKinds.List := nil;
    130131  end;
    131132  FGameSystem := AValue;
    132133  if Assigned(FGameSystem) then begin
    133134    FormUnitKinds.UnitKinds := GameSystem.UnitKinds;
    134     FormNations.Nations := GameSystem.Nations;
    135     FormBuildingKinds.BuildingKinds := GameSystem.BuildingKinds;
     135    FormNations.List := GameSystem.Nations;
     136    FormBuildingKinds.List := GameSystem.BuildingKinds;
    136137  end;
    137138end;
  • trunk/Languages/xtactics.cs.po

    r289 r290  
    113113msgstr "Přepnout Skrytou mapu"
    114114
    115 #: tformbuildingkind.buttoncancel.caption
    116 #, fuzzy
    117 msgctxt "tformbuildingkind.buttoncancel.caption"
    118 msgid "Cancel"
    119 msgstr "Zrušit"
    120 
    121 #: tformbuildingkind.buttonok.caption
    122 #, fuzzy
    123 msgctxt "tformbuildingkind.buttonok.caption"
    124 msgid "OK"
    125 msgstr "OK"
    126 
    127 #: tformbuildingkind.caption
    128 msgid "Building kind"
    129 msgstr ""
    130 
    131 #: tformbuildingkind.labelname.caption
    132 #, fuzzy
    133 msgctxt "tformbuildingkind.labelname.caption"
    134 msgid "Name:"
    135 msgstr "Jméno:"
    136 
    137 #: tformbuildingkinds.aadd.caption
    138 #, fuzzy
    139 msgctxt "tformbuildingkinds.aadd.caption"
    140 msgid "Add"
    141 msgstr "Přidat"
    142 
    143 #: tformbuildingkinds.aclone.caption
    144 #, fuzzy
    145 msgctxt "tformbuildingkinds.aclone.caption"
    146 msgid "Clone"
    147 msgstr "Klonovat"
    148 
    149 #: tformbuildingkinds.amodify.caption
    150 #, fuzzy
    151 msgctxt "tformbuildingkinds.amodify.caption"
    152 msgid "Modify"
    153 msgstr "Upravit"
    154 
    155 #: tformbuildingkinds.aremove.caption
    156 #, fuzzy
    157 msgctxt "tformbuildingkinds.aremove.caption"
    158 msgid "Remove"
    159 msgstr "Odstranit"
    160 
    161 #: tformbuildingkinds.aselectall.caption
    162 #, fuzzy
    163 msgctxt "tformbuildingkinds.aselectall.caption"
    164 msgid "Select all"
    165 msgstr "Vybrat vše"
    166 
    167 #: tformbuildingkinds.caption
    168 msgid "Building kinds"
    169 msgstr ""
    170 
    171 #: tformbuildingkinds.listview1.columns[0].caption
    172 #, fuzzy
    173 msgctxt "tformbuildingkinds.listview1.columns[0].caption"
    174 msgid "Name"
    175 msgstr "Jméno"
    176 
    177115#: tformcharts.caption
    178116msgctxt "tformcharts.caption"
     
    283221#: tformgamesystem.tabsheetbuildings.caption
    284222msgid "Buildings"
    285 msgstr ""
     223msgstr "Budovy"
    286224
    287225#: tformgamesystem.tabsheetgeneral.caption
     
    331269#: tformgamesystems.listview1.columns[0].caption
    332270msgctxt "tformgamesystems.listview1.columns[0].caption"
     271msgid "Name"
     272msgstr "Jméno"
     273
     274#: tformitem.buttoncancel.caption
     275msgctxt "tformitem.buttoncancel.caption"
     276msgid "Cancel"
     277msgstr "Zrušit"
     278
     279#: tformitem.buttonok.caption
     280msgctxt "tformitem.buttonok.caption"
     281msgid "OK"
     282msgstr "OK"
     283
     284#: tformitem.caption
     285msgctxt "tformitem.caption"
     286msgid "Item"
     287msgstr "Položka"
     288
     289#: tformlist.aadd.caption
     290msgctxt "tformlist.aadd.caption"
     291msgid "Add"
     292msgstr "Přidat"
     293
     294#: tformlist.aclone.caption
     295msgctxt "tformlist.aclone.caption"
     296msgid "Clone"
     297msgstr "Klonovat"
     298
     299#: tformlist.amodify.caption
     300msgctxt "tformlist.amodify.caption"
     301msgid "Modify"
     302msgstr "Upravit"
     303
     304#: tformlist.aremove.caption
     305msgctxt "tformlist.aremove.caption"
     306msgid "Remove"
     307msgstr "Odstranit"
     308
     309#: tformlist.aselectall.caption
     310msgctxt "tformlist.aselectall.caption"
     311msgid "Select all"
     312msgstr "Vybrat vše"
     313
     314#: tformlist.caption
     315msgid "List"
     316msgstr "Seznam"
     317
     318#: tformlist.listview1.columns[0].caption
     319msgctxt "tformlist.listview1.columns[0].caption"
    333320msgid "Name"
    334321msgstr "Jméno"
     
    462449msgstr "   "
    463450
    464 #: tformnation.buttoncancel.caption
    465 msgctxt "tformnation.buttoncancel.caption"
    466 msgid "Cancel"
    467 msgstr "Zrušit"
    468 
    469 #: tformnation.buttonok.caption
    470 msgctxt "tformnation.buttonok.caption"
    471 msgid "OK"
    472 msgstr "OK"
    473 
    474 #: tformnation.caption
    475 msgctxt "tformnation.caption"
    476 msgid "Nation"
    477 msgstr "Národ"
    478 
    479 #: tformnation.labelhealth.caption
    480 msgctxt "tformnation.labelhealth.caption"
    481 msgid "Color:"
    482 msgstr "Barva:"
    483 
    484 #: tformnation.labelname.caption
    485 msgctxt "tformnation.labelname.caption"
    486 msgid "Name:"
    487 msgstr "Jméno:"
    488 
    489 #: tformnations.aadd.caption
    490 msgctxt "tformnations.aadd.caption"
    491 msgid "Add"
    492 msgstr "Přidat"
    493 
    494 #: tformnations.aclone.caption
    495 msgctxt "tformnations.aclone.caption"
    496 msgid "Clone"
    497 msgstr "Klonovat"
    498 
    499 #: tformnations.amodify.caption
    500 msgctxt "tformnations.amodify.caption"
    501 msgid "Modify"
    502 msgstr "Upravit"
    503 
    504 #: tformnations.aremove.caption
    505 msgctxt "tformnations.aremove.caption"
    506 msgid "Remove"
    507 msgstr "Odstranit"
    508 
    509 #: tformnations.aselectall.caption
    510 msgctxt "tformnations.aselectall.caption"
    511 msgid "Select all"
    512 msgstr "Vybrat vše"
    513 
    514 #: tformnations.caption
    515 msgctxt "tformnations.caption"
    516 msgid "Nations"
    517 msgstr "Národy"
    518 
    519 #: tformnations.listview1.columns[0].caption
    520 msgctxt "tformnations.listview1.columns[0].caption"
    521 msgid "Name"
    522 msgstr "Jméno"
    523 
    524 #: tformnations.listview1.columns[1].caption
    525 msgctxt "tformnations.listview1.columns[1].caption"
    526 msgid "Color"
    527 msgstr "Barva"
    528 
    529 #: tformnations.listview1.columns[2].caption
    530 msgid "Bonuses"
    531 msgstr "Bonusy"
    532 
    533451#: tformnew.aserveradd.caption
    534452msgctxt "tformnew.aserveradd.caption"
     
    1016934msgstr "Jméno"
    1017935
    1018 #: ubuilding.sbuilding
     936#: ubuilding.sbuildingkind
     937msgctxt "ubuilding.sbuildingkind"
    1019938msgid "Building"
    1020 msgstr ""
     939msgstr "Budovy"
     940
     941#: ubuilding.scost
     942msgid "Cost"
     943msgstr "Cena"
    1021944
    1022945#: uclientgui.swrongarrowangle
     
    10771000msgid "Version"
    10781001msgstr "Verze"
    1079 
    1080 #: uformbuildingkinds.snewbuildingkind
    1081 msgid "New building kind"
    1082 msgstr ""
    1083 
    1084 #: uformbuildingkinds.sremoveitems
    1085 #, fuzzy
    1086 msgctxt "uformbuildingkinds.sremoveitems"
    1087 msgid "Remove items"
    1088 msgstr "Odstranit položky"
    1089 
    1090 #: uformbuildingkinds.sremoveitemsquery
    1091 #, fuzzy
    1092 msgctxt "uformbuildingkinds.sremoveitemsquery"
    1093 msgid "Do you want to remove selected items?"
    1094 msgstr "Opravdu chcete odstranit vybrané položky?"
    10951002
    10961003#: uformcharts.scitiescount
     
    11761083msgstr "Hlavní okno"
    11771084
     1085#: uformlist.snewitem
     1086msgid "New item"
     1087msgstr "Nová položka"
     1088
     1089#: uformlist.sremoveitems
     1090msgctxt "uformlist.sremoveitems"
     1091msgid "Remove items"
     1092msgstr "Odstranit položky"
     1093
     1094#: uformlist.sremoveitemsquery
     1095msgctxt "uformlist.sremoveitemsquery"
     1096msgid "Do you want to remove selected items?"
     1097msgstr "Opravdu chcete odstranit vybrané položky?"
     1098
    11781099#: uformmain.sturn
    11791100msgctxt "uformmain.sturn"
     
    11811102msgstr "tah"
    11821103
    1183 #: uformnations.snewunitkind
    1184 msgid "New nation"
    1185 msgstr "Nový národ"
    1186 
    1187 #: uformnations.sremoveitems
    1188 msgctxt "uformnations.sremoveitems"
    1189 msgid "Remove items"
    1190 msgstr "Odstranit položky"
    1191 
    1192 #: uformnations.sremoveitemsquery
    1193 msgctxt "uformnations.sremoveitemsquery"
    1194 msgid "Do you want to remove selected items?"
    1195 msgstr "Opravdu chcete odstranit vybrané položky?"
    1196 
    11971104#: uformnew.sfromimagefile
    11981105msgid "From image file"
     
    13531260msgstr "Chybný formát souboru"
    13541261
     1262#: uitemlist.sitem
     1263msgctxt "uitemlist.sitem"
     1264msgid "Item"
     1265msgstr "Položka"
     1266
     1267#: uitemlist.sname
     1268msgctxt "uitemlist.sname"
     1269msgid "Name"
     1270msgstr "Jméno"
     1271
     1272#: uitemlist.sno
     1273msgid "No"
     1274msgstr "Ne"
     1275
     1276#: uitemlist.syes
     1277msgid "Yes"
     1278msgstr "Ano"
     1279
    13551280#: umap.scellremoveneighborerror
    13561281msgctxt "umap.scellremoveneighborerror"
     
    13911316msgstr "Trojúhelníková"
    13921317
     1318#: unation.scolor
     1319msgctxt "unation.scolor"
     1320msgid "Color"
     1321msgstr "Barva"
     1322
    13931323#: unation.snation
    13941324msgctxt "unation.snation"
  • trunk/Languages/xtactics.po

    r289 r290  
    103103msgstr ""
    104104
    105 #: tformbuildingkind.buttoncancel.caption
    106 msgctxt "tformbuildingkind.buttoncancel.caption"
    107 msgid "Cancel"
    108 msgstr ""
    109 
    110 #: tformbuildingkind.buttonok.caption
    111 msgctxt "tformbuildingkind.buttonok.caption"
    112 msgid "OK"
    113 msgstr ""
    114 
    115 #: tformbuildingkind.caption
    116 msgid "Building kind"
    117 msgstr ""
    118 
    119 #: tformbuildingkind.labelname.caption
    120 msgctxt "tformbuildingkind.labelname.caption"
    121 msgid "Name:"
    122 msgstr ""
    123 
    124 #: tformbuildingkinds.aadd.caption
    125 msgctxt "tformbuildingkinds.aadd.caption"
    126 msgid "Add"
    127 msgstr ""
    128 
    129 #: tformbuildingkinds.aclone.caption
    130 msgctxt "tformbuildingkinds.aclone.caption"
    131 msgid "Clone"
    132 msgstr ""
    133 
    134 #: tformbuildingkinds.amodify.caption
    135 msgctxt "tformbuildingkinds.amodify.caption"
    136 msgid "Modify"
    137 msgstr ""
    138 
    139 #: tformbuildingkinds.aremove.caption
    140 msgctxt "tformbuildingkinds.aremove.caption"
    141 msgid "Remove"
    142 msgstr ""
    143 
    144 #: tformbuildingkinds.aselectall.caption
    145 msgctxt "tformbuildingkinds.aselectall.caption"
    146 msgid "Select all"
    147 msgstr ""
    148 
    149 #: tformbuildingkinds.caption
    150 msgid "Building kinds"
    151 msgstr ""
    152 
    153 #: tformbuildingkinds.listview1.columns[0].caption
    154 msgctxt "tformbuildingkinds.listview1.columns[0].caption"
    155 msgid "Name"
    156 msgstr ""
    157 
    158105#: tformcharts.caption
    159106msgctxt "tformcharts.caption"
     
    315262msgstr ""
    316263
     264#: tformitem.buttoncancel.caption
     265msgctxt "tformitem.buttoncancel.caption"
     266msgid "Cancel"
     267msgstr ""
     268
     269#: tformitem.buttonok.caption
     270msgctxt "tformitem.buttonok.caption"
     271msgid "OK"
     272msgstr ""
     273
     274#: tformitem.caption
     275msgctxt "tformitem.caption"
     276msgid "Item"
     277msgstr ""
     278
     279#: tformlist.aadd.caption
     280msgctxt "tformlist.aadd.caption"
     281msgid "Add"
     282msgstr ""
     283
     284#: tformlist.aclone.caption
     285msgctxt "tformlist.aclone.caption"
     286msgid "Clone"
     287msgstr ""
     288
     289#: tformlist.amodify.caption
     290msgctxt "tformlist.amodify.caption"
     291msgid "Modify"
     292msgstr ""
     293
     294#: tformlist.aremove.caption
     295msgctxt "tformlist.aremove.caption"
     296msgid "Remove"
     297msgstr ""
     298
     299#: tformlist.aselectall.caption
     300msgctxt "tformlist.aselectall.caption"
     301msgid "Select all"
     302msgstr ""
     303
     304#: tformlist.caption
     305msgid "List"
     306msgstr ""
     307
     308#: tformlist.listview1.columns[0].caption
     309msgctxt "tformlist.listview1.columns[0].caption"
     310msgid "Name"
     311msgstr ""
     312
    317313#: tformmain.amapgridvisible.caption
    318314msgid "Map grid visible"
     
    442438msgstr ""
    443439
    444 #: tformnation.buttoncancel.caption
    445 msgctxt "tformnation.buttoncancel.caption"
    446 msgid "Cancel"
    447 msgstr ""
    448 
    449 #: tformnation.buttonok.caption
    450 msgctxt "tformnation.buttonok.caption"
    451 msgid "OK"
    452 msgstr ""
    453 
    454 #: tformnation.caption
    455 msgctxt "tformnation.caption"
    456 msgid "Nation"
    457 msgstr ""
    458 
    459 #: tformnation.labelhealth.caption
    460 msgctxt "tformnation.labelhealth.caption"
    461 msgid "Color:"
    462 msgstr ""
    463 
    464 #: tformnation.labelname.caption
    465 msgctxt "tformnation.labelname.caption"
    466 msgid "Name:"
    467 msgstr ""
    468 
    469 #: tformnations.aadd.caption
    470 msgctxt "tformnations.aadd.caption"
    471 msgid "Add"
    472 msgstr ""
    473 
    474 #: tformnations.aclone.caption
    475 msgctxt "tformnations.aclone.caption"
    476 msgid "Clone"
    477 msgstr ""
    478 
    479 #: tformnations.amodify.caption
    480 msgctxt "tformnations.amodify.caption"
    481 msgid "Modify"
    482 msgstr ""
    483 
    484 #: tformnations.aremove.caption
    485 msgctxt "tformnations.aremove.caption"
    486 msgid "Remove"
    487 msgstr ""
    488 
    489 #: tformnations.aselectall.caption
    490 msgctxt "tformnations.aselectall.caption"
    491 msgid "Select all"
    492 msgstr ""
    493 
    494 #: tformnations.caption
    495 msgctxt "tformnations.caption"
    496 msgid "Nations"
    497 msgstr ""
    498 
    499 #: tformnations.listview1.columns[0].caption
    500 msgctxt "tformnations.listview1.columns[0].caption"
    501 msgid "Name"
    502 msgstr ""
    503 
    504 #: tformnations.listview1.columns[1].caption
    505 msgctxt "tformnations.listview1.columns[1].caption"
    506 msgid "Color"
    507 msgstr ""
    508 
    509 #: tformnations.listview1.columns[2].caption
    510 msgid "Bonuses"
    511 msgstr ""
    512 
    513440#: tformnew.aserveradd.caption
    514441msgctxt "tformnew.aserveradd.caption"
     
    993920msgstr ""
    994921
    995 #: ubuilding.sbuilding
     922#: ubuilding.sbuildingkind
     923msgctxt "ubuilding.sbuildingkind"
    996924msgid "Building"
     925msgstr ""
     926
     927#: ubuilding.scost
     928msgid "Cost"
    997929msgstr ""
    998930
     
    1053985#: uformabout.sversion
    1054986msgid "Version"
    1055 msgstr ""
    1056 
    1057 #: uformbuildingkinds.snewbuildingkind
    1058 msgid "New building kind"
    1059 msgstr ""
    1060 
    1061 #: uformbuildingkinds.sremoveitems
    1062 msgctxt "uformbuildingkinds.sremoveitems"
    1063 msgid "Remove items"
    1064 msgstr ""
    1065 
    1066 #: uformbuildingkinds.sremoveitemsquery
    1067 msgctxt "uformbuildingkinds.sremoveitemsquery"
    1068 msgid "Do you want to remove selected items?"
    1069987msgstr ""
    1070988
     
    11431061msgstr ""
    11441062
     1063#: uformlist.snewitem
     1064msgid "New item"
     1065msgstr ""
     1066
     1067#: uformlist.sremoveitems
     1068msgctxt "uformlist.sremoveitems"
     1069msgid "Remove items"
     1070msgstr ""
     1071
     1072#: uformlist.sremoveitemsquery
     1073msgctxt "uformlist.sremoveitemsquery"
     1074msgid "Do you want to remove selected items?"
     1075msgstr ""
     1076
    11451077#: uformmain.sturn
    11461078msgctxt "uformmain.sturn"
     
    11481080msgstr ""
    11491081
    1150 #: uformnations.snewunitkind
    1151 msgid "New nation"
    1152 msgstr ""
    1153 
    1154 #: uformnations.sremoveitems
    1155 msgctxt "uformnations.sremoveitems"
    1156 msgid "Remove items"
    1157 msgstr ""
    1158 
    1159 #: uformnations.sremoveitemsquery
    1160 msgctxt "uformnations.sremoveitemsquery"
    1161 msgid "Do you want to remove selected items?"
    1162 msgstr ""
    1163 
    11641082#: uformnew.sfromimagefile
    11651083msgid "From image file"
     
    13201238msgstr ""
    13211239
     1240#: uitemlist.sitem
     1241msgctxt "uitemlist.sitem"
     1242msgid "Item"
     1243msgstr ""
     1244
     1245#: uitemlist.sname
     1246msgctxt "uitemlist.sname"
     1247msgid "Name"
     1248msgstr ""
     1249
     1250#: uitemlist.sno
     1251msgid "No"
     1252msgstr ""
     1253
     1254#: uitemlist.syes
     1255msgid "Yes"
     1256msgstr ""
     1257
    13221258#: umap.scellremoveneighborerror
    13231259msgid "Can't remove cell from neighbour cell"
     
    13501286#: umaptype.sgridtypetriangle
    13511287msgid "Triangural"
     1288msgstr ""
     1289
     1290#: unation.scolor
     1291msgctxt "unation.scolor"
     1292msgid "Color"
    13521293msgstr ""
    13531294
  • trunk/UBuilding.pas

    r289 r290  
    66
    77uses
    8   Classes, SysUtils, fgl, UGeometry, DOM, UXMLUtils;
     8  Classes, SysUtils, UItemList;
    99
    1010type
     
    1212  { TBuildingKind }
    1313
    14   TBuildingKind = class
    15     Id: Integer;
    16     Name: string;
     14  TBuildingKind = class(TItem)
    1715    Cost: Integer;
    18     procedure Assign(Source: TBuildingKind);
    19     procedure LoadFromNode(Node: TDOMNode);
    20     procedure SaveToNode(Node: TDOMNode);
     16    class function GetFields: TItemFields; override;
     17    procedure GetValue(Index: Integer; out Value); override;
     18    procedure SetValue(Index: Integer; var Value); override;
     19    class function GetClassSysName: string; override;
     20    class function GetClassName: string; override;
    2121  end;
    2222
    2323  { TBuildingKinds }
    2424
    25   TBuildingKinds = class(TFPGObjectList<TBuildingKind>)
    26     function AddNew(Name: string): TBuildingKind;
    27     procedure LoadFromNode(Node: TDOMNode);
    28     procedure SaveToNode(Node: TDOMNode);
    29     procedure Assign(Source: TBuildingKinds);
     25  TBuildingKinds = class(TItemList)
     26    class function GetItemClass: TItemClass; override;
    3027  end;
    3128
     
    3532
    3633resourcestring
    37   SBuilding = 'Building';
     34  SBuildingKind = 'Building';
     35  SCost = 'Cost';
    3836
    3937
     
    4240{ TBuildingKind }
    4341
    44 procedure TBuildingKind.Assign(Source: TBuildingKind);
     42class function TBuildingKind.GetFields: TItemFields;
    4543begin
    46   Name := Source.Name;
    47   Cost := Source.Cost;
     44  Result := inherited;
     45  Result.AddField(2, 'Cost', SCost, dtInteger);
    4846end;
    4947
    50 procedure TBuildingKind.LoadFromNode(Node: TDOMNode);
     48procedure TBuildingKind.GetValue(Index: Integer; out Value);
    5149begin
    52   Id := ReadInteger(Node, 'Id', 0);
    53   Name := ReadString(Node, 'Name', '');
    54   Cost := ReadInteger(Node, 'Cost', 0);
     50  if Index = 1 then string(Value) := Name
     51  else if Index = 2 then Integer(Value) := Cost
     52  else raise Exception.Create('Unsupported value index ' + IntToStr(Index));
    5553end;
    5654
    57 procedure TBuildingKind.SaveToNode(Node: TDOMNode);
     55procedure TBuildingKind.SetValue(Index: Integer; var Value);
    5856begin
    59   WriteInteger(Node, 'Id', Id);
    60   WriteString(Node, 'Name', Name);
    61   WriteInteger(Node, 'Cost', Cost);
     57  if Index = 1 then Name := string(Value)
     58  else if Index = 2 then Cost := Integer(Value)
     59  else raise Exception.Create('Unsupported value index ' + IntToStr(Index));
     60end;
     61
     62class function TBuildingKind.GetClassSysName: string;
     63begin
     64  Result := 'BuildingKind';
     65end;
     66
     67class function TBuildingKind.GetClassName: string;
     68begin
     69  Result := SBuildingKind;
    6270end;
    6371
    6472{ TBuildingKinds }
    6573
    66 function TBuildingKinds.AddNew(Name: string): TBuildingKind;
     74class function TBuildingKinds.GetItemClass: TItemClass;
    6775begin
    68   Result := TBuildingKind.Create;
    69   Result.Name := Name;
    70   Add(Result);
    71 end;
    72 
    73 procedure TBuildingKinds.LoadFromNode(Node: TDOMNode);
    74 var
    75   Node2: TDOMNode;
    76   NewItem: TBuildingKind;
    77 begin
    78   Count := 0;
    79   Node2 := Node.FirstChild;
    80   while Assigned(Node2) and (Node2.NodeName = 'BuildingKind') do begin
    81     NewItem := TBuildingKind.Create;
    82     NewItem.LoadFromNode(Node2);
    83     Add(NewItem);
    84     Node2 := Node2.NextSibling;
    85   end;
    86 end;
    87 
    88 procedure TBuildingKinds.SaveToNode(Node: TDOMNode);
    89 var
    90   I: Integer;
    91   NewNode2: TDOMNode;
    92 begin
    93   for I := 0 to Count - 1 do
    94   with Items[I] do begin
    95     NewNode2 := Node.OwnerDocument.CreateElement('BuildingKind');
    96     Node.AppendChild(NewNode2);
    97     SaveToNode(NewNode2);
    98   end;
    99 end;
    100 
    101 procedure TBuildingKinds.Assign(Source: TBuildingKinds);
    102 var
    103   I: Integer;
    104 begin
    105   while Count > Source.Count do Delete(Count - 1);
    106   while Count < Source.Count do AddNew('');
    107   for I := 0 to Count - 1 do
    108     Items[I].Assign(Source.Items[I]);
     76  Result := TBuildingKind;
    10977end;
    11078
  • trunk/UItemList.pas

    r285 r290  
    1111  TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor,
    1212    dtTime, dtDate, dtDateTime);
     13
     14  { TItemField }
    1315
    1416  TItemField = class
     
    1921    Position: TPoint;
    2022    Size: TPoint;
     23    procedure Assign(Source: TItemField);
    2124  end;
    2225
     
    2528  TItemFields = class(TFPGObjectList<TItemField>)
    2629    function AddField(Index: Integer; SysName, Name: string; DataType: TDataType): TItemField;
     30    function SearchByIndex(Index: Integer): TItemField;
    2731  end;
    2832
     
    3741    Id: Integer;
    3842    Name: string;
    39     function GetFields: TItemFields; virtual;
     43    class function GetFields: TItemFields; virtual;
     44    function GetField(Index: Integer): TItemField;
    4045    procedure GetValue(Index: Integer; out Value); virtual;
     46    function GetValueInteger(Index: Integer): Integer;
     47    function GetValueString(Index: Integer): string;
     48    function GetValueColor(Index: Integer): TColor;
     49    function GetValueBoolean(Index: Integer): Boolean;
     50    function GetValueAsText(Index: Integer): string;
    4151    procedure SetValue(Index: Integer; var Value); virtual;
     52    procedure SetValueInteger(Index: Integer; Value: Integer);
     53    procedure SetValueString(Index: Integer; Value: string);
     54    procedure SetValueColor(Index: Integer; Value: TColor);
     55    procedure SetValueBoolean(Index: Integer; Value: Boolean);
    4256    procedure Assign(Source: TItem); virtual;
    4357    procedure LoadFromNode(Node: TDOMNode); virtual;
    4458    procedure SaveToNode(Node: TDOMNode); virtual;
    4559    class function GetClassSysName: string; virtual;
     60    class function GetClassName: string; virtual;
    4661  end;
    4762
     
    6883implementation
    6984
     85resourcestring
     86  SYes = 'Yes';
     87  SNo = 'No';
     88  SItem = 'Item';
     89  SName = 'Name';
     90
     91{ TItemField }
     92
     93procedure TItemField.Assign(Source: TItemField);
     94begin
     95  SysName := Source.SysName;
     96  Name := Source.Name;
     97  Index := Source.Index;
     98  DataType := Source.DataType;
     99  Position := Source.Position;
     100  Size := Source.Size;
     101end;
     102
    70103{ TItemList }
    71104
     
    185218end;
    186219
     220function TItemFields.SearchByIndex(Index: Integer): TItemField;
     221var
     222  I: Integer;
     223begin
     224  I := 0;
     225  while (I < Count) and (Items[I].Index <> Index) do Inc(I);
     226  if I < Count then Result := Items[I]
     227    else Result := nil;
     228end;
     229
    187230{ TItem }
    188231
     
    192235  ValueColor: TColor;
    193236  ValueInteger: Integer;
     237  ValueBoolean: Boolean;
    194238begin
    195239  if Field.DataType = dtString then begin
     
    205249    SetValue(Field.Index, ValueInteger);
    206250  end else
     251  if Field.DataType = dtBoolean then begin
     252    Source.GetValue(Field.Index, ValueBoolean);
     253    SetValue(Field.Index, ValueBoolean);
     254  end else
    207255  raise Exception.Create('Unsupported field value data type');
    208256end;
     
    250298end;
    251299
    252 function TItem.GetFields: TItemFields;
     300class function TItem.GetFields: TItemFields;
    253301begin
    254302  Result := TItemFields.Create;
    255   Result.AddField(1, 'Name', 'Name', dtString);
     303  Result.AddField(1, 'Name', SName, dtString);
     304end;
     305
     306function TItem.GetField(Index: Integer): TItemField;
     307var
     308  Fields: TItemFields;
     309begin
     310  Result := TItemField.Create;
     311  Fields := GetFields;
     312  try
     313    Result.Assign(Fields[Index]);
     314  finally
     315    Fields.Free;
     316  end;
    256317end;
    257318
     
    260321end;
    261322
     323function TItem.GetValueString(Index: Integer): string;
     324begin
     325  GetValue(Index, Result);
     326end;
     327
     328function TItem.GetValueInteger(Index: Integer): Integer;
     329begin
     330  GetValue(Index, Result);
     331end;
     332
     333function TItem.GetValueColor(Index: Integer): TColor;
     334begin
     335  GetValue(Index, Result);
     336end;
     337
     338function TItem.GetValueBoolean(Index: Integer): Boolean;
     339begin
     340  GetValue(Index, Result);
     341end;
     342
     343function TItem.GetValueAsText(Index: Integer): string;
     344var
     345  Fields: TItemFields;
     346  ItemField: TItemField;
     347begin
     348  Fields := GetFields;
     349  ItemField := GetField(Fields.IndexOf(Fields.SearchByIndex(Index)));
     350  if ItemField.DataType = dtInteger then Result := IntToStr(GetValueInteger(Index))
     351  else if ItemField.DataType = dtString then Result := GetValueString(Index)
     352  else if ItemField.DataType = dtColor then Result := ''
     353  else if ItemField.DataType = dtBoolean then begin
     354    if GetValueBoolean(Index) then Result := SYes else Result := SNo;
     355  end;
     356  ItemField.Free;
     357  Fields.Free;
     358end;
     359
    262360procedure TItem.SetValue(Index: Integer; var Value);
    263361begin
     362end;
     363
     364procedure TItem.SetValueInteger(Index: Integer; Value: Integer);
     365begin
     366  SetValue(Index, Value);
     367end;
     368
     369procedure TItem.SetValueString(Index: Integer; Value: string);
     370begin
     371  SetValue(Index, Value);
     372end;
     373
     374procedure TItem.SetValueColor(Index: Integer; Value: TColor);
     375begin
     376  SetValue(Index, Value);
     377end;
     378
     379procedure TItem.SetValueBoolean(Index: Integer; Value: Boolean);
     380begin
     381  SetValue(Index, Value);
    264382end;
    265383
     
    318436end;
    319437
     438class function TItem.GetClassName: string;
     439begin
     440  Result := SItem;
     441end;
     442
    320443end.
    321444
  • trunk/UNation.pas

    r285 r290  
    1414  TNation = class(TItem)
    1515    Color: TColor;
    16     function GetFields: TItemFields; override;
     16    class function GetFields: TItemFields; override;
    1717    procedure GetValue(Index: Integer; out Value); override;
    1818    procedure SetValue(Index: Integer; var Value); override;
    1919    class function GetClassSysName: string; override;
     20    class function GetClassName: string; override;
    2021  end;
    2122
     
    2829resourcestring
    2930  SNation = 'Nation';
     31  SColor = 'Color';
    3032
    3133
     
    3739{ TNation }
    3840
    39 function TNation.GetFields: TItemFields;
     41class function TNation.GetFields: TItemFields;
    4042begin
    4143  Result := inherited;
    42   Result.AddField(2, 'Color', 'Color', dtColor);
     44  Result.AddField(2, 'Color', SColor, dtColor);
    4345end;
    4446
     
    6264end;
    6365
     66class function TNation.GetClassName: string;
     67begin
     68  Result := SNation;
     69end;
     70
    6471{ TNations }
    6572
  • trunk/UPlayer.pas

    r285 r290  
    119119    Units: TUnits;
    120120    Nation: TNation;
    121     function GetFields: TItemFields; override;
     121    class function GetFields: TItemFields; override;
    122122    procedure GetValue(Index: Integer; out Value); override;
    123123    procedure SetValue(Index: Integer; var Value); override;
     
    12651265end;
    12661266
    1267 function TPlayer.GetFields: TItemFields;
     1267class function TPlayer.GetFields: TItemFields;
    12681268begin
    12691269  Result := inherited;
  • trunk/xtactics.lpi

    r289 r290  
    110110      </Item7>
    111111    </RequiredPackages>
    112     <Units Count="48">
     112    <Units Count="46">
    113113      <Unit0>
    114114        <Filename Value="xtactics.lpr"/>
     
    348348      </Unit43>
    349349      <Unit44>
    350         <Filename Value="Forms/UFormNation.pas"/>
    351         <IsPartOfProject Value="True"/>
    352         <ComponentName Value="FormNation"/>
     350        <Filename Value="Forms/UFormList.pas"/>
     351        <IsPartOfProject Value="True"/>
     352        <ComponentName Value="FormList"/>
    353353        <HasResources Value="True"/>
    354354        <ResourceBaseClass Value="Form"/>
    355355      </Unit44>
    356356      <Unit45>
    357         <Filename Value="Forms/UFormNations.pas"/>
    358         <IsPartOfProject Value="True"/>
    359         <ComponentName Value="FormNations"/>
     357        <Filename Value="Forms/UFormItem.pas"/>
     358        <IsPartOfProject Value="True"/>
     359        <ComponentName Value="FormItem"/>
    360360        <HasResources Value="True"/>
    361361        <ResourceBaseClass Value="Form"/>
    362362      </Unit45>
    363       <Unit46>
    364         <Filename Value="Forms/UFormBuildingKind.pas"/>
    365         <IsPartOfProject Value="True"/>
    366         <ComponentName Value="FormBuildingKind"/>
    367         <HasResources Value="True"/>
    368         <ResourceBaseClass Value="Form"/>
    369       </Unit46>
    370       <Unit47>
    371         <Filename Value="Forms/UFormBuildingKinds.pas"/>
    372         <IsPartOfProject Value="True"/>
    373         <ComponentName Value="FormBuildingKinds"/>
    374         <HasResources Value="True"/>
    375         <ResourceBaseClass Value="Form"/>
    376       </Unit47>
    377363    </Units>
    378364  </ProjectOptions>
Note: See TracChangeset for help on using the changeset viewer.