comparison mde/gui/WidgetDataSet.d @ 137:9f035cd139c6

BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed. Content restrutured a lot: New IContent module, Content module includes more functionality. New ContentLoader module to manage content loading/saving/translation. Translation module moved to content dir and cut down to reflect current usage. File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen. Font render mode and LCD filter options are now enums. GUI loading needs to create content (and set type for enums), but doesn't save/load value. Some setup of mainSchedule moved to mde.mainLoop. Content callbacks are called on content change now. ContentLists are set up implicitly from content symbols. Not as fast but much easier! Bug-fix in the new MTTagReader. Renamed MT *Reader maker functions to avoid confusion in paths.d. New mde.setup.logger module to allow logger setup before any other module's static this().
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 07 Feb 2009 12:46:03 +0000
parents 41582439a42b
children 66c58e5b0062
comparison
equal deleted inserted replaced
136:4084f07f2c7a 137:9f035cd139c6
27 *************************************************************************************************/ 27 *************************************************************************************************/
28 module mde.gui.WidgetDataSet; 28 module mde.gui.WidgetDataSet;
29 29
30 public import mde.gui.types; 30 public import mde.gui.types;
31 import mde.content.AStringContent; 31 import mde.content.AStringContent;
32 import Items = mde.content.Items;
33 32
34 // For loading from file: 33 // For loading from file:
35 import mt = mde.file.mergetag.DataSet; 34 import mt = mde.file.mergetag.DataSet;
36 import mt = mde.file.mergetag.DefaultData; 35 import mt = mde.file.mergetag.DefaultData;
37 import mde.file.serialize; 36 import mde.file.serialize;
41 private Logger logger; 40 private Logger logger;
42 static this () { 41 static this () {
43 logger = Log.getLogger ("mde.gui.WidgetDataSet"); 42 logger = Log.getLogger ("mde.gui.WidgetDataSet");
44 } 43 }
45 44
46 /************************************************************************************************* 45 /******************************************************************************
47 * Contains data for all widgets in a GUI. 46 * Contains data for all widgets in a GUI.
48 *************************************************************************************************/ 47 *****************************************************************************/
49 class WidgetDataSet : mt.IDataSection 48 class WidgetDataSet : mt.IDataSection
50 { 49 {
51 //BEGIN Mergetag code 50 //BEGIN Mergetag code
52 void addTag (char[] tp, mt.ID id, char[] dt) { 51 void addTag (char[] tp, mt.ID id, char[] dt) {
53 // Priority is HIGH_LOW. Only load tag if it doesn't already exist. 52 // Priority is HIGH_LOW. Only load tag if it doesn't already exist.
54 if (tp == "WidgetData" && (id in widgetData) is null) { 53 if (tp == "WidgetData" && (id in widgetData) is null) {
55 widgetData[id] = deserialize!(WidgetData) (dt); 54 widgetData[id] = deserialize!(WidgetData) (dt);
56 } else if (tp == "WDims" && (id in dimData) is null) { 55 } else if (tp == "WDims" && (id in dimData) is null) {
57 dimData[id] = cast(wdims) deserialize!(int[]) (dt); 56 dimData[id] = cast(wdims) deserialize!(int[]) (dt);
58 } else if (tp == "EnumContent" && (id in enumContent) is null) { 57 } else if (tp == "EnumContent" && (id in Content.allContent) is null) {
59 // Add dynamic content. NOTE: could confict with content from another design/section. 58 // Add dynamic content.
60 EnumContent a = new EnumContent (id, deserialize!(EnumContent.EnumCStruct) (dt)); 59 new EnumContent (id, deserialize!(char[][]) (dt));
61 enumContent[id] = a;
62 Items.addContent (a);
63 } 60 }
64 } 61 }
65 // Only WidgetDataChanges is used for writing. 62 // Only WidgetDataChanges is used for writing.
66 void writeAll (ItemDelg dlg) {} 63 void writeAll (ItemDelg dlg) {}
67 //END Mergetag code 64 //END Mergetag code
83 } 80 }
84 81
85 protected: 82 protected:
86 WidgetData[widgetID] widgetData; // Per-widget data 83 WidgetData[widgetID] widgetData; // Per-widget data
87 wdims[widgetID] dimData; // Per-widget sizes 84 wdims[widgetID] dimData; // Per-widget sizes
88 EnumContent[char[]] enumContent;
89 } 85 }
90 86
91 /************************************************************************************************* 87 /*************************************************************************************************
92 * Contains changes to widget data. 88 * Contains changes to widget data.
93 * 89 *
110 void writeAll (ItemDelg dlg) { 106 void writeAll (ItemDelg dlg) {
111 foreach (id,data; widgetData) 107 foreach (id,data; widgetData)
112 dlg ("WidgetData", id, serialize!(WidgetData) (data)); 108 dlg ("WidgetData", id, serialize!(WidgetData) (data));
113 foreach (id,dim; dimData) 109 foreach (id,dim; dimData)
114 dlg ("WDims", id, serialize!(int[]) (cast(int[]) dim)); 110 dlg ("WDims", id, serialize!(int[]) (cast(int[]) dim));
115 foreach (id,c; base.enumContent)
116 dlg ("EnumContent", id, serialize (c.structOf));
117 } 111 }
118 //END Mergetag code 112 //END Mergetag code
119 113
120 /** Set the widget data for widget i. 114 /** Set the widget data for widget i.
121 */ 115 */
130 base.dimData[id] = d; 124 base.dimData[id] = d;
131 } 125 }
132 126
133 /** Do any changes exist? True if no changes have been stored. */ 127 /** Do any changes exist? True if no changes have been stored. */
134 bool noChanges () { 128 bool noChanges () {
135 return widgetData.length == 0 && dimData.length == 0 && enumContent.length == 0; 129 return widgetData.length == 0 && dimData.length == 0;
136 } 130 }
137 131
138 protected WidgetDataSet base; 132 protected WidgetDataSet base;
139 } 133 }