diff options
Diffstat (limited to 'src/area_popup.cpp')
-rw-r--r-- | src/area_popup.cpp | 118 |
1 files changed, 79 insertions, 39 deletions
diff --git a/src/area_popup.cpp b/src/area_popup.cpp index 6bbc0cf..8f694bb 100644 --- a/src/area_popup.cpp +++ b/src/area_popup.cpp | |||
@@ -2,73 +2,113 @@ | |||
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 | ||
8 | AreaPopup::AreaPopup(wxWindow* parent, int area_id) | 9 | AreaPopup::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 | ||
44 | void AreaPopup::UpdateIndicators() { | 29 | void 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 | SetVirtualSize(full_width, acc_height); | ||
68 | |||
69 | rendered_ = wxBitmap(full_width, acc_height); | ||
70 | mem_dc.SelectObject(rendered_); | ||
71 | mem_dc.SetPen(*wxTRANSPARENT_PEN); | ||
72 | mem_dc.SetBrush(*wxBLACK_BRUSH); | ||
73 | mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); | ||
74 | |||
75 | mem_dc.SetFont(GetFont().Bold()); | ||
76 | mem_dc.SetTextForeground(*wxWHITE); | ||
77 | mem_dc.DrawText(map_area.name, | ||
78 | {(full_width - header_extent.GetWidth()) / 2, 10}); | ||
79 | |||
80 | int cur_height = header_extent.GetHeight() + 20; | ||
81 | |||
82 | mem_dc.SetFont(GetFont()); | ||
83 | |||
84 | for (int section_id : real_locations) { | ||
85 | const Location& location = map_area.locations.at(section_id); | ||
86 | |||
62 | bool checked = | 87 | bool checked = |
63 | AP_HasCheckedGameLocation(location.ap_location_id) || | 88 | AP_HasCheckedGameLocation(location.ap_location_id) || |
64 | (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id)); | 89 | (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id)); |
90 | |||
91 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; | ||
92 | |||
93 | mem_dc.DrawBitmap(*eye_ptr, {10, cur_height}); | ||
94 | |||
65 | bool reachable = IsLocationReachable(location.ap_location_id); | 95 | bool reachable = IsLocationReachable(location.ap_location_id); |
66 | const wxColour* text_color = reachable ? wxWHITE : wxRED; | 96 | const wxColour* text_color = reachable ? wxWHITE : wxRED; |
97 | mem_dc.SetTextForeground(*text_color); | ||
67 | 98 | ||
68 | section_labels_[section_id]->SetForegroundColour(*text_color); | 99 | wxSize item_extent = mem_dc.GetTextExtent(location.name); |
69 | eye_indicators_[section_id]->SetChecked(checked); | 100 | mem_dc.DrawText( |
101 | location.name, | ||
102 | {10 + 32 + 10, cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); | ||
103 | |||
104 | cur_height += 10 + 32; | ||
70 | } | 105 | } |
106 | } | ||
107 | |||
108 | void AreaPopup::OnPaint(wxPaintEvent& event) { | ||
109 | wxPaintDC dc(this); | ||
110 | PrepareDC(dc); | ||
111 | dc.DrawBitmap(rendered_, 0, 0); | ||
71 | 112 | ||
72 | section_labels_[0]->GetContainingSizer()->Layout(); | 113 | event.Skip(); |
73 | GetSizer()->Fit(this); | ||
74 | } | 114 | } |