about summary refs log tree commit diff stats
path: root/src/area_popup.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-01-30 16:38:08 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2024-01-30 16:38:08 -0500
commit19959f8479d1bb74f75890dcccbc038871771480 (patch)
tree56aab329819e56a7bcf405f08f2c0fbda9480270 /src/area_popup.cpp
parent90a208870cfe150f494e21b351152119f98633a2 (diff)
parent7cb55acb62c5a03df75edd0c3c8f228295c1bee8 (diff)
downloadlingo-ap-tracker-19959f8479d1bb74f75890dcccbc038871771480.tar.gz
lingo-ap-tracker-19959f8479d1bb74f75890dcccbc038871771480.tar.bz2
lingo-ap-tracker-19959f8479d1bb74f75890dcccbc038871771480.zip
Merge branch 'main' into future
Diffstat (limited to 'src/area_popup.cpp')
-rw-r--r--src/area_popup.cpp119
1 files changed, 80 insertions, 39 deletions
diff --git a/src/area_popup.cpp b/src/area_popup.cpp index 6bbc0cf..9c97d78 100644 --- a/src/area_popup.cpp +++ b/src/area_popup.cpp
@@ -2,73 +2,114 @@
2 2
3#include "ap_state.h" 3#include "ap_state.h"
4#include "game_data.h" 4#include "game_data.h"
5#include "global.h"
5#include "tracker_config.h" 6#include "tracker_config.h"
6#include "tracker_state.h" 7#include "tracker_state.h"
7 8
8AreaPopup::AreaPopup(wxWindow* parent, int area_id) 9AreaPopup::AreaPopup(wxWindow* parent, int area_id)
9 : wxScrolledWindow(parent, wxID_ANY), area_id_(area_id) { 10 : wxScrolledCanvas(parent, wxID_ANY), area_id_(area_id) {
10 const MapArea& map_area = GD_GetMapArea(area_id); 11 unchecked_eye_ =
11 12 wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(),
12 wxFlexGridSizer* section_sizer = new wxFlexGridSizer(2, 10, 10); 13 wxBITMAP_TYPE_PNG)
13 14 .Scale(32, 32));
14 for (const Location& location : map_area.locations) { 15 checked_eye_ = wxBitmap(
15 EyeIndicator* eye_indicator = new EyeIndicator(this); 16 wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG)
16 section_sizer->Add(eye_indicator, wxSizerFlags().Expand()); 17 .Scale(32, 32));
17 eye_indicators_.push_back(eye_indicator);
18
19 wxStaticText* section_label = new wxStaticText(this, -1, location.name);
20 section_label->SetForegroundColour(*wxWHITE);
21 section_sizer->Add(
22 section_label,
23 wxSizerFlags().Align(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL));
24 section_labels_.push_back(section_label);
25 }
26
27 wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL);
28
29 wxStaticText* top_label = new wxStaticText(this, -1, map_area.name);
30 top_label->SetForegroundColour(*wxWHITE);
31 top_label->SetFont(top_label->GetFont().Bold());
32 top_sizer->Add(top_label,
33 wxSizerFlags().Center().DoubleBorder(wxUP | wxLEFT | wxRIGHT));
34
35 top_sizer->Add(section_sizer, wxSizerFlags().DoubleBorder(wxALL).Expand());
36 18
37 SetSizerAndFit(top_sizer);
38 SetScrollRate(5, 5); 19 SetScrollRate(5, 5);
39 20
40 SetBackgroundColour(*wxBLACK); 21 SetBackgroundColour(*wxBLACK);
41 Hide(); 22 Hide();
23
24 Bind(wxEVT_PAINT, &AreaPopup::OnPaint, this);
25
26 UpdateIndicators();
42} 27}
43 28
44void AreaPopup::UpdateIndicators() { 29void AreaPopup::UpdateIndicators() {
45 const MapArea& map_area = GD_GetMapArea(area_id_); 30 const MapArea& map_area = GD_GetMapArea(area_id_);
31
32 // Start calculating extents.
33 wxMemoryDC mem_dc;
34 mem_dc.SetFont(GetFont().Bold());
35 wxSize header_extent = mem_dc.GetTextExtent(map_area.name);
36
37 int acc_height = header_extent.GetHeight() + 20;
38 int col_width = 0;
39
40 mem_dc.SetFont(GetFont());
41
42 std::vector<int> real_locations;
43
46 for (int section_id = 0; section_id < map_area.locations.size(); 44 for (int section_id = 0; section_id < map_area.locations.size();
47 section_id++) { 45 section_id++) {
48 const Location& location = map_area.locations.at(section_id); 46 const Location& location = map_area.locations.at(section_id);
49 wxSizer* container_sizer =
50 section_labels_[section_id]->GetContainingSizer();
51 47
52 if (!AP_IsLocationVisible(location.classification) && 48 if (!AP_IsLocationVisible(location.classification) &&
53 !(location.hunt && GetTrackerConfig().show_hunt_panels)) { 49 !(location.hunt && GetTrackerConfig().show_hunt_panels)) {
54 container_sizer->Hide(section_labels_[section_id]);
55 container_sizer->Hide(eye_indicators_[section_id]);
56 continue; 50 continue;
57 } else {
58 container_sizer->Show(section_labels_[section_id]);
59 container_sizer->Show(eye_indicators_[section_id]);
60 } 51 }
61 52
53 real_locations.push_back(section_id);
54
55 wxSize item_extent = mem_dc.GetTextExtent(location.name);
56 int item_height = std::max(32, item_extent.GetHeight()) + 10;
57 acc_height += item_height;
58
59 if (item_extent.GetWidth() > col_width) {
60 col_width = item_extent.GetWidth();
61 }
62 }
63
64 int item_width = col_width + 10 + 32;
65 int full_width = std::max(header_extent.GetWidth(), item_width) + 20;
66
67 Fit();
68 SetVirtualSize(full_width, acc_height);
69
70 rendered_ = wxBitmap(full_width, acc_height);
71 mem_dc.SelectObject(rendered_);
72 mem_dc.SetPen(*wxTRANSPARENT_PEN);
73 mem_dc.SetBrush(*wxBLACK_BRUSH);
74 mem_dc.DrawRectangle({0, 0}, {full_width, acc_height});
75
76 mem_dc.SetFont(GetFont().Bold());
77 mem_dc.SetTextForeground(*wxWHITE);
78 mem_dc.DrawText(map_area.name,
79 {(full_width - header_extent.GetWidth()) / 2, 10});
80
81 int cur_height = header_extent.GetHeight() + 20;
82
83 mem_dc.SetFont(GetFont());
84
85 for (int section_id : real_locations) {
86 const Location& location = map_area.locations.at(section_id);
87
62 bool checked = 88 bool checked =
63 AP_HasCheckedGameLocation(location.ap_location_id) || 89 AP_HasCheckedGameLocation(location.ap_location_id) ||
64 (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id)); 90 (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id));
91
92 wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_;
93
94 mem_dc.DrawBitmap(*eye_ptr, {10, cur_height});
95
65 bool reachable = IsLocationReachable(location.ap_location_id); 96 bool reachable = IsLocationReachable(location.ap_location_id);
66 const wxColour* text_color = reachable ? wxWHITE : wxRED; 97 const wxColour* text_color = reachable ? wxWHITE : wxRED;
98 mem_dc.SetTextForeground(*text_color);
67 99
68 section_labels_[section_id]->SetForegroundColour(*text_color); 100 wxSize item_extent = mem_dc.GetTextExtent(location.name);
69 eye_indicators_[section_id]->SetChecked(checked); 101 mem_dc.DrawText(
102 location.name,
103 {10 + 32 + 10, cur_height + (32 - mem_dc.GetFontMetrics().height) / 2});
104
105 cur_height += 10 + 32;
70 } 106 }
107}
108
109void AreaPopup::OnPaint(wxPaintEvent& event) {
110 wxPaintDC dc(this);
111 PrepareDC(dc);
112 dc.DrawBitmap(rendered_, 0, 0);
71 113
72 section_labels_[0]->GetContainingSizer()->Layout(); 114 event.Skip();
73 GetSizer()->Fit(this);
74} 115}