Jump to content

Gui vs GuiObject


photo

Recommended Posts

Hi Again,

Happy to say that I found the difference. It feels like a bug though or at least missing information.

Step one declare all of the widgets as global variables in the script, did not seem to affect me (for now)

The difference seems to be in setting the Ptr< > to the Gui.

  • To add a widget to a other widget or the display Gui you need to add the child widget. (Ptr<Widget>)
    And not construct it using the Gui.
    Gui.Get().AddChild(GetWidget());    
     In codeblock 2
     
  • To add a widget to a GuiObject you need to add the Gui gui = (node as ObjectGui).GetGui(); on constructing the widget.
    And then still add the child 
    gui.AddChild(CreateWidget(gui));     In codeblock 3
    Widget window = new WidgetWindow(gui, "demo window", 2, 2);       In codeblock 1
using Unigine;

[Component(PropertyGuid = "81bb314c3900bc3bce3b045ea659a0250867d340")]
public class ParentWindow : Component
{
	//Widget window;
	//Widget Button;
	protected Widget GetWidget()
	{
		Widget window = new WidgetWindow("demo window",2,2);
		Widget Button = new WidgetButton("test button");
		window.AddChild(Button);

		return window;
	}

	protected Widget CreateWidget(Gui gui)
	{
		Widget window = new WidgetWindow(gui, "demo window", 2, 2);
		Widget Button = new WidgetButton("test button");
		window.AddChild(Button);

		return window;
	}
}
using Unigine;

[Component(PropertyGuid = "bd991e51d532c37c610248ab2b33c60e66579615")]
public class PlayerWindow : ParentWindow
{
	private void Init()
	{
		Gui.Get().AddChild(GetWidget());
	}
}
using Unigine;

[Component(PropertyGuid = "ddfca6ca7671e7a1413adc8c89f7ee7b510e119e")]
public class GuiObjectWindow : ParentWindow
{
	private void Init()
	{
		node.WorldRotate(00.0f, 00.0f, 180.0f);
		Gui gui = (node as ObjectGui).GetGui();
		gui.AddChild(CreateWidget(gui));
	}
}

I hope this convoluted example makes sense and helps.

PS: don’t ask me why I have to rotate the GuiObject.

Gui vs GuiObject Solved.PNG

Link to comment

Hi Silent,

I'm sorry to hear that truly passing widget between Gui's is not supported.
Despite this i tried and got pretty far trying to rebuild the widgets.
To not have all my effort lost on myself i attache this project.

It has a 99%working Example like the C++ code. Plus Inventory drag and drop example
Only checkbox does not add to menubox.

The code to copy widgets to a new Gui only fails for the List tabs.

unigine_UI_Component_problem.zip

Link to comment
×
×
  • Create New...