Jump to content

problem loading UI files


photo

Recommended Posts

This is a stupid question, Im sure Im doing something wrong here. I have an empty world test.world and this test.cpp:

 

Gui gui;				// gui
UserInterface ui;

int init() {
   create_scene();
   return 1;
}


void create_scene() {
gui = engine.getGui();
ui = engine.gui.addUserInterface(gui,"test.ui");
return "";
}

 

This is test.ui

 

<?xml version="1.0" encoding="utf-8"?>
<ui version="1.0">

<button name="test_butt" pos_x="10" pos_y="10" export="1"/>

</ui>

 

But when I run it, I get this error:

 

Loading "test.cpp" 0ms
Loading "test.world" 0ms
Interpreter::setVariable(): unknown variable "test_butt"

 

Whats my mistake here? I have been looking in the demos and I cant see any extra step that I could be missing.

Link to comment

No GUI knowledge at all, so just a blind guess: Widgets (e.g. button) might have to be embedded into Containers (e.g. window, vbox). See docmentation section "Programming\Gui\UI Files" and search within SDK data subdirectory for *.ui samples.

 

Maybe something like

 

<?xml version="1.0" encoding="utf-8"?>
<ui version="1.0">

<window name="window" /* required parameters */>
   <button name="test_butt" pos_x="10" pos_y="10" export="1"/>
</window>

</ui>

Link to comment

Nope, that just added another error: Interpreter::setVariable(): unknown variable "window", besides the one for test_butt. tried copying ui_01.ui from samples and I got the same error for each widget declared there.

Link to comment

Nope, that just added another error: Interpreter::setVariable(): unknown variable "window", besides the one for test_butt. tried copying ui_01.ui from samples and I got the same error for each widget declared there.

 

Post your test scene as zip file, I will take a look into engine source

Link to comment

The world is empty:

 

test.world

<?xml version="1.0" encoding="utf-8"?>
<world version="1.12"/>

 

Also I have experienced this error on every application I have made with unigine, with empty worlds or not.

Link to comment

Solution is to define corresponding widget variable with same name as stated in export argument in test.cpp

 

WidgetButton test_butt;     // will be initialized by engine.gui.addUserInterface(gui,"test.ui") call

Gui gui;		
UserInterface ui;

int init() {
   create_scene();
   return 1;
}

void create_scene() {
gui = engine.getGui();
ui = engine.gui.addUserInterface(gui,"test.ui");
return "";
}

Link to comment

Ok! That fixed the error, but still the button is not visible.

 

Maybe you have to set button text. Also there are working samples data\widgets\ui_00/01

Link to comment

Maybe you use different namespaces in your class/package and ui-layout? (Try use custom package, not global)

Correct ui-part:

<vbox name="Source::MainMenu::mainPanel" export="1">
<sprite align="background" texture="source/textures/gui/window.png"/>

Package-part:

namespace Source
{
namespace MainMenu
{
	WidgetVBox mainPanel;

 

Also see data\samples\widgets\ for template

Link to comment

Again, no buttons.

Here are my project files with latest updates:

 

test.cpp:

namespace Testing {

WidgetButton test_butt;

Gui gui;				// gui
UserInterface ui;

int init() {
   create_scene();
   return 1;
}

void test_callback() {
   printf("test \n");
}

int update(){
   return 1;
}

void create_scene() {
gui = engine.getGui();
ui = engine.gui.addUserInterface(gui,"test.ui");
       test_butt.setCallback(GUI_CLICKED,"test_callback");   
return "";
}

}

 

test.ui:

<?xml version="1.0" encoding="utf-8"?>
<ui version="1.0">

<button name="Testing::test_butt" pos_x="10" pos_y="10" export="1">
	<text>Press me</text>
</button>
<button align="overlap" pos_x="80" pos_y="110">
	<text>Press me 2</text>
	<callback type="clicked">Testing::test_callback</callback>
</button>
</ui>

 

and an empty world, test.world:

<?xml version="1.0" encoding="utf-8"?>
<world version="1.12"/>

Link to comment

Well, seems that the problem is not related to UI files only. Added a button in code and it is not visible neither:

 

test_butt2 = new WidgetButton(gui,"Next");
   test_butt2.setPosition(20, 80);
   gui.addChild(test_butt2,GUI_ALIGN_OVERLAP);

 

also tried adding a PlayerSpectator and creating lights, but didnt worked. Do i need to include some specific unigine header or something?

Link to comment

You need to add your button to gui also:

void create_scene() {
       gui = engine.getGui();
       ui = engine.gui.addUserInterface(gui,"test.ui");

       gui.addChild(test_butt, GUI_ALIGN_OVERLAP); // add your button 

       test_butt.setCallback(GUI_CLICKED,"test_callback");   
       return "";
}

Link to comment

That solved the problem. And the previous post about missing button when created via code, solved too, when I removed the namespace. Weird, isnt it?

Now, isnt UI files suppossed to do all that work for me? If I have to create the variables and also add them manually to the gui, then Im just saving a couple of lines for each gui element.

Link to comment

That solved the problem. And the previous post about missing button when created via code, solved too, when I removed the namespace. Weird, isnt it?

Now, isnt UI files suppossed to do all that work for me? If I have to create the variables and also add them manually to the gui, then Im just saving a couple of lines for each gui element.

Yes, you are. Also you could describe all form in UI with one root element, for example:

<vbox name="Source::MainMenu::mainPanel" export="1">

<button name="Testing::test_butt" pos_x="10" pos_y="10" export="1">
               <text>Press me</text>
       </button>
<button align="overlap" pos_x="80" pos_y="110">
               <text>Press me 2</text>
               <callback type="clicked">Testing::test_callback</callback>
       </button>

<button name="Testing::test_butt2" pos_x="10" pos_y="10" export="1">
               <text>Press me</text>
       </button>
<button align="overlap" pos_x="80" pos_y="110">
               <text>Press me 2</text>
               <callback type="clicked">Testing::test_callback</callback>
       </button>
</vbox>

 

and then you need use only:

gui.addChild(mainPanel, GUI_ALIGN_OVERLAP); // add all your buttons with container

and all you buttons will be added automatically

Link to comment
×
×
  • Create New...