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

Added a grid settings panel and grid settings button to entity editor, made glsl shader template files contain basic GLSL code, added toNumber and toInteger to String class, UIWindow now sets enabled and visible to false on close by default

Ivan Safrin 12 лет назад
Родитель
Сommit
e52dec6349

+ 4 - 0
Core/Contents/Include/PolyString.h

@@ -175,6 +175,10 @@ namespace Polycode {
 			* @return A string converted from the Number.
 			*/																										
 			static String NumberToString(Number value, int precision = 2);
+        
+        
+            Number toNumber();
+            int toInteger();
 
 			/**
 			* Convert an integer to a String.

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

@@ -157,6 +157,14 @@ vector<String> String::split(const String &delim) const {
 	return tokens;
 }
 
+Number String::toNumber() {
+    return atof(contents.c_str());
+}
+
+int String::toInteger() {
+    return atoi(contents.c_str());
+}
+
 String String::replace(const String &what, const String &withWhat) const {
 
 	size_t pos = 0;

Разница между файлами не показана из-за своего большого размера
+ 3 - 3
IDE/Assets/ide_icons.ai


+ 48 - 3
IDE/Contents/Include/EditorGrid.h

@@ -22,7 +22,9 @@
 
 #pragma once
 
-#include "Polycode.h"
+#include <Polycode.h>
+#include "PolycodeUI.h"
+
 #include "OSBasics.h"
 
 using namespace Polycode;
@@ -32,8 +34,23 @@ class EditorGrid : public Entity {
 		EditorGrid();
 		~EditorGrid();
 		
-		void setGrid(int gridSize);
         void setGridMode(int mode);
+    
+        Number getGridSize();
+        int getGridLen();
+    
+        void setGridSize(Number size);
+        void setGridLen(int len);
+    
+        bool isXAxisEnabled();
+        bool isYAxisEnabled();
+        bool isZAxisEnabled();
+
+        void enableXAxis(bool val);
+        void enableYAxis(bool val);
+        void enableZAxis(bool val);
+    
+        void rebuildGrid();
 		
         static const int GRID_MODE_3D = 0;
         static const int GRID_MODE_2D = 1;
@@ -41,4 +58,32 @@ class EditorGrid : public Entity {
 	private:
         int gridMode;
 		SceneMesh *grid;
-};
+    
+        SceneLine *yLine;
+        SceneLine *xLine;
+        SceneLine *zLine;
+    
+        Number gridSize;
+        int gridLen;
+    
+        bool threeDeeGrid;
+};
+
+
+class EditorGridSettingsWindow : public UIWindow {
+public:
+    EditorGridSettingsWindow(EditorGrid *grid);
+    ~EditorGridSettingsWindow();
+    
+    void handleEvent(Event *event);
+    
+protected:
+    
+    EditorGrid *grid;
+    UITextInput *sizeInput;
+    UITextInput *countInput;
+    
+    UICheckBox *xAxisBox;
+    UICheckBox *yAxisBox;
+    UICheckBox *zAxisBox;
+};

+ 4 - 1
IDE/Contents/Include/PolycodeEntityEditor.h

@@ -244,7 +244,10 @@ class EntityEditorMainView : public UIElement {
             UIImageButton *moveUpButton;
             UIImageButton *moveTopButton;
             UIImageButton *moveDownButton;
-            UIImageButton *moveBottomButton;
+            UIImageButton *moveBottomButton;    
+    
+            UIImageButton *gridSettingsButton;
+            EditorGridSettingsWindow *gridSettings;
     
             CameraPreviewWindow *cameraPreview;
     

+ 7 - 0
IDE/Contents/Resources/FileTemplates/Materials and Shaders/GLSL Fragment Shader.frag

@@ -0,0 +1,7 @@
+
+varying vec4 vertexColor;
+
+void main()
+{
+    gl_FragColor = vertexColor;
+}

+ 8 - 0
IDE/Contents/Resources/FileTemplates/Materials and Shaders/GLSL Vertex Shader.vert

@@ -0,0 +1,8 @@
+
+varying vec4 vertexColor;
+void main()
+{
+    gl_TexCoord[0] = gl_MultiTexCoord0;		
+    vertexColor = gl_Color;
+    gl_Position = ftransform();
+}

BIN
IDE/Contents/Resources/Images/entityEditor/grid_button.png


BIN
IDE/Contents/Resources/ImagesRetina/entityEditor/grid_button.png


BIN
IDE/Contents/Resources/ImagesRetina/entityEditor/snap_off.png


BIN
IDE/Contents/Resources/ImagesRetina/entityEditor/snap_on.png


+ 156 - 25
IDE/Contents/Source/EditorGrid.cpp

@@ -22,47 +22,178 @@
  
 #include "EditorGrid.h"
 
+EditorGridSettingsWindow::EditorGridSettingsWindow(EditorGrid *grid) : UIWindow("Grid Settings", 100, 160) {
+    
+    visible = false;
+    enabled = false;
+    
+    this->grid = grid;
+    
+    UILabel *label = new UILabel("Size:", 12);
+    label->setColor(1.0, 1.0 ,1.0, 1.0);
+    addChild(label);
+    label->setPosition(10, 40);
+    
+    sizeInput = new UITextInput(false, 50, 10);
+    addChild(sizeInput);
+    sizeInput->setPosition(60, 38);
+    sizeInput->setNumberOnly(true);
+    sizeInput->setText(String::NumberToString(grid->getGridSize()));
+    sizeInput->addEventListener(this, UIEvent::CHANGE_EVENT);
+    
+    label = new UILabel("Count:", 12);
+    label->setColor(1.0, 1.0 ,1.0, 1.0);
+    addChild(label);
+    label->setPosition(10, 70);
+
+    countInput = new UITextInput(false, 50, 10);
+    addChild(countInput);
+    countInput->setPosition(60, 68);
+    countInput->setNumberOnly(true);
+    countInput->setText(String::IntToString(grid->getGridLen()));
+    countInput->addEventListener(this, UIEvent::CHANGE_EVENT);
+    
+    xAxisBox = new UICheckBox("X Axis", grid->isXAxisEnabled());
+    addChild(xAxisBox);
+    xAxisBox->setPosition(10, 100);
+    xAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT);
+    
+    yAxisBox = new UICheckBox("Y Axis", grid->isYAxisEnabled());
+    addChild(yAxisBox);
+    yAxisBox->setPosition(10, 125);
+    yAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT);
+    
+    zAxisBox = new UICheckBox("Z Axis", grid->isZAxisEnabled());
+    addChild(zAxisBox);
+    zAxisBox->setPosition(10, 150);
+    zAxisBox->addEventListener(this, UIEvent::CHANGE_EVENT);
+}
+
+void EditorGridSettingsWindow::handleEvent(Event *event) {
+    if(event->getDispatcher() == sizeInput) {
+        grid->setGridSize(sizeInput->getText().toNumber());
+    } else if(event->getDispatcher() == countInput) {
+        grid->setGridLen(countInput->getText().toInteger());
+    } else if(event->getDispatcher() == xAxisBox) {
+        grid->enableXAxis(xAxisBox->isChecked());
+    } else if(event->getDispatcher() == yAxisBox) {
+        grid->enableYAxis(yAxisBox->isChecked());
+    } else if(event->getDispatcher() == zAxisBox) {
+        grid->enableZAxis(zAxisBox->isChecked());
+    }
+    UIWindow::handleEvent(event);
+}
+
+EditorGridSettingsWindow::~EditorGridSettingsWindow() {
+    
+}
+
 EditorGrid::EditorGrid() : Entity() {
 	grid = NULL;
     gridMode = GRID_MODE_3D;
     
-	setGrid(1.0);
-	setPitch(90);
+    Mesh *gridMesh = new Mesh(Mesh::LINE_MESH);
+    
+    grid = new SceneMesh(gridMesh);
+    grid->setColor(0.3, 0.3, 0.3, 1.0);
+    grid->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
+    addChild(grid);
+    
+    yLine = new SceneLine(Vector3(), Vector3());
+    addChild(yLine);
+    yLine->setColor(0.0, 0.8, 0.0, 1.0);
+
+    xLine = new SceneLine(Vector3(), Vector3());
+    addChild(xLine);
+    xLine->setColor(0.8, 0.0, 0.0, 1.0);
+    
+    zLine = new SceneLine(Vector3(), Vector3());
+    addChild(zLine);
+    zLine->setColor(0.0, 0.0, 0.8, 1.0);
+
+    gridSize = 1.0;
+    gridLen = 16;
+    
+    
+    rebuildGrid();
+    grid->setPitch(90);
 }
 
-void EditorGrid::setGrid(int gridSize) {
-	int gridLen = 16;
+void EditorGrid::setGridSize(Number size) {
+    gridSize = size;
+    rebuildGrid();
+}
+
+void EditorGrid::setGridLen(int len) {
+    gridLen = len;
+    rebuildGrid();
+}
+
+Number EditorGrid::getGridSize() {
+    return gridSize;
+}
+
+int EditorGrid::getGridLen() {
+    return gridLen;
+}
+
+bool EditorGrid::isXAxisEnabled() {
+    return xLine->visible;
+}
+
+bool EditorGrid::isYAxisEnabled() {
+    return yLine->visible;
+}
+
+bool EditorGrid::isZAxisEnabled() {
+     return zLine->visible;
+}
+
+void EditorGrid::enableXAxis(bool val) {
+    xLine->visible = val;
+}
+
+void EditorGrid::enableYAxis(bool val) {
+    yLine->visible = val;
+}
+
+void EditorGrid::enableZAxis(bool val) {
+    zLine->visible = val;
+}
+
+void EditorGrid::rebuildGrid() {
     
-	if(grid) {
-        grid->getMesh()->clearMesh();
-	} else {
-        Mesh *gridMesh = new Mesh(Mesh::LINE_MESH);
-        
-        grid = new SceneMesh(gridMesh);
-        grid->setColor(0.3, 0.3, 0.3, 1.0);
-        grid->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
-        addChild(grid);
-	}
+    grid->getMesh()->clearMesh();
+
+    for(int x=0; x < gridLen+1; x++) {
+        grid->getMesh()->addVertex((-gridSize * gridLen * 0.5) + (x * gridSize), (-gridSize * gridLen * 0.5), 0);
+        grid->getMesh()->addVertex((-gridSize * gridLen * 0.5) + (x * gridSize) , (-gridSize * gridLen * 0.5) + (gridSize * gridLen), 0);
+    }
     
-	for(int x=0; x < gridLen+1; x++) {
-			grid->getMesh()->addVertex((-gridSize * gridLen * 0.5) + (x * gridSize), (-gridSize * gridLen * 0.5), 0);
-			grid->getMesh()->addVertex((-gridSize * gridLen * 0.5) + (x * gridSize) , (-gridSize * gridLen * 0.5) + (gridSize * gridLen), 0);
-	}
+    for(int y=0; y < gridLen+1; y++) {
+        grid->getMesh()->addVertex((-gridSize * gridLen * 0.5), (-gridSize * gridLen * 0.5) + (y * gridSize), 0);
+        grid->getMesh()->addVertex((-gridSize * gridLen * 0.5) + (gridSize * gridLen), (-gridSize * gridLen * 0.5) + (y * gridSize), 0);
+    }
+    
+    yLine->setStart(Vector3(0.0, gridSize * gridLen * 0.5, 0.0));
+    yLine->setEnd(Vector3(0.0, gridSize * gridLen * -0.5, 0.0));
+    yLine->visible = false;
+
+    xLine->setStart(Vector3(gridSize * gridLen * 0.5, 0.0, 0.0));
+    xLine->setEnd(Vector3(gridSize * gridLen * -0.5, 0.0, 0.0));
 
-	for(int y=0; y < gridLen+1; y++) {
-			grid->getMesh()->addVertex((-gridSize * gridLen * 0.5), (-gridSize * gridLen * 0.5) + (y * gridSize), 0);
-			grid->getMesh()->addVertex((-gridSize * gridLen * 0.5) + (gridSize * gridLen), (-gridSize * gridLen * 0.5) + (y * gridSize), 0);
-	}
+    zLine->setStart(Vector3(0.0, 0.0, gridSize * gridLen * 0.5));
+    zLine->setEnd(Vector3(0.0, 0.0, gridSize * gridLen * -0.5));
     
-    grid->cacheToVertexBuffer(true);    
+    grid->cacheToVertexBuffer(true);
 }
 
 void EditorGrid::setGridMode(int mode) {
     gridMode = mode;
     if(gridMode == GRID_MODE_3D) {
-        grid->setPitch(0);
-    } else {
         grid->setPitch(90);
+    } else {
+        grid->setPitch(0);
     }
 }
 

+ 12 - 1
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -393,7 +393,7 @@ EntityEditorMainView::EntityEditorMainView(PolycodeEditor *editor) {
 	mainScene->addChild(transformGizmo);		
 	trackballCamera = new TrackballCamera(mainScene->getDefaultCamera(), renderTextureShape);
     trackballCamera->addEventListener(this, Event::CHANGE_EVENT);
-	
+	   
     addEntityButton = new UIImageButton("entityEditor/add_entity.png", 1.0, 24, 24);
 	topBar->addChild(addEntityButton);
     addEntityButton->setPosition(4, 2);
@@ -447,11 +447,19 @@ EntityEditorMainView::EntityEditorMainView(PolycodeEditor *editor) {
     moveBottomButton->setPosition(82, 2);
     moveBottomButton->addEventListener(this, UIEvent::CLICK_EVENT);
     
+    gridSettingsButton = new UIImageButton("entityEditor/grid_button.png", 1.0, 24, 24);
+	bottomBar->addChild(gridSettingsButton);
+    gridSettingsButton->setPosition(120, 2);
+    gridSettingsButton->addEventListener(this, UIEvent::CLICK_EVENT);
     
     editorMode = EDITOR_MODE_3D;
     
     input = CoreServices::getInstance()->getCore()->getInput();
     input->addEventListener(this, InputEvent::EVENT_KEYDOWN);
+    
+    gridSettings = new EditorGridSettingsWindow(grid);
+    addChild(gridSettings);
+    gridSettings->setPosition(30,40);
 }
 
 std::vector<Entity*> EntityEditorMainView::getSelectedEntities() {
@@ -1131,6 +1139,9 @@ void EntityEditorMainView::handleEvent(Event *event) {
         moveSelectedDown();
     } else if(event->getDispatcher() == moveBottomButton) {
         moveSelectedBottom();
+    } else if(event->getDispatcher() == gridSettingsButton) {
+        gridSettings->visible = !gridSettings->visible;
+        gridSettings->enabled = !gridSettings->enabled;
     } else {
         if(event->getEventCode() == InputEvent::EVENT_MOUSEDOWN && hasFocus && event->getDispatcher() != renderTextureShape) {
             InputEvent *inputEvent = (InputEvent*) event;

+ 1 - 1
Modules/Contents/UI/Include/PolyUIWindow.h

@@ -43,7 +43,7 @@ namespace Polycode {
 			void showWindow();
 			void hideWindow();
 			void onKeyDown(PolyKEY key, wchar_t charCode);
-			virtual void onClose(){}
+			virtual void onClose();
 			void onLoseFocus();
 			
 			void setWindowSize(Number w, Number h);

+ 5 - 0
Modules/Contents/UI/Source/PolyUIWindow.cpp

@@ -176,6 +176,11 @@ void UIWindow::hideWindow() {
 	enabled = false;
 }
 
+void UIWindow::onClose() {
+    visible = false;
+    enabled = false;
+}
+
 void UIWindow::handleEvent(Event *event) {
 
 	if(event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) {

Некоторые файлы не были показаны из-за большого количества измененных файлов