Просмотр исходного кода

Project file saving/loading in IDE

Ivan Safrin 14 лет назад
Родитель
Сommit
de739af9de

+ 1 - 0
Core/Contents/Include/PolyObject.h

@@ -160,6 +160,7 @@ namespace Polycode {
 			return entry;			
 		}		
 		
+		void Clear();
 		
 		static const int FLOAT_ENTRY = 0;		
 		static const int INT_ENTRY = 1;

+ 8 - 0
Core/Contents/Source/PolyObject.cpp

@@ -25,6 +25,14 @@
 
 using namespace Polycode;
 
+void ObjectEntry::Clear() {
+	for(int i=0; i < children.size(); i++) {
+		children[i]->Clear();
+		delete children[i];
+	}
+	children.clear();
+}
+
 Object::Object() {
 	
 }

+ 7 - 1
IDE/Contents/Include/PolycodeProjectEditor.h

@@ -40,8 +40,14 @@ class PolycodeProjectEditor : public PolycodeEditor {
 	
 	protected:
 	
+	Object configFile;	
+	
+	std::vector<UICheckBox*> moduleCheckboxes;
+	
+	UIWindow *mainSettingsWindow;
+	UIWindow *moduleSettingsWindow;
+		
 	UICheckBox *vSyncCheckBox;
-	UIWindow *mainSettingsWindow;	
 	UITextInput *defaultWidthInput;
 	UITextInput *defaultHeightInput;	
 	UITextInput *framerateInput;	

+ 92 - 11
IDE/Contents/Source/PolycodeProjectEditor.cpp

@@ -21,17 +21,40 @@
  */
  
 #include "PolycodeProjectEditor.h"
+#include "OSBasics.h"
 
 PolycodeProjectEditor::PolycodeProjectEditor() : PolycodeEditor(true){
-	mainSettingsWindow = new UIWindow("Project Settings", 300, 500);
-	mainSettingsWindow->setPosition(10,10);
-	addChild(mainSettingsWindow);
-	
+
 	Config *conf = CoreServices::getInstance()->getConfig();	
 	String fontName = conf->getStringValue("Polycode", "uiDefaultFontName");
 	int fontSize = conf->getNumericValue("Polycode", "uiDefaultFontSize");	
 	Number padding = conf->getNumericValue("Polycode", "uiWindowSkinPadding");	
 		
+
+	moduleSettingsWindow = new UIWindow("Project Modules", 300, 200);
+	moduleSettingsWindow->setPosition(350,10);
+	addChild(moduleSettingsWindow);
+	
+	Number lastYPos = 50;
+	
+	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
+		
+	std::vector<OSFileEntry> moduleFolders = OSBasics::parseFolder(polycodeBasePath+"/Standalone/Modules", false);
+	for(int i=0; i < moduleFolders.size(); i++) {
+		OSFileEntry entry = moduleFolders[i];
+		if(entry.type == OSFileEntry::TYPE_FOLDER) {
+			UICheckBox *moduleCheckBox = new UICheckBox(entry.name, false);
+			moduleCheckBox->setPosition(padding, lastYPos);
+			lastYPos += moduleCheckBox->getHeight() + 5;
+			moduleSettingsWindow->addChild(moduleCheckBox);
+			moduleCheckboxes.push_back(moduleCheckBox);
+		}
+	}
+
+	mainSettingsWindow = new UIWindow("Project Settings", 300, 500);
+	mainSettingsWindow->setPosition(10,10);
+	addChild(mainSettingsWindow);
+	
 	ScreenLabel *label2 = new ScreenLabel(L"DEFAULT VIDEO OPTIONS", fontSize+2, fontName, Label::ANTIALIAS_FULL);	
 	label2->setColor(1.0, 1.0, 1.0, 0.5);
 	mainSettingsWindow->addChild(label2);
@@ -127,27 +150,43 @@ PolycodeProjectEditor::~PolycodeProjectEditor() {
 
 bool PolycodeProjectEditor::openFile(String filePath) {
 
-	Object configFile;
+
 	if(!configFile.loadFromXML(filePath)) {
 		return false;
 	}
 	
 	if(configFile.root["entryPoint"]) {	
 		entryPointInput->setText(configFile.root["entryPoint"]->stringVal);
+	} else {
+		configFile.root.addChild("entryPoint", "Source/Main.lua");		
 	}
 	
 	if(configFile.root["defaultWidth"]) {	
 		defaultWidthInput->setText(configFile.root["defaultWidth"]->stringVal);
+	} else {
+		configFile.root.addChild("defaultWidth", 640);	
 	}
+	
 	if(configFile.root["defaultHeight"]) {		
 		defaultHeightInput->setText(configFile.root["defaultHeight"]->stringVal);
+	} else {
+		configFile.root.addChild("defaultHeight", 480);
 	}
 
+	if(configFile.root["vSync"]) {	
+		vSyncCheckBox->setChecked(configFile.root["vSync"]->boolVal);
+	} else {
+		configFile.root.addChild("vSync", false);
+	}
+
+	
+
 	unsigned int aaMap[7] = {0,1,1,1,2,2,3};
 	if(configFile.root["antiAliasingLevel"]) {
 		aaLevelComboBox->setSelectedIndex(aaMap[configFile.root["antiAliasingLevel"]->intVal]);
 	} else {
 		aaLevelComboBox->setSelectedIndex(0);
+		configFile.root.addChild("antiAliasingLevel", 0);
 	}
 
 	unsigned int afMap[17] = {0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5};
@@ -155,25 +194,41 @@ bool PolycodeProjectEditor::openFile(String filePath) {
 		afLevelComboBox->setSelectedIndex(afMap[configFile.root["anisotropyLevel"]->intVal]);
 	} else {
 		afLevelComboBox->setSelectedIndex(0);
+		configFile.root.addChild("anisotropyLevel", 0);
 	}
 
-
 	if(configFile.root["frameRate"]) {
 		framerateInput->setText(configFile.root["frameRate"]->stringVal);	
+	} else {
+		configFile.root.addChild("frameRate", 60);	
 	}
-/*
+	
+	if(configFile.root["modules"]) {
+		for(int i=0; i < configFile.root["modules"]->length; i++) {
+			ObjectEntry *module = (*configFile.root["modules"])[i];
+			for(int j=0; j < moduleCheckboxes.size(); j++) {
+				if(moduleCheckboxes[j]->getCaptionLabel() == module->stringVal) {
+					moduleCheckboxes[j]->setChecked(true);
+				}
+			}
+		}
+	}	
+
+	Number backgroundColorR, backgroundColorG, backgroundColorB;	
 	if(configFile.root["backgroundColor"]) {
 		ObjectEntry *color = configFile.root["backgroundColor"];
 		if((*color)["red"] && (*color)["green"] && (*color)["blue"]) {
 			backgroundColorR = (*color)["red"]->NumberVal;
 			backgroundColorG = (*color)["green"]->NumberVal;
 			backgroundColorB = (*color)["blue"]->NumberVal;
-			printf("Background color: %f %f %f\n", backgroundColorR, backgroundColorG, backgroundColorB);
-
+			bgColorBox->setBoxColor(Color(backgroundColorR, backgroundColorG, backgroundColorB, 1.0));	
 		} else {
-			printf("backgroundColor node specified, but missing all three color attributes (red,green,blue). Ignoring.\n");
+			ObjectEntry *color = configFile.root.addChild("backgroundColor");
+			color->addChild("red", 0.0);
+			color->addChild("green", 0.0);
+			color->addChild("blue", 0.0);						
 		}
-	}*/
+	}
 	
 	PolycodeEditor::openFile(filePath);	
 	return true;
@@ -184,4 +239,30 @@ void PolycodeProjectEditor::Resize(int x, int y) {
 
 void PolycodeProjectEditor::saveFile() {
 
+	configFile.root["frameRate"]->intVal = atoi(framerateInput->getText().c_str());
+	configFile.root["defaultWidth"]->intVal = atoi(defaultWidthInput->getText().c_str());
+	configFile.root["defaultHeight"]->intVal = atoi(defaultHeightInput->getText().c_str());	
+	configFile.root["entryPoint"]->stringVal = entryPointInput->getText();
+	
+	ObjectEntry *color = configFile.root["backgroundColor"];	
+	(*color)["red"]->NumberVal = bgColorBox->getSelectedColor().r;
+	(*color)["green"]->NumberVal = bgColorBox->getSelectedColor().g;
+	(*color)["blue"]->NumberVal = bgColorBox->getSelectedColor().b;
+
+
+	configFile.root["modules"]->Clear();
+	for(int j=0; j < moduleCheckboxes.size(); j++) {
+		if(moduleCheckboxes[j]->isChecked()) {
+			configFile.root["modules"]->addChild("module", moduleCheckboxes[j]->getCaptionLabel());
+		}
+	}
+	
+	unsigned int afMap[6] = {0,1,2,4,8,16};
+	unsigned int aaMap[4] = {0,2,4,6};
+		
+	configFile.root["antiAliasingLevel"]->intVal = aaMap[aaLevelComboBox->getSelectedIndex()];
+	configFile.root["anisotropyLevel"]->intVal = afMap[afLevelComboBox->getSelectedIndex()];
+	configFile.root["vSync"]->boolVal = vSyncCheckBox->isChecked();
+	
+	configFile.saveToXML(filePath);
 }

+ 3 - 1
Modules/Contents/UI/Include/PolyUICheckBox.h

@@ -36,10 +36,12 @@ namespace Polycode {
 			UICheckBox(String caption, bool checked);
 			~UICheckBox();
 		
+			void setChecked(bool val);
 			void changeCheck();
 			bool isChecked();
 			void handleEvent(Event *event);
-				
+			String getCaptionLabel();
+			
 		private:
 			bool checked;
 			ScreenLabel *captionLabel;

+ 2 - 0
Modules/Contents/UI/Include/PolyUIColorBox.h

@@ -89,6 +89,8 @@ namespace Polycode {
 			UIColorBox(Color initialColor, Number width, Number height);
 			~UIColorBox();
 			
+			Color getSelectedColor();
+			
 			void setBoxColor(Color newColor);
 			void showColorPicker();			
 			void handleEvent(Event *event);

+ 10 - 0
Modules/Contents/UI/Source/PolyUICheckBox.cpp

@@ -65,6 +65,10 @@ UICheckBox::UICheckBox(String caption, bool checked) : ScreenEntity() {
 	
 }
 
+String UICheckBox::getCaptionLabel() {
+	return captionLabel->getText();
+}
+
 UICheckBox::~UICheckBox() {
 
 }
@@ -73,6 +77,12 @@ bool UICheckBox::isChecked() {
 	return checked;
 }
 		
+void UICheckBox::setChecked(bool val) {
+	checked = val;
+	buttonImageChecked->visible = checked;
+	buttonImageUnchecked->visible = !checked;
+}
+
 void UICheckBox::changeCheck() {
 	checked = !checked;
 	buttonImageChecked->visible = checked;

+ 4 - 0
Modules/Contents/UI/Source/PolyUIColorBox.cpp

@@ -411,6 +411,10 @@ UIColorBox::UIColorBox(Color initialColor, Number width, Number height) : Screen
 	setBoxColor(initialColor);
 }
 
+Color UIColorBox::getSelectedColor() {
+	return colorPicker->getSelectedColor();
+}
+
 UIColorBox::~UIColorBox() {
 
 }