- Timestamp:
- Mar 29, 2019, 12:58:09 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormItem.lfm
r295 r296 28 28 Left = 220 29 29 Height = 32 30 Top = 2 5730 Top = 260 31 31 Width = 94 32 32 Anchors = [akLeft] -
trunk/Forms/UFormItem.pas
r291 r296 89 89 Fields: TItemFields; 90 90 I: Integer; 91 J: Integer; 91 92 Control: TControl; 92 93 begin … … 99 100 else if DataType = dtColor then TColorBox(Control).Selected := Item.GetValueColor(Index) 100 101 else if DataType = dtBoolean then TCheckBox(Control).Checked := Item.GetValueBoolean(Index) 101 else raise Exception.Create('Unsupported type ' + IntToStr(Integer(DataType))); 102 else if DataType = dtEnumeration then begin 103 TComboBox(Control).Items.BeginUpdate; 104 try 105 TComboBox(Control).Items.Clear; 106 for J := 0 to EnumStates.Count - 1 do 107 TComboBox(Control).Items.Add(EnumStates[J]); 108 TComboBox(Control).ItemIndex := Integer(Item.GetValueEnumeration(Index)); 109 finally 110 TComboBox(Control).Items.EndUpdate; 111 end; 112 end 113 else raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]])); 102 114 end; 103 115 Fields.Free; … … 118 130 else if DataType = dtColor then Item.SetValueColor(Index, TColorBox(Control).Selected) 119 131 else if DataType = dtBoolean then Item.SetValueBoolean(Index, TCheckBox(Control).Checked) 120 else raise Exception.Create('Unsupported type ' + IntToStr(Integer(DataType))); 132 else if DataType = dtEnumeration then Item.SetValueEnumeration(Index, TUndefinedEnum(TComboBox(Control).ItemIndex)) 133 else raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]])); 121 134 end; 122 135 Fields.Free; … … 145 158 NewControl := TSpinEdit.Create(nil); 146 159 NewControl.Width := 100; 160 TSpinEdit(NewControl).MaxValue := High(Integer); 147 161 end else 148 162 if DataType = dtString then begin … … 154 168 NewControl.Width := 200; 155 169 end else 170 if DataType = dtEnumeration then begin 171 NewControl := TComboBox.Create(nil); 172 NewControl.Width := 200; 173 TComboBox(NewControl).Style := csDropDownList; 174 end else 156 175 if DataType = dtBoolean then begin 157 176 NewControl := TCheckBox.Create(nil); 158 end else raise Exception.Create('Unsupported type ' + IntToStr(Integer(DataType))); 177 end else 178 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]])); 159 179 NewControl.Left := 150; 160 180 NewControl.Top := Y; -
trunk/Languages/xtactics.cs.po
r295 r296 962 962 msgstr "Budovy" 963 963 964 #: ubuilding.scity 965 msgid "City" 966 msgstr "Město" 967 964 968 #: ubuilding.scost 965 969 msgctxt "ubuilding.scost" 966 970 msgid "Cost" 967 971 msgstr "Cena" 972 973 #: ubuilding.snone 974 msgctxt "ubuilding.snone" 975 msgid "None" 976 msgstr "Žádný" 968 977 969 978 #: ubuilding.sspecialtype … … 1288 1297 msgstr "Ne" 1289 1298 1299 #: uitemlist.sunsupporteddatatype 1300 msgid "Unsupported field value data type %s" 1301 msgstr "Nepodporovaný datový typ hodnoty pole %s" 1302 1290 1303 #: uitemlist.syes 1291 1304 msgid "Yes" -
trunk/Languages/xtactics.po
r295 r296 947 947 msgstr "" 948 948 949 #: ubuilding.scity 950 msgid "City" 951 msgstr "" 952 949 953 #: ubuilding.scost 950 954 msgctxt "ubuilding.scost" 951 955 msgid "Cost" 956 msgstr "" 957 958 #: ubuilding.snone 959 msgctxt "ubuilding.snone" 960 msgid "None" 952 961 msgstr "" 953 962 … … 1265 1274 msgstr "" 1266 1275 1276 #: uitemlist.sunsupporteddatatype 1277 msgid "Unsupported field value data type %s" 1278 msgstr "" 1279 1267 1280 #: uitemlist.syes 1268 1281 msgid "Yes" -
trunk/UBuilding.pas
r294 r296 52 52 SCost = 'Cost'; 53 53 SSpecialType = 'Special type'; 54 SNone = 'None'; 55 SCity = 'City'; 54 56 55 57 … … 83 85 84 86 class function TBuildingKind.GetFields: TItemFields; 87 var 88 Field: TItemField; 85 89 begin 86 90 Result := inherited; 87 91 Result.AddField(2, 'Cost', SCost, dtInteger); 88 Result.AddField(3, 'SpecialType', SSpecialType, dtInteger); 92 Field := Result.AddField(3, 'SpecialType', SSpecialType, dtEnumeration); 93 Field.EnumStates.Add(SNone); 94 Field.EnumStates.Add(SCity); 89 95 end; 90 96 … … 94 100 else if Index = 2 then Integer(Value) := Cost 95 101 else if Index = 3 then TBuildingSpecialType(Value) := SpecialType 96 else raise Exception.Create('Unsupported value index ' + IntToStr(Index));102 else inherited; 97 103 end; 98 104 … … 102 108 else if Index = 2 then Cost := Integer(Value) 103 109 else if Index = 3 then SpecialType := TBuildingSpecialType(Value) 104 else raise Exception.Create('Unsupported value index ' + IntToStr(Index));110 else inherited; 105 111 end; 106 112 -
trunk/UItemList.pas
r294 r296 9 9 10 10 type 11 TUndefinedEnum = (eeNone); 12 11 13 TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor, 12 14 dtTime, dtDate, dtDateTime, dtEnumeration); … … 21 23 Position: TPoint; 22 24 Size: TPoint; 25 EnumStates: TStringList; 26 constructor Create; 27 destructor Destroy; override; 23 28 procedure Assign(Source: TItemField); 24 29 end; … … 48 53 function GetValueColor(Index: Integer): TColor; 49 54 function GetValueBoolean(Index: Integer): Boolean; 55 function GetValueEnumeration(Index: Integer): TUndefinedEnum; 50 56 function GetValueAsText(Index: Integer): string; 51 57 procedure SetValue(Index: Integer; var Value); virtual; … … 54 60 procedure SetValueColor(Index: Integer; Value: TColor); 55 61 procedure SetValueBoolean(Index: Integer; Value: Boolean); 62 procedure SetValueEnumeration(Index: Integer; Value: TUndefinedEnum); 56 63 procedure Assign(Source: TItem); virtual; 57 64 procedure LoadFromNode(Node: TDOMNode); virtual; … … 80 87 end; 81 88 89 const 90 DataTypeStr: array[TDataType] of string = ('None', 'String', 'Boolean', 91 'Integer', 'Float', 'Color', 'Time', 'Date', 'DateTime', 'Enumeration'); 92 93 resourcestring 94 SUnsupportedDataType = 'Unsupported field value data type %s'; 95 82 96 83 97 implementation … … 90 104 91 105 { TItemField } 106 107 constructor TItemField.Create; 108 begin 109 EnumStates := TStringList.Create; 110 end; 111 112 destructor TItemField.Destroy; 113 begin 114 EnumStates.Free; 115 inherited Destroy; 116 end; 92 117 93 118 procedure TItemField.Assign(Source: TItemField); … … 99 124 Position := Source.Position; 100 125 Size := Source.Size; 126 EnumStates.Assign(Source.EnumStates); 101 127 end; 102 128 … … 231 257 232 258 procedure TItem.AssignValue(Source: TItem; Field: TItemField); 233 var234 ValueString: string;235 ValueColor: TColor;236 ValueInteger: Integer;237 ValueBoolean: Boolean;238 259 begin 239 260 if Field.DataType = dtString then begin 240 Source.GetValue(Field.Index, ValueString); 241 SetValue(Field.Index, ValueString); 261 SetValueString(Field.Index, Source.GetValueString(Field.Index)); 242 262 end else 243 263 if Field.DataType = dtColor then begin 244 Source.GetValue(Field.Index, ValueColor); 245 SetValue(Field.Index, ValueColor); 264 SetValueColor(Field.Index, Source.GetValueColor(Field.Index)); 246 265 end else 247 266 if Field.DataType = dtInteger then begin 248 Source.GetValue(Field.Index, ValueInteger); 249 SetValue(Field.Index, ValueInteger); 267 SetValueInteger(Field.Index, Source.GetValueInteger(Field.Index)); 250 268 end else 251 269 if Field.DataType = dtBoolean then begin 252 Source.GetValue(Field.Index, ValueBoolean); 253 SetValue(Field.Index, ValueBoolean); 254 end else 255 raise Exception.Create('Unsupported field value data type'); 270 SetValueBoolean(Field.Index, Source.GetValueBoolean(Field.Index)); 271 end else 272 if Field.DataType = dtEnumeration then begin 273 SetValueEnumeration(Field.Index, Source.GetValueEnumeration(Field.Index)); 274 end else 275 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 256 276 end; 257 277 258 278 procedure TItem.LoadValueFromNode(Node: TDOMNode; Field: TItemField); 259 var260 ValueString: string;261 ValueColor: TColor;262 ValueInteger: Integer;263 279 begin 264 280 if Field.DataType = dtString then begin 265 ValueString := ReadString(Node, Field.SysName, ''); 266 SetValue(Field.Index, ValueString); 281 SetValueString(Field.Index, ReadString(Node, Field.SysName, '')); 267 282 end else 268 283 if Field.DataType = dtColor then begin 269 ValueColor := ReadInteger(Node, Field.SysName, 0); 270 SetValue(Field.Index, ValueColor); 284 SetValueColor(Field.Index, ReadInteger(Node, Field.SysName, 0)); 271 285 end else 272 286 if Field.DataType = dtInteger then begin 273 ValueInteger := ReadInteger(Node, Field.SysName, 0); 274 SetValue(Field.Index, ValueInteger); 275 end else 276 raise Exception.Create('Unsupported field value data type'); 287 SetValueInteger(Field.Index, ReadInteger(Node, Field.SysName, 0)); 288 end else 289 if Field.DataType = dtBoolean then begin 290 SetValueBoolean(Field.Index, ReadBoolean(Node, Field.SysName, False)); 291 end else 292 if Field.DataType = dtEnumeration then begin 293 SetValueEnumeration(Field.Index, TUndefinedEnum(ReadInteger(Node, Field.SysName, 0))); 294 end else 295 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 277 296 end; 278 297 279 298 procedure TItem.SaveValueToNode(Node: TDOMNode; Field: TItemField); 280 var281 ValueString: string;282 ValueColor: TColor;283 ValueInteger: Integer;284 299 begin 285 300 if Field.DataType = dtString then begin 286 GetValue(Field.Index, ValueString); 287 WriteString(Node, Field.SysName, ValueString); 301 WriteString(Node, Field.SysName, GetValueString(Field.Index)); 288 302 end else 289 303 if Field.DataType = dtColor then begin 290 GetValue(Field.Index, ValueColor); 291 WriteInteger(Node, Field.SysName, ValueColor); 304 WriteInteger(Node, Field.SysName, GetValueColor(Field.Index)); 292 305 end else 293 306 if Field.DataType = dtInteger then begin 294 GetValue(Field.Index, ValueInteger); 295 WriteInteger(Node, Field.SysName, ValueInteger); 296 end else 297 raise Exception.Create('Unsupported field value data type'); 307 WriteInteger(Node, Field.SysName, GetValueInteger(Field.Index)); 308 end else 309 if Field.DataType = dtBoolean then begin 310 WriteBoolean(Node, Field.SysName, GetValueBoolean(Field.Index)); 311 end else 312 if Field.DataType = dtEnumeration then begin 313 WriteInteger(Node, Field.SysName, Integer(GetValueEnumeration(Field.Index))); 314 end else 315 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 298 316 end; 299 317 … … 319 337 procedure TItem.GetValue(Index: Integer; out Value); 320 338 begin 339 raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 321 340 end; 322 341 … … 341 360 end; 342 361 362 function TItem.GetValueEnumeration(Index: Integer): TUndefinedEnum; 363 begin 364 GetValue(Index, Result); 365 end; 366 343 367 function TItem.GetValueAsText(Index: Integer): string; 344 368 var 345 369 Fields: TItemFields; 346 ItemField: TItemField;370 Field: TItemField; 347 371 begin 348 372 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 373 Field := GetField(Fields.IndexOf(Fields.SearchByIndex(Index))); 374 if Field.DataType = dtInteger then Result := IntToStr(GetValueInteger(Index)) 375 else if Field.DataType = dtString then Result := GetValueString(Index) 376 else if Field.DataType = dtColor then Result := '' 377 else if Field.DataType = dtEnumeration then Result := Field.EnumStates[Integer(GetValueEnumeration(Index))] 378 else if Field.DataType = dtBoolean then begin 354 379 if GetValueBoolean(Index) then Result := SYes else Result := SNo; 355 end; 356 ItemField.Free; 380 end else 381 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 382 Field.Free; 357 383 Fields.Free; 358 384 end; … … 360 386 procedure TItem.SetValue(Index: Integer; var Value); 361 387 begin 388 raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 362 389 end; 363 390 … … 378 405 379 406 procedure TItem.SetValueBoolean(Index: Integer; Value: Boolean); 407 begin 408 SetValue(Index, Value); 409 end; 410 411 procedure TItem.SetValueEnumeration(Index: Integer; 412 Value: TUndefinedEnum); 380 413 begin 381 414 SetValue(Index, Value); -
trunk/UNation.pas
r290 r296 6 6 7 7 uses 8 Classes, SysUtils, DOM, UXMLUtils,Graphics, UItemList;8 Classes, SysUtils, Graphics, UItemList; 9 9 10 10 type … … 49 49 if Index = 1 then string(Value) := Name 50 50 else if Index = 2 then TColor(Value) := Color 51 else raise Exception.Create('Unsupported value index ' + IntToStr(Index));51 else inherited; 52 52 end; 53 53 … … 56 56 if Index = 1 then Name := string(Value) 57 57 else if Index = 2 then Color := TColor(Value) 58 else raise Exception.Create('Unsupported value index ' + IntToStr(Index));58 else inherited; 59 59 end; 60 60 -
trunk/UUnit.pas
r291 r296 115 115 else if Index = 6 then Integer(Value) := PowerDefense 116 116 else if Index = 7 then Integer(Value) := ViewRange 117 else raise Exception.Create('Unsupported value index ' + IntToStr(Index));117 else inherited; 118 118 end; 119 119 … … 127 127 else if Index = 6 then PowerDefense := Integer(Value) 128 128 else if Index = 7 then ViewRange := Integer(Value) 129 else raise Exception.Create('Unsupported value index ' + IntToStr(Index));129 else inherited; 130 130 end; 131 131
Note:
See TracChangeset
for help on using the changeset viewer.