Ticket #3737: optionsDependances.patch
File optionsDependances.patch, 9.1 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/options/options.js
1 var g_ hasCallback = false;2 var g_ controls;1 var g_HasCallback = false; 2 var g_Controls; 3 3 4 4 function init(data) 5 5 { 6 6 if (data && data.callback) 7 g_ hasCallback = true;7 g_HasCallback = true; 8 8 let revert = data && data.revert; 9 g_ controls = [];9 g_Controls = {}; 10 10 11 11 var options = Engine.ReadJSONFile("gui/options/options.json"); 12 12 for (let category of Object.keys(options)) … … 15 15 for (let i = 0; i < options[category].length; ++i) 16 16 { 17 17 let option = options[category][i]; 18 if (!option.label )18 if (!option.label || !option.parameters || !option.parameters.config) 19 19 continue; 20 20 let body = Engine.GetGUIObjectByName(category + "[" + i + "]"); 21 21 let label = Engine.GetGUIObjectByName(category + "Label[" + i + "]"); 22 setupControl(option, i, category, revert); 22 let config = option.parameters.config; 23 g_Controls[config] = { "control": setupControl(option, i, category, revert), "type": option.type }; 24 if (option.dependencies) 25 g_Controls[config].dependencies = option.dependencies; 23 26 label.caption = translate(option.label); 24 27 label.tooltip = option.tooltip ? translate(option.tooltip) : ""; 25 28 // Move each element to the correct place. 26 if ( i > 0)29 if (lastSize) 27 30 { 28 31 let newSize = new GUISize(); 29 32 newSize.left = lastSize.left; … … 35 38 } 36 39 else 37 40 lastSize = body.size; 41 // small right shift of options which depends on another one 42 for (let opt of options[category]) 43 { 44 if (!opt.label || !opt.parameters || !opt.parameters.config) 45 continue; 46 if (!opt.dependencies || opt.dependencies.indexOf(config) === -1) 47 continue; 48 label.caption = " " + label.caption; 49 break; 50 } 38 51 // Show element. 39 52 body.hidden = false; 40 53 } 41 54 } 42 55 56 updateDependencies(); 43 57 if (!revert) 44 58 updateStatus(); 45 59 } … … 58 72 switch (option.type) 59 73 { 60 74 case "boolean": 75 case "antiboolean": 61 76 // More space for the label 62 77 let text = Engine.GetGUIObjectByName(category + "Label[" + i + "]"); 63 78 let size = text.size; … … 78 93 if (checked === undefined || revert) 79 94 checked = Engine.ConfigDB_GetValue("user", keyConfig) === "true"; 80 95 else if ((Engine.ConfigDB_GetValue("user", keyConfig) === "true") !== checked) 96 { 81 97 Engine.ConfigDB_CreateValue("user", keyConfig, String(checked)); 98 updateStatus(true); 99 } 82 100 break; 83 101 case "renderer": 84 102 keyRenderer = option.parameters.renderer; … … 97 115 warn("Unknown option source type '" + param + "'"); 98 116 } 99 117 } 118 // antiboolean when we want to display the opposite of the flag value 119 var anti = false; 120 if (option.type === "antiboolean") 121 { 122 anti = true; 123 checked = !checked; 124 } 100 125 101 onUpdate = function(keyRenderer, keyConfig )126 onUpdate = function(keyRenderer, keyConfig, anti) 102 127 { 103 128 return function() 104 129 { 130 let val = anti ? !this.checked : this.checked; 105 131 if (keyRenderer) 106 Engine["Renderer_Set" + keyRenderer + "Enabled"]( this.checked);132 Engine["Renderer_Set" + keyRenderer + "Enabled"](val); 107 133 if (keyConfig) 108 Engine.ConfigDB_CreateValue("user", keyConfig, String(this.checked)); 134 Engine.ConfigDB_CreateValue("user", keyConfig, String(val)); 135 updateDependencies(); 109 136 updateStatus(true); 110 137 }; 111 }(keyRenderer, keyConfig );138 }(keyRenderer, keyConfig, anti); 112 139 113 140 // Load final data to the control element. 114 141 control.checked = checked; … … 143 170 maxval = option.parameters.max; 144 171 break; 145 172 default: 146 warn("Unknown option source type '" + action+ "'");173 warn("Unknown option source type '" + param + "'"); 147 174 } 148 175 } 149 176 … … 164 191 Engine.ConfigDB_CreateValue("user", key, this.caption); 165 192 if (functionBody) 166 193 Engine[functionBody](+this.caption); 194 updateDependencies(); 167 195 updateStatus(true); 168 196 }; 169 197 }(key, functionBody, minval, maxval); … … 171 199 control.caption = caption; 172 200 control.onPress = onUpdate; 173 201 control.onMouseLeave = onUpdate; 174 g_controls.push(control);175 202 break; 176 203 case "dropdown": 177 204 control = Engine.GetGUIObjectByName(category + "Dropdown[" + i + "]"); … … 199 226 control.list_data = option.parameters.list_data; 200 227 break; 201 228 default: 202 warn("Unknown option source type '" + action+ "'");229 warn("Unknown option source type '" + param + "'"); 203 230 } 204 231 } 205 232 … … 211 238 if (key === "materialmgr.quality") 212 239 val = val == 0 ? 2 : val == 1 ? 5 : 8; 213 240 Engine.ConfigDB_CreateValue("user", key, val); 241 updateDependencies(); 214 242 updateStatus(true); 215 243 }; 216 244 }(key); … … 243 271 */ 244 272 function registerChanges() 245 273 { 246 for (let control of g_controls) 247 control.onPress(); 274 for (let item in g_Controls) 275 if (g_Controls[item].type === "number" || g_Controls[item].type === "string") 276 g_Controls[item].control.onPress(); 248 277 } 249 278 279 function updateDependencies() 280 { 281 for (let item in g_Controls) 282 { 283 let control = g_Controls[item]; 284 if (control.type !== "boolean" && control.type !== "antiboolean" || !control.dependencies) 285 continue; 286 for (let dependency of control.dependencies) 287 g_Controls[dependency].control.enabled = control.control.checked; 288 } 289 } 290 250 291 function revertChanges() 251 292 { 252 293 Engine.ConfigDB_Reload("user"); … … 280 321 281 322 function closePageWithoutConfirmation() 282 323 { 283 if (g_ hasCallback)324 if (g_HasCallback) 284 325 Engine.PopGuiPageCB(); 285 326 else 286 327 Engine.PopGuiPage(); -
binaries/data/mods/public/gui/options/options.json
71 71 "parameters": { "renderer": "Postproc", "config": "postproc" } 72 72 }, 73 73 { 74 "type": "dropdown", 75 "label": "Graphics quality", 76 "tooltip": "Graphics quality. REQUIRES GAME RESTART", 77 "parameters": { "list": [ "Low", "Medium", "High" ], "config": "materialmgr.quality" } 78 }, 79 { 74 80 "type": "boolean", 75 81 "label": "Shadows", 76 82 "tooltip": "Enable shadows", 77 "parameters": { "renderer": "Shadows", "config": "shadows"} 83 "parameters": { "renderer": "Shadows", "config": "shadows"}, 84 "dependencies": [ "shadowpcf" ] 78 85 }, 79 86 { 80 87 "type": "boolean", 81 "label": " Particles",82 "tooltip": " Enable particles",83 "parameters": { "renderer": " Particles", "config": "particles" }88 "label": "Shadow Filtering", 89 "tooltip": "Smooth shadows", 90 "parameters": { "renderer": "ShadowPCF", "config": "shadowpcf" } 84 91 }, 85 92 { 86 93 "type": "boolean", 87 "label": "Show Sky",88 "tooltip": "Render Sky",89 "parameters": { "renderer": "ShowSky", "config": "showsky" }90 },91 {92 "type": "boolean",93 "label": "Smooth LOS",94 "tooltip": "Lift darkness and fog-of-war smoothly",95 "parameters": { "renderer": "SmoothLOS", "config": "smoothlos" }96 },97 {98 "type": "boolean",99 94 "label": "Unit Silhouettes", 100 95 "tooltip": "Show outlines of units behind buildings", 101 96 "parameters": { "renderer": "Silhouettes", "config": "silhouettes" } … … 102 97 }, 103 98 { 104 99 "type": "boolean", 105 "label": " Shadow Filtering",106 "tooltip": " Smooth shadows",107 "parameters": { "renderer": " ShadowPCF", "config": "shadowpcf" }100 "label": "Particles", 101 "tooltip": "Enable particles", 102 "parameters": { "renderer": "Particles", "config": "particles" } 108 103 }, 109 104 { 110 "type": "boolean", 111 "label": "Fast & Ugly Water", 112 "tooltip": "Use the lowest settings possible to render water. This makes other settings irrelevant.", 113 "parameters": { "renderer": "WaterUgly", "config": "waterugly" } 105 "type": "antiboolean", 106 "label": "Activate water effects", 107 "tooltip": "When OFF, use the lowest settings possible to render water. This makes other settings irrelevant.", 108 "parameters": { "renderer": "WaterUgly", "config": "waterugly" }, 109 "dependencies": [ "waterfancyeffects", "waterrealdepth", "waterreflection", "waterrefraction", "watershadows" ] 114 110 }, 115 111 { 116 112 "type": "boolean", … … 144 140 }, 145 141 { 146 142 "type": "boolean", 143 "label": "Smooth LOS", 144 "tooltip": "Lift darkness and fog-of-war smoothly", 145 "parameters": { "renderer": "SmoothLOS", "config": "smoothlos" } 146 }, 147 { 148 "type": "boolean", 149 "label": "Show Sky", 150 "tooltip": "Render Sky", 151 "parameters": { "renderer": "ShowSky", "config": "showsky" } 152 }, 153 { 154 "type": "boolean", 147 155 "label": "VSync", 148 156 "tooltip": "Run vertical sync to fix screen tearing. REQUIRES GAME RESTART", 149 157 "parameters": { "config": "vsync" } … … 153 161 "label": "Limit FPS in Menus", 154 162 "tooltip": "Limit FPS to 50 in all menus, to save power.", 155 163 "parameters": { "config": "gui.menu.limitfps" } 156 },157 {158 "type": "dropdown",159 "label": "Graphics quality",160 "tooltip": "Graphics quality. REQUIRES GAME RESTART",161 "parameters": { "list": [ "Low", "Medium", "High" ], "config": "materialmgr.quality" }162 163 164 } 164 165 ], 165 166 "soundSetting":