editor: show "Map Saved" and "Scenario Saved" messages as floating label
gui2 messages grab mouse focus (modal dialog), so the user needs to click on it first before doing anything else
This commit is contained in:
parent
fe9aeb6548
commit
a25d10bbed
4 changed files with 44 additions and 6 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "editor/editor_display.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "font/sdl_ttf_compat.hpp" // for pango_line_width
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "team.hpp"
|
||||
|
@ -111,7 +112,7 @@ void editor_display::layout()
|
|||
display::layout();
|
||||
|
||||
config element;
|
||||
config::attribute_value &text = element.add_child("element")["text"];
|
||||
config::attribute_value& text = element.add_child("element")["text"];
|
||||
// Fill in the terrain report
|
||||
if (get_map().on_board_with_border(mouseoverHex_)) {
|
||||
text = get_map().get_terrain_editor_string(mouseoverHex_);
|
||||
|
@ -157,6 +158,33 @@ display::overlay_map& editor_display::get_overlays()
|
|||
return controller_.get_current_map_context().get_overlays();
|
||||
}
|
||||
|
||||
void editor_display::set_status(const std::string& str, const bool is_success)
|
||||
{
|
||||
const color_t color{0, 0, 0, 0xbb};
|
||||
int size = font::SIZE_SMALL;
|
||||
point canvas_size = video::game_canvas_size();
|
||||
const int border = 3;
|
||||
|
||||
std::string formatted_str;
|
||||
if (is_success) {
|
||||
formatted_str = VGETTEXT("<span color='#66ff00'><span face='DejaVuSans'>✔</span> $msg</span>", {{"msg", str}});
|
||||
} else {
|
||||
formatted_str = VGETTEXT("<span color='red'><span face='DejaVuSans'>✘</span> $msg</span>", {{"msg", str}});
|
||||
}
|
||||
|
||||
font::floating_label flabel(formatted_str);
|
||||
flabel.set_font_size(size);
|
||||
flabel.set_position(0, canvas_size.y);
|
||||
flabel.set_bg_color(color);
|
||||
flabel.set_border_size(border);
|
||||
flabel.set_lifetime(1000, 10);
|
||||
flabel.use_markup(true);
|
||||
|
||||
const int f_handle = font::add_floating_label(flabel);
|
||||
const auto& r = font::get_floating_label_rect(f_handle);
|
||||
font::move_floating_label(f_handle, r.w, -r.h);
|
||||
}
|
||||
|
||||
void editor_display::set_help_string_enabled(bool value)
|
||||
{
|
||||
help_string_enabled_ = value;
|
||||
|
|
|
@ -61,6 +61,16 @@ public:
|
|||
mouseover_hex_overlay_.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a status text at the bottom left of the map area
|
||||
*
|
||||
* @param str The text to display.
|
||||
* @param is_success Type of message.
|
||||
* When true, message is shown in green with checkmark.
|
||||
* When false, message is shown in red with cross mark
|
||||
*/
|
||||
void set_status(const std::string& str, const bool is_success);
|
||||
|
||||
/**
|
||||
* Sets and shows the tooltip-like text at the top or bottom of the map area.
|
||||
*
|
||||
|
|
|
@ -887,10 +887,10 @@ bool context_manager::write_scenario(bool display_confirmation)
|
|||
try {
|
||||
get_map_context().save_scenario();
|
||||
if(display_confirmation) {
|
||||
gui2::show_transient_message("", _("Scenario saved."));
|
||||
gui_.set_status(_("Scenario saved."), true);
|
||||
}
|
||||
} catch (const editor_map_save_exception& e) {
|
||||
gui2::show_transient_message("", e.what());
|
||||
gui_.set_status(e.what(), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -902,10 +902,10 @@ bool context_manager::write_map(bool display_confirmation)
|
|||
try {
|
||||
get_map_context().save_map();
|
||||
if(display_confirmation) {
|
||||
gui2::show_transient_message("", _("Map saved."));
|
||||
gui_.set_status(_("Map saved"), true);
|
||||
}
|
||||
} catch (const editor_map_save_exception& e) {
|
||||
gui2::show_transient_message("", e.what());
|
||||
gui_.set_status(e.what(), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ bool floating_label::create_texture()
|
|||
return false;
|
||||
}
|
||||
|
||||
DBG_FT << "creating floating label texture";
|
||||
DBG_FT << "creating floating label texture, text: " << text_.substr(0,15);
|
||||
font::pango_text& text = font::get_text_renderer();
|
||||
|
||||
text.set_link_aware(false)
|
||||
|
|
Loading…
Add table
Reference in a new issue