messy map tooltip demo

This commit is contained in:
2025-08-06 12:21:39 -05:00
parent 4fb08daae5
commit b64f5fc814
4 changed files with 33 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ extern short d_rect_index[80];
extern bool map_visible; extern bool map_visible;
extern cUniverse univ; extern cUniverse univ;
extern void draw_map(bool need_refresh); extern void draw_map(bool need_refresh, std::string tooltip_text = "");
short selected; short selected;
@@ -685,17 +685,19 @@ short get_num_of_items(short max_num) {
// extern declaration doesn't work here?? // extern declaration doesn't work here??
const short view_max_dim = 40; const short view_max_dim = 40;
const short map_window_width = 296;
const short map_window_height = 307;
void init_mini_map() { void init_mini_map() {
double map_scale = get_ui_scale_map(); double map_scale = get_ui_scale_map();
if (map_scale < 0.1) map_scale = 1.0; if (map_scale < 0.1) map_scale = 1.0;
if (mini_map().isOpen()) mini_map().close(); if (mini_map().isOpen()) mini_map().close();
mini_map().create(sf::VideoMode(map_scale*296,map_scale*277), "Map", sf::Style::Titlebar | sf::Style::Close); mini_map().create(sf::VideoMode(map_scale*map_window_width,map_scale*map_window_height), "Map", sf::Style::Titlebar | sf::Style::Close);
// TODO why is 52,62 the default position, anyway? // TODO why is 52,62 the default position, anyway?
int map_x = get_int_pref("MapWindowX", 52); int map_x = get_int_pref("MapWindowX", 52);
int map_y = get_int_pref("MapWindowY", 62); int map_y = get_int_pref("MapWindowY", 62);
mini_map().setPosition(sf::Vector2i(map_x,map_y)); mini_map().setPosition(sf::Vector2i(map_x,map_y));
sf::View view; sf::View view;
view.reset(sf::FloatRect(0, 0, map_scale*296,map_scale*277)); view.reset(sf::FloatRect(0, 0, map_scale*map_window_width,map_scale*map_window_height));
view.setViewport(sf::FloatRect(0, 0, map_scale, map_scale)); view.setViewport(sf::FloatRect(0, 0, map_scale, map_scale));
mini_map().setView(view); mini_map().setView(view);
mini_map().setVisible(false); mini_map().setVisible(false);

View File

@@ -92,6 +92,8 @@ boost::optional<location> scen_arg_out_sec, scen_arg_loc;
extern std::string last_load_file; extern std::string last_load_file;
std::string help_text_rsrc = "help"; std::string help_text_rsrc = "help";
std::string last_tooltip_text = "";
/* /*
// Example feature flags: // Example feature flags:
{ {
@@ -1444,6 +1446,26 @@ void handle_one_minimap_event(const sf::Event& event) {
map_window_lost_focus = true; map_window_lost_focus = true;
}else if(event.type == sf::Event::MouseMoved){ }else if(event.type == sf::Event::MouseMoved){
check_window_moved(mini_map(), last_map_x, last_map_y, "MapWindow"); check_window_moved(mini_map(), last_map_x, last_map_y, "MapWindow");
// Check if something interesting is hovered
location tile = minimap_view_rect().topLeft();
int x = event.mouseMove.x;
int y = event.mouseMove.y;
tile.x += (x - (47 * get_ui_scale_map())) / get_ui_scale_map() / 6;
tile.y += (y - (29 * get_ui_scale_map())) / get_ui_scale_map() / 6;
std::string tooltip_text = "";
if(is_explored(tile.x, tile.y)){
const std::vector<info_rect_t>& area_desc = is_out() ? univ.out->area_desc : univ.town->area_desc;
for(info_rect_t area : area_desc){
if(area.contains(tile)){
tooltip_text += area.descr + " |";
}
}
}
if(tooltip_text != last_tooltip_text)
draw_map(false, tooltip_text);
last_tooltip_text = tooltip_text;
}else if(event.type == sf::Event::KeyPressed){ }else if(event.type == sf::Event::KeyPressed){
switch(event.key.code){ switch(event.key.code){
case sf::Keyboard::Escape: case sf::Keyboard::Escape:
@@ -1491,7 +1513,7 @@ void update_everything() {
void redraw_everything() { void redraw_everything() {
redraw_screen(REFRESH_ALL); redraw_screen(REFRESH_ALL);
if(map_visible) draw_map(false); if(map_visible) draw_map(false, last_tooltip_text);
} }
void Mouse_Pressed(const sf::Event& event, cFramerateLimiter& fps_limiter) { void Mouse_Pressed(const sf::Event& event, cFramerateLimiter& fps_limiter) {

View File

@@ -62,6 +62,7 @@ location town_force_loc;
bool shop_button_active[12]; bool shop_button_active[12];
rectangle map_title_rect = {3,50,15,300}; rectangle map_title_rect = {3,50,15,300};
rectangle map_bar_rect = {15,50,27,300}; rectangle map_bar_rect = {15,50,27,300};
rectangle map_tooltip_rect = {270,50,307,350};
void force_town_enter(short which_town,location where_start) { void force_town_enter(short which_town,location where_start) {
town_force = which_town; town_force = which_town;
@@ -1312,7 +1313,7 @@ rectangle minimap_view_rect() {
return view_rect; return view_rect;
} }
void draw_map(bool need_refresh) { void draw_map(bool need_refresh, std::string tooltip_text) {
if(!map_visible) return; if(!map_visible) return;
pic_num_t pic; pic_num_t pic;
rectangle the_rect; rectangle the_rect;
@@ -1542,6 +1543,8 @@ void draw_map(bool need_refresh) {
} }
} }
win_draw_string(mini_map(), map_tooltip_rect,tooltip_text,eTextMode::WRAP,style);
mini_map().setActive(false); mini_map().setActive(false);
mini_map().display(); mini_map().display();

View File

@@ -29,7 +29,7 @@ void erase_out_specials();
bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec type); bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec type);
void clear_map(); void clear_map();
rectangle minimap_view_rect(); rectangle minimap_view_rect();
void draw_map(bool need_refresh); void draw_map(bool need_refresh, std::string tooltip_text = "");
bool is_door(location destination); bool is_door(location destination);
void display_map(); void display_map();
void check_done(); void check_done();