Preferences: Reimplement orb color options

This commit is contained in:
Celtic Minstrel 2016-02-16 23:23:58 -05:00
parent d8268c0bd6
commit 38ddbb98f2
9 changed files with 479 additions and 55 deletions

View file

@ -176,13 +176,13 @@
type=custom
[/advanced_preference]
#ifdef __UNUSED__
[advanced_preference]
field=orb_color
name= _ "Customize orb colors (unimplemented)"
name= _ "Customize orb colors"
type=custom
[/advanced_preference]
#ifdef __UNUSED__
[advanced_preference]
field=joystick_support_enabled
name= _ "Joystick support"

View file

@ -13,28 +13,13 @@
rgb=FF0000,FFFFFF,000000,FF0000
name= _ "Red"
[/color_range]
[color_range]
id=orb_3red
rgb=FF0000,FFFFFF,000000,FF0000
name= _ "Red"
[/color_range]
[color_range]
id=orb_lightred
rgb=D1620D,FFFFFF,000000,FF0000
name= _ "Light Red"
[/color_range]
[color_range]
id=lightred
rgb=D1620D,FFFFFF,000000,FF0000
name= _ "Light Red"
[/color_range]
[color_range]
id=orb_darkred
rgb=8A0808,FFFFFF,000000,FF0000
name= _ "Dark Red"
[/color_range]
[color_range]
id=darkred
rgb=8A0808,FFFFFF,000000,FF0000
@ -46,17 +31,7 @@
rgb=2E419B,FFFFFF,0F0F0F,0000FF
name= _ "Blue"
[/color_range]
[color_range]
id=orb_6blue
rgb=2E419B,FFFFFF,0F0F0F,0000FF
name= _ "Blue"
[/color_range]
[color_range]
id=orb_5lightblue
rgb=00A4FF,FFFFFF,000A21,00A4FF
name= _ "Light blue"
[/color_range]
[color_range]
id=lightblue
rgb=00A4FF,FFFFFF,000A21,00A4FF
@ -69,11 +44,6 @@
name= _ "Green"
[/color_range]
[color_range]
id=orb_1brightgreen
rgb=8CFF00,EBFFBF,2D4001,8CFF00
name= _ "Bright green"
[/color_range]
[color_range]
id=brightgreen
rgb=8CFF00,EBFFBF,2D4001,8CFF00
@ -92,12 +62,6 @@
name= _ "Black"
[/color_range]
[color_range]
id=orb_6black
rgb=5A5A5A,FFFFFF,000000,000000
name= _ "Black"
[/color_range]
[color_range]
id=brown
rgb=945027,FFFFFF,000000,AA4600
@ -111,7 +75,7 @@
[/color_range]
[color_range]
id=orb_2brightorange
id=brightorange
rgb=FFC600,FFF7E6,792A00,FFC600
name= _ "Bright orange"
[/color_range]
@ -121,11 +85,6 @@
rgb=E1E1E1,FFFFFF,1E1E1E,FFFFFF
name= _ "White"
[/color_range]
[color_range]
id=orb_7white
rgb=E1E1E1,FFFFFF,1E1E1E,FFFFFF
name= _ "White"
[/color_range]
[color_range]
id=teal
@ -138,11 +97,6 @@
rgb=FFF35A,FFF8D2,994F13,FFF35A
name= _ "Gold"
[/color_range]
[color_range]
id=orb_8gold
rgb=FFF35A,FFF8D2,994F13,FFF35A
name= _ "Gold"
[/color_range]
# The following team colors are an extended palette meant specifically to recolor the background of terrain type icons
# Each color range is named after the terrain type it corresponds to.

View file

@ -47,11 +47,11 @@
footprint_teleport_exit="footsteps/teleport-out.png"
[colors]
enemy_orb_color="orb_6black"
unmoved_orb_color="orb_1brightgreen"
ally_orb_color="orb_5lightblue"
partial_orb_color="orb_2brightorange"
moved_orb_color="orb_3red"
enemy_orb_color="black"
unmoved_orb_color="brightgreen"
ally_orb_color="lightblue"
partial_orb_color="brightorange"
moved_orb_color="red"
[/colors]
[images]

View file

@ -0,0 +1,112 @@
#textdomain wesnoth-lib
###
### Definition of a selectable orb button.
###
#define _GUI_ICON SIZE STATE
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "('buttons/misc/orb{STATE}.png" + <<~RC(magenta>{icon})')>>
[/image]
#enddef
#define _GUI_RESOLUTION RESOLUTION SIZE
[resolution]
{RESOLUTION}
min_width = {SIZE}
min_height = {SIZE}
default_width = {SIZE}
default_height = {SIZE}
max_width = {SIZE}
max_height = {SIZE}
text_extra_width = 0
text_font_size = 0
[state]
[enabled]
[draw]
{_GUI_ICON ({SIZE}) ()}
[/draw]
[/enabled]
[disabled]
[draw]
{_GUI_ICON ({SIZE}) ()}
[/draw]
[/disabled]
[focused]
[draw]
{_GUI_ICON ({SIZE}) (-active)}
[/draw]
[/focused]
[/state]
###
### Selected
###
[state]
[enabled]
[draw]
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "buttons/button_square/button_square_30-pressed.png"
[/image]
{_GUI_ICON ({SIZE}) (-pressed)}
[/draw]
[/enabled]
[disabled]
[draw]
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "buttons/button_square/button_square_30-pressed.png"
[/image]
{_GUI_ICON ({SIZE}) (-pressed)}
[/draw]
[/disabled]
[focused]
[draw]
[image]
x = 0
y = 0
w = {SIZE}
h = {SIZE}
name = "buttons/button_square/button_square_30-active-pressed.png"
[/image]
{_GUI_ICON ({SIZE}) (-active)}
[/draw]
[/focused]
[/state]
[/resolution]
#enddef
[toggle_button_definition]
id = "orb"
description = "This toggle button is meant to be used in the select orbs dialog."
{_GUI_RESOLUTION ({GUI_NORMAL__RESOLUTION}) 30 }
[/toggle_button_definition]
#undef _GUI_RESOLUTION
#undef _GUI_ICON

View file

@ -0,0 +1,136 @@
#define _GUI_ORB_CELL PURPOSE COLOR
[column]
border = "all"
border_size = 5
[toggle_button]
id = "orb_{PURPOSE}_{COLOR}"
definition = "orb"
icon = "{COLOR}"
[/toggle_button]
[/column]
#enddef
#define _GUI_ORB_ROW PURPOSE
[grid]
id = "orb_{PURPOSE}_selection"
[row]
{_GUI_ORB_CELL {PURPOSE} brightgreen}
{_GUI_ORB_CELL {PURPOSE} brightorange}
{_GUI_ORB_CELL {PURPOSE} red}
{_GUI_ORB_CELL {PURPOSE} lightblue}
{_GUI_ORB_CELL {PURPOSE} black}
{_GUI_ORB_CELL {PURPOSE} blue}
{_GUI_ORB_CELL {PURPOSE} white}
{_GUI_ORB_CELL {PURPOSE} gold}
{_GUI_ORB_CELL {PURPOSE} darkred}
{_GUI_ORB_CELL {PURPOSE} lightred}
[/row]
[/grid]
#enddef
#define _GUI_ORB_GROUP PURPOSE LABEL
[row]
[column]
horizontal_alignment = "left"
border = "all"
border_size = 5
[toggle_button]
id = "orb_{PURPOSE}_show"
definition = "default"
label = {LABEL}
[/toggle_button]
[/column]
[/row]
[row]
[column]
horizontal_alignment = "left"
{_GUI_ORB_ROW {PURPOSE}}
[/column]
[/row]
#enddef
[window]
id = "select_orb_colors"
description = "Select the colors of orbs displayed on units for various purposes."
[resolution]
definition = "default"
click_dismiss = "true"
maximum_width = 600
maximum_height = 480
[tooltip]
id = "tooltip_large"
[/tooltip]
[helptip]
id = "tooltip_large"
[/helptip]
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Choose Orb/Minimap Colors"
[/label]
[/column]
[/row]
{_GUI_ORB_GROUP unmoved (_"Show unmoved orb")}
{_GUI_ORB_GROUP partial (_"Show partial moved orb")}
{_GUI_ORB_GROUP moved (_"Show moved orb")}
{_GUI_ORB_GROUP ally (_"Show ally orb")}
{_GUI_ORB_GROUP enemy (_"Show enemy orb")}
[row]
[column]
horizontal_grow = "true"
[grid]
[row]
[column]
horizontal_alignment = "left"
grow_factor = 1
border = "all"
border_size = 5
[button]
id = "orb_defaults"
definition = "default"
label = _ "Defaults"
[/button]
[/column]
[column]
horizontal_alignment = "right"
grow_factor = 0
border = "all"
border_size = 5
[button]
id = "ok"
definition = "default"
label = _ "OK"
[/button]
[/column]
[column]
horizontal_alignment = "right"
grow_factor = 0
border = "all"
border_size = 5
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
#undef _GUI_ORB_GROUP
#undef _GUI_ORB_ROW
#undef _GUI_ORB_CELL

View file

@ -77,6 +77,8 @@
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
911F2DAD1BA086A400E3102E /* window.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911F2DAB1BA086A400E3102E /* window.cpp */; };
911F2DB01BA086FA00E3102E /* alpha.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 911F2DAE1BA086F900E3102E /* alpha.cpp */; };
9130A4601C73BB6100852782 /* select_orb_colors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9130A45E1C73BB6100852782 /* select_orb_colors.cpp */; };
9130A4611C73BB6100852782 /* select_orb_colors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9130A45E1C73BB6100852782 /* select_orb_colors.cpp */; };
919B37F81BAF789E00E0094C /* synced_user_choice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B37F71BAF789D00E0094C /* synced_user_choice.cpp */; };
919B37FC1BAF7A9D00E0094C /* synced_choice_wait.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */; };
91B6217C1B74E6D200B00E0F /* label_settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B6217A1B74E6D100B00E0F /* label_settings.cpp */; };
@ -1264,6 +1266,8 @@
911F2DAE1BA086F900E3102E /* alpha.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = alpha.cpp; sourceTree = "<group>"; };
911F2DAF1BA086FA00E3102E /* alpha.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alpha.hpp; sourceTree = "<group>"; };
911F2DB11BA0870E00E3102E /* compat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = compat.hpp; sourceTree = "<group>"; };
9130A45E1C73BB6100852782 /* select_orb_colors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = select_orb_colors.cpp; sourceTree = "<group>"; };
9130A45F1C73BB6100852782 /* select_orb_colors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = select_orb_colors.hpp; sourceTree = "<group>"; };
919B37F71BAF789D00E0094C /* synced_user_choice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = synced_user_choice.cpp; sourceTree = "<group>"; };
919B37F91BAF78AB00E0094C /* synced_user_choice.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = synced_user_choice.hpp; sourceTree = "<group>"; };
919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = synced_choice_wait.cpp; sourceTree = "<group>"; };
@ -4046,6 +4050,8 @@
91F462831C71139B0050A9C9 /* preferences_dialog.hpp */,
EC19E6EE18B7F24B003B4B81 /* screenshot_notification.cpp */,
EC19E6EF18B7F24B003B4B81 /* screenshot_notification.hpp */,
9130A45E1C73BB6100852782 /* select_orb_colors.cpp */,
9130A45F1C73BB6100852782 /* select_orb_colors.hpp */,
B5CE470312A041EF00D665EE /* simple_item_selector.cpp */,
B5CE470412A041EF00D665EE /* simple_item_selector.hpp */,
919B37FA1BAF7A9D00E0094C /* synced_choice_wait.cpp */,
@ -5061,6 +5067,7 @@
91F4628C1C7116C40050A9C9 /* combobox.cpp in Sources */,
91F462901C7116E30050A9C9 /* combobox.cpp in Sources */,
91F462941C7117400050A9C9 /* drop_down_list.cpp in Sources */,
9130A4601C73BB6100852782 /* select_orb_colors.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -5389,6 +5396,7 @@
91F4628D1C7116C40050A9C9 /* combobox.cpp in Sources */,
91F462911C7116E30050A9C9 /* combobox.cpp in Sources */,
91F462951C7117400050A9C9 /* drop_down_list.cpp in Sources */,
9130A4611C73BB6100852782 /* select_orb_colors.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -30,6 +30,7 @@
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/dialogs/game_cache_options.hpp"
#include "gui/dialogs/mp_alerts_options.hpp"
#include "gui/dialogs/select_orb_colors.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/dialogs/transient_message.hpp"
@ -837,7 +838,7 @@ void tpreferences::on_advanced_prefs_list_select(tlistbox& list, twindow& window
}
if (selected_field == "orb_color") {
// TODO
gui2::tselect_orb_colors::display(window.video());
}
// Add more options here as needed

View file

@ -0,0 +1,160 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "select_orb_colors.hpp"
#include "gui/auxiliary/event/dispatcher.hpp"
#include "gui/auxiliary/find_widget.tpp"
#include "gui/auxiliary/iterator/walker.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "preferences.hpp"
#include "game_config.hpp"
#include <boost/bind.hpp>
namespace gui2 {
REGISTER_DIALOG(select_orb_colors);
tselect_orb_colors::tselect_orb_colors()
: show_unmoved_(preferences::show_unmoved_orb())
, show_partial_(preferences::show_partial_orb())
, show_moved_(preferences::show_moved_orb())
, show_ally_(preferences::show_allied_orb())
, show_enemy_(preferences::show_enemy_orb())
, unmoved_(preferences::unmoved_color())
, partial_(preferences::partial_color())
, moved_(preferences::moved_color())
, ally_(preferences::allied_color())
, enemy_(preferences::enemy_color())
{
}
void tselect_orb_colors::pre_show(CVideo&, twindow& window)
{
setup_orb_group("unmoved", show_unmoved_, unmoved_, window);
setup_orb_group("partial", show_partial_, partial_, window);
setup_orb_group("moved", show_moved_, moved_, window);
setup_orb_group("ally", show_ally_, ally_, window);
setup_orb_group("enemy", show_enemy_, enemy_, window);
tbutton& reset = find_widget<tbutton>(&window, "orb_defaults", false);
event::connect_signal_mouse_left_click(reset, boost::bind(
&tselect_orb_colors::handle_reset_click,
this, boost::ref(window)
));
}
void tselect_orb_colors::display(CVideo& video)
{
tselect_orb_colors dialog;
if(dialog.show(video)) {
preferences::set_show_unmoved_orb(dialog.show_unmoved_);
preferences::set_show_partial_orb(dialog.show_partial_);
preferences::set_show_moved_orb(dialog.show_moved_);
preferences::set_show_allied_orb(dialog.show_ally_);
preferences::set_show_enemy_orb(dialog.show_enemy_);
preferences::set_unmoved_color(dialog.unmoved_);
preferences::set_partial_color(dialog.partial_);
preferences::set_moved_color(dialog.moved_);
preferences::set_allied_color(dialog.ally_);
preferences::set_enemy_color(dialog.enemy_);
}
}
void tselect_orb_colors::setup_orb_group(const std::string& base_id, bool& shown, std::string& color, twindow& window, bool connect)
{
ttoggle_button& toggle = find_widget<ttoggle_button>(&window, "orb_" + base_id + "_show", false);
toggle.set_value_bool(shown);
if(connect) {
event::connect_signal_mouse_left_click(toggle, boost::bind(
&tselect_orb_colors::handle_toggle_click,
this,
boost::ref(shown)
));
}
tgrid& selection = find_widget<tgrid>(&window, "orb_" + base_id + "_selection", false);
std::vector<ttoggle_button*>& group = groups_[base_id];
using iterator::twalker_;
twalker_* iter = selection.create_walker();
while(!iter->at_end(twalker_::child)) {
twidget* next = iter->get(twalker_::child);
if(ttoggle_button* button = dynamic_cast<ttoggle_button*>(next)) {
group.push_back(button);
if(button->id().rfind("_" + color) != std::string::npos) {
button->set_value_bool(true);
} else {
button->set_value_bool(false);
}
if(connect) {
event::connect_signal_mouse_left_click(*button, boost::bind(
&tselect_orb_colors::handle_orb_click,
this,
button,
boost::ref(group),
boost::ref(color)
));
}
}
iter->next(twalker_::child);
}
}
void tselect_orb_colors::handle_orb_click(ttoggle_button* clicked, const std::vector<ttoggle_button*>& group, std::string& storage)
{
int split = clicked->id().find_last_of('_');
storage = clicked->id().substr(split + 1);
FOREACH(const AUTO& button, group) {
button->set_value_bool(false);
}
clicked->set_value_bool(true);
}
void tselect_orb_colors::handle_toggle_click(bool& storage)
{
storage = !storage;
}
void tselect_orb_colors::handle_reset_click(twindow& window)
{
show_unmoved_ = game_config::show_unmoved_orb;
show_partial_ = game_config::show_partial_orb;
show_moved_ = game_config::show_moved_orb;
show_ally_ = game_config::show_ally_orb;
show_enemy_ = game_config::show_enemy_orb;
unmoved_ = game_config::colors::unmoved_orb_color;
partial_ = game_config::colors::partial_orb_color;
moved_ = game_config::colors::moved_orb_color;
ally_ = game_config::colors::ally_orb_color;
enemy_ = game_config::colors::enemy_orb_color;
setup_orb_group("unmoved", show_unmoved_, unmoved_, window, false);
setup_orb_group("partial", show_partial_, partial_, window, false);
setup_orb_group("moved", show_moved_, moved_, window, false);
setup_orb_group("ally", show_ally_, ally_, window, false);
setup_orb_group("enemy", show_enemy_, enemy_, window, false);
}
}

View file

@ -0,0 +1,53 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_DIALOGS_SELECT_ORB_COLORS_HPP_INCLUDED
#define GUI_DIALOGS_SELECT_ORB_COLORS_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include <map>
namespace gui2 {
class ttoggle_button;
class tselect_orb_colors : public tdialog {
public:
tselect_orb_colors();
/**
* The display function.
*
* See @ref tdialog for more information.
*/
static void display(CVideo& video);
private:
void setup_orb_group(const std::string& base_id, bool& shown, std::string& color, twindow& window, bool connect = true);
void handle_orb_click(ttoggle_button* clicked, const std::vector<ttoggle_button*>& group, std::string& storage);
void handle_toggle_click(bool& storage);
void handle_reset_click(twindow& window);
bool show_unmoved_, show_partial_, show_moved_, show_ally_, show_enemy_;
std::string unmoved_, partial_, moved_, ally_, enemy_;
std::map<std::string, std::vector<ttoggle_button*> > groups_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
};
}
#endif