Fix visual bug in the announces system.

Follow up 'ceba081542a4'. It is nice to remove the previously
announced message when announces are being delivered very quickly, but
maybe movement feedback announces should be exempt of that. Before
this rev, Whenever an 'Enemy unit sighted' message was being ordered
coupled with a subsequent 'press $HOTKEY to keep moving', the 'Enemy
unit sighted' message was getting discarded.

src/actions/move.cpp: Movement feedback is important, do not remove
previous messaging when announcing.

src/display.cpp: Do not remove previously announced label when so
requested.

src/display.hpp: Add a `struct` device meant to pass optional
arguments to `void announce(const std::string&, const color_t&, ...)`
instead of primitive typed optional arguments (one, `int`, was being
in use, I would have needed to add a second one, `bool`, but when
trying to do that, the `bool` value would be received by the function
as the `int` argument when not providing an explicit value for the
`int` argument (see `src/actions/move.cpp`). Given C++11, for optional
arguments, does not (to the extent of my understanding) allow
specifying the argument name on the calling place, I was forced into
adding this struct in order to jail all primitive typed optional
arguments.

src/synced_commands.cpp: Adapt to new public API in `class display`.
This commit is contained in:
galegosimpatico 2017-10-13 22:30:24 +02:00 committed by Charles Dang
parent 78ffabd254
commit d98d7aa80c
5 changed files with 38 additions and 8 deletions

View File

@ -3,6 +3,8 @@ Version 1.13.10+dev:
* Updated translations: Chinese (Simplified)
* User Interface:
* Removed broken Unit Box and Widescreen themes.
* Fixed a bug that partially prevented movement feedback announce messages
to be displayed (UI regression bug #2130, affecting 1.13.8 and 1.13.10).
* WML Engine:
* File paths are now case sensitive even on Windows.

View File

@ -1133,10 +1133,13 @@ namespace { // Private helpers for move_unit()
redraw = true;
}
display::announce_options announce_options;
announce_options.discard_previous = false;
// Failed teleport feedback?
if ( playing_team_is_viewing_ && teleport_failed_ ) {
std::string teleport_string = _("Failed teleport! Exit not empty");
disp.announce(message_prefix + teleport_string, font::BAD_COLOR);
disp.announce(message_prefix + teleport_string, font::BAD_COLOR, announce_options);
message_prefix += " \n";
redraw = true;
}
@ -1166,7 +1169,7 @@ namespace { // Private helpers for move_unit()
msg_color = font::GOOD_COLOR;
}
disp.announce(message_prefix + message, msg_color);
disp.announce(message_prefix + message, msg_color, announce_options);
message_prefix += " \n";
redraw = true;
}
@ -1179,7 +1182,7 @@ namespace { // Private helpers for move_unit()
utils::string_map symbols;
symbols["hotkey"] = name;
std::string message = vgettext("(press $hotkey to keep moving)", symbols);
disp.announce(message_prefix + message, font::NORMAL_COLOR);
disp.announce(message_prefix + message, font::NORMAL_COLOR, announce_options);
message_prefix += " \n";
redraw = true;
}

View File

@ -1775,14 +1775,16 @@ void display::enable_menu(const std::string& item, bool enable)
}
}
void display::announce(const std::string& message, const color_t& color, int lifetime)
void display::announce(const std::string& message, const color_t& color, const announce_options& options)
{
font::remove_floating_label(prevLabel);
if(options.discard_previous) {
font::remove_floating_label(prevLabel);
}
font::floating_label flabel(message);
flabel.set_font_size(font::SIZE_XLARGE);
flabel.set_color(color);
flabel.set_position(map_outside_area().w/2, map_outside_area().h/3);
flabel.set_lifetime(lifetime);
flabel.set_lifetime(options.lifetime);
flabel.set_clip_rect(map_outside_area());
prevLabel = font::add_floating_label(flabel);

View File

@ -583,9 +583,30 @@ public:
map_labels& labels();
const map_labels& labels() const;
/** Holds options for calls to function 'announce' (@ref announce). */
struct announce_options
{
/** Lifetime measured in frames. */
int lifetime;
/**
* An announcement according these options should replace the
* previous announce (typical of fast announcing) or not
* (typical of movement feedback).
*/
bool discard_previous;
announce_options()
: lifetime(100)
, discard_previous(false)
{
}
};
/** Announce a message prominently. */
void announce(const std::string& msg,
const color_t& color = font::GOOD_COLOR, int lifetime = 100);
const color_t& color = font::GOOD_COLOR,
const announce_options& options = announce_options());
/**
* Schedule the minimap for recalculation.

View File

@ -392,7 +392,9 @@ namespace
{
utils::string_map symbols;
symbols["player"] = resources::controller->current_team().current_player();
resources::screen->announce(vgettext(message, symbols), font::NORMAL_COLOR, 1000);
display::announce_options announce_options;
announce_options.lifetime = 1000;
resources::screen->announce(vgettext(message, symbols), font::NORMAL_COLOR, announce_options);
}
}
SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_handler*/)