RVargas Posted May 12, 2011 Share Posted May 12, 2011 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
ulf.schroeter Posted May 12, 2011 Share Posted May 12, 2011 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
RVargas Posted May 12, 2011 Author Share Posted May 12, 2011 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
ulf.schroeter Posted May 12, 2011 Share Posted May 12, 2011 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
RVargas Posted May 12, 2011 Author Share Posted May 12, 2011 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
ulf.schroeter Posted May 12, 2011 Share Posted May 12, 2011 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
RVargas Posted May 12, 2011 Author Share Posted May 12, 2011 Hmm, that crossed my mind, but it wasnt explicitly explained in the manual, so I thought it was a bad idea. Link to comment
RVargas Posted May 13, 2011 Author Share Posted May 13, 2011 Ok! That fixed the error, but still the button is not visible. Link to comment
ulf.schroeter Posted May 13, 2011 Share Posted May 13, 2011 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
RVargas Posted May 16, 2011 Author Share Posted May 16, 2011 Nope, setting the text doesnt fix it. Button still invisible. Link to comment
eugene.litvinov Posted May 17, 2011 Share Posted May 17, 2011 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
RVargas Posted May 17, 2011 Author Share Posted May 17, 2011 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
RVargas Posted May 17, 2011 Author Share Posted May 17, 2011 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
eugene.litvinov Posted May 17, 2011 Share Posted May 17, 2011 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
RVargas Posted May 17, 2011 Author Share Posted May 17, 2011 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
eugene.litvinov Posted May 18, 2011 Share Posted May 18, 2011 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
Recommended Posts