2
0

uGBEOptionsUtils.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. unit uGBEOptionsUtils;
  2. interface
  3. uses
  4. FMX.Types3D,
  5. System.IniFiles,
  6. System.SysUtils,
  7. System.Classes;
  8. type
  9. TKeyboardType = (QWERTY, AZERTY);
  10. TGBEOptions = record
  11. afficherLignes, activerMusiques, activerSons, activerVagues, activerHerbe,
  12. activerHerbeVent, activerNuages, afficherFPS, utilisationTasks,
  13. pleinEcran: boolean;
  14. volumeSons, volumeMusiques: single;
  15. detailsHeightmap, nbNuages, nbHerbe, detailsVagues: integer;
  16. Filter: TMultisample;
  17. Keyboard: TKeyboardType;
  18. procedure WriteConfig(configFile: string);
  19. procedure SaveOption(configFile, section, option, value: string);
  20. procedure ReadConfig(configFile: string);
  21. function ReadOption(configFile, section, option: string): string;
  22. end;
  23. implementation // ----------------------------------------------------------
  24. // TGBEOptions
  25. procedure TGBEOptions.ReadConfig(configFile: string);
  26. var
  27. IniFile: TIniFile;
  28. begin
  29. if fileexists(configFile) then
  30. begin
  31. IniFile := TInifile.create(configFile);
  32. afficherLignes := IniFile.ReadBool('OPTIONS', 'showLines', false);
  33. activerMusiques := IniFile.ReadBool('OPTIONS', 'musics', false);
  34. activerSons := IniFile.ReadBool('OPTIONS', 'sounds', false);
  35. activerVagues := IniFile.ReadBool('OPTIONS', 'activeWaves', false);
  36. activerHerbe := IniFile.ReadBool('OPTIONS', 'activeGrass', true);
  37. activerHerbeVent := IniFile.ReadBool('OPTIONS', 'activeGrassWind', true);
  38. activerNuages := IniFile.ReadBool('OPTIONS', 'activeClouds', true);
  39. afficherFPS := IniFile.ReadBool('OPTIONS', 'showFPS', false);
  40. utilisationTasks := IniFile.ReadBool('OPTIONS', 'useTasks', false);
  41. pleinEcran := IniFile.ReadBool('OPTIONS', 'fullScreen', false);
  42. detailsHeightmap := IniFile.ReadInteger('OPTIONS', 'detailsHeightmap', 0);
  43. nbNuages := IniFile.ReadInteger('OPTIONS', 'nbNuages', 15);
  44. nbHerbe := IniFile.ReadInteger('OPTIONS', 'nbHerbe', 50);
  45. volumeSons := IniFile.ReadFloat('OPTIONS', 'volumeSons', 1);
  46. volumeMusiques := IniFile.ReadFloat('OPTIONS', 'volumeMusiques', 1);
  47. detailsVagues := IniFile.ReadInteger('OPTIONS', 'detailsWaves', 1);
  48. case IniFile.ReadInteger('OPTIONS', 'Filter', 0) of
  49. 0:
  50. Filter := TMultisample.None;
  51. 1:
  52. Filter := TMultisample.TwoSamples;
  53. 2:
  54. Filter := TMultisample.FourSamples;
  55. end;
  56. case IniFile.ReadInteger('OPTIONS', 'Keyboard', 0) of
  57. 0:
  58. Keyboard := TKeyboardType.AZERTY;
  59. 1:
  60. Keyboard := TKeyboardType.QWERTY;
  61. end;
  62. IniFile.Free;
  63. end
  64. else
  65. begin
  66. afficherLignes := false;
  67. activerMusiques := false;
  68. activerSons := false;
  69. activerVagues := true;
  70. activerHerbe := true;
  71. activerHerbeVent := true;
  72. activerNuages := true;
  73. afficherFPS := false;
  74. utilisationTasks := false;
  75. pleinEcran := false;
  76. detailsHeightmap := 0;
  77. nbNuages := 15;
  78. nbHerbe := 50;
  79. volumeSons := 1;
  80. volumeMusiques := 1;
  81. detailsVagues := 1;
  82. Filter := TMultisample.None;
  83. end;
  84. end;
  85. procedure TGBEOptions.WriteConfig(configFile: string);
  86. var
  87. IniFile: TInifile;
  88. begin
  89. IniFile := TInifile.create(configFile);
  90. IniFile.writeBool('OPTIONS', 'showLines', afficherLignes);
  91. IniFile.writeBool('OPTIONS', 'musics', activerMusiques);
  92. IniFile.writeBool('OPTIONS', 'sounds', activerSons);
  93. IniFile.writeBool('OPTIONS', 'activeWaves', activerVagues);
  94. IniFile.writeBool('OPTIONS', 'activeGrass', activerHerbe);
  95. IniFile.writeBool('OPTIONS', 'activeGrassWind', activerHerbeVent);
  96. IniFile.writeBool('OPTIONS', 'activeClouds', activerNuages);
  97. IniFile.writeBool('OPTIONS', 'showFPS', afficherFPS);
  98. IniFile.writeBool('OPTIONS', 'useTasks', utilisationTasks);
  99. IniFile.writeBool('OPTIONS', 'fullScreen', pleinEcran);
  100. IniFile.writeInteger('OPTIONS', 'detailsHeightmap', detailsHeightmap);
  101. IniFile.writeInteger('OPTIONS', 'nbNuages', nbNuages);
  102. IniFile.writeInteger('OPTIONS', 'nbHerbe', nbHerbe);
  103. IniFile.writefloat('OPTIONS', 'volumeSons', volumeSons);
  104. IniFile.writefloat('OPTIONS', 'volumeMusiques', volumeMusiques);
  105. IniFile.writeInteger('OPTIONS', 'detailsWaves', detailsVagues);
  106. case Filter of
  107. TMultisample.None:
  108. IniFile.writeInteger('OPTIONS', 'Filter', 0);
  109. TMultisample.TwoSamples:
  110. IniFile.writeInteger('OPTIONS', 'Filter', 1);
  111. TMultisample.FourSamples:
  112. IniFile.writeInteger('OPTIONS', 'Filter', 2);
  113. end;
  114. case Keyboard of
  115. QWERTY:
  116. IniFile.writeInteger('OPTIONS', 'Keyboard', 1);
  117. AZERTY:
  118. IniFile.writeInteger('OPTIONS', 'Keyboard', 0);
  119. end;
  120. IniFile.Free;
  121. end;
  122. procedure TGBEOptions.SaveOption(configFile, section, option, value: string);
  123. var
  124. IniFile: TInifile;
  125. begin
  126. IniFile := TInifile.create(configFile);
  127. IniFile.writeString(section, option, value);
  128. IniFile.Free;
  129. end;
  130. function TGBEOptions.ReadOption(configFile, section, option: string): string;
  131. var
  132. IniFile: TInifile;
  133. begin
  134. IniFile := TInifile.create(configFile);
  135. Result := IniFile.ReadString(section, option, '');
  136. IniFile.Free;
  137. end;
  138. end.