completed 'floating labels' feature

This commit is contained in:
Dave White 2004-04-02 15:45:15 +00:00
parent 7cb180bd7d
commit 43a9d14974
5 changed files with 48 additions and 6 deletions

View file

@ -427,6 +427,7 @@ speed_normal="Normal"
speed_turbo="Accelerated Speed"
grid_button="Show Grid"
floating_labels_button="Show floating labels"
sound_settings="Sound Settings..."
sound_volume="SFX Volume:"

View file

@ -627,28 +627,34 @@ void attack(display& gui, const gamemap& map,
if(stats.attack_special == poison_string &&
d->second.has_flag("poisoned") == false &&
!d->second.type().not_living()) {
gui.float_label(d->first,translate_string("poisoned"),255,0,0);
d->second.set_flag("poisoned");
}
static const std::string slow_string("slow");
if(stats.attack_special == slow_string &&
d->second.has_flag("slowed") == false) {
gui.float_label(d->first,translate_string("slowed"),255,0,0);
d->second.set_flag("slowed");
if(stats.ndefends > 1)
--stats.ndefends;
}
if(stats.amount_attacker_drains > 0) {
char buf[50];
sprintf(buf,"%d",stats.amount_attacker_drains);
gui.float_label(a->first,buf,0,255,0);
a->second.gets_hit(-stats.amount_attacker_drains);
}
//if the defender is turned to stone, the fight stops immediately
static const std::string stone_string("stone");
if(stats.attack_special == stone_string) {
d->second.set_flag("stone");
gui.float_label(d->first,translate_string("stone"),255,0,0);
d->second.set_flag(stone_string);
stats.ndefends = 0;
stats.nattacks = 0;
game_events::fire("stone",d->first,a->first);
game_events::fire(stone_string,d->first,a->first);
}
}
@ -756,28 +762,35 @@ void attack(display& gui, const gamemap& map,
if(stats.defend_special == poison_string &&
a->second.has_flag("poisoned") == false &&
!a->second.type().not_living()) {
gui.float_label(a->first,translate_string("poisoned"),255,0,0);
a->second.set_flag("poisoned");
}
static const std::string slow_string("slow");
if(stats.defend_special == slow_string &&
a->second.has_flag("slowed") == false) {
gui.float_label(a->first,translate_string("slowed"),255,0,0);
a->second.set_flag("slowed");
if(stats.nattacks > 1)
--stats.nattacks;
}
if(stats.amount_defender_drains > 0) {
char buf[50];
sprintf(buf,"%d",stats.amount_defender_drains);
gui.float_label(d->first,buf,0,255,0);
d->second.gets_hit(-stats.amount_defender_drains);
}
//if the attacker is turned to stone, the fight stops immediately
static const std::string stone_string("stone");
if(stats.defend_special == stone_string) {
a->second.set_flag("stone");
gui.float_label(a->first,translate_string("stone"),255,0,0);
a->second.set_flag(stone_string);
stats.ndefends = 0;
stats.nattacks = 0;
game_events::fire("stone",a->first,d->first);
game_events::fire(stone_string,a->first,d->first);
}
}

View file

@ -1794,9 +1794,13 @@ void display::move_unit(const std::vector<gamemap::location>& path, unit& u)
void display::float_label(const gamemap::location& loc, const std::string& text,
int red, int green, int blue)
{
if(preferences::show_floating_labels() == false) {
return;
}
const SDL_Color colour = {red,green,blue,255};
font::add_floating_label(text,20,colour,get_location_x(loc)+zoom_*0.5,get_location_y(loc),
0,-3,40,screen_area());
font::add_floating_label(text,24,colour,get_location_x(loc)+zoom_*0.5,get_location_y(loc),
0,-2,60,screen_area());
}
bool display::unit_attack_ranged(const gamemap::location& a,

View file

@ -411,6 +411,16 @@ void set_colour_cursors(bool value)
cursor::use_colour(value);
}
bool show_floating_labels()
{
return prefs["floating_labels"] != "no";
}
void set_show_floating_labels(bool value)
{
prefs["floating_labels"] = value ? "yes" : "no";
}
void show_preferences_dialog(display& disp)
{
const events::resize_lock prevent_resizing;
@ -516,6 +526,12 @@ void show_preferences_dialog(display& disp)
grid_button.set_x(slider_left);
grid_button.set_y(sound_pos + 80 + 100);
gui::button floating_labels_button(disp,string_table["floating_labels_button"],
gui::button::TYPE_CHECK);
floating_labels_button.set_check(show_floating_labels());
floating_labels_button.set_x(slider_left);
floating_labels_button.set_y(sound_pos + 80 + 150);
gui::button resolution_button(disp,string_table["video_mode"]);
resolution_button.set_x(slider_left);
resolution_button.set_y(sound_pos + 80 + 200);
@ -573,6 +589,7 @@ void show_preferences_dialog(display& disp)
fullscreen_button.draw();
turbo_button.draw();
grid_button.draw();
floating_labels_button.draw();
close_button.draw();
resolution_button.draw();
turn_dialog_button.draw();
@ -607,6 +624,10 @@ void show_preferences_dialog(display& disp)
set_grid(grid_button.checked());
}
if(floating_labels_button.process(mousex,mousey,left_button)) {
set_show_floating_labels(floating_labels_button.checked());
}
if(resolution_button.process(mousex,mousey,left_button)) {
const bool mode_changed = show_video_mode_dialog(disp);
if(mode_changed) {

View file

@ -85,6 +85,9 @@ namespace preferences {
bool use_colour_cursors();
void set_colour_cursors(bool value);
bool show_floating_labels();
void set_show_floating_labels(bool value);
std::string client_type();
void set_theme(const std::string& theme);