Skip to content

Commit

Permalink
Enable the tooltips for the editor tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
fendrin committed May 15, 2013
1 parent 9464494 commit 4e17d42
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
17 changes: 16 additions & 1 deletion data/themes/editor.cfg
Expand Up @@ -690,6 +690,7 @@
items=editor-tool-paint
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="=+14,=+10,+30,+30"
xanchor=right
Expand All @@ -700,6 +701,7 @@
items=editor-tool-select
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -710,6 +712,7 @@
items=editor-tool-starting-position
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -720,6 +723,7 @@
items=editor-tool-item
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -730,6 +734,7 @@
items=editor-tool-village
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -741,6 +746,7 @@
items=editor-tool-fill
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
ref=tool-button1
rect="=,+2,+30,+30"
Expand All @@ -752,6 +758,7 @@
items=editor-paste
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -762,6 +769,7 @@
items=editor-tool-label
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -772,6 +780,7 @@
items=editor-tool-soundsource
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -782,6 +791,7 @@
items=editor-tool-unit
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+24,+24"
xanchor=right
Expand All @@ -793,8 +803,9 @@
items=editor-clipboard-flip-horizontal
#type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
ref=tool-button6
ref=tool-button6
rect="=,+18,+30,+30"
xanchor=right
yanchor=top
Expand All @@ -804,6 +815,7 @@
items=editor-clipboard-flip-vertical
#type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -814,6 +826,7 @@
items=editor-clipboard-rotate-cw
#type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -824,6 +837,7 @@
items=editor-clipboard-rotate-ccw
type=radiobox
image=button_square/button_square_30
auto_tooltip=yes
tooltip_name_prepend=yes
rect="+2,=,+30,+30"
xanchor=right
Expand All @@ -833,6 +847,7 @@
id=tool-button15
items=null
#type=radiobox
#auto_tooltip=yes
image=button_square/button_square_30
rect="+2,=,+30,+30"
xanchor=right
Expand Down
4 changes: 2 additions & 2 deletions src/display.cpp
Expand Up @@ -879,8 +879,8 @@ void display::create_buttons()
b.set_id(i->get_id());
const SDL_Rect& loc = i->location(screen_area());
b.set_location(loc.x,loc.y);
if (!i->tooltip().empty()){
b.set_tooltip_string(i->tooltip());
if (!i->tooltip(0).empty()){
b.set_tooltip_string(i->tooltip(0));
}
if(rects_overlap(b.location(),map_outside_area())) {
b.set_volatile(true);
Expand Down
5 changes: 3 additions & 2 deletions src/hotkeys.cpp
Expand Up @@ -1251,20 +1251,21 @@ void command_executor::set_button_state(display& disp) {

gui::button* button = disp.find_action_button(action.get_id());
bool enabled = false;
int i = 0;
BOOST_FOREACH(const std::string& command, action.items()) {

hotkey::HOTKEY_COMMAND command_id = hotkey::get_id(command);
std::string tooltip = action.tooltip();
std::string tooltip = action.tooltip(i);
if (file_exists(game_config::path + "/images/icons/action/" + command + "_30.png" ))
button->set_overlay("icons/action/" + command);
if (!tooltip.empty())
button->set_tooltip_string(tooltip);

bool can_execute = can_execute_command(command_id);
i++;
if (!can_execute) continue;
enabled = true;


ACTION_STATE state = get_action_state(command_id, -1);
switch (state) {
case ACTION_SELECTED:
Expand Down
24 changes: 19 additions & 5 deletions src/theme.cpp
Expand Up @@ -555,15 +555,29 @@ theme::action::action() :

theme::action::action(const config &cfg):
object(cfg), context_(cfg["is_context_menu"].to_bool()),
auto_tooltip_(cfg["auto_tooltip"].to_bool(false)),
tooltip_name_prepend_(cfg["tooltip_name_prepend"].to_bool(false)),
title_(cfg["title"].str() + cfg["title_literal"].str()),
tooltip_(cfg["tooltip"]), image_(cfg["image"]), overlay_(cfg["overlay"]), type_(cfg["type"]),
items_(utils::split(cfg["items"]))
{
if (cfg["auto_tooltip"].to_bool() && tooltip_.empty() && items_.size() == 1) {
tooltip_ = hotkey::get_description(items_[0]) + " hotkeys: " + hotkey::get_names(items_[0]) + "\n" + hotkey::get_tooltip(items_[0]);
} else if (cfg["tooltip_name_prepend"].to_bool() && items_.size() == 1) {
tooltip_ = hotkey::get_description(items_[0]) + " hotkeys: " + hotkey::get_names(items_[0]) + "\n" + tooltip_;
{}

const std::string theme::action::tooltip(size_t index) const {

std::stringstream result;
if (auto_tooltip_ && tooltip_.empty() && items_.size() > index) {
result << hotkey::get_description(items_[index]);
if (!hotkey::get_names(items_[index]).empty())
result << N_(" hotkeys: ") << hotkey::get_names(items_[index]);
result << "\n" << hotkey::get_tooltip(items_[index]);
} else if (tooltip_name_prepend_ && items_.size() == 1) {
result << hotkey::get_description(items_[index]); // << " hotkeys: "
if (!hotkey::get_names(items_[index]).empty())
result << N_(" hotkeys: ") << hotkey::get_names(items_[index]);
result << hotkey::get_names(items_[index]) << "\n" << tooltip_;
}

return result.str();
}

theme::theme(const config& cfg, const SDL_Rect& screen) :
Expand Down
4 changes: 2 additions & 2 deletions src/theme.hpp
Expand Up @@ -175,7 +175,7 @@ class theme

const std::string& title() const { return title_; }

const std::string& tooltip() const { return tooltip_; }
const std::string tooltip(size_t index) const;

const std::string& type() const { return type_; }

Expand All @@ -187,7 +187,7 @@ class theme

void set_title(const std::string& new_title) { title_ = new_title; }
private:
bool context_;
bool context_, auto_tooltip_, tooltip_name_prepend_;
std::string title_, tooltip_, image_, overlay_, type_;
std::vector<std::string> items_;
};
Expand Down

0 comments on commit 4e17d42

Please sign in to comment.