PolycodeProjectEditor.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "PolycodeProjectEditor.h"
  20. #include "OSBasics.h"
  21. PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
  22. Config *conf = CoreServices::getInstance()->getConfig();
  23. String fontName = conf->getStringValue("Polycode", "uiDefaultFontName");
  24. int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");
  25. Number padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");
  26. moduleSettingsWindow = new UIWindow("Project Modules", 300, 200);
  27. moduleSettingsWindow->setPosition(350,10);
  28. addChild(moduleSettingsWindow);
  29. Number lastYPos = 50;
  30. String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
  31. std::vector<OSFileEntry> moduleFolders = OSBasics::parseFolder(polycodeBasePath+"/Standalone/Modules", false);
  32. for(int i=0; i < moduleFolders.size(); i++) {
  33. OSFileEntry entry = moduleFolders[i];
  34. if(entry.type == OSFileEntry::TYPE_FOLDER) {
  35. UICheckBox *moduleCheckBox = new UICheckBox(entry.name, false);
  36. moduleCheckBox->setPosition(padding, lastYPos);
  37. lastYPos += moduleCheckBox->getHeight() + 5;
  38. moduleSettingsWindow->addChild(moduleCheckBox);
  39. moduleCheckboxes.push_back(moduleCheckBox);
  40. }
  41. }
  42. mainSettingsWindow = new UIWindow("Project Settings", 300, 500);
  43. mainSettingsWindow->setPosition(10,10);
  44. addChild(mainSettingsWindow);
  45. ScreenLabel *label2 = new ScreenLabel(L"DEFAULT VIDEO OPTIONS", fontSize+2, fontName, Label::ANTIALIAS_FULL);
  46. label2->setColor(1.0, 1.0, 1.0, 0.5);
  47. mainSettingsWindow->addChild(label2);
  48. label2->setPosition(padding, 50);
  49. label2 = new ScreenLabel(L"Width:", fontSize, fontName, Label::ANTIALIAS_FULL);
  50. mainSettingsWindow->addChild(label2);
  51. label2->setPosition(padding, 80);
  52. defaultWidthInput = new UITextInput(false, 60, 12);
  53. mainSettingsWindow->addChild(defaultWidthInput);
  54. defaultWidthInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  55. label2 = new ScreenLabel(L"Height:", fontSize, fontName, Label::ANTIALIAS_FULL);
  56. mainSettingsWindow->addChild(label2);
  57. label2->setPosition(padding + 80, 80);
  58. defaultHeightInput = new UITextInput(false, 60, 12);
  59. mainSettingsWindow->addChild(defaultHeightInput);
  60. defaultHeightInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  61. label2 = new ScreenLabel(L"Anti-aliasing:", fontSize, fontName, Label::ANTIALIAS_FULL);
  62. mainSettingsWindow->addChild(label2);
  63. label2->setPosition(padding + 160, 80);
  64. aaLevelComboBox = new UIComboBox(120);
  65. aaLevelComboBox->addComboItem("No AA");
  66. aaLevelComboBox->addComboItem("2x MSAA");
  67. aaLevelComboBox->addComboItem("4x MSAA");
  68. aaLevelComboBox->addComboItem("6x MSAA");
  69. aaLevelComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  70. label2 = new ScreenLabel(L"Anisotropic filtering:", fontSize, fontName, Label::ANTIALIAS_FULL);
  71. mainSettingsWindow->addChild(label2);
  72. label2->setPosition(padding, defaultHeightInput->getPosition().y+defaultHeightInput->getHeight()+10);
  73. afLevelComboBox = new UIComboBox(250);
  74. afLevelComboBox->addComboItem("No Anisotropic Filtering");
  75. afLevelComboBox->addComboItem("1x Anisotropic Filtering");
  76. afLevelComboBox->addComboItem("2x Anisotropic Filtering");
  77. afLevelComboBox->addComboItem("4x Anisotropic Filtering");
  78. afLevelComboBox->addComboItem("8x Anisotropic Filtering");
  79. afLevelComboBox->addComboItem("16x Anisotropic Filtering");
  80. afLevelComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  81. label2 = new ScreenLabel(L"Framerate:", fontSize, fontName, Label::ANTIALIAS_FULL);
  82. mainSettingsWindow->addChild(label2);
  83. label2->setPosition(padding, afLevelComboBox->getPosition().y+afLevelComboBox->getHeight()+10);
  84. framerateInput = new UITextInput(false, 60, 12);
  85. mainSettingsWindow->addChild(framerateInput);
  86. framerateInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  87. vSyncCheckBox = new UICheckBox("V-Sync", false);
  88. vSyncCheckBox->setPosition(padding, framerateInput->getPosition().y+framerateInput->getHeight()+10);
  89. mainSettingsWindow->addChild(vSyncCheckBox);
  90. label2 = new ScreenLabel(L"STARTUP OPTIONS", fontSize+2, fontName, Label::ANTIALIAS_FULL);
  91. label2->setColor(1.0, 1.0, 1.0, 0.5);
  92. mainSettingsWindow->addChild(label2);
  93. label2->setPosition(padding, vSyncCheckBox->getPosition().y+vSyncCheckBox->getHeight()+30);
  94. label2 = new ScreenLabel(L"Entry point file:", fontSize, fontName, Label::ANTIALIAS_FULL);
  95. mainSettingsWindow->addChild(label2);
  96. label2->setPosition(padding, vSyncCheckBox->getPosition().y+vSyncCheckBox->getHeight()+60);
  97. entryPointInput = new UITextInput(false, 200, 12);
  98. mainSettingsWindow->addChild(entryPointInput);
  99. entryPointInput->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  100. mainSettingsWindow->addChild(afLevelComboBox);
  101. mainSettingsWindow->addChild(aaLevelComboBox);
  102. label2 = new ScreenLabel(L"Background color:", fontSize, fontName, Label::ANTIALIAS_FULL);
  103. mainSettingsWindow->addChild(label2);
  104. label2->setPosition(padding, entryPointInput->getPosition().y+entryPointInput->getHeight()+10);
  105. bgColorBox = new UIColorBox(Color(1.0, 0.5, 0.0, 0.9), 30,30);
  106. bgColorBox->setPosition(label2->getPosition().x, label2->getPosition().y+label2->getHeight());
  107. mainSettingsWindow->addChild(bgColorBox);
  108. }
  109. PolycodeProjectEditor::~PolycodeProjectEditor() {
  110. }
  111. bool PolycodeProjectEditor::openFile(String filePath) {
  112. if(!configFile.loadFromXML(filePath)) {
  113. return false;
  114. }
  115. if(configFile.root["entryPoint"]) {
  116. entryPointInput->setText(configFile.root["entryPoint"]->stringVal);
  117. } else {
  118. configFile.root.addChild("entryPoint", "Source/Main.lua");
  119. }
  120. if(configFile.root["defaultWidth"]) {
  121. defaultWidthInput->setText(configFile.root["defaultWidth"]->stringVal);
  122. } else {
  123. configFile.root.addChild("defaultWidth", 640);
  124. }
  125. if(configFile.root["defaultHeight"]) {
  126. defaultHeightInput->setText(configFile.root["defaultHeight"]->stringVal);
  127. } else {
  128. configFile.root.addChild("defaultHeight", 480);
  129. }
  130. if(configFile.root["vSync"]) {
  131. vSyncCheckBox->setChecked(configFile.root["vSync"]->boolVal);
  132. } else {
  133. configFile.root.addChild("vSync", false);
  134. }
  135. unsigned int aaMap[7] = {0,1,1,1,2,2,3};
  136. if(configFile.root["antiAliasingLevel"]) {
  137. aaLevelComboBox->setSelectedIndex(aaMap[configFile.root["antiAliasingLevel"]->intVal]);
  138. } else {
  139. aaLevelComboBox->setSelectedIndex(0);
  140. configFile.root.addChild("antiAliasingLevel", 0);
  141. }
  142. unsigned int afMap[17] = {0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5};
  143. if(configFile.root["anisotropyLevel"]) {
  144. afLevelComboBox->setSelectedIndex(afMap[configFile.root["anisotropyLevel"]->intVal]);
  145. } else {
  146. afLevelComboBox->setSelectedIndex(0);
  147. configFile.root.addChild("anisotropyLevel", 0);
  148. }
  149. if(configFile.root["frameRate"]) {
  150. framerateInput->setText(configFile.root["frameRate"]->stringVal);
  151. } else {
  152. configFile.root.addChild("frameRate", 60);
  153. }
  154. if(configFile.root["modules"]) {
  155. for(int i=0; i < configFile.root["modules"]->length; i++) {
  156. ObjectEntry *module = (*configFile.root["modules"])[i];
  157. for(int j=0; j < moduleCheckboxes.size(); j++) {
  158. if(moduleCheckboxes[j]->getCaptionLabel() == module->stringVal) {
  159. moduleCheckboxes[j]->setChecked(true);
  160. }
  161. }
  162. }
  163. }
  164. Number backgroundColorR, backgroundColorG, backgroundColorB;
  165. if(configFile.root["backgroundColor"]) {
  166. ObjectEntry *color = configFile.root["backgroundColor"];
  167. if((*color)["red"] && (*color)["green"] && (*color)["blue"]) {
  168. backgroundColorR = (*color)["red"]->NumberVal;
  169. backgroundColorG = (*color)["green"]->NumberVal;
  170. backgroundColorB = (*color)["blue"]->NumberVal;
  171. bgColorBox->setBoxColor(Color(backgroundColorR, backgroundColorG, backgroundColorB, 1.0));
  172. } else {
  173. ObjectEntry *color = configFile.root.addChild("backgroundColor");
  174. color->addChild("red", 0.0);
  175. color->addChild("green", 0.0);
  176. color->addChild("blue", 0.0);
  177. }
  178. }
  179. PolycodeEditor::openFile(filePath);
  180. return true;
  181. }
  182. void PolycodeProjectEditor::Resize(int x, int y) {
  183. }
  184. void PolycodeProjectEditor::saveFile() {
  185. configFile.root["frameRate"]->intVal = atoi(framerateInput->getText().c_str());
  186. configFile.root["defaultWidth"]->intVal = atoi(defaultWidthInput->getText().c_str());
  187. configFile.root["defaultHeight"]->intVal = atoi(defaultHeightInput->getText().c_str());
  188. configFile.root["entryPoint"]->stringVal = entryPointInput->getText();
  189. ObjectEntry *color = configFile.root["backgroundColor"];
  190. (*color)["red"]->NumberVal = bgColorBox->getSelectedColor().r;
  191. (*color)["green"]->NumberVal = bgColorBox->getSelectedColor().g;
  192. (*color)["blue"]->NumberVal = bgColorBox->getSelectedColor().b;
  193. if(configFile.root["modules"]) {
  194. configFile.root["modules"]->Clear();
  195. }
  196. for(int j=0; j < moduleCheckboxes.size(); j++) {
  197. if(moduleCheckboxes[j]->isChecked()) {
  198. if(!configFile.root["modules"]) {
  199. configFile.root.addChild("modules");
  200. }
  201. configFile.root["modules"]->addChild("module", moduleCheckboxes[j]->getCaptionLabel());
  202. }
  203. }
  204. unsigned int afMap[6] = {0,1,2,4,8,16};
  205. unsigned int aaMap[4] = {0,2,4,6};
  206. configFile.root["antiAliasingLevel"]->intVal = aaMap[aaLevelComboBox->getSelectedIndex()];
  207. configFile.root["anisotropyLevel"]->intVal = afMap[afLevelComboBox->getSelectedIndex()];
  208. configFile.root["vSync"]->boolVal = vSyncCheckBox->isChecked();
  209. configFile.saveToXML(filePath);
  210. }