messy map tooltip demo

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

View File

@@ -42,7 +42,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;
@@ -684,17 +684,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);

View File

@@ -93,6 +93,8 @@ boost::optional<location> 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:
{
@@ -1445,6 +1447,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<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){
switch(event.key.code){
case sf::Keyboard::Escape:
@@ -1492,7 +1514,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) {

View File

@@ -63,6 +63,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;
@@ -1313,7 +1314,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;
@@ -1543,6 +1544,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();

View File

@@ -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();