Settings.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. /******************************************************************************/
  4. TextData Settings;
  5. /******************************************************************************/
  6. bool SaveSettings(C Str &name)
  7. {
  8. TextData data;
  9. TextNode &main=data.getNode("Main");
  10. {
  11. main.getNode("ProjectsPath" ).value=RelativePath(ProjectsPath);
  12. main.getNode("ServerAddress" ).value=Projs.server();
  13. main.getNode("Email" ).value=Projs.email ();
  14. main.getNode("NetworkInterface").value=Projs.editor_network_interface();
  15. TextNode &pl=main.getNode("ProjectList");
  16. {
  17. pl.getNode( "ChildrenFileSize" ).value=Proj.list.ics;
  18. pl.getNode( "TextureFileSize" ).value=Proj.list.its;
  19. pl.getNode( "TextureFileSizeInOjects").value=Proj.list.include_texture_size_in_object;
  20. pl.getNode("UnpublishedFileSize" ).value=Proj.list.include_unpublished_elm_size;
  21. }
  22. TextNode &fp=main.getNode("FilePaths");
  23. {
  24. TextNode &favorite=fp.getNode("Favorite"); FREPA(WindowIOFavorites)favorite.nodes.New().set("Path", WindowIOFavorites[i]);
  25. TextNode &recent =fp.getNode("Recent" ); FREPA(WindowIORecents )recent .nodes.New().set("Path", WindowIORecents [i]);
  26. }
  27. }
  28. TextNode &store=data.getNode("Store");
  29. {
  30. store.getNode("Email").value=AppStore.login.email();
  31. }
  32. TextNode &object=data.getNode("Object");
  33. {
  34. TextNode &general=object.getNode("General");
  35. general.nodes.New().set("ActiveViewport" , ObjEdit.v4.sel());
  36. general.nodes.New().set("CameraMoveMode" , ObjEdit.v4. moveMode());
  37. general.nodes.New().set("CameraOrientation", ObjEdit.v4.orientMode());
  38. general.nodes.New().set("CameraZoom" , ObjEdit.v4. drawZoom());
  39. }
  40. TextNode &anim=data.getNode("Animation");
  41. {
  42. TextNode &general=anim.getNode("General");
  43. general.nodes.New().set("ActiveViewport" , AnimEdit.v4.sel());
  44. general.nodes.New().set("CameraMoveMode" , AnimEdit.v4. moveMode());
  45. general.nodes.New().set("CameraOrientation", AnimEdit.v4.orientMode());
  46. general.nodes.New().set("CameraZoom" , AnimEdit.v4. drawZoom());
  47. }
  48. TextNode &world=data.getNode("World");
  49. {
  50. TextNode &brush=world.getNode("Brush");
  51. brush.nodes.New().set("SizeProportional", Brush.bsize());
  52. brush.nodes.New().set("Image" , RelativePath(Brush.image_name));
  53. TextNode &colors=world.getNode("Colors");
  54. FREPA(ColorBrush.col)colors.nodes.New().set("Color", ColorBrush.col[i].col);
  55. TextNode &general=world.getNode("General");
  56. //general.nodes.New().set("CursorCollidesWithHeightmaps", MainMenu("WE Edit/Cursor Collides with Heightmaps"));
  57. //general.nodes.New().set("CursorCollidesWithObjects" , MainMenu("WE Edit/Cursor Collides with Objects"));
  58. general.nodes.New().set("VisibleRadius" , WorldEdit.visibleRadius());
  59. general.nodes.New().set("ActiveViewport" , WorldEdit.v4.sel());
  60. general.nodes.New().set("CameraMoveMode" , WorldEdit.v4. moveMode());
  61. general.nodes.New().set("CameraOrientation" , WorldEdit.v4.orientMode());
  62. general.nodes.New().set("CameraZoom" , WorldEdit.v4. drawZoom());
  63. general.nodes.New().set("CameraSpherical" , WorldEdit.cam_spherical());
  64. general.nodes.New().set("CameraFppSpeed" , WorldEdit.fpp_speed());
  65. }
  66. TextNode &code=data.getNode("Code");
  67. CodeEdit.saveSettings(code);
  68. TextNode &video=data.getNode("Video");
  69. {
  70. video.nodes.New().set("ScreenX" , D.resW());
  71. video.nodes.New().set("ScreenY" , D.resH());
  72. video.nodes.New().set("Fullscreen" , D.full());
  73. video.nodes.New().set("Exclusive" , D.exclusive());
  74. video.nodes.New().set("Synchronization" , D.sync());
  75. video.nodes.New().set("Renderer" , Renderer.type());
  76. video.nodes.New().set("EdgeSoftening" , D.edgeSoften());
  77. video.nodes.New().set("Shadows" , D.shadowMode()==SHADOW_MAP);
  78. video.nodes.New().set("ShadowMapSize" , D.shadowMapSize());
  79. video.nodes.New().set("ShadowMapNum" , D.shadowMapNum());
  80. video.nodes.New().set("ShadowSoft" , D.shadowSoft());
  81. video.nodes.New().set("ShadowJitter" , D.shadowJitter());
  82. video.nodes.New().set("ShadowReduceFlicker" , D.shadowReduceFlicker());
  83. video.nodes.New().set("ShadowRangeFraction" , D.shadowFrac());
  84. video.nodes.New().set("ShadowFadeFraction" , D.shadowFade());
  85. video.nodes.New().set("BumpMapping" , D.bumpMode());
  86. video.nodes.New().set("MotionBlur" , D.motionMode());
  87. video.nodes.New().set("BloomSaturate" , DefaultEnvironment.bloom.saturate);
  88. video.nodes.New().set("AmbientLight" , DefaultEnvironment.ambient.color.max());
  89. video.nodes.New().set("AmbientOcclusion" , D.ambientMode());
  90. video.nodes.New().set("AmbientOcclusionRange" , D.ambientRange().x);
  91. video.nodes.New().set("AmbientOcclusionContrast", D.ambientContrast());
  92. video.nodes.New().set("EyeAdaptation" , D.eyeAdaptation());
  93. video.nodes.New().set("EyeAdaptationBrightness" , D.eyeAdaptationBrightness());
  94. video.nodes.New().set("MonitorPrecision" , D.monitorPrecision());
  95. video.nodes.New().set("Dither" , D.dither());
  96. video.nodes.New().set("ColRTPrecision" , D.highPrecColRT ());
  97. video.nodes.New().set("NrmCalcPrecision" , D.highPrecNrmCalc ());
  98. video.nodes.New().set("NrmRTPrecision" , D.highPrecNrmRT ());
  99. video.nodes.New().set("LumRTPrecision" , D.highPrecLumRT ());
  100. video.nodes.New().set("LitColRTPrecision" , D.litColRTPrecision());
  101. video.nodes.New().set("GuiScale" , VidOpt.scale);
  102. video.nodes.New().set("GuiScaleWin" , VidOpt.scale_win);
  103. video.nodes.New().set("GuiSkin" , VidOpt.skinName());
  104. video.nodes.New().set("FieldOfView" , RadToDeg(VidOpt.advanced.fov));
  105. video.nodes.New().set("TextureFiltering" , D.texFilter());
  106. video.nodes.New().set("TextureMipFiltering" , D.texMipFilter());
  107. video.nodes.New().set("DetailTexture" , D.texDetail());
  108. video.nodes.New().set("Samples" , D.samples());
  109. video.nodes.New().set("Density" , D.density());
  110. video.nodes.New().set("DensityFilter" , VidOpt.advanced.DensityFilter(VidOpt.advanced));
  111. video.nodes.New().set("SoftParticles" , D.particlesSoft());
  112. video.nodes.New().set("GrassRange" , D.grassRange());
  113. video.nodes.New().set("MaxLights" , D.maxLights());
  114. video.nodes.New().set("EdgeDetect" , D.edgeDetect());
  115. video.nodes.New().set("AllowGlow" , D.glowAllow());
  116. video.nodes.New().set("SimpleRendererPerPixel" , Renderer.simplePrecision());
  117. video.nodes.New().set("MaterialBlendPerPixel" , D.materialBlend());
  118. }
  119. TextNode &theater=data.getNode("Theater");
  120. SaveProperties(Theater.options.props, theater.nodes);
  121. if(TextNode *env=theater.findNode("Environment"))theater.nodes.removeData(env, true); // don't store project element
  122. theater.nodes.New().set("Mode", Theater.mode());
  123. return data.save(name);
  124. }
  125. /******************************************************************************/
  126. bool LoadSettings(C Str &name)
  127. {
  128. return Settings.load(name);
  129. }
  130. void ApplyVideoSettings(C TextData &data)
  131. {
  132. if(C TextNode *video=data.findNode("Video"))
  133. {
  134. int x=-1, y=-1, full=-1;
  135. if(C TextParam *p=video->findNode("ScreenX" ))x=p->asInt();
  136. if(C TextParam *p=video->findNode("ScreenY" ))y=p->asInt();
  137. if(C TextParam *p=video->findNode("Fullscreen" ))full=p->asBool();
  138. if(C TextParam *p=video->findNode("Exclusive" ))D.exclusive(p->asBool());
  139. if(C TextParam *p=video->findNode("Synchronization" ))D.sync(p->asBool());
  140. if(C TextParam *p=video->findNode("Renderer" ))Renderer.type(RENDER_TYPE(p->asInt()));
  141. if(C TextParam *p=video->findNode("EdgeSoftening" ))D.edgeSoften(EDGE_SOFTEN_MODE(p->asInt()));
  142. if(C TextParam *p=video->findNode("Shadows" ))D.shadowMode(p->asBool() ? SHADOW_MAP : SHADOW_NONE);
  143. if(C TextParam *p=video->findNode("ShadowMapSize" ))D.shadowMapSize(p->asInt());
  144. if(C TextParam *p=video->findNode("ShadowMapNum" ))D.shadowMapNum(p->asInt());
  145. if(C TextParam *p=video->findNode("ShadowSoft" ))D.shadowSoft(p->asInt());
  146. if(C TextParam *p=video->findNode("ShadowJitter" ))D.shadowJitter(p->asBool());
  147. if(C TextParam *p=video->findNode("ShadowReduceFlicker" ))D.shadowReduceFlicker(p->asBool());
  148. if(C TextParam *p=video->findNode("ShadowRangeFraction" ))D.shadowFrac(p->asFlt());
  149. if(C TextParam *p=video->findNode("ShadowFadeFraction" ))D.shadowFade(p->asFlt());
  150. if(C TextParam *p=video->findNode("BumpMapping" ))D.bumpMode(BUMP_MODE(p->asInt()));
  151. if(C TextParam *p=video->findNode("MotionBlur" ))D.motionMode(MOTION_MODE(p->asInt()));
  152. if(C TextParam *p=video->findNode("AmbientOcclusion" ))D.ambientMode (AMBIENT_MODE(p->asInt()));
  153. if(C TextParam *p=video->findNode("AmbientOcclusionRange" ))D.ambientRange (p->asFlt());
  154. if(C TextParam *p=video->findNode("AmbientOcclusionContrast"))D.ambientContrast(p->asFlt());
  155. if(C TextParam *p=video->findNode("EyeAdaptation" ))D.eyeAdaptation(p->asBool());
  156. if(C TextParam *p=video->findNode("EyeAdaptationBrightness" ))D.eyeAdaptationBrightness(p->asFlt());
  157. if(C TextParam *p=video->findNode("MonitorPrecision" ))D.monitorPrecision(IMAGE_PRECISION(p->asInt()));
  158. if(C TextParam *p=video->findNode("Dither" ))D.dither(p->asBool());
  159. if(C TextParam *p=video->findNode("ColRTPrecision" ))D.highPrecColRT (p->asBool());
  160. if(C TextParam *p=video->findNode("NrmCalcPrecision" ))D.highPrecNrmCalc (p->asBool());
  161. if(C TextParam *p=video->findNode("NrmRTPrecision" ))D.highPrecNrmRT (p->asBool());
  162. if(C TextParam *p=video->findNode("LumRTPrecision" ))D.highPrecLumRT (p->asBool());
  163. if(C TextParam *p=video->findNode("LitColRTPrecision" ))D.litColRTPrecision(IMAGE_PRECISION(p->asInt()));
  164. if(C TextParam *p=video->findNode("FieldOfView" ))VidOpt.advanced.setFov(DegToRad(p->asFlt()));
  165. if(C TextParam *p=video->findNode("TextureFiltering" ))D.texFilter(p->asInt());
  166. if(C TextParam *p=video->findNode("TextureMipFiltering" ))D.texMipFilter(p->asBool());
  167. if(C TextParam *p=video->findNode("DetailTexture" ))D.texDetail(TEXTURE_USAGE(p->asInt()));
  168. if(C TextParam *p=video->findNode("Samples" ))D.samples(p->asInt());
  169. if(C TextParam *p=video->findNode("Density" ))D.density(p->asFlt());
  170. if(C TextParam *p=video->findNode("DensityFilter" ))VidOpt.advanced.DensityFilter(VidOpt.advanced, p->asText());
  171. if(C TextParam *p=video->findNode("SoftParticles" ))D.particlesSoft(p->asBool());
  172. if(C TextParam *p=video->findNode("GrassRange" ))D.grassRange(p->asFlt());
  173. if(C TextParam *p=video->findNode("MaxLights" ))D.maxLights(p->asInt());
  174. if(C TextParam *p=video->findNode("EdgeDetect" ))D.edgeDetect(EDGE_DETECT_MODE(p->asInt()));
  175. if(C TextParam *p=video->findNode("AllowGlow" ))D.glowAllow(p->asBool());
  176. if(C TextParam *p=video->findNode("SimpleRendererPerPixel" ))Renderer.simplePrecision(p->asBool());
  177. if(C TextParam *p=video->findNode("MaterialBlendPerPixel" ))D.materialBlend(p->asBool());
  178. D.mode(x, y, full);
  179. // following needs to be called after setting resolution
  180. if(C TextParam *p=video->findNode("GuiScale" ))VidOpt.setScale (p->asFlt ());
  181. if(C TextParam *p=video->findNode("GuiScaleWin"))VidOpt.setScaleWin(p->asBool());
  182. }
  183. }
  184. void ApplySettings(C TextData &data)
  185. {
  186. if(C TextNode *main=data.findNode("Main"))
  187. {
  188. if(C TextParam *p=main->findNode("ProjectsPath" ))Projs.proj_path.set(MakeFullPath(p->value));
  189. if(C TextParam *p=main->findNode("ServerAddress" ))Projs.server .set(p->value);
  190. if(C TextParam *p=main->findNode("Email" ))Projs.email .set(p->value);
  191. if(C TextParam *p=main->findNode("NetworkInterface" ))Projs.editor_network_interface.set(p->asBool(), QUIET);
  192. if(C TextNode *pl=main->findNode("ProjectList"))
  193. {
  194. if(C TextParam *p=pl->findNode( "ChildrenFileSize" ))Proj.includeChildrenSize (ProjectEx::ElmList::INCLUDE_CHILDREN_SIZE(p->asInt()));
  195. if(C TextParam *p=pl->findNode( "TextureFileSize" ))Proj.includeTextureSize (ProjectEx::ElmList::INCLUDE_TEXTURE_SIZE (p->asInt()));
  196. if(C TextParam *p=pl->findNode( "TextureFileSizeInOjects"))Proj.includeTextureSizeInObject(p->asBool());
  197. if(C TextParam *p=pl->findNode("UnpublishedFileSize" ))Proj.includeUnpublishedElmSize (p->asBool());
  198. }
  199. if(C TextNode *fp=main->findNode("FilePaths"))
  200. {
  201. if(C TextNode *favorite=fp->findNode("Favorite"))for(int i=0; C TextParam *path=favorite->findNode("Path", i); i++)WindowIOFavorites.include(path->value);
  202. if(C TextNode *recent =fp->findNode("Recent" ))for(int i=0; C TextParam *path=recent ->findNode("Path", i); i++)WindowIORecents .include(path->value);
  203. }
  204. }
  205. if(C TextNode *video=data.findNode("Video"))
  206. {
  207. if(C TextParam *p=video->findNode("BloomSaturate"))DefaultEnvironment.bloom.saturate=p->asBool();
  208. if(C TextParam *p=video->findNode("AmbientLight" ))DefaultEnvironment.ambient.color =p->asFlt ();
  209. }
  210. if(C TextNode *store=data.findNode("Store"))
  211. {
  212. if(C TextParam *p=store->findNode("Email"))AppStore.login.email.set(p->value);
  213. }
  214. if(C TextNode *object=data.findNode("Object"))
  215. {
  216. if(C TextNode *general=object->findNode("General"))
  217. {
  218. if(C TextParam *p=general->findNode("ActiveViewport" ))ObjEdit. setView(p->asInt());
  219. if(C TextParam *p=general->findNode("CameraMoveMode" ))ObjEdit. moveMode(Edit::Viewport4:: MOVE_MODE(p->asInt ()));
  220. if(C TextParam *p=general->findNode("CameraOrientation"))ObjEdit.orientMode(Edit::Viewport4::ORIENT_MODE(p->asInt ()));
  221. if(C TextParam *p=general->findNode("CameraZoom" ))ObjEdit. zoom( p->asBool() );
  222. }
  223. }
  224. if(C TextNode *anim=data.findNode("Animation"))
  225. {
  226. if(C TextNode *general=anim->findNode("General"))
  227. {
  228. if(C TextParam *p=general->findNode("ActiveViewport" ))AnimEdit. setView(p->asInt());
  229. if(C TextParam *p=general->findNode("CameraMoveMode" ))AnimEdit. moveMode(Edit::Viewport4:: MOVE_MODE(p->asInt ()));
  230. if(C TextParam *p=general->findNode("CameraOrientation"))AnimEdit.orientMode(Edit::Viewport4::ORIENT_MODE(p->asInt ()));
  231. if(C TextParam *p=general->findNode("CameraZoom" ))AnimEdit. zoom( p->asBool() );
  232. }
  233. }
  234. if(C TextNode *world=data.findNode("World"))
  235. {
  236. if(C TextNode *brush=world->findNode("Brush"))
  237. {
  238. if(C TextParam *p=brush->findNode("SizeProportional"))Brush.bsize.set(p->asBool());
  239. if(C TextParam *p=brush->findNode("Image" ))Brush.setImage (p->value);
  240. }
  241. if(C TextNode *colors=world->findNode("Colors"))
  242. {
  243. FREPA(ColorBrush.col)if(C TextParam *p=colors->findNode("Color", i))ColorBrush.col[i].col=TextVec(p->value);
  244. }
  245. if(C TextNode *general=world->findNode("General"))
  246. {
  247. //if(C TextParam *p=general.findNode("CursorCollidesWithHeightmaps"))MainMenu("WE Edit/Cursor Collides with Heightmaps", p.asBool());
  248. //if(C TextParam *p=general.findNode("CursorCollidesWithObjects" ))MainMenu("WE Edit/Cursor Collides with Objects" , p.asBool());
  249. if(C TextParam *p=general->findNode("VisibleRadius" ))WorldEdit.visibleRadius(p->asInt());
  250. if(C TextParam *p=general->findNode("ActiveViewport" ))WorldEdit.setView (p->asInt());
  251. if(C TextParam *p=general->findNode("CameraMoveMode" ))WorldEdit. moveMode (Edit::Viewport4:: MOVE_MODE(p->asInt ()));
  252. if(C TextParam *p=general->findNode("CameraOrientation" ))WorldEdit.orientMode (Edit::Viewport4::ORIENT_MODE(p->asInt ()));
  253. if(C TextParam *p=general->findNode("CameraZoom" ))WorldEdit. zoom ( p->asBool() );
  254. if(C TextParam *p=general->findNode("CameraSpherical" ))WorldEdit.cam_spherical.set(p->asBool());
  255. if(C TextParam *p=general->findNode("CameraFppSpeed" ))WorldEdit.fpp_speed .set(p->asFlt ());
  256. }
  257. }
  258. if(C TextNode *theater=data.findNode("Theater"))
  259. {
  260. LoadProperties(Theater.options.props, ConstCast(theater->nodes));
  261. if(C TextNode *mode=theater->findNode("Mode"))Theater.mode.set(mode->asInt());
  262. }
  263. }
  264. /******************************************************************************/
  265. /******************************************************************************/