From b64f5fc814a8270782c411235259acec3ea84822 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 6 Aug 2025 12:21:39 -0500 Subject: [PATCH] messy map tooltip demo --- src/game/boe.items.cpp | 8 +++++--- src/game/boe.main.cpp | 24 +++++++++++++++++++++++- src/game/boe.town.cpp | 5 ++++- src/game/boe.town.hpp | 2 +- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/game/boe.items.cpp b/src/game/boe.items.cpp index 6ffaba6a..bb7a7533 100644 --- a/src/game/boe.items.cpp +++ b/src/game/boe.items.cpp @@ -41,7 +41,7 @@ extern short d_rect_index[80]; extern bool map_visible; extern cUniverse univ; -extern void draw_map(bool need_refresh); +extern void draw_map(bool need_refresh, std::string tooltip_text = ""); short selected; @@ -685,17 +685,19 @@ short get_num_of_items(short max_num) { // extern declaration doesn't work here?? const short view_max_dim = 40; +const short map_window_width = 296; +const short map_window_height = 307; void init_mini_map() { double map_scale = get_ui_scale_map(); if (map_scale < 0.1) map_scale = 1.0; 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? int map_x = get_int_pref("MapWindowX", 52); int map_y = get_int_pref("MapWindowY", 62); mini_map().setPosition(sf::Vector2i(map_x,map_y)); 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)); mini_map().setView(view); mini_map().setVisible(false); diff --git a/src/game/boe.main.cpp b/src/game/boe.main.cpp index 9eb4aa3f..5faaa4db 100644 --- a/src/game/boe.main.cpp +++ b/src/game/boe.main.cpp @@ -92,6 +92,8 @@ boost::optional scen_arg_out_sec, scen_arg_loc; extern std::string last_load_file; std::string help_text_rsrc = "help"; +std::string last_tooltip_text = ""; + /* // Example feature flags: { @@ -1444,6 +1446,26 @@ void handle_one_minimap_event(const sf::Event& event) { map_window_lost_focus = true; }else if(event.type == sf::Event::MouseMoved){ 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& 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){ switch(event.key.code){ case sf::Keyboard::Escape: @@ -1491,7 +1513,7 @@ void update_everything() { void redraw_everything() { 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) { diff --git a/src/game/boe.town.cpp b/src/game/boe.town.cpp index acc15dab..b3860ba3 100644 --- a/src/game/boe.town.cpp +++ b/src/game/boe.town.cpp @@ -62,6 +62,7 @@ location town_force_loc; bool shop_button_active[12]; rectangle map_title_rect = {3,50,15,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) { town_force = which_town; @@ -1312,7 +1313,7 @@ rectangle minimap_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; pic_num_t pic; 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().display(); diff --git a/src/game/boe.town.hpp b/src/game/boe.town.hpp index 8bb6429c..5916f7be 100644 --- a/src/game/boe.town.hpp +++ b/src/game/boe.town.hpp @@ -29,7 +29,7 @@ void erase_out_specials(); bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec type); void clear_map(); 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); void display_map(); void check_done();