Accessory sorting due to price.
[scorched3d/parasti.git] / src / client / graph / OptionsDisplay.cpp
blob69d8d333f1bb2a305db4e347389475ac8be2fad4
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <graph/OptionsDisplay.h>
22 #include <common/Defines.h>
23 #include <stdio.h>
25 // This is a mirror of AccessoryStore::SortKey.
27 static OptionEntryEnum::EnumEntry accessorySortKeyEnum[] =
29 { "SortNothing", 0 },
30 { "SortName", 1 },
31 { "SortPrice", 2 },
32 { "", -1 }
35 OptionsDisplay *OptionsDisplay::instance_ = 0;
37 OptionsDisplay *OptionsDisplay::instance()
39 if (!instance_)
41 instance_ = new OptionsDisplay;
44 return instance_;
47 OptionsDisplay::OptionsDisplay() :
48 detailTexture_(options_, "DetailTexture",
49 "Use detail textures on the landscape."
50 "Adds the texture seen when very close to the landscape."
51 "Requires multi-texturing", RWAccess, true),
52 hideFinalScore_(options_, "HideFinalScore",
53 "Hide the score dialog that is automatically shown after shots", RWAccess | NoRestore, false),
54 depricatedUniqueUserId_(options_, "UniqueUserId",
55 "The unique string given by this client to any servers to uniquely identify itself."
56 "Used for server stats and logging (confidentially)", RAccess | OptionEntry::DataDepricated | NoRestore, ""),
57 hostDescription_(options_, "HostDescription",
58 "The description of this host given to any servers for stats.", RAccess | NoRestore, ""),
59 onlineUserIcon_(options_, "OnlineUserIcon",
60 "The players icon, must be PNG 32x32.", RAccess | NoRestore, ""),
61 buyTab_(options_, "BuyTab",
62 "The default buy tab", RWAccess | NoRestore, ""),
63 depricatedRoamVarianceStart_(options_, "RoamVarianceStart",
64 "The minimum variance to allow", RWAccess | OptionEntry::DataDepricated, 2),
65 depricatedRoamVarianceRamp_(options_, "RoamVarianceRamp",
66 "The variance ramping for each distance unit", RWAccess | OptionEntry::DataDepricated, 10),
67 depricatedRoamVarianceTank_(options_, "RoamVarianceTank",
68 "The variance difference for ROAM areas with tanks on them", RWAccess | OptionEntry::DataDepricated, 50),
69 onlineUserName_(options_, "OnlineUserName",
70 "The player name that will be used for all online games.", RAccess | NoRestore, "Player"),
71 onlineTankModel_(options_, "OnlineTankModel",
72 "The tank model that will be used for all online games.", RAccess | NoRestore, ""),
73 onlineColor_(options_, "OnlineColor",
74 "The tank color that will be used for all online (non-team) games.", RAccess | NoRestore, Vector::getNullVector(), true),
75 explosionParts_(options_, "ExplosionParts",
76 "How many explosion clouds are drawn", RAccess, 8, 0, 10, 1),
77 explosionSubParts_(options_, "ExplosionSubParts",
78 "How many explosion sub clouds are drawn", RAccess, 4, 0, 5, 1),
79 dialogSize_(options_, "DialogSize",
80 "How large the on screen dialogs and menus are.", RAccess, 2, 0, 3, 1),
81 tankModelSize_(options_, "TankModelSize",
82 "The percentage size of the tank models", RWAccess, 100),
83 depricatedMaxModelTriPercentage_(options_, "MaxModelTriPercentage",
84 "", RAccess | OptionEntry::DataDepricated, 100, 50, 100, 1),
85 explosionParticleMult_(options_, "ExplosionParticleMult",
86 "The number of particles that each explosion will create (relative to explosion size)", RAccess, 20, 0, 100, 10),
87 depricatedDayTime_(options_, "DayTime",
88 "", RWAccess | OptionEntry::DataDepricated, 2),
89 depricatedSunXYAng_(options_, "SunXYAng",
90 "", RAccess | OptionEntry::DataDepricated, 110),
91 depricatedSunYZAng_(options_, "SunYZAng",
92 "", RAccess | OptionEntry::DataDepricated, 25),
93 toolTipTime_(options_, "ToolTipTime",
94 "The milliseconds before showing a tool tip.", RWAccess, 100),
95 toolTipSpeed_(options_, "ToolTipSpeed",
96 "The speed at which a tool tip will fade in.", RWAccess, 6),
97 framesPerSecondLimit_(options_, "FramesPerSecondLimit",
98 "The maximum frame rate that the game will run at", RWAccess, 250),
99 brightness_(options_, "Brightness",
100 "The game screen brightness (gamma).", RAccess, 10, 3, 40, 1),
101 fullScreen_(options_, "FullScreen",
102 "Run the game in a full screen mode.", RAccess | NoRestore, (S3D::getOSDesc() == "Windows")),
103 moreRes_(options_, "MoreRes",
104 "Show more screen resolutions in the drop down. By default only hardware supported modes are shown.", RAccess, false),
105 depricatedFullClear_(options_, "FullClear",
106 "Completely clear the screen before drawing each frame", RWAccess | OptionEntry::DataDepricated, true),
107 invertElevation_(options_, "InvertUpDownKeys",
108 "Invert/reverse the tanks up/down elevation directions.", RWAccess | NoRestore, false),
109 invertMouse_(options_, "InvertMouse",
110 "Invert/reverse the mouses y-axis when rotating camera.", RWAccess | NoRestore, false),
111 saveWindowPositions_(options_, "SaveWindowPositions",
112 "Save the positions of all the onscreen windows.", RWAccess | NoRestore, true),
113 swapYAxis_(options_, "SwapYAxis",
114 "Remaps mouse pointer from top of window to the bottom and vice-versa (MAC/OSX)", RWAccess | NoRestore, false),
115 sideScroll_(options_, "SideScroll",
116 "Allows the user to scroll the viewport moving the mouse to the sides of the screen", RWAccess | NoRestore, true),
117 storePlayerCamera_(options_, "StorePlayerCamera",
118 "Stores the camera position for each player and resets to that position on thier turn", RWAccess | NoRestore, false),
119 drawPlayerNames_(options_, "DrawPlayerNames",
120 "Draw the names above the tanks", RWAccess, true),
121 drawPlayerIcons_(options_, "DrawPlayerIcons",
122 "Draw the icons above the tanks", RWAccess, true),
123 smoothLines_(options_, "SmoothLines",
124 "Smooth/AA the dialog lines", RWAccess, true),
125 drawPlayerSight_(options_, "DrawPlayerSight",
126 "Draw the aiming sight infront of the tanks", RWAccess, true),
127 depricatedDrawDistance_(options_, "DrawDistance",
128 "The distance at which objects will be culled", OptionEntry::DataDepricated, 160.0f),
129 depricatedDrawDistanceFade_(options_, "DrawDistanceFade",
130 "The distance before the draw distance at which objects will be faded", OptionEntry::DataDepricated, 100.0f),
131 drawCullingDistance_(options_, "DrawCullingDistance",
132 "The distance at which objects will be culled", RWAccess, 200.0f),
133 drawFadeStartDistance_(options_, "DrawFadeStartDistance",
134 "The distance before the draw distance at which objects will be faded", RWAccess, 180.0f),
135 oldSightPosition_(options_, "OldSightPosition",
136 "Draw the aiming sight aligned with the model and not the shot", RWAccess, false),
137 drawPlayerColor_(options_, "DrawPlayerColor",
138 "Draw the player color triangle over the tank", RWAccess, true),
139 drawPlayerHealth_(options_, "DrawPlayerHealth",
140 "Draw the health bars above the tank", RWAccess, true),
141 depricatedFirstTimePlayed_(options_, "FirstTimePlayed",
142 "Is this the first time the user has played Scorched3D", OptionEntry::DataDepricated, true),
143 lastVersionPlayed_(options_, "LastVersionPlayed",
144 "What was the last version of scorched3d played", RWAccess | NoRestore, ""),
145 hideMenus_(options_, "HideMenus",
146 "Should the menu title bars always be visible", RWAccess, false),
147 noGLTexSubImage_(options_, "NoGLTexSubImage",
148 "Do not use texture area replacing. Required to be able to scorch the ground.", RAccess, false),
149 noGLShaders_(options_, "NoGLShaders",
150 "Do not use shaders.", RAccess, false),
151 simpleWaterShaders_(options_, "SimpleWaterShaders",
152 "Use simple shaders for the water.", RAccess, false),
153 noPlanDraw_(options_, "NoPlanDraw",
154 "Do not show any drawings from other players on the plan window.", RWAccess, false),
155 noFog_(options_, "NoFog",
156 "Do not use any fog extensions.", RWAccess, false),
157 noGLExt_(options_, "NoGLExt",
158 "Do not use any OpenGL extensions. Turn off to disable any extra OpenGL features.", RAccess, false),
159 noGLMultiTex_(options_, "NoGLMultiTex",
160 "Only use one texture for all models and the landscape.", RAccess, false),
161 depricatedNoGLCompiledArrays_(options_, "NoGLCompiledArrays",
162 "Do not compile vertex arrays.", OptionEntry::DataDepricated, false),
163 noThreadedDraw_(options_, "NoThreadedDraw",
164 "Don't calculate landscape in another thread", RWAccess, false),
165 noGLEnvCombine_(options_, "NoGLEnvCombine",
166 "Only use one texture on the landscape.", RAccess, false),
167 noGLCubeMap_(options_, "NoGLCubeMap",
168 "Draw the water without using cubemap relfections.", RAccess, false),
169 noGLSphereMap_(options_, "NoGLSphereMap",
170 "Draw the water without using sphere map relfections.", RAccess, false),
171 noGLDrawElements_(options_, "NoGLDrawElements",
172 "Draw grids without using draw elements.", RWAccess, false),
173 noGLHardwareMipmaps_(options_, "NoGLHardwareMipmaps",
174 "Generate texture LOD in software only.", RAccess, false),
175 soundChannels_(options_, "SoundChannels",
176 "Number of sound channels to mix.", RAccess, 8),
177 noSound_(options_, "NoSound",
178 "Do not play any sound.", RWAccess, false),
179 noMusic_(options_, "NoMusic",
180 "Do not play any music.", RWAccess, false),
181 noProgressBackdrop_(options_, "NoProgressBackdrop",
182 "Do capture a screen shot and use it as the progress backdrop", RWAccess, false),
183 depricatedNoAmbientSound_(options_, "NoAmbientSound",
184 "Do not play any ambient sounds.", OptionEntry::DataDepricated, false),
185 depricatedNoBoidSound_(options_, "NoBoidSound",
186 "Do not play any sounds from boids.", OptionEntry::DataDepricated, false),
187 noShadows_(options_, "NoShadows",
188 "Do not draw real-time shadows.", RWAccess, false),
189 noGLShadows_(options_, "NoGLShadows",
190 "Do not draw GL shadow map shadows.", RAccess, false),
191 noGLObjectShadows_(options_, "NoGLObjectShadows",
192 "Do not draw GL shadow map shadows for objects (trees/tanks).", RWAccess, true),
193 noSimulateParticles_(options_, "NoParticleSimulate",
194 "Do not use custom simulations for the particles.", RWAccess, false),
195 noDrawParticles_(options_, "NoParticleDraw",
196 "Do not draw any particles.", RWAccess, false),
197 noTrees_(options_, "NoTrees",
198 "Do not draw any trees", RWAccess, false),
199 lowTreeDetail_(options_, "LowTreeDetail",
200 "Only use low detail trees. Faster.", RWAccess, false),
201 depricatedNoWaves_(options_, "NoWaves",
202 "Do not draw the moving shore waves.", OptionEntry::DataDepricated, false),
203 noDepthSorting_(options_, "NoDepthSorting",
204 "Do not depth sort sprites.", RWAccess, false),
205 clientLogToFile_(options_, "ClientLogToFile",
206 "Client logs to file", RAccess, false),
207 clientLogState_(options_, "ClientLogState",
208 "Client logs state (0 is off)", RAccess, 0),
209 validateServerIp_(options_, "ValidateServerIp",
210 "Checks if the server ip address matches the published address", RAccess, true),
211 drawLines_(options_, "DrawLines",
212 "Do not fill in the landscape", DebugOnly | RWAccess, false),
213 drawLandLOD_(options_, "DrawLandLOD",
214 "Show the LOD levels and indices of the land patches", DebugOnly | RWAccess, false),
215 drawNormals_(options_, "DrawNormals",
216 "Show landscape normals on the landscape", RWAccess, false),
217 drawGraphicalShadowMap_(options_, "DrawGraphicalShadowMap",
218 "Shows the depth map used for shadowing", RWAccess, false),
219 drawGraphicalReflectionMap_(options_, "DrawGraphicalReflectionMap",
220 "Shows the reflection map used for water reflections", RWAccess, false),
221 drawCollisionGeoms_(options_, "DrawCollisionGeoms",
222 "Show object collision geoms", DebugOnly | RWAccess, false),
223 drawCollisionSpace_(options_, "DrawCollisionSpace",
224 "Show object collision space", DebugOnly | RWAccess, false),
225 drawBoundingSpheres_(options_, "DrawBoundingSpheres",
226 "Show landscape bounding spheres on the landscape", DebugOnly | RWAccess, false),
227 depricatedDrawShipPaths_(options_, "DrawShipPaths",
228 "Show paths for the ships", OptionEntry::DataDepricated, false),
229 frameTimer_(options_, "FrameTimer",
230 "Show the current number of frames per second (FPS)", RWAccess | NoRestore, false),
231 noSkins_(options_,"NoTankSkins",
232 "Do not texture the tank models.", RAccess, false),
233 drawWater_(options_,"DrawWater",
234 "Draw the water", RWAccess, true),
235 drawLandscape_(options_, "DrawLandscape",
236 "Draw the landscape", DebugOnly | RWAccess, true),
237 drawSurround_(options_, "DrawSurround",
238 "Draw the surround", RWAccess, true),
239 drawMovement_(options_, "DrawMovement",
240 "Draw the movement paths", DebugOnly | RWAccess, false),
241 noWaterMovement_(options_, "NoWaterMovement",
242 "Draw simpler less detailed water", RWAccess, false),
243 noWaterReflections_(options_, "NoWaterReflections",
244 "Draw reflections in the water", RWAccess, false),
245 noWaterWaves_(options_, "NoWaterWaves",
246 "Draw water waves (breakers)", RWAccess, false),
247 noWaterLOD_(options_, "NoWaterLOD",
248 "Draw water at minimum detail", RWAccess, false),
249 noLandLOD_(options_, "NoLandLOD",
250 "Draw water at MAXIMUM detail", RWAccess, false),
251 noSkyLayers_(options_, "NoSkyLayers",
252 "Only draw one sky layer.", RWAccess, false),
253 noSkyMovement_(options_, "NoSkyMovement",
254 "Do not animate the sky", RWAccess, false),
255 depricatedNoROAM_(options_, "NoROAM",
256 "Do not use ROAM algorithm", RWAccess | OptionEntry::DataDepricated, false),
257 depricatedNoBOIDS_(options_,"NoBOIDS",
258 "Do not use BOIDS", OptionEntry::DataDepricated, false),
259 depricatedNoShips_(options_,"NoShips",
260 "Do not use ships", OptionEntry::DataDepricated, false),
261 noPrecipitation_(options_, "NoPrecipitation",
262 "Do not draw precipitation", RWAccess, false),
263 depricatedNoTessalation_(options_,"NoTessalation",
264 "Do not use ROAM tessalation algorithm", OptionEntry::DataDepricated, false),
265 noVBO_(options_,"NoVBO",
266 "Do not use Vertex Buffer Objects (if avaialable)", RWAccess, false),
267 depricatedMoWaterBuffers_(options_, "NoWaterBuffers",
268 "Do not use Vertex Buffers for water (if avaialable)", RAccess | OptionEntry::DataDepricated, false),
269 depricatedNoCg_(options_,"NoCg",
270 "Do not use vertex or pixel shaders (if avaialable)", RWAccess | OptionEntry::DataDepricated, true),
271 noModelLOD_(options_, "NoModelLOD",
272 "Do not use LOD optimizations for models", RWAccess, true),
273 noModelLighting_(options_, "NoModelLighting",
274 "Do not use dynamic lighting calculations for models", RWAccess, false),
275 useLandscapeTexture_(options_, "LandscapeTexture",
276 "Texture the landscape", RWAccess, true),
277 useWaterTexture_(options_, "WaterTexture",
278 "Texture the water", RWAccess, true),
279 noLenseFlare_(options_,"NoLenseFlare",
280 "Do not show the full lense flare effect", RWAccess, true),
281 softwareMouse_(options_,"SoftwareMouse",
282 "Use a software mouse pointer. Useful if mouse clicks are not aligned.", RWAccess, false),
283 depricatedUseHex_(options_,"UseHexidecimal",
284 "Show the tank angles and amounts in hex", RWAccess | OptionEntry::DataDepricated, false),
285 soundVolume_(options_, "SoundVolume",
286 "The master volume. Max = 128, Min = 0", RAccess | NoRestore, 128, 0, 128, 1),
287 ambientSoundVolume_(options_, "AmbientSoundVolume",
288 "The ambient sound effect volume. Max = 128, Min = 0", RAccess | NoRestore, 128, 0, 128, 1),
289 musicVolume_(options_, "MusicVolume",
290 "The music effect volume. Max = 128, Min = 0", RAccess | NoRestore, 128, 0, 128, 1),
291 antiAlias_(options_, "AntiAlias",
292 "Use anti aliasing", RAccess, 0, 0, 4, 1),
293 texSize_(options_, "TexureSize",
294 "The texture details setting. Lower is faster.", RAccess, 1, 0, 2, 1),
295 bannerRowsDepricated_(options_, "BannerRows",
296 "", RAccess | OptionEntry::DataDepricated, 6),
297 tankDetail_(options_, "TankDetail",
298 "The tank details setting. Lower is faster but shows less tank models.", RAccess, 2, 0, 2, 1),
299 effectsDetail_(options_, "EffectsDetail",
300 "The number of effects allowed at once.", RAccess, 1, 0, 2, 1),
301 screenWidth_(options_, "ScreenWidth",
302 "The window width to use (in pixels)", RAccess, 800),
303 screenHeight_(options_, "ScreenHeight",
304 "The window height to use (in pixels)", RAccess, 600),
305 depthBufferBits_(options_, "DepthBufferBits",
306 "The number of bits requested for the depth buffer", RAccess, 24),
307 doubleBuffer_(options_, "DoubleBuffer",
308 "Use double buffering", RAccess, true),
309 colorComponentSize_(options_, "ColorComponentSize",
310 "The number of bits to use for each of the RGBA components (0 = use default)", RAccess, 0),
311 bitsPerPixel_(options_, "BitsPerPixel",
312 "The number of bits per pixel to use for the display (0 = current display bbp)", RAccess, 0),
313 showContextHelp_(options_, "ShowContextHelp",
314 "Show in game help tooltips for items that have it", RWAccess, true),
315 showContextInfo_(options_, "ShowContextInfo",
316 "Show in game information tooltips for items that have it", RWAccess, true),
317 deprecatedSortAccessories_(options_, "SortAccessories",
318 "Sort accessories alphabetically by name before displaying",
319 RWAccess | OptionEntry::DataDepricated, false),
320 accessorySortKey_(options_, "AccessorySortKey",
321 "The key to sort accessories by before displaying",
322 RWAccess, 0, accessorySortKeyEnum),
323 focusPause_(options_, "FocusPause",
324 "Pause the graphics display when mouse leaves window.", RWAccess, true)
329 OptionsDisplay::~OptionsDisplay()
333 bool OptionsDisplay::writeOptionsToFile()
335 std::string path = S3D::getSettingsFile("display.xml");
337 // Check the options files are writeable
338 FILE *checkfile = fopen(path.c_str(), "a");
339 if (!checkfile)
341 S3D::dialogMessage(
342 "Scorched3D", S3D::formatStringBuffer(
343 "Warning: Your display settings file (%s) cannot be\n"
344 "written to. Your settings will not be saved from one game to the next.\n\n"
345 "To fix this problem correct the permissions for this file.",
346 path.c_str()));
348 else fclose(checkfile);
350 if (!OptionEntryHelper::writeToFile(options_, path)) return false;
351 return true;
354 bool OptionsDisplay::readOptionsFromFile()
356 std::string path = S3D::getSettingsFile("display.xml");
358 if (!OptionEntryHelper::readFromFile(options_, path))
360 S3D::dialogMessage(
361 "Scorched3D", S3D::formatStringBuffer(
362 "Warning: Your display settings file (%s) cannot be\n"
363 "read. This may be because it was create by an out of date version of Scorched3D.\n"
364 "If this is the case it can be safely deleted.",
365 path.c_str()));
366 return false;
369 return true;
372 void OptionsDisplay::loadDefaultValues()
374 std::list<OptionEntry *>::iterator itor;
375 for (itor = options_.begin();
376 itor != options_.end();
377 itor++)
379 OptionEntry *entry = (*itor);
380 if (!(entry->getData() & NoRestore))
382 entry->setValueFromString(entry->getDefaultValueAsString());
387 void OptionsDisplay::loadSafeValues()
389 std::string path = S3D::getDataFile("data/safedisplay.xml");
390 OptionEntryHelper::readFromFile(options_, path);
393 void OptionsDisplay::loadMediumValues()
395 std::string path = S3D::getDataFile("data/mediumdisplay.xml");
396 OptionEntryHelper::readFromFile(options_, path);
399 void OptionsDisplay::loadFastestValues()
401 std::string path = S3D::getDataFile("data/fastestdisplay.xml");
402 OptionEntryHelper::readFromFile(options_, path);