input = text_;
}
+void
+MenuItem::set_help(const std::string& help_text)
+{
+ help = help_text;
+}
+
std::string MenuItem::get_input_with_symbol(bool active_item)
{
if(!active_item) {
for(std::vector<MenuItem*>::iterator i = items.begin();
i != items.end(); ++i)
delete *i;
+
if(current_ == this)
current_ = NULL;
+
+ if (previous == this)
+ previous = NULL;
}
Menu::Menu()
}
}
-void
+MenuItem*
Menu::add_hl()
{
- additem(new MenuItem(MN_HL));
+ MenuItem* item = new MenuItem(MN_HL);
+ additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_label(const std::string& text)
{
MenuItem* item = new MenuItem(MN_LABEL);
item->text = text;
additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_controlfield(int id, const std::string& text,
const std::string& mapping)
{
item->change_text(text);
item->change_input(mapping);
additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_entry(int id, const std::string& text)
{
MenuItem* item = new MenuItem(MN_ACTION, id);
item->text = text;
additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_deactive(int id, const std::string& text)
{
MenuItem* item = new MenuItem(MN_DEACTIVE, id);
item->text = text;
additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_toggle(int id, const std::string& text, bool toogled)
{
MenuItem* item = new MenuItem(MN_TOGGLE, id);
item->text = text;
item->toggled = toogled;
additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_back(const std::string& text)
{
MenuItem* item = new MenuItem(MN_BACK);
item->text = text;
additem(item);
+ return item;
}
-void
+MenuItem*
Menu::add_submenu(const std::string& text, Menu* submenu, int id)
{
MenuItem* item = new MenuItem(MN_GOTO, id);
item->text = text;
item->target_menu = submenu;
additem(item);
+ return item;
}
void
void
Menu::update()
{
+ int menu_height = get_height();
+ if (menu_height > SCREEN_HEIGHT)
+ { // Scrolling
+ int scroll_offset = (menu_height - SCREEN_HEIGHT) / 2 + 32;
+ pos_y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f;
+ }
+
effect_progress = (real_time - effect_start_time) * 6.0f;
if(effect_progress >= 1.0f) {
case MN_DEACTIVE:
{
context.draw_text(deactive_font, pitem.text,
- Vector(SCREEN_WIDTH/2, y_pos - int(deactive_font->get_height()/2)),
+ Vector(pos_x, y_pos - int(deactive_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
break;
}
case MN_LABEL:
{
context.draw_text(label_font, pitem.text,
- Vector(SCREEN_WIDTH/2, y_pos - int(label_font->get_height()/2)),
+ Vector(pos_x, y_pos - int(label_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
break;
}
case MN_NUMFIELD:
case MN_CONTROLFIELD:
{
- float left = SCREEN_WIDTH/2 - menu_width/2 + 16;
- float right = SCREEN_WIDTH/2 + menu_width/2 - 16;
+ float left = pos_x - menu_width/2 + 16;
+ float right = pos_x + menu_width/2 - 16;
if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
{
Color(0, 0, 0, 0.5f), LAYER_GUI - 5);
context.draw_text(text_font, pitem.list[pitem.selected],
- Vector(SCREEN_WIDTH/2 + text_pos, y_pos - int(text_font->get_height()/2)),
+ Vector(pos_x + text_pos, y_pos - int(text_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
context.draw_text(text_font, pitem.text,
- Vector(SCREEN_WIDTH/2 + list_pos_2/2, y_pos - int(text_font->get_height()/2)),
+ Vector(pos_x + list_pos_2/2, y_pos - int(text_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
break;
}
case MN_BACK:
{
context.draw_text(text_font, pitem.text,
- Vector(SCREEN_WIDTH/2, y_pos - int(text_font->get_height()/2)),
+ Vector(pos_x, y_pos - int(text_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
context.draw_surface(back.get(),
Vector(x_pos + text_width/2 + 16, y_pos - 8),
case MN_TOGGLE:
{
context.draw_text(text_font, pitem.text,
- Vector(SCREEN_WIDTH/2 - menu_width/2 + 16, y_pos - (text_font->get_height()/2)),
+ Vector(pos_x - menu_width/2 + 16, y_pos - (text_font->get_height()/2)),
ALIGN_LEFT, LAYER_GUI);
if(pitem.toggled)
}
case MN_ACTION:
context.draw_text(text_font, pitem.text,
- Vector(SCREEN_WIDTH/2, y_pos - int(text_font->get_height()/2)),
+ Vector(pos_x, y_pos - int(text_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
break;
case MN_GOTO:
context.draw_text(text_font, pitem.text,
- Vector(SCREEN_WIDTH/2, y_pos - int(text_font->get_height()/2)),
+ Vector(pos_x, y_pos - int(text_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI);
break;
}
return get_item_by_id(id).toggled;
}
+Menu*
+Menu::get_parent() const
+{
+ if (last_menus.empty())
+ return 0;
+ else
+ return last_menus.back();
+}
+
/* Check for menu event */
void
Menu::event(const SDL_Event& event)