Jump to content

[SOLVED] Dynamic addition of GUI elements


photo

Recommended Posts

Привет!

 

Может кто создавал подобное. Я хочу в интерфейсе (загруженный через *.ui файл) создавать динамические GUI элементы.

Пример: Есть диалоговое окно, на котором будет вопрос WidgetLabel, а ниже несколько вариантов ответов (WidgetButton или WidgetSprite) варианты с WidgetListBox и WidgetMenuBox не надо.

Спасибо!

 

===================== translation from google =====================

 

Hello!

 

Who can create similar. I want to interface (loaded via *. Ui file) to create dynamic GUI elements.

Example: There is a dialog box that will question WidgetLabel, but below are a few answers (WidgetButton or WidgetSprite) options with WidgetListBox and WidgetMenuBox not.

Thanks!

Link to comment

Hi, I really cant russia, but google translated it, hopefully its correct what i read ;).

To create a dynamic GUI you can use .addChild methods.

 

So the normal way would be to create a WidgetVBox add this to the gui with "gui.addChild(vBox,Overlap (or so))"

 

and then add the widgets dynamic to this vBox.

 

Callbacks and so on can be declared with the instance.

 

 

WidgetLabel myLabel = new WidgetLabel();

vBox.addChild(myLabel).

 

And so on.

Hope this helps you

Best regards

Lars

Link to comment
  • 2 weeks later...

Hi vita, hi Lars!

 

I wrote some code for you, hope this will help. ;) You can find full sample in the attachments.

 

/*
*/
WidgetWindow question_window;
WidgetLabel question_counter;
WidgetVBox question_container;
UserInterface ui;

/*
*/
class WidgetQuestion {
private:

 WidgetGroupBox container;

public:

 /*
  */
 WidgetQuestion(Gui gui,string question,string answers[]) {

  container = new WidgetGroupBox(gui,question,0,5);

  forloop(int i = 0; answers.size()) {
WidgetCheckBox answer_box = new WidgetCheckBox(gui);
answer_box.setText(answers[i]);

container.addChild(answer_box,GUI_ALIGN_LEFT);
  }
 }

 /*
  */
  WidgetGroupBox getContainer() { return container; }
};

/*
*/
WidgetQuestion questions[0];
int current_question_index = 0;

/*
*/
int init() {

// Get the default GUI used by the engine.
Gui gui = engine.getGui();

ui = engine.gui.addUserInterface(gui,"ui_layout_6/ui_layout_6.ui");
gui.addChild(question_window,GUI_ALIGN_EXPAND | GUI_ALIGN_OVERLAP);

questions.append(
    new WidgetQuestion(
     gui,
     "Are you familiar with UNIGINE ui system?",
     ("Yeah","Kind of","Nope","Never heard of it","Wait, what?")
    )
);

questions.append(
    new WidgetQuestion(
     gui,
     "Do you like dogs?",
     ("Yes","No","Actually, I have fifty dogs!")
    )
);

question_container.addChild(questions[current_question_index].getContainer());
update_question_counter();

return 1;
}

/*
*/
void update_questions(int new_question_index,int old_question_index) {
WidgetGroupBox new_question = questions[new_question_index].getContainer();
WidgetGroupBox old_question = questions[old_question_index].getContainer();
question_container.replaceChild(new_question,old_question);
}

/*
*/
void update_question_counter() {
question_counter.setText(format("Question #%d (%d\%d)",current_question_index + 1,current_question_index + 1,questions.size()));
}

/*
*/
void next_question() {
if(current_question_index + 1 >= questions.size()) return;

update_questions(current_question_index + 1,current_question_index);
current_question_index++;
update_question_counter();
}

/*
*/
void prev_question() {
if(current_question_index - 1 < 0) return;

update_questions(current_question_index - 1,current_question_index);
current_question_index--;
update_question_counter();
}

ui_layout_6.zip

Link to comment
×
×
  • Create New...