diff options
Diffstat (limited to 'src/tracker_panel.cpp')
-rw-r--r-- | src/tracker_panel.cpp | 206 |
1 files changed, 99 insertions, 107 deletions
diff --git a/src/tracker_panel.cpp b/src/tracker_panel.cpp index 04b970c..ddb4df9 100644 --- a/src/tracker_panel.cpp +++ b/src/tracker_panel.cpp | |||
@@ -9,7 +9,6 @@ | |||
9 | #include "area_popup.h" | 9 | #include "area_popup.h" |
10 | #include "game_data.h" | 10 | #include "game_data.h" |
11 | #include "global.h" | 11 | #include "global.h" |
12 | #include "godot_variant.h" | ||
13 | #include "ipc_state.h" | 12 | #include "ipc_state.h" |
14 | #include "tracker_config.h" | 13 | #include "tracker_config.h" |
15 | #include "tracker_state.h" | 14 | #include "tracker_state.h" |
@@ -44,58 +43,46 @@ TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { | |||
44 | areas_.push_back(area); | 43 | areas_.push_back(area); |
45 | } | 44 | } |
46 | 45 | ||
46 | Resize(); | ||
47 | Redraw(); | 47 | Redraw(); |
48 | 48 | ||
49 | Bind(wxEVT_PAINT, &TrackerPanel::OnPaint, this); | 49 | Bind(wxEVT_PAINT, &TrackerPanel::OnPaint, this); |
50 | Bind(wxEVT_MOTION, &TrackerPanel::OnMouseMove, this); | 50 | Bind(wxEVT_MOTION, &TrackerPanel::OnMouseMove, this); |
51 | } | 51 | } |
52 | 52 | ||
53 | void TrackerPanel::UpdateIndicators() { | 53 | void TrackerPanel::UpdateIndicators(bool reset) { |
54 | if (panels_mode_ && !savedata_path_) { | 54 | if (reset) { |
55 | solved_panels_ = IPC_GetSolvedPanels(); | 55 | for (AreaIndicator &area : areas_) { |
56 | } | 56 | const MapArea &map_area = GD_GetMapArea(area.area_id); |
57 | 57 | ||
58 | for (AreaIndicator &area : areas_) { | 58 | if ((!AP_IsLocationVisible(map_area.classification) || |
59 | area.popup->UpdateIndicators(); | 59 | IsAreaPostgame(area.area_id)) && |
60 | } | 60 | !(map_area.hunt && |
61 | 61 | GetTrackerConfig().visible_panels == TrackerConfig::kHUNT_PANELS) && | |
62 | Redraw(); | 62 | !(map_area.has_single_panel && |
63 | } | 63 | GetTrackerConfig().visible_panels == TrackerConfig::kALL_PANELS) && |
64 | 64 | !(AP_IsPaintingShuffle() && !map_area.paintings.empty())) { | |
65 | void TrackerPanel::SetPanelsMode() { panels_mode_ = true; } | 65 | area.active = false; |
66 | 66 | } else { | |
67 | void TrackerPanel::SetSavedataPath(std::string savedata_path) { | 67 | area.active = true; |
68 | if (!savedata_path_) { | 68 | } |
69 | wxButton *refresh_button = | ||
70 | new wxButton(this, wxID_ANY, "Refresh", {15, 15}); | ||
71 | refresh_button->Bind(wxEVT_BUTTON, &TrackerPanel::OnRefreshSavedata, this); | ||
72 | } | ||
73 | |||
74 | savedata_path_ = savedata_path; | ||
75 | panels_mode_ = true; | ||
76 | |||
77 | RefreshSavedata(); | ||
78 | } | ||
79 | 69 | ||
80 | void TrackerPanel::RefreshSavedata() { | 70 | area.popup->ResetIndicators(); |
81 | solved_panels_.clear(); | 71 | } |
82 | 72 | ||
83 | GodotVariant godot_variant = ParseGodotFile(*savedata_path_); | 73 | Resize(); |
84 | for (const GodotVariant &panel_node : godot_variant.AsArray()) { | 74 | } else { |
85 | const std::vector<GodotVariant> &fields = panel_node.AsArray(); | 75 | for (AreaIndicator &area : areas_) { |
86 | if (fields[1].AsBool()) { | 76 | area.popup->UpdateIndicators(); |
87 | const std::vector<std::string> &nodepath = fields[0].AsNodePath(); | ||
88 | std::string key = fmt::format("{}/{}", nodepath[3], nodepath[4]); | ||
89 | solved_panels_.insert(key); | ||
90 | } | 77 | } |
91 | } | 78 | } |
92 | 79 | ||
93 | UpdateIndicators(); | 80 | Redraw(); |
94 | Refresh(); | ||
95 | } | 81 | } |
96 | 82 | ||
97 | void TrackerPanel::OnPaint(wxPaintEvent &event) { | 83 | void TrackerPanel::OnPaint(wxPaintEvent &event) { |
98 | if (GetSize() != rendered_.GetSize()) { | 84 | if (GetSize() != rendered_.GetSize()) { |
85 | Resize(); | ||
99 | Redraw(); | 86 | Redraw(); |
100 | } | 87 | } |
101 | 88 | ||
@@ -103,10 +90,13 @@ void TrackerPanel::OnPaint(wxPaintEvent &event) { | |||
103 | dc.DrawBitmap(rendered_, 0, 0); | 90 | dc.DrawBitmap(rendered_, 0, 0); |
104 | 91 | ||
105 | std::optional<std::tuple<int, int>> player_position; | 92 | std::optional<std::tuple<int, int>> player_position; |
106 | if (IPC_IsConnected()) { | 93 | if (GetTrackerConfig().track_position) |
107 | player_position = IPC_GetPlayerPosition(); | 94 | { |
108 | } else { | 95 | if (IPC_IsConnected()) { |
109 | player_position = AP_GetPlayerPosition(); | 96 | player_position = IPC_GetPlayerPosition(); |
97 | } else { | ||
98 | player_position = AP_GetPlayerPosition(); | ||
99 | } | ||
110 | } | 100 | } |
111 | 101 | ||
112 | if (player_position.has_value()) { | 102 | if (player_position.has_value()) { |
@@ -142,12 +132,8 @@ void TrackerPanel::OnMouseMove(wxMouseEvent &event) { | |||
142 | event.Skip(); | 132 | event.Skip(); |
143 | } | 133 | } |
144 | 134 | ||
145 | void TrackerPanel::OnRefreshSavedata(wxCommandEvent &event) { | 135 | void TrackerPanel::Resize() { |
146 | RefreshSavedata(); | 136 | wxSize panel_size = GetClientSize(); |
147 | } | ||
148 | |||
149 | void TrackerPanel::Redraw() { | ||
150 | wxSize panel_size = GetSize(); | ||
151 | wxSize image_size = map_image_.GetSize(); | 137 | wxSize image_size = map_image_.GetSize(); |
152 | 138 | ||
153 | int final_x = 0; | 139 | int final_x = 0; |
@@ -166,7 +152,7 @@ void TrackerPanel::Redraw() { | |||
166 | final_x = (panel_size.GetWidth() - final_width) / 2; | 152 | final_x = (panel_size.GetWidth() - final_width) / 2; |
167 | } | 153 | } |
168 | 154 | ||
169 | rendered_ = wxBitmap( | 155 | scaled_map_ = wxBitmap( |
170 | map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL) | 156 | map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL) |
171 | .Size(panel_size, {final_x, final_y}, 0, 0, 0)); | 157 | .Size(panel_size, {final_x, final_y}, 0, 0, 0)); |
172 | 158 | ||
@@ -181,30 +167,61 @@ void TrackerPanel::Redraw() { | |||
181 | wxBitmap(player_image_.Scale(player_width > 0 ? player_width : 1, | 167 | wxBitmap(player_image_.Scale(player_width > 0 ? player_width : 1, |
182 | player_height > 0 ? player_height : 1)); | 168 | player_height > 0 ? player_height : 1)); |
183 | 169 | ||
170 | real_area_size_ = final_width * AREA_EFFECTIVE_SIZE / image_size.GetWidth(); | ||
171 | |||
172 | for (AreaIndicator &area : areas_) { | ||
173 | const MapArea &map_area = GD_GetMapArea(area.area_id); | ||
174 | |||
175 | int real_area_x = final_x + (map_area.map_x - (AREA_EFFECTIVE_SIZE / 2)) * | ||
176 | final_width / image_size.GetWidth(); | ||
177 | int real_area_y = final_y + (map_area.map_y - (AREA_EFFECTIVE_SIZE / 2)) * | ||
178 | final_width / image_size.GetWidth(); | ||
179 | |||
180 | area.real_x1 = real_area_x; | ||
181 | area.real_x2 = real_area_x + real_area_size_; | ||
182 | area.real_y1 = real_area_y; | ||
183 | area.real_y2 = real_area_y + real_area_size_; | ||
184 | |||
185 | int popup_x = | ||
186 | final_x + map_area.map_x * final_width / image_size.GetWidth(); | ||
187 | int popup_y = | ||
188 | final_y + map_area.map_y * final_width / image_size.GetWidth(); | ||
189 | |||
190 | area.popup->SetClientSize( | ||
191 | area.popup->GetFullWidth(), | ||
192 | std::min(panel_size.GetHeight(), area.popup->GetFullHeight())); | ||
193 | |||
194 | if (area.popup->GetSize().GetHeight() > panel_size.GetHeight()) { | ||
195 | area.popup->SetSize(area.popup->GetSize().GetWidth(), | ||
196 | panel_size.GetHeight()); | ||
197 | } | ||
198 | |||
199 | if (popup_x + area.popup->GetSize().GetWidth() > panel_size.GetWidth()) { | ||
200 | popup_x = panel_size.GetWidth() - area.popup->GetSize().GetWidth(); | ||
201 | } | ||
202 | if (popup_y + area.popup->GetSize().GetHeight() > panel_size.GetHeight()) { | ||
203 | popup_y = panel_size.GetHeight() - area.popup->GetSize().GetHeight(); | ||
204 | } | ||
205 | area.popup->SetPosition({popup_x, popup_y}); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | void TrackerPanel::Redraw() { | ||
210 | rendered_ = scaled_map_; | ||
211 | |||
184 | wxMemoryDC dc; | 212 | wxMemoryDC dc; |
185 | dc.SelectObject(rendered_); | 213 | dc.SelectObject(rendered_); |
186 | 214 | ||
187 | int real_area_size = | ||
188 | final_width * AREA_EFFECTIVE_SIZE / image_size.GetWidth(); | ||
189 | int actual_border_size = | 215 | int actual_border_size = |
190 | real_area_size * AREA_BORDER_SIZE / AREA_EFFECTIVE_SIZE; | 216 | real_area_size_ * AREA_BORDER_SIZE / AREA_EFFECTIVE_SIZE; |
191 | const wxPoint upper_left_triangle[] = { | 217 | const wxPoint upper_left_triangle[] = { |
192 | {0, 0}, {0, real_area_size}, {real_area_size, 0}}; | 218 | {0, 0}, {0, real_area_size_}, {real_area_size_, 0}}; |
193 | const wxPoint lower_right_triangle[] = {{0, real_area_size - 1}, | 219 | const wxPoint lower_right_triangle[] = {{0, real_area_size_ - 1}, |
194 | {real_area_size - 1, 0}, | 220 | {real_area_size_ - 1, 0}, |
195 | {real_area_size, real_area_size}}; | 221 | {real_area_size_, real_area_size_}}; |
196 | 222 | ||
197 | for (AreaIndicator &area : areas_) { | 223 | for (AreaIndicator &area : areas_) { |
198 | const MapArea &map_area = GD_GetMapArea(area.area_id); | 224 | const MapArea &map_area = GD_GetMapArea(area.area_id); |
199 | if (panels_mode_) { | ||
200 | area.active = map_area.has_single_panel; | ||
201 | } else if (!AP_IsLocationVisible(map_area.classification) && | ||
202 | !(map_area.hunt && GetTrackerConfig().show_hunt_panels) && | ||
203 | !(AP_IsPaintingShuffle() && !map_area.paintings.empty())) { | ||
204 | area.active = false; | ||
205 | } else { | ||
206 | area.active = true; | ||
207 | } | ||
208 | 225 | ||
209 | if (!area.active) { | 226 | if (!area.active) { |
210 | continue; | 227 | continue; |
@@ -216,19 +233,15 @@ void TrackerPanel::Redraw() { | |||
216 | bool has_unchecked = false; | 233 | bool has_unchecked = false; |
217 | if (IsLocationWinCondition(section)) { | 234 | if (IsLocationWinCondition(section)) { |
218 | has_unchecked = !AP_HasReachedGoal(); | 235 | has_unchecked = !AP_HasReachedGoal(); |
219 | } else if (panels_mode_) { | 236 | } else if (AP_IsLocationVisible(section.classification) && |
220 | if (section.single_panel) { | 237 | !IsLocationPostgame(section.ap_location_id)) { |
221 | const Panel &panel = GD_GetPanel(*section.single_panel); | ||
222 | if (panel.non_counting) { | ||
223 | has_unchecked = !AP_HasCheckedGameLocation(section.ap_location_id); | ||
224 | } else { | ||
225 | has_unchecked = !GetSolvedPanels().contains(panel.nodepath); | ||
226 | } | ||
227 | } | ||
228 | } else if (AP_IsLocationVisible(section.classification)) { | ||
229 | has_unchecked = !AP_HasCheckedGameLocation(section.ap_location_id); | 238 | has_unchecked = !AP_HasCheckedGameLocation(section.ap_location_id); |
230 | } else if (section.hunt && GetTrackerConfig().show_hunt_panels) { | 239 | } else if ((section.hunt && GetTrackerConfig().visible_panels == |
231 | has_unchecked = !AP_HasCheckedHuntPanel(section.ap_location_id); | 240 | TrackerConfig::kHUNT_PANELS) || |
241 | (section.single_panel && GetTrackerConfig().visible_panels == | ||
242 | TrackerConfig::kALL_PANELS)) { | ||
243 | has_unchecked = | ||
244 | !AP_IsPanelSolved(GD_GetPanel(*section.single_panel).solve_index); | ||
232 | } | 245 | } |
233 | 246 | ||
234 | if (has_unchecked) { | 247 | if (has_unchecked) { |
@@ -240,8 +253,12 @@ void TrackerPanel::Redraw() { | |||
240 | } | 253 | } |
241 | } | 254 | } |
242 | 255 | ||
243 | if (AP_IsPaintingShuffle() && !panels_mode_) { | 256 | if (AP_IsPaintingShuffle()) { |
244 | for (int painting_id : map_area.paintings) { | 257 | for (int painting_id : map_area.paintings) { |
258 | if (IsPaintingPostgame(painting_id)) { | ||
259 | continue; | ||
260 | } | ||
261 | |||
245 | const PaintingExit &painting = GD_GetPaintingExit(painting_id); | 262 | const PaintingExit &painting = GD_GetPaintingExit(painting_id); |
246 | bool reachable = IsPaintingReachable(painting_id); | 263 | bool reachable = IsPaintingReachable(painting_id); |
247 | if (!reachable || !AP_IsPaintingChecked(painting.internal_id)) { | 264 | if (!reachable || !AP_IsPaintingChecked(painting.internal_id)) { |
@@ -254,10 +271,8 @@ void TrackerPanel::Redraw() { | |||
254 | } | 271 | } |
255 | } | 272 | } |
256 | 273 | ||
257 | int real_area_x = final_x + (map_area.map_x - (AREA_EFFECTIVE_SIZE / 2)) * | 274 | int real_area_x = area.real_x1; |
258 | final_width / image_size.GetWidth(); | 275 | int real_area_y = area.real_y1; |
259 | int real_area_y = final_y + (map_area.map_y - (AREA_EFFECTIVE_SIZE / 2)) * | ||
260 | final_width / image_size.GetWidth(); | ||
261 | 276 | ||
262 | if (has_reachable_unchecked && has_unreachable_unchecked && | 277 | if (has_reachable_unchecked && has_unreachable_unchecked && |
263 | GetTrackerConfig().hybrid_areas) { | 278 | GetTrackerConfig().hybrid_areas) { |
@@ -271,7 +286,7 @@ void TrackerPanel::Redraw() { | |||
271 | dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size)); | 286 | dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size)); |
272 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | 287 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
273 | dc.DrawRectangle({real_area_x, real_area_y}, | 288 | dc.DrawRectangle({real_area_x, real_area_y}, |
274 | {real_area_size, real_area_size}); | 289 | {real_area_size_, real_area_size_}); |
275 | 290 | ||
276 | } else { | 291 | } else { |
277 | const wxBrush *brush_color = wxGREY_BRUSH; | 292 | const wxBrush *brush_color = wxGREY_BRUSH; |
@@ -286,30 +301,7 @@ void TrackerPanel::Redraw() { | |||
286 | dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size)); | 301 | dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size)); |
287 | dc.SetBrush(*brush_color); | 302 | dc.SetBrush(*brush_color); |
288 | dc.DrawRectangle({real_area_x, real_area_y}, | 303 | dc.DrawRectangle({real_area_x, real_area_y}, |
289 | {real_area_size, real_area_size}); | 304 | {real_area_size_, real_area_size_}); |
290 | } | 305 | } |
291 | |||
292 | area.real_x1 = real_area_x; | ||
293 | area.real_x2 = real_area_x + real_area_size; | ||
294 | area.real_y1 = real_area_y; | ||
295 | area.real_y2 = real_area_y + real_area_size; | ||
296 | |||
297 | int popup_x = | ||
298 | final_x + map_area.map_x * final_width / image_size.GetWidth(); | ||
299 | int popup_y = | ||
300 | final_y + map_area.map_y * final_width / image_size.GetWidth(); | ||
301 | |||
302 | area.popup->SetClientSize( | ||
303 | area.popup->GetVirtualSize().GetWidth(), | ||
304 | std::min(panel_size.GetHeight(), | ||
305 | area.popup->GetVirtualSize().GetHeight())); | ||
306 | |||
307 | if (popup_x + area.popup->GetSize().GetWidth() > panel_size.GetWidth()) { | ||
308 | popup_x = panel_size.GetWidth() - area.popup->GetSize().GetWidth(); | ||
309 | } | ||
310 | if (popup_y + area.popup->GetSize().GetHeight() > panel_size.GetHeight()) { | ||
311 | popup_y = panel_size.GetHeight() - area.popup->GetSize().GetHeight(); | ||
312 | } | ||
313 | area.popup->SetPosition({popup_x, popup_y}); | ||
314 | } | 306 | } |
315 | } | 307 | } |