From 712313d825db7ce7c9d4457f7564b27d3dd4ce64 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 8 Feb 2025 15:11:23 -0500 Subject: Added a scrollbar to subway reports --- src/subway_map.cpp | 127 ++++++++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 75 deletions(-) (limited to 'src/subway_map.cpp') diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 0a250fb..c554b16 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp @@ -9,6 +9,7 @@ #include "ap_state.h" #include "game_data.h" #include "global.h" +#include "report_popup.h" #include "tracker_state.h" constexpr int AREA_ACTUAL_SIZE = 21; @@ -31,14 +32,6 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { return; } - unchecked_eye_ = - wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), - wxBITMAP_TYPE_PNG) - .Scale(32, 32)); - checked_eye_ = wxBitmap( - wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) - .Scale(32, 32)); - tree_ = std::make_unique>( quadtree::Box{0, 0, static_cast(map_image_.GetWidth()), static_cast(map_image_.GetHeight())}); @@ -63,6 +56,8 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { help_button_ = new wxButton(this, wxID_ANY, "Help"); help_button_->Bind(wxEVT_BUTTON, &SubwayMap::OnClickHelp, this); SetUpHelpButton(); + + report_popup_ = new ReportPopup(this); } void SubwayMap::OnConnect() { @@ -202,6 +197,8 @@ void SubwayMap::UpdateIndicators() { } } + report_popup_->UpdateIndicators(); + Redraw(); } @@ -310,67 +307,6 @@ void SubwayMap::OnPaint(wxPaintEvent &event) { } if (hovered_item_) { - // Note that these requirements are duplicated on OnMouseClick so that it - // knows when an item has a hover effect. - const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); - std::optional subway_door = GetRealSubwayDoor(subway_item); - - if (subway_door && !GetDoorRequirements(*subway_door).empty()) { - const std::map &report = - GetDoorRequirements(*subway_door); - - int acc_height = 10; - int col_width = 0; - - for (const auto &[text, obtained] : report) { - wxSize item_extent = dc.GetTextExtent(text); - int item_height = std::max(32, item_extent.GetHeight()) + 10; - acc_height += item_height; - - if (item_extent.GetWidth() > col_width) { - col_width = item_extent.GetWidth(); - } - } - - int item_width = col_width + 10 + 32; - int full_width = item_width + 20; - - wxPoint popup_pos = - MapPosToRenderPos({subway_item.x + AREA_ACTUAL_SIZE / 2, - subway_item.y + AREA_ACTUAL_SIZE / 2}); - - if (popup_pos.x + full_width > GetSize().GetWidth()) { - popup_pos.x = GetSize().GetWidth() - full_width; - } - if (popup_pos.y + acc_height > GetSize().GetHeight()) { - popup_pos.y = GetSize().GetHeight() - acc_height; - } - - dc.SetPen(*wxTRANSPARENT_PEN); - dc.SetBrush(*wxBLACK_BRUSH); - dc.DrawRectangle(popup_pos, {full_width, acc_height}); - - dc.SetFont(GetFont()); - - int cur_height = 10; - - for (const auto &[text, obtained] : report) { - wxBitmap *eye_ptr = obtained ? &checked_eye_ : &unchecked_eye_; - - dc.DrawBitmap(*eye_ptr, popup_pos + wxPoint{10, cur_height}); - - dc.SetTextForeground(obtained ? *wxWHITE : *wxRED); - wxSize item_extent = dc.GetTextExtent(text); - dc.DrawText( - text, - popup_pos + - wxPoint{10 + 32 + 10, - cur_height + (32 - dc.GetFontMetrics().height) / 2}); - - cur_height += 10 + 32; - } - } - if (networks_.IsItemInNetwork(*hovered_item_)) { dc.SetBrush(*wxTRANSPARENT_BRUSH); @@ -470,9 +406,7 @@ void SubwayMap::OnMouseMove(wxMouseEvent &event) { } if (!sticky_hover_ && actual_hover_ != hovered_item_) { - hovered_item_ = actual_hover_; - - Refresh(); + EvaluateHover(); } if (scroll_mode_) { @@ -514,13 +448,11 @@ void SubwayMap::OnMouseClick(wxMouseEvent &event) { if ((subway_door && !GetDoorRequirements(*subway_door).empty()) || networks_.IsItemInNetwork(*hovered_item_)) { if (actual_hover_ != hovered_item_) { - hovered_item_ = actual_hover_; + EvaluateHover(); if (!hovered_item_) { sticky_hover_ = false; } - - Refresh(); } else { sticky_hover_ = !sticky_hover_; } @@ -723,6 +655,51 @@ void SubwayMap::EvaluateScroll(wxPoint pos) { SetScrollSpeed(scroll_x, scroll_y); } +void SubwayMap::EvaluateHover() { + hovered_item_ = actual_hover_; + + if (hovered_item_) { + // Note that these requirements are duplicated on OnMouseClick so that it + // knows when an item has a hover effect. + const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); + std::optional subway_door = GetRealSubwayDoor(subway_item); + + if (subway_door && !GetDoorRequirements(*subway_door).empty()) { + report_popup_->SetDoorId(*subway_door); + + wxPoint popupPos = + MapPosToRenderPos({subway_item.x + AREA_ACTUAL_SIZE / 2, + subway_item.y + AREA_ACTUAL_SIZE / 2}); + + report_popup_->SetClientSize( + report_popup_->GetVirtualSize().GetWidth(), + std::min(GetSize().GetHeight(), + report_popup_->GetVirtualSize().GetHeight())); + + if (popupPos.x + report_popup_->GetSize().GetWidth() > + GetSize().GetWidth()) { + popupPos.x = GetSize().GetWidth() - report_popup_->GetSize().GetWidth(); + } + if (popupPos.y + report_popup_->GetSize().GetHeight() > + GetSize().GetHeight()) { + popupPos.y = + GetSize().GetHeight() - report_popup_->GetSize().GetHeight(); + } + report_popup_->SetPosition(popupPos); + + report_popup_->Show(); + } else { + report_popup_->Reset(); + report_popup_->Hide(); + } + } else { + report_popup_->Reset(); + report_popup_->Hide(); + } + + Refresh(); +} + wxPoint SubwayMap::MapPosToRenderPos(wxPoint pos) const { return {static_cast(pos.x * render_width_ * zoom_ / map_image_.GetSize().GetWidth() + -- cgit 1.4.1