Browse Source

Deactivating Menu Items

Added code to allow menu items to be disabled and enabled by name. Also did some improvements to the themes and improved the display of tree items by adding the text.
Peter Robinson 2 years ago
parent
commit
c4a71dcec8

+ 4 - 0
editor/EditorCore/EditorCore.cs

@@ -93,6 +93,7 @@ function EditorCore::initGui(%this)
 		};
 		};
 		new GuiMenuItemCtrl() {
 		new GuiMenuItemCtrl() {
 			Text = "File";
 			Text = "File";
+			Active = "0";
 
 
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "New Gui...";
 				Text = "New Gui...";
@@ -113,6 +114,7 @@ function EditorCore::initGui(%this)
 		};
 		};
 		new GuiMenuItemCtrl() {
 		new GuiMenuItemCtrl() {
 			Text = "Edit";
 			Text = "Edit";
+			Active = "0";
 
 
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Undo";
 				Text = "Undo";
@@ -143,6 +145,7 @@ function EditorCore::initGui(%this)
 		};
 		};
 		new GuiMenuItemCtrl() {
 		new GuiMenuItemCtrl() {
 			Text = "Layout";
 			Text = "Layout";
+			Active = "0";
 
 
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Nudge Up";
 				Text = "Nudge Up";
@@ -246,6 +249,7 @@ function EditorCore::initGui(%this)
 		};
 		};
 		new GuiMenuItemCtrl() {
 		new GuiMenuItemCtrl() {
 			Text = "Select";
 			Text = "Select";
+			Active = "0";
 
 
 			new GuiMenuItemCtrl() {
 			new GuiMenuItemCtrl() {
 				Text = "Select All";
 				Text = "Select All";

+ 1 - 1
editor/EditorCore/Themes/BaseTheme/BaseTheme.cs

@@ -1459,7 +1459,7 @@ function BaseTheme::makeMenuProfile(%this)
 		fontColor = %this.color4;
 		fontColor = %this.color4;
 		fontColorHL = %this.adjustValue(%this.color4, 10);
 		fontColorHL = %this.adjustValue(%this.color4, 10);
 		fontColorSL = %this.color4;
 		fontColorSL = %this.color4;
-		fontColorNA = %this.adjustValue(%this.color4, 100);
+		fontColorNA = %this.setAlpha(%this.color4, 100);
 
 
 		canKeyFocus = true;
 		canKeyFocus = true;
 	};
 	};

+ 48 - 45
editor/EditorCore/Themes/TorqueSuit/TorqueSuitTheme.cs

@@ -511,72 +511,48 @@ function TorqueSuitTheme::makeConsoleProfile(%this)
 
 
 function TorqueSuitTheme::makeMenuProfile(%this)
 function TorqueSuitTheme::makeMenuProfile(%this)
 {
 {
-	%menuBarBorder = new GuiBorderProfile()
-	{
-		padding = 2;
-	};
-
 	%this.menuBarProfile = new GuiControlProfile()
 	%this.menuBarProfile = new GuiControlProfile()
 	{
 	{
 		fillColor = %this.adjustValue(%this.color1, -7);
 		fillColor = %this.adjustValue(%this.color1, -7);
 		canKeyFocus = true;
 		canKeyFocus = true;
-		borderDefault = %menuBarBorder;
+		borderDefault = %this.emptyBorder;
 	};
 	};
 
 
 	%menuBorder = new GuiBorderProfile()
 	%menuBorder = new GuiBorderProfile()
 	{
 	{
-		margin = 2;
-		marginHL = 0;
-		marginSL = 0;
-		marginNA = 2;
-
-		border = 0;
-		borderHL = 2;
-		borderSL = 2;
-		borderNA = 0;
-
-		borderColorHL = "255 255 255 30";
-		borderColorSL = %this.color5;
+		padding = 3;
+		paddingHL = 3;
+		paddingSL = 3;
+		paddingNA = 3;
 	};
 	};
 
 
 	%menuBottomBorder = new GuiBorderProfile()
 	%menuBottomBorder = new GuiBorderProfile()
 	{
 	{
-		paddingSL = 2;
-
-		margin = 2;
-		marginHL = 0;
-		marginSL = 0;
-		marginNA = 2;
+		padding = 3;
+		paddingHL = 1;
+		paddingSL = 3;
+		paddingNA = 3;
 
 
 		border = 0;
 		border = 0;
 		borderHL = 2;
 		borderHL = 2;
-		borderSL = 2;
+		borderSL = 0;
 		borderNA = 0;
 		borderNA = 0;
 
 
-		borderColorHL = "255 255 255 30";
-		borderColorSL = %this.color5;
+		borderColorHL = %this.color5;
 	};
 	};
 
 
 	%menuSideBorder = new GuiBorderProfile()
 	%menuSideBorder = new GuiBorderProfile()
 	{
 	{
-		border = 0;
-		borderHL = 2;
-		borderSL = 2;
-		borderNA = 0;
-
-		padding = 10;
-		paddingHL = 8;
-		paddingSL = 8;
-		paddingNA = 10;
-
-		borderColorHL = "255 255 255 30";
-		borderColorSL = %this.color5;
+		padding = 14;
+		paddingHL = 14;
+		paddingSL = 14;
+		paddingNA = 14;
 	};
 	};
 
 
 	%this.menuProfile = new GuiControlProfile()
 	%this.menuProfile = new GuiControlProfile()
 	{
 	{
 		fillColor = "0 0 0 0";
 		fillColor = "0 0 0 0";
-		fillColorHL = "255 255 255 10";
+		fillColorHL = %this.color2;
 		fillColorSL = %this.adjustValue(%this.color5, -15);
 		fillColorSL = %this.adjustValue(%this.color5, -15);
 		fillColorNA = "0 0 0 0";
 		fillColorNA = "0 0 0 0";
 
 
@@ -587,12 +563,12 @@ function TorqueSuitTheme::makeMenuProfile(%this)
 
 
 		fontType = %this.font[3];
 		fontType = %this.font[3];
 		fontDirectory = %this.fontDirectory;
 		fontDirectory = %this.fontDirectory;
-		fontSize = %this.fontSize;
+		fontSize = %this.fontSize + 2;
 
 
 		fontColor = %this.color4;
 		fontColor = %this.color4;
 		fontColorHL = %this.adjustValue(%this.color4, 10);
 		fontColorHL = %this.adjustValue(%this.color4, 10);
 		fontColorSL = %this.color1;
 		fontColorSL = %this.color1;
-		fontColorNA = %this.adjustValue(%this.color4, 100);
+		fontColorNA = %this.color2;
 
 
 		canKeyFocus = true;
 		canKeyFocus = true;
 	};
 	};
@@ -660,7 +636,7 @@ function TorqueSuitTheme::makeMenuProfile(%this)
 	{
 	{
 		fillColor = %this.adjustValue(%this.color1, -5);
 		fillColor = %this.adjustValue(%this.color1, -5);
 		fillColorHL = %this.adjustValue(%this.color5, -15);
 		fillColorHL = %this.adjustValue(%this.color5, -15);
-		fillColorNA = %this.color1;
+		fillColorNA = %this.adjustValue(%this.color1, -5);
 		align = left;
 		align = left;
 
 
 		tab = false;
 		tab = false;
@@ -668,11 +644,11 @@ function TorqueSuitTheme::makeMenuProfile(%this)
 
 
 		fontType = %this.font[3];
 		fontType = %this.font[3];
 		fontDirectory = %this.fontDirectory;
 		fontDirectory = %this.fontDirectory;
-		fontSize = %this.fontSize;
+		fontSize = %this.fontSize + 2;
 
 
 		fontColor = %this.color4;
 		fontColor = %this.color4;
 		fontColorHL = %this.adjustValue(%this.color1, 10);
 		fontColorHL = %this.adjustValue(%this.color1, 10);
-		fontColorNA = %this.setAlpha(%this.color1, 150);
+		fontColorNA = %this.color2;
 
 
 		borderDefault = %menuItemBorderSide;
 		borderDefault = %menuItemBorderSide;
 		borderTop = %menuItemBorderTop;
 		borderTop = %menuItemBorderTop;
@@ -735,3 +711,30 @@ function TorqueSuitTheme::makeListBoxProfile(%this)
 		borderLeft = %leftBorderProfile;
 		borderLeft = %leftBorderProfile;
 	};
 	};
 }
 }
+
+function TorqueSuitTheme::makeTreeViewProfile(%this)
+{
+	%this.treeViewProfile = new GuiControlProfile ()
+	{
+	    // fill color
+	    fillColor = %this.adjustValue(%this.color1, 2);
+	    fillColorHL = %this.adjustValue(%this.color1, 4);
+	    fillColorSL = %this.color5;
+	    fillColorNA = %this.setAlpha(%this.color1, 150);
+		align = left;
+		vAlign = middle;
+
+		tab = false;
+		canKeyFocus = true;
+
+		fontType = %this.font[3];
+		fontDirectory = %this.fontDirectory;
+		fontSize = %this.fontSize - 4;
+		fontColor = %this.color4;
+		fontColorHL = %this.adjustValue(%this.color4, 20);
+		fontColorSL = %this.adjustValue(%this.color1, 2);
+		fontColorNA = %this.adjustValue(%this.color4, -30);
+
+		borderDefault = %this.emptyBorder;
+	};
+}

+ 8 - 2
editor/GuiEditor/GuiEditor.cs

@@ -150,12 +150,18 @@ function GuiEditor::destroy( %this )
 
 
 function GuiEditor::open(%this, %content)
 function GuiEditor::open(%this, %content)
 {
 {
-    
+    EditorCore.menuBar.setMenuActive("File", true);
+    EditorCore.menuBar.setMenuActive("Edit", true);
+    EditorCore.menuBar.setMenuActive("Layout", true);
+    EditorCore.menuBar.setMenuActive("Select", true);
 }
 }
 
 
 function GuiEditor::close(%this)
 function GuiEditor::close(%this)
 {
 {
-
+    EditorCore.menuBar.setMenuActive("File", false);
+    EditorCore.menuBar.setMenuActive("Edit", false);
+    EditorCore.menuBar.setMenuActive("Layout", false);
+    EditorCore.menuBar.setMenuActive("Select", false);
 }
 }
 
 
 //MENU FUNCTIONS---------------------------------------------------------------
 //MENU FUNCTIONS---------------------------------------------------------------

+ 16 - 0
editor/GuiEditor/scripts/GuiEditorBrain.cs

@@ -66,31 +66,37 @@ function GuiEditorBrain::onSelect(%this, %ctrl)
 	%this.clearSelection();
 	%this.clearSelection();
 	%this.select(%ctrl);
 	%this.select(%ctrl);
     %this.postEvent("Inspect", %ctrl);
     %this.postEvent("Inspect", %ctrl);
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onRemoveSelected(%this,%ctrl)
 function GuiEditorBrain::onRemoveSelected(%this,%ctrl)
 {
 {
     %this.postEvent("ClearInspect", %ctrl);
     %this.postEvent("ClearInspect", %ctrl);
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onClearSelected(%this)
 function GuiEditorBrain::onClearSelected(%this)
 {
 {
     %this.postEvent("ClearInspectAll");
     %this.postEvent("ClearInspectAll");
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onAddSelected(%this, %ctrl)
 function GuiEditorBrain::onAddSelected(%this, %ctrl)
 {
 {
     %this.postEvent("AlsoInspect", %ctrl);
     %this.postEvent("AlsoInspect", %ctrl);
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onDelete(%this)
 function GuiEditorBrain::onDelete(%this)
 {
 {
 	%this.postEvent("ObjectRemoved", %ctrl);
 	%this.postEvent("ObjectRemoved", %ctrl);
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onSelectionParentChange(%this, %parent)
 function GuiEditorBrain::onSelectionParentChange(%this, %parent)
 {
 {
     %this.postEvent("ParentChange", %parent);
     %this.postEvent("ParentChange", %parent);
+    %this.toggleDeselect();
 }
 }
 
 
 //Receiving Callbacks - Events that happened at other controls and need to be reflected with this control.
 //Receiving Callbacks - Events that happened at other controls and need to be reflected with this control.
@@ -100,6 +106,7 @@ function GuiEditorBrain::onInspect(%this, %ctrl)
     %this.clearSelection();
     %this.clearSelection();
 	%this.select(%ctrl);
 	%this.select(%ctrl);
     %this.endRadioSilence();
     %this.endRadioSilence();
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
 function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
@@ -107,6 +114,7 @@ function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.addSelection(%ctrl);
 	%this.addSelection(%ctrl);
     %this.endRadioSilence();
     %this.endRadioSilence();
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onClearInspect(%this, %ctrl)
 function GuiEditorBrain::onClearInspect(%this, %ctrl)
@@ -114,6 +122,7 @@ function GuiEditorBrain::onClearInspect(%this, %ctrl)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.removeSelection(%ctrl);
 	%this.removeSelection(%ctrl);
     %this.endRadioSilence();
     %this.endRadioSilence();
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onClearInspectAll(%this)
 function GuiEditorBrain::onClearInspectAll(%this)
@@ -121,6 +130,7 @@ function GuiEditorBrain::onClearInspectAll(%this)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.clearSelection();
 	%this.clearSelection();
     %this.endRadioSilence();
     %this.endRadioSilence();
+    %this.toggleDeselect();
 }
 }
 
 
 function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
 function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
@@ -128,4 +138,10 @@ function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
     %this.startRadioSilence();
     %this.startRadioSilence();
 	%this.deleteSelection();
 	%this.deleteSelection();
     %this.endRadioSilence();
     %this.endRadioSilence();
+    %this.toggleDeselect();
+}
+
+function GuiEditorBrain::toggleDeselect(%this)
+{
+    EditorCore.menuBar.setMenuActive("Deselect", %this.getSelected().getCount() != 0);
 }
 }

+ 34 - 7
engine/source/gui/editor/guiMenuBarCtrl.cc

@@ -311,13 +311,28 @@ void GuiMenuBarCtrl::ApplyMenuSettings()
 	for (i = begin(); i != end(); i++)
 	for (i = begin(); i != end(); i++)
 	{
 	{
 		GuiMenuItemCtrl *ctrl = static_cast<GuiMenuItemCtrl *>(*i);
 		GuiMenuItemCtrl *ctrl = static_cast<GuiMenuItemCtrl *>(*i);
-		if (ctrl->isVisible() && ctrl->isActive() && ctrl->mHasGoodChildren)
+		ctrl->ApplyMenuSettings();
+		ctrl->setControlProfile(mMenuProfile);
+	}
+	setUpdate();
+}
+
+void GuiMenuBarCtrl::setMenuActive(const char* name, bool isActive)
+{
+	iterator i;
+	for (i = begin(); i != end(); i++)
+	{
+		GuiMenuItemCtrl* ctrl = static_cast<GuiMenuItemCtrl*>(*i);
+		StringTableEntry ctrlName = StringTable->insert(ctrl->getText(), true);
+		StringTableEntry target = StringTable->insert(name, true);
+		if (ctrlName == target)
 		{
 		{
-			ctrl->ApplyMenuSettings();
+			ctrl->setActive(isActive);
 		}
 		}
+		ctrl->setMenuActive(target, isActive);
+		ctrl->ApplyMenuSettings();
 		ctrl->setControlProfile(mMenuProfile);
 		ctrl->setControlProfile(mMenuProfile);
 	}
 	}
-	setUpdate();
 }
 }
 
 
 void GuiMenuBarCtrl::acceleratorKeyPress(U32 index)
 void GuiMenuBarCtrl::acceleratorKeyPress(U32 index)
@@ -792,10 +807,7 @@ void GuiMenuItemCtrl::ApplyMenuSettings()
 	for (i = begin(); i != end(); i++)
 	for (i = begin(); i != end(); i++)
 	{
 	{
 		GuiMenuItemCtrl *ctrl = static_cast<GuiMenuItemCtrl *>(*i);
 		GuiMenuItemCtrl *ctrl = static_cast<GuiMenuItemCtrl *>(*i);
-		if (ctrl->isVisible() && ctrl->isActive() && ctrl->mHasGoodChildren)
-		{
-			ctrl->ApplyMenuSettings();
-		}
+		ctrl->ApplyMenuSettings();
 	}
 	}
 	setControlProfile(mMenuBar->mMenuItemProfile);
 	setControlProfile(mMenuBar->mMenuItemProfile);
 }
 }
@@ -1008,6 +1020,21 @@ bool GuiMenuItemCtrl::onKeyDown(const GuiEvent &event)
 		return true;
 		return true;
 	}
 	}
 }
 }
+
+void GuiMenuItemCtrl::setMenuActive(StringTableEntry name, bool isActive)
+{
+	iterator i;
+	for (i = begin(); i != end(); i++)
+	{
+		GuiMenuItemCtrl* ctrl = static_cast<GuiMenuItemCtrl*>(*i);
+		StringTableEntry ctrlName = StringTable->insert(ctrl->getText(), true);
+		if (ctrlName == name)
+		{
+			ctrl->setActive(isActive);
+		}
+		ctrl->setMenuActive(name, isActive);
+	}
+}
 #pragma endregion
 #pragma endregion
 
 
 #pragma region GuiMenuBGCtrl
 #pragma region GuiMenuBGCtrl

+ 2 - 0
engine/source/gui/editor/guiMenuBarCtrl.h

@@ -71,6 +71,7 @@ public:
    void openMenu();
    void openMenu();
    void closeMenu();
    void closeMenu();
    void ApplyMenuSettings();
    void ApplyMenuSettings();
+   void setMenuActive(const char* name, bool isActive);
 
 
    bool mUseKeyMode;
    bool mUseKeyMode;
    virtual void acceleratorKeyPress(U32 index);
    virtual void acceleratorKeyPress(U32 index);
@@ -171,6 +172,7 @@ public:
 	virtual void turnOffPrevRadio();
 	virtual void turnOffPrevRadio();
 	virtual void turnOffNextRadio();
 	virtual void turnOffNextRadio();
 	virtual bool onKeyDown(const GuiEvent &event);
 	virtual bool onKeyDown(const GuiEvent &event);
+	void setMenuActive(StringTableEntry name, bool isActive);
 };
 };
 
 
 class GuiMenuBGCtrl : public GuiControl
 class GuiMenuBGCtrl : public GuiControl

+ 16 - 0
engine/source/gui/editor/guiMenuBarCtrl_ScriptBinding.h

@@ -106,4 +106,20 @@ ConsoleMethodWithDocs(GuiMenuBarCtrl, setArrowProfile, ConsoleVoid, 3, 3, (GuiCo
 		object->setControlArrowProfile(profile);
 		object->setControlArrowProfile(profile);
 }
 }
 
 
+/*! Sets a menu item to active or inactive based on a name.
+	@param menuName The name of the menu that should be enabled or disabled. If multiple menu items have the same name they will all be enabled or disabled. Case sensative.
+	@param isActive True if the menu should be enabled. False if it is disabled.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiMenuBarCtrl, setMenuActive, ConsoleVoid, 4, 4, ("string menuName, bool isActive"))
+{
+	if (argc != 4)
+	{
+		Con::warnf("GuiMenuBarCtrl::setMenuActive() - Invalid number of parameters! Should be (string menuName, bool isActive).");
+		return;
+	}
+
+	object->setMenuActive(argv[2], dAtob(argv[3]));
+}
+
 ConsoleMethodGroupEndWithDocs(GuiMenuBarCtrl)
 ConsoleMethodGroupEndWithDocs(GuiMenuBarCtrl)

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

@@ -582,12 +582,27 @@ StringTableEntry GuiTreeViewCtrl::getObjectText(SimObject* obj)
 		}
 		}
 		const char* pObjName = obj->getName();
 		const char* pObjName = obj->getName();
 		const char* pInternalName = obj->getInternalName();
 		const char* pInternalName = obj->getInternalName();
-		if (pObjName != NULL)
-			dSprintf(buffer, sizeof(buffer), "%d: %s - %s", obj->getId(), obj->getClassName(), pObjName);
-		else if (pInternalName != NULL)
-			dSprintf(buffer, sizeof(buffer), "%d: %s [%s]", obj->getId(), obj->getClassName(), pInternalName);
-		else
-			dSprintf(buffer, sizeof(buffer), "%d: %s", obj->getId(), obj->getClassName());
+		GuiControl* ctrl = dynamic_cast<GuiControl*>(obj);
+		const char* theText = ctrl ? ctrl->getText() : "";
+		StringTableEntry textEntry = StringTable->insert(theText, true);
+		if(textEntry == StringTable->EmptyString)
+		{
+			if (pObjName != NULL)
+				dSprintf(buffer, sizeof(buffer), "%d: %s - %s", obj->getId(), obj->getClassName(), pObjName);
+			else if (pInternalName != NULL)
+				dSprintf(buffer, sizeof(buffer), "%d: %s [%s]", obj->getId(), obj->getClassName(), pInternalName);
+			else
+				dSprintf(buffer, sizeof(buffer), "%d: %s", obj->getId(), obj->getClassName());
+		}
+		else 
+		{
+			if (pObjName != NULL)
+				dSprintf(buffer, sizeof(buffer), "%d: %s \"%s\" - %s", obj->getId(), obj->getClassName(), textEntry, pObjName);
+			else if (pInternalName != NULL)
+				dSprintf(buffer, sizeof(buffer), "%d: %s \"%s\" [%s]", obj->getId(), obj->getClassName(), textEntry, pInternalName);
+			else
+				dSprintf(buffer, sizeof(buffer), "%d: %s \"%s\"", obj->getId(), obj->getClassName(), textEntry);
+		}
 	}
 	}
 
 
 	return StringTable->insert(buffer, true);
 	return StringTable->insert(buffer, true);