Implemented a gui1 radiobutton

Put it in place at the editor toolbar and the lobby preferences.
This commit is contained in:
fendrin 2013-03-29 17:22:24 +01:00
parent e047ba879f
commit 4f2e9e3e1a
5 changed files with 37 additions and 16 deletions

View file

@ -213,9 +213,11 @@
# The toolbar.
# First row.
[menu]
type=checkbox
type=radiobox
#type=checkbox
id=draw_button_editor
image=draw_button_editor
#image=checkbox
items=editor-tool-paint
# wmllint: local spelling left/right Ctrl+click
tooltip= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor."
@ -226,9 +228,11 @@
yanchor=fixed
[/menu]
[menu]
type=checkbox
type=radiobox
#type=checkbox
id=start_position_button_editor
image=start_position_button_editor
#image=checkbox
items=editor-tool-starting-position
# wmllint: local spelling alt+number
tooltip= _ "Left mouse button displays player selection, right clears. Number keys scroll to the starting position, alt+number sets respective starting position under cursor, delete clears."
@ -273,9 +277,11 @@
#Second Row.
[menu]
type=checkbox
type=radiobox
#type=checkbox
id=flood_button_editor
image=flood_button_editor
#image=checkbox
items=editor-tool-fill
# wmllint: local spelling fore-/background
tooltip= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor."
@ -286,9 +292,11 @@
yanchor=fixed
[/menu]
[menu]
type=checkbox
type=radiobox
#type=checkbox
id=select_button_editor
image=select_button_editor
#image=checkbox
items=editor-tool-select
# wmllint: local spelling deselects
tooltip= _ "Left mouse button selects, right deselects. Hold Shift for magic-wand selection of tiles with same terrain."
@ -343,6 +351,7 @@
[/menu]
[menu]
id=toggle_grid_button_editor
type=checkbox
image=toggle_grid_button_editor
items=togglegrid
tooltip_name_prepend=yes

View file

@ -821,6 +821,7 @@ gui::button::TYPE display::string_to_button_type(std::string type)
gui::button::TYPE res = gui::button::TYPE_PRESS;
if (type == "checkbox") { res = gui::button::TYPE_CHECK; }
else if (type == "image") { res = gui::button::TYPE_IMAGE; }
else if (type == "radiobox") { res = gui::button::TYPE_RADIO; }
return res;
}

View file

@ -175,9 +175,9 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
show_grid_button_(disp.video(), _("Show grid"), gui::button::TYPE_CHECK),
save_replays_button_(disp.video(), _("Save replays at the end of scenarios"), gui::button::TYPE_CHECK),
delete_saves_button_(disp.video(), _("Delete auto-saves at the end of scenarios"), gui::button::TYPE_CHECK),
show_lobby_joins_button1_(disp.video(), _("Do not show lobby joins"), gui::button::TYPE_CHECK),
show_lobby_joins_button2_(disp.video(), _("Show lobby joins of friends only"), gui::button::TYPE_CHECK),
show_lobby_joins_button3_(disp.video(), _("Show all lobby joins"), gui::button::TYPE_CHECK),
show_lobby_joins_button1_(disp.video(), _("Do not show lobby joins"), gui::button::TYPE_RADIO),
show_lobby_joins_button2_(disp.video(), _("Show lobby joins of friends only"), gui::button::TYPE_RADIO),
show_lobby_joins_button3_(disp.video(), _("Show all lobby joins"), gui::button::TYPE_RADIO),
sort_list_by_group_button_(disp.video(), _("Sort lobby list"), gui::button::TYPE_CHECK),
iconize_list_button_(disp.video(), _("Iconize lobby list"), gui::button::TYPE_CHECK),
remember_pw_button_(disp.video(), _("Save password to preferences (plain text)"), gui::button::TYPE_CHECK),

View file

@ -48,6 +48,10 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
button_image_name = "button";
} else if(button_image_name.empty() && type == TYPE_CHECK) {
button_image_name = "checkbox";
} else if(button_image_name.empty() && type == TYPE_RADIO) {
//TODO
//button_image_name = "radiobox";
button_image_name = "checkbox";
}
const std::string button_image_file = "buttons/" + button_image_name + ".png";
@ -63,7 +67,7 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
if (active_image.null())
active_image.assign(button_image);
if (type == TYPE_CHECK) {
if (type == TYPE_CHECK || type == TYPE_RADIO) {
touched_image.assign(image::get_image("buttons/" + button_image_name + "-touched.png"));
if (touched_image.null())
touched_image.assign(pressed_image);
@ -86,7 +90,7 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
set_label(label);
}
if(type == TYPE_PRESS) {
if(type_ == TYPE_PRESS) {
image_.assign(scale_surface(button_image,location().w,location().h));
pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
activeImage_.assign(scale_surface(active_image,location().w,location().h));
@ -94,7 +98,7 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
image_.assign(scale_surface(button_image,button_image->w,button_image->h));
pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
if (type == TYPE_CHECK)
if (type_ == TYPE_CHECK || type_ == TYPE_RADIO)
pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h));
touchedImage_.assign(scale_surface(touched_image, button_image->w, button_image->h));
}
@ -162,7 +166,7 @@ void button::calculate_size()
void button::set_check(bool check)
{
if (type_ != TYPE_CHECK)
if (type_ != TYPE_CHECK && type_ != TYPE_RADIO)
return;
STATE new_state = check ? PRESSED : NORMAL;
if (state_ != new_state) {
@ -231,7 +235,7 @@ void button::draw_contents()
const int texty = loc.y + loc.h / 2 - textRect_.h / 2 + offset;
int textx;
if (type_ != TYPE_CHECK)
if (type_ != TYPE_CHECK && type_ != TYPE_RADIO)
textx = loc.x + image->w / 2 - textRect_.w / 2 + offset;
else {
clipArea.w += image_w + checkbox_horizontal_padding;
@ -295,7 +299,7 @@ void button::mouse_motion(SDL_MouseMotionEvent const &event)
} else {
// the cursor is not over the widget
if (type_ == TYPE_CHECK) {
if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
switch (state_) {
case TOUCHED_NORMAL:
@ -320,8 +324,8 @@ void button::mouse_motion(SDL_MouseMotionEvent const &event)
void button::mouse_down(SDL_MouseButtonEvent const &event)
{
if (hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT) { //&& type_ != TYPE_CHECK){
if (type_ == TYPE_CHECK) {
if (hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT) {
if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
if (state_ == PRESSED_ACTIVE)
state_ = TOUCHED_PRESSED;
else if (state_ == ACTIVE)
@ -361,6 +365,13 @@ void button::mouse_up(SDL_MouseButtonEvent const &event)
}
if (pressed_) sound::play_UI_sound(game_config::sounds::checkbox_release);
break;
case TYPE_RADIO:
if (state_ == TOUCHED_NORMAL) {
state_ = PRESSED_ACTIVE;
pressed_ = true;
sound::play_UI_sound(game_config::sounds::checkbox_release);
}
break;
case TYPE_PRESS:
if (state_ == PRESSED) {
state_ = ACTIVE;

View file

@ -29,7 +29,7 @@ public:
{}
};
enum TYPE { TYPE_PRESS, TYPE_CHECK, TYPE_TURBO, TYPE_IMAGE };
enum TYPE { TYPE_PRESS, TYPE_CHECK, TYPE_TURBO, TYPE_IMAGE, TYPE_RADIO };
enum SPACE_CONSUMPTION { DEFAULT_SPACE, MINIMUM_SPACE };