#include "control/controller.hpp"
#include "gui/menu_manager.hpp"
+#include "gui/menu.hpp"
#include "gui/mousecursor.hpp"
#include "supertux/resources.hpp"
+#include "supertux/colorscheme.hpp"
#include "video/drawing_context.hpp"
#include "video/renderer.hpp"
#include "video/video_system.hpp"
m_text(),
m_buttons(),
m_selected_button(),
+ m_cancel_button(-1),
m_text_size()
{
}
}
void
-Dialog::add_button(const std::string& text, const std::function<void ()>& callback, bool focus)
+Dialog::clear_buttons()
{
- m_buttons.push_back({text, callback});
+ m_buttons.clear();
+ m_selected_button = 0;
+ m_cancel_button = -1;
+}
- if (focus)
- {
- m_selected_button = m_buttons.size() - 1;
- }
+void
+Dialog::add_default_button(const std::string& text, const std::function<void ()>& callback)
+{
+ add_button(text, callback);
+ m_selected_button = m_buttons.size() - 1;
+}
+
+void
+Dialog::add_cancel_button(const std::string& text, const std::function<void ()>& callback)
+{
+ add_button(text, callback);
+ m_cancel_button = m_buttons.size() - 1;
+}
+
+void
+Dialog::add_button(const std::string& text, const std::function<void ()>& callback)
+{
+ m_buttons.push_back({text, callback});
}
int
{
m_selected_button = new_button;
on_button_click(m_selected_button);
-
- // warning: this will "delete this"
- MenuManager::instance().set_dialog({});
}
}
break;
controller.pressed(Controller::MENU_SELECT))
{
on_button_click(m_selected_button);
+ }
- // warning: this will "delete this"
- MenuManager::instance().set_dialog({});
+ if (m_cancel_button != -1 &&
+ (controller.pressed(Controller::ESCAPE) ||
+ controller.pressed(Controller::MENU_BACK)))
+ {
+ on_button_click(m_cancel_button);
}
}
ctx.draw_text(Resources::normal_font, m_buttons[i].text,
Vector(pos.x, pos.y - int(Resources::normal_font->get_height()/2)),
- ALIGN_CENTER, LAYER_GUI);
+ ALIGN_CENTER, LAYER_GUI,
+ i == m_selected_button ? ColorScheme::Menu::active_color : ColorScheme::Menu::default_color);
}
}
{
m_buttons[button].callback();
}
+ MenuManager::instance().set_dialog({});
}
/* EOF */