Ver Fonte

Grid Size Dialog

Adds a dialog to set the grid size in the Gui Editor.
Peter Robinson há 2 anos atrás
pai
commit
6c4a7fe32b

+ 14 - 1
editor/GuiEditor/GuiEditor.cs

@@ -30,6 +30,7 @@ function GuiEditor::create( %this )
 	exec("./scripts/GuiEditorExplorerWindow.cs");
     exec("./scripts/GuiEditorExplorerTree.cs");
     exec("./scripts/GuiEditorSaveGuiDialog.cs");
+    exec("./scripts/GuiEditorGridSizeDialog.cs");
 
 	%this.guiPage = EditorCore.RegisterEditor("Gui Editor", %this);
 
@@ -388,7 +389,19 @@ function GuiEditor::changeExtent(%this, %x, %y)
 
 function GuiEditor::SetGridSize(%this)
 {
-    
+    %width = 300;
+	%height = 140;
+	%dialog = new GuiControl()
+	{
+		class = "GuiEditorGridSizeDialog";
+		superclass = "EditorDialog";
+		dialogSize = (%width + 8) SPC (%height + 8);
+		dialogCanClose = true;
+		dialogText = "Grid Size";
+	};
+	%dialog.init(%width, %height);
+
+	Canvas.pushDialog(%dialog);
 }
 
 function GuiEditor::SnapToGrid(%this, %gridOn)

+ 78 - 0
editor/GuiEditor/scripts/GuiEditorGridSizeDialog.cs

@@ -0,0 +1,78 @@
+
+function GuiEditorGridSizeDialog::init(%this, %width, %height)
+{
+	//Get the dialog contents
+	%window = %this.getObject(0);
+	%content = %window.getObject(0);
+
+	%form = new GuiGridCtrl()
+	{
+		class = "EditorForm";
+		extent = %width SPC %height;
+		cellSizeX = %width;
+		cellSizeY = 50;
+	};
+	%form.addListener(%this);
+
+	%item = %form.addFormItem("Between 5 and 50", %width SPC 30);
+	%this.gridSizeBox = %form.createTextEditItem(%item);
+	%this.gridSizeBox.Command = %this.getId() @ ".Validate();";
+    %this.gridSizeBox.setInputMode("Number");
+    %this.gridSizeBox.align = "center";
+    %grid = GuiEditor.brain.getGridSize();
+	%this.gridSizeBox.text = %grid;
+    if(%grid < 10)
+    {
+        %this.gridSizeBox.setCursorPos(1);
+    }
+    else 
+    {
+        %this.gridSizeBox.setCursorPos(2);
+    }
+    %this.gridSizeBox.ReturnCommand = %this.getId() @ ".onDone();";
+    %this.gridSizeBox.EscapeCommand = %this.getId() @ ".onClose();";
+    
+
+	%content.add(%form);
+
+	%this.okButton = new GuiButtonCtrl()
+	{
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = "188 68";
+		Extent = "100 34";
+		Text = "OK";
+		Command = %this.getID() @ ".onDone();";
+	};
+	ThemeManager.setProfile(%this.okButton, "primaryButtonProfile");
+
+	%content.add(%this.okButton);
+
+	%this.validate();
+}
+
+function GuiEditorGridSizeDialog::Validate(%this)
+{
+	%this.okButton.active = false;
+
+	%grid = %this.gridSizeBox.getText();
+
+	if(%grid $= "" || %grid < 5 || %grid > 50)
+	{
+		return false;
+	}
+
+	%this.okButton.active = true;
+	return true;
+}
+
+function GuiEditorGridSizeDialog::onDone(%this)
+{
+	if(%this.validate())
+	{
+	    %grid = %this.gridSizeBox.getText();
+		GuiEditor.brain.setSnapToGrid(%grid);
+
+		%this.onClose();
+	}
+}

+ 7 - 0
engine/source/gui/editor/guiEditCtrl.cc

@@ -1441,6 +1441,13 @@ ConsoleMethod(GuiEditCtrl, setSnapToGrid, void, 3, 3, "(gridsize) Set the size o
    object->setSnapToGrid(gridsize);
 }
 
+ConsoleMethod(GuiEditCtrl, getGridSize, S32, 2, 2, "() Returns the grid size even if the grid is off.\n"
+	"@return A single int as the grid size.")
+{
+	U32 gridSize = object->getGridSize();
+	return gridSize;
+}
+
 void GuiEditCtrl::setSnapToGrid(U32 gridsize)
 {
 	if (gridsize == 0)

+ 1 - 0
engine/source/gui/editor/guiEditCtrl.h

@@ -136,6 +136,7 @@ class GuiEditCtrl : public GuiControl
    void pushToBack();
    void setSnapToGrid(U32 gridsize);
    bool hasSnapToGrid() { return mUseGridSnap; }
+   S32 getGridSize() { return mGridSnap.x; }
    void moveSelectionToCtrl(GuiControl*);
 };