Pārlūkot izejas kodu

GuiEditor Load and New

This adds the load and new menu items for the GuiEditor.
Peter Robinson 2 gadi atpakaļ
vecāks
revīzija
f7bbbc87fe

+ 6 - 0
editor/EditorCore/EditorCore.cs

@@ -509,3 +509,9 @@ function EditorCore::finishProjectSelection(%this)
 	ModuleDatabase.LoadExplicit("AppCore", 1);
 	%this.editorKeyMap.bindCmd( "keyboard", "ctrl tilde", "EditorCore.toggleEditor();", "");
 }
+
+function EditorCore::alert(%this, %text)
+{
+	//Eventually this should open a dialog with this text. For now we'll dump it into the console and hope the user notices.
+	warn(%text);
+}

+ 56 - 12
editor/GuiEditor/GuiEditor.cs

@@ -26,6 +26,7 @@ function GuiEditor::create( %this )
 	exec("./scripts/GuiEditorControlListWindow.cs");
 	exec("./scripts/GuiEditorControlListBox.cs");
 	exec("./scripts/GuiEditorInspectorWindow.cs");
+    exec("./scripts/GuiEditorInspector.cs");
 	exec("./scripts/GuiEditorExplorerWindow.cs");
     exec("./scripts/GuiEditorExplorerTree.cs");
     exec("./scripts/GuiEditorSaveGuiDialog.cs");
@@ -132,7 +133,7 @@ function GuiEditor::create( %this )
     %this.guiPage.add(%this.explorerWindow);
     %this.explorerWindow.startListening(%this.brain);
 
-    %this.onNewGui();
+    %this.NewGui();
 
     EditorCore.FinishRegistration(%this.guiPage);
 }
@@ -141,19 +142,26 @@ function GuiEditor::create( %this )
 
 function GuiEditor::destroy( %this )
 {
+    if(isObject(%this.rootGui))
+    {
+        %this.content.removeIfMember(%this.rootGui);
+    }
 }
 
-function GuiEditor::open(%this)
+function GuiEditor::open(%this, %content)
 {
+    
 }
 
 function GuiEditor::close(%this)
 {
+
 }
 
-function GuiEditor::onNewGui(%this)
+//MENU FUNCTIONS---------------------------------------------------------------
+function GuiEditor::NewGui(%this)
 {
-    %this.rootGui = new GuiControl()
+    %content = new GuiControl()
     {
         HorizSizing = "width";
         VertSizing = "height";
@@ -161,21 +169,57 @@ function GuiEditor::onNewGui(%this)
         Extent = %this.guiPage.getExtent();
         Profile = GuiDefaultProfile;
     };
-    %this.content.add(%this.rootGui);
-    %this.brain.setRoot(%this.rootGui);
-    %this.brain.root = %this.rootGui;
-    %this.explorerWindow.open(%this.rootGui);
+    %this.DisplayGuiContent(%content);
 }
 
-//MENU FUNCTIONS---------------------------------------------------------------
-function GuiEditor::NewGui(%this)
+function GuiEditor::OpenGui(%this)
 {
+    %path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder());
+	%dialog = new OpenFileDialog()
+	{
+		Filters = "GUI (*.GUI;*.GUI.DSO)|*.GUI;*.GUI.DSO";
+		ChangePath = false;
+		MultipleFiles = false;
+		DefaultFile = "";
+		defaultPath = %path;
+		title = "Open Gui File";
+	};
+	%result = %dialog.execute();
 
+	if ( %result )
+	{
+        exec(%dialog.fileName);
+        if(isObject(%guiContent))
+        {
+            %this.DisplayGuiContent(%guiContent, %dialog.fileName);
+        }
+        else 
+        {
+            EditorCore.alert("Something went wrong while opening the Gui File. Gui Files should be structures with the root object assigned to %guiContent. If this file was made outside of the editor, you can change it manually and then open it in the Gui Editor.");
+        }
+	}
+	// Cleanup
+	%dialog.delete();
 }
 
-function GuiEditor::OpenGui(%this)
+function GuiEditor::DisplayGuiContent(%this, %content, %filePath)
 {
-    
+    if(isObject(%this.rootGui))
+    {
+        %this.filePath = "";
+        %this.content.removeIfMember(%this.rootGui);
+        %this.explorerWindow.tree.uninspect();
+        %this.prevGui = %this.rootGui;
+    }
+
+    %this.filePath = %filePath;
+    %this.rootGui = %content;
+    %this.content.add(%content);
+    %this.brain.setRoot(%content);
+    %this.brain.root = %content;
+    %this.explorerWindow.inspect(%content);
+
+    %this.brain.onSelect(%content);
 }
 
 function GuiEditor::SaveGui(%this)

+ 9 - 0
editor/GuiEditor/scripts/GuiEditorExplorerTree.cs

@@ -40,4 +40,13 @@ function GuiEditorExplorerTree::onUnselectAll(%this)
 function GuiEditorExplorerTree::onDeleteKey(%this, %index, %text, %item)
 {
 	%this.postEvent("ObjectRemoved", %item);
+}
+
+function GuiEditorExplorerTree::onPostApply(%this, %obj)
+{
+    %index = %this.findItemID(%obj.getId());
+    if(%index > -1)
+    {
+        %this.refreshItemText(%index);
+    }
 }

+ 3 - 2
editor/GuiEditor/scripts/GuiEditorExplorerWindow.cs

@@ -29,11 +29,12 @@ function GuiEditorExplorerWindow::onAdd(%this)
 	};
 	ThemeManager.setProfile(%this.tree, "listboxProfile");
 	%this.scroller.add(%this.tree);
+	%this.tree.startListening(GuiEditor.inspectorWindow.inspector);
 }
 
-function GuiEditorExplorerWindow::open(%this, %object)
+function GuiEditorExplorerWindow::inspect(%this, %object)
 {
-    %this.tree.open(%object);
+    %this.tree.inspect(%object);
 }
 
 function GuiEditorExplorerWindow::onInspect(%this, %ctrl)

+ 4 - 0
editor/GuiEditor/scripts/GuiEditorInspector.cs

@@ -0,0 +1,4 @@
+function GuiEditorInspector::onPostApply(%this, %obj)
+{
+    %this.postEvent("PostApply", %obj);
+}

+ 7 - 5
editor/GuiEditor/scripts/GuiEditorInspectorWindow.cs

@@ -22,6 +22,7 @@ function GuiEditorInspectorWindow::onAdd(%this)
 
     %this.inspector = new GuiInspector()
 	{
+		Class = "GuiEditorInspector";
 		HorizSizing="width";
 		VertSizing="height";
 		Position="0 0";
@@ -81,11 +82,12 @@ function GuiEditorInspectorWindow::onClearInspect(%this, %object)
             %this.inspector.inspect(%this.inspectList.getObject(%count - 1));
         }
     }
-    else 
-    {
-        %this.inspectList.clear();
-        %this.inspector.clear();
-    }
+}
+
+function GuiEditorInspectorWindow::onClearInspectAll(%this)
+{
+	%this.inspectList.clear();
+    %this.inspector.clear();
 }
 
 function GuiEditorInspectorWindow::onAlsoInspect(%this, %object)

+ 8 - 0
engine/source/gui/editor/guiInspector.cc

@@ -488,6 +488,10 @@ void GuiInspectorField::setData( const char* data )
       return;
 
    mTarget->inspectPreApply();
+   if (mGroup->mInspector->isMethod("onPreApply"))
+   {
+	   Con::executef(mGroup->mInspector, 3, "onPreApply", Con::getIntArg(mTarget->getId()));
+   }
 
    mTarget->setDataField( mField->pFieldname, mFieldArrayIndex, data );
 
@@ -495,6 +499,10 @@ void GuiInspectorField::setData( const char* data )
    updateValue( data );
 
    mTarget->inspectPostApply();
+   if (mGroup->mInspector->isMethod("onPostApply"))
+   {
+	   Con::executef(mGroup->mInspector, 3, "onPostApply", Con::getIntArg(mTarget->getId()));
+   }
 }
 
 const char* GuiInspectorField::getData()

+ 6 - 0
engine/source/gui/guiTreeViewCtrl.cc

@@ -395,6 +395,12 @@ void GuiTreeViewCtrl::inspectObject(SimObject* obj)
 	addBranches(treeItem, obj, 1);
 }
 
+void GuiTreeViewCtrl::uninspectObject()
+{
+	clearItems();
+	mRootObject = NULL;
+}
+
 void GuiTreeViewCtrl::addBranches(TreeItem* treeItem, SimObject* obj, U16 level)
 {
 	SimGroup* setObj = dynamic_cast<SimGroup*>(obj);

+ 1 - 0
engine/source/gui/guiTreeViewCtrl.h

@@ -95,6 +95,7 @@ public:
 	virtual void handleItemClick_ClickCallbacks(LBItem* hitItem, S32 hitIndex, const GuiEvent& event);
 
 	void inspectObject(SimObject* obj);
+	void uninspectObject();
 	void addBranches(TreeItem* treeItem, SimObject* obj, U16 level);
 	void refreshTree();
 	StringTableEntry getObjectText(SimObject* obj);

+ 26 - 1
engine/source/gui/guiTreeViewCtrl_ScriptBinding.h

@@ -26,7 +26,7 @@ ConsoleMethodGroupBeginWithDocs(GuiTreeViewCtrl, GuiListBoxCtrl)
 	@param obj A SimGroup that will be viewed as a tree.
 	@return No return value.
 */
-ConsoleMethodWithDocs( GuiTreeViewCtrl, open, ConsoleVoid, 3, 3, (SimGroup obj))
+ConsoleMethodWithDocs( GuiTreeViewCtrl, inspect, ConsoleVoid, 3, 3, (SimGroup obj))
 {
    SimGroup* treeRoot = NULL;
    SimObject* target = Sim::findObject(argv[2]);
@@ -37,6 +37,15 @@ ConsoleMethodWithDocs( GuiTreeViewCtrl, open, ConsoleVoid, 3, 3, (SimGroup obj))
    object->inspectObject(treeRoot);
 }
 
+
+/*! Removes the root object.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiTreeViewCtrl, uninspect, ConsoleVoid, 2, 2, ())
+{
+	object->uninspectObject();
+}
+
 /*! Informs the tree that the contents of the tree have changed and should be refreshed but preserves selection if possible.
 	@return No return value.
 */
@@ -90,4 +99,20 @@ ConsoleMethodWithDocs(GuiTreeViewCtrl, getItemParent, ConsoleInt, 3, 3, "(int in
 	return object->getItemTrunk(dAtoi(argv[2]));
 }
 
+/*! Refreshes the text of the item based on the inspected object.
+	@param index The zero-based index of the item that will be updated.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiTreeViewCtrl, refreshItemText, ConsoleVoid, 3, 3, "(S32 index)")
+{
+	S32 index = dAtoi(argv[2]);
+	if (index < 0 || index >= object->mItems.size())
+	{
+		Con::warnf("GuiTreeViewCtrl::refreshItemText() - Invalid index given.");
+		return;
+	}
+	SimObject* sub = static_cast<SimObject*>(object->mItems[index]->itemData);
+	object->setItemText(index, object->getObjectText(sub));
+}
+
 ConsoleMethodGroupEndWithDocs(GuiTreeViewCtrl)