diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-08 10:52:51 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-08 10:52:51 -0500 |
commit | f8f55976533ac3b77bb8d31697ba2f1e54a994c1 (patch) | |
tree | 59b4cd49e64af291b2fd0b22711174bfd79149fa /src | |
parent | 5fe5bec92e86a4a94cddefec51fabc22212b7364 (diff) | |
download | lingo-ap-tracker-f8f55976533ac3b77bb8d31697ba2f1e54a994c1.tar.gz lingo-ap-tracker-f8f55976533ac3b77bb8d31697ba2f1e54a994c1.tar.bz2 lingo-ap-tracker-f8f55976533ac3b77bb8d31697ba2f1e54a994c1.zip |
Made indicator updates more fine-grained
Diffstat (limited to 'src')
-rw-r--r-- | src/ap_state.cpp | 93 | ||||
-rw-r--r-- | src/ap_state.h | 6 | ||||
-rw-r--r-- | src/ipc_state.cpp | 4 | ||||
-rw-r--r-- | src/paintings_pane.cpp | 12 | ||||
-rw-r--r-- | src/paintings_pane.h | 3 | ||||
-rw-r--r-- | src/subway_map.cpp | 2 | ||||
-rw-r--r-- | src/tracker_frame.cpp | 73 | ||||
-rw-r--r-- | src/tracker_frame.h | 37 |
8 files changed, 133 insertions, 97 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 29e649f..d01290b 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp | |||
@@ -243,7 +243,7 @@ struct APState { | |||
243 | checked_paintings.count(painting_mapping.at(painting_id))); | 243 | checked_paintings.count(painting_mapping.at(painting_id))); |
244 | } | 244 | } |
245 | 245 | ||
246 | std::string GetItemName(int id) { return apclient->get_item_name(id); } | 246 | std::string GetItemName(int id) { return apclient->get_item_name(id, "Lingo"); } |
247 | 247 | ||
248 | void RevealPaintings() { | 248 | void RevealPaintings() { |
249 | std::lock_guard state_guard(state_mutex); | 249 | std::lock_guard state_guard(state_mutex); |
@@ -369,7 +369,7 @@ struct APState { | |||
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | RefreshTracker(false); | 372 | RefreshTracker(StateUpdate{.cleared_locations = true}); |
373 | } | 373 | } |
374 | 374 | ||
375 | void OnSlotDisconnected() { | 375 | void OnSlotDisconnected() { |
@@ -391,51 +391,53 @@ struct APState { | |||
391 | } | 391 | } |
392 | 392 | ||
393 | void OnItemsReceived(const std::list<APClient::NetworkItem>& items) { | 393 | void OnItemsReceived(const std::list<APClient::NetworkItem>& items) { |
394 | std::vector<ItemState> item_states; | ||
395 | |||
394 | { | 396 | { |
395 | std::lock_guard state_guard(state_mutex); | 397 | std::lock_guard state_guard(state_mutex); |
396 | 398 | ||
399 | std::map<int64_t, int> index_by_item; | ||
400 | |||
397 | for (const APClient::NetworkItem& item : items) { | 401 | for (const APClient::NetworkItem& item : items) { |
398 | inventory[item.item]++; | 402 | inventory[item.item]++; |
399 | TrackerLog(fmt::format("Item: {}", item.item)); | 403 | TrackerLog(fmt::format("Item: {}", item.item)); |
404 | |||
405 | index_by_item[item.item] = item.index; | ||
406 | } | ||
407 | |||
408 | for (const auto& [item_id, item_index] : index_by_item) { | ||
409 | item_states.push_back(ItemState{.name = GetItemName(item_id), | ||
410 | .amount = inventory[item_id], | ||
411 | .index = item_index}); | ||
400 | } | 412 | } |
401 | } | 413 | } |
402 | 414 | ||
403 | RefreshTracker(false); | 415 | RefreshTracker(StateUpdate{.items = item_states}); |
404 | } | 416 | } |
405 | 417 | ||
406 | void OnRetrieved(const std::map<std::string, nlohmann::json>& data) { | 418 | void OnRetrieved(const std::map<std::string, nlohmann::json>& data) { |
419 | StateUpdate state_update; | ||
420 | |||
407 | { | 421 | { |
408 | std::lock_guard state_guard(state_mutex); | 422 | std::lock_guard state_guard(state_mutex); |
409 | 423 | ||
410 | for (const auto& [key, value] : data) { | 424 | for (const auto& [key, value] : data) { |
411 | HandleDataStorage(key, value); | 425 | HandleDataStorage(key, value, state_update); |
412 | } | 426 | } |
413 | } | 427 | } |
414 | 428 | ||
415 | RefreshTracker(false); | 429 | RefreshTracker(state_update); |
416 | } | 430 | } |
417 | 431 | ||
418 | void OnSetReply(const std::string& key, const nlohmann::json& value) { | 432 | void OnSetReply(const std::string& key, const nlohmann::json& value) { |
419 | bool should_refresh = false; | 433 | StateUpdate state_update; |
420 | bool should_redraw_position = false; | 434 | |
421 | { | 435 | { |
422 | std::lock_guard state_guard(state_mutex); | 436 | std::lock_guard state_guard(state_mutex); |
423 | HandleDataStorage(key, value); | 437 | HandleDataStorage(key, value, state_update); |
424 | |||
425 | if (key.ends_with("PlayerPos")) | ||
426 | { | ||
427 | should_redraw_position = true; | ||
428 | } else { | ||
429 | should_refresh = true; | ||
430 | } | ||
431 | } | 438 | } |
432 | 439 | ||
433 | if (should_refresh) | 440 | RefreshTracker(state_update); |
434 | { | ||
435 | RefreshTracker(false); | ||
436 | } else if (should_redraw_position) { | ||
437 | tracker_frame->RedrawPosition(); | ||
438 | } | ||
439 | } | 441 | } |
440 | 442 | ||
441 | void OnSlotConnected(std::string player, std::string server, | 443 | void OnSlotConnected(std::string player, std::string server, |
@@ -531,7 +533,7 @@ struct APState { | |||
531 | } | 533 | } |
532 | 534 | ||
533 | ResetReachabilityRequirements(); | 535 | ResetReachabilityRequirements(); |
534 | RefreshTracker(true); | 536 | RefreshTracker(std::nullopt); |
535 | } | 537 | } |
536 | 538 | ||
537 | void OnSlotRefused(const std::list<std::string>& errors) { | 539 | void OnSlotRefused(const std::list<std::string>& errors) { |
@@ -574,11 +576,15 @@ struct APState { | |||
574 | } | 576 | } |
575 | 577 | ||
576 | // Assumes state mutex is locked. | 578 | // Assumes state mutex is locked. |
577 | void HandleDataStorage(const std::string& key, const nlohmann::json& value) { | 579 | void HandleDataStorage(const std::string& key, const nlohmann::json& value, StateUpdate& state_update) { |
578 | if (value.is_boolean()) { | 580 | if (value.is_boolean()) { |
579 | data_storage[key] = value.get<bool>(); | 581 | data_storage[key] = value.get<bool>(); |
580 | TrackerLog(fmt::format("Data storage {} retrieved as {}", key, | 582 | TrackerLog(fmt::format("Data storage {} retrieved as {}", key, |
581 | (value.get<bool>() ? "true" : "false"))); | 583 | (value.get<bool>() ? "true" : "false"))); |
584 | |||
585 | if (key.find("Achievement|") != std::string::npos) { | ||
586 | state_update.achievements = true; | ||
587 | } | ||
582 | } else if (value.is_number()) { | 588 | } else if (value.is_number()) { |
583 | data_storage[key] = value.get<int>(); | 589 | data_storage[key] = value.get<int>(); |
584 | TrackerLog(fmt::format("Data storage {} retrieved as {}", key, | 590 | TrackerLog(fmt::format("Data storage {} retrieved as {}", key, |
@@ -587,6 +593,7 @@ struct APState { | |||
587 | if (key.ends_with("PlayerPos")) { | 593 | if (key.ends_with("PlayerPos")) { |
588 | auto map_value = value.get<std::map<std::string, int>>(); | 594 | auto map_value = value.get<std::map<std::string, int>>(); |
589 | player_pos = std::tuple<int, int>(map_value["x"], map_value["z"]); | 595 | player_pos = std::tuple<int, int>(map_value["x"], map_value["z"]); |
596 | state_update.player_position = true; | ||
590 | } else { | 597 | } else { |
591 | data_storage[key] = value.get<std::map<std::string, int>>(); | 598 | data_storage[key] = value.get<std::map<std::string, int>>(); |
592 | } | 599 | } |
@@ -595,6 +602,7 @@ struct APState { | |||
595 | } else if (value.is_null()) { | 602 | } else if (value.is_null()) { |
596 | if (key.ends_with("PlayerPos")) { | 603 | if (key.ends_with("PlayerPos")) { |
597 | player_pos = std::nullopt; | 604 | player_pos = std::nullopt; |
605 | state_update.player_position = true; | ||
598 | } else { | 606 | } else { |
599 | data_storage.erase(key); | 607 | data_storage.erase(key); |
600 | } | 608 | } |
@@ -606,6 +614,8 @@ struct APState { | |||
606 | if (key.ends_with("Paintings")) { | 614 | if (key.ends_with("Paintings")) { |
607 | data_storage[key] = | 615 | data_storage[key] = |
608 | std::set<std::string>(list_value.begin(), list_value.end()); | 616 | std::set<std::string>(list_value.begin(), list_value.end()); |
617 | state_update.paintings = | ||
618 | std::vector<std::string>(list_value.begin(), list_value.end()); | ||
609 | } else { | 619 | } else { |
610 | data_storage[key] = list_value; | 620 | data_storage[key] = list_value; |
611 | } | 621 | } |
@@ -616,29 +626,34 @@ struct APState { | |||
616 | } | 626 | } |
617 | 627 | ||
618 | // State mutex should NOT be locked. | 628 | // State mutex should NOT be locked. |
619 | void RefreshTracker(bool reset) { | 629 | // nullopt state_update indicates a reset. |
630 | void RefreshTracker(std::optional<StateUpdate> state_update) { | ||
620 | TrackerLog("Refreshing display..."); | 631 | TrackerLog("Refreshing display..."); |
621 | 632 | ||
622 | std::string prev_msg; | 633 | if (!state_update || !state_update->items.empty() || |
623 | { | 634 | !state_update->paintings.empty()) { |
624 | std::lock_guard state_guard(state_mutex); | 635 | std::string prev_msg; |
636 | { | ||
637 | std::lock_guard state_guard(state_mutex); | ||
625 | 638 | ||
626 | prev_msg = status_message; | 639 | prev_msg = status_message; |
627 | SetStatusMessage(fmt::format("{} Recalculating...", status_message)); | 640 | SetStatusMessage(fmt::format("{} Recalculating...", status_message)); |
628 | } | 641 | } |
629 | 642 | ||
630 | RecalculateReachability(); | 643 | RecalculateReachability(); |
631 | 644 | ||
632 | if (reset) { | 645 | { |
633 | tracker_frame->ResetIndicators(); | 646 | std::lock_guard state_guard(state_mutex); |
634 | } else { | ||
635 | tracker_frame->UpdateIndicators(); | ||
636 | } | ||
637 | 647 | ||
638 | { | 648 | SetStatusMessage(prev_msg); |
639 | std::lock_guard state_guard(state_mutex); | 649 | } |
650 | } | ||
651 | |||
640 | 652 | ||
641 | SetStatusMessage(prev_msg); | 653 | if (!state_update) { |
654 | tracker_frame->ResetIndicators(); | ||
655 | } else { | ||
656 | tracker_frame->UpdateIndicators(*state_update); | ||
642 | } | 657 | } |
643 | } | 658 | } |
644 | 659 | ||
diff --git a/src/ap_state.h b/src/ap_state.h index 4de7689..8b8db03 100644 --- a/src/ap_state.h +++ b/src/ap_state.h | |||
@@ -39,6 +39,12 @@ struct SunwarpMapping { | |||
39 | int exit_index; | 39 | int exit_index; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | struct ItemState { | ||
43 | std::string name; | ||
44 | int amount = 0; | ||
45 | int index = 0; | ||
46 | }; | ||
47 | |||
42 | void AP_SetTrackerFrame(TrackerFrame* tracker_frame); | 48 | void AP_SetTrackerFrame(TrackerFrame* tracker_frame); |
43 | 49 | ||
44 | void AP_Connect(std::string server, std::string player, std::string password); | 50 | void AP_Connect(std::string server, std::string player, std::string password); |
diff --git a/src/ipc_state.cpp b/src/ipc_state.cpp index 1f8d286..a99fa89 100644 --- a/src/ipc_state.cpp +++ b/src/ipc_state.cpp | |||
@@ -313,7 +313,7 @@ struct IPCState { | |||
313 | player_position = | 313 | player_position = |
314 | std::make_tuple<int, int>(msg["position"]["x"], msg["position"]["z"]); | 314 | std::make_tuple<int, int>(msg["position"]["x"], msg["position"]["z"]); |
315 | 315 | ||
316 | tracker_frame->RedrawPosition(); | 316 | tracker_frame->UpdateIndicators(StateUpdate{.player_position = true}); |
317 | } else if (msg["cmd"] == "SolvePanels") { | 317 | } else if (msg["cmd"] == "SolvePanels") { |
318 | std::lock_guard state_guard(state_mutex); | 318 | std::lock_guard state_guard(state_mutex); |
319 | 319 | ||
@@ -321,7 +321,7 @@ struct IPCState { | |||
321 | solved_panels.insert(std::move(panel)); | 321 | solved_panels.insert(std::move(panel)); |
322 | } | 322 | } |
323 | 323 | ||
324 | tracker_frame->UpdateIndicators(kUPDATE_ONLY_PANELS); | 324 | tracker_frame->UpdateIndicators(StateUpdate{.open_panels_tab = true}); |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
diff --git a/src/paintings_pane.cpp b/src/paintings_pane.cpp index dc6f050..51c4995 100644 --- a/src/paintings_pane.cpp +++ b/src/paintings_pane.cpp | |||
@@ -39,15 +39,15 @@ PaintingsPane::PaintingsPane(wxWindow* parent) : wxPanel(parent, wxID_ANY) { | |||
39 | reveal_btn_->Bind(wxEVT_BUTTON, &PaintingsPane::OnClickRevealPaintings, this); | 39 | reveal_btn_->Bind(wxEVT_BUTTON, &PaintingsPane::OnClickRevealPaintings, this); |
40 | } | 40 | } |
41 | 41 | ||
42 | void PaintingsPane::UpdateIndicators() { | 42 | void PaintingsPane::ResetIndicators() { |
43 | tree_ctrl_->DeleteAllItems(); | 43 | tree_ctrl_->DeleteAllItems(); |
44 | reveal_btn_->Enable(AP_IsPaintingShuffle()); | ||
45 | } | ||
44 | 46 | ||
45 | if (!AP_IsPaintingShuffle()) { | 47 | void PaintingsPane::UpdateIndicators(const std::vector<std::string>&) { |
46 | reveal_btn_->Disable(); | 48 | // TODO: Optimize this by using the paintings delta. |
47 | return; | ||
48 | } | ||
49 | 49 | ||
50 | reveal_btn_->Enable(); | 50 | tree_ctrl_->DeleteAllItems(); |
51 | 51 | ||
52 | std::map<std::string, std::set<std::string>> grouped_paintings; | 52 | std::map<std::string, std::set<std::string>> grouped_paintings; |
53 | 53 | ||
diff --git a/src/paintings_pane.h b/src/paintings_pane.h index 4c7856f..2b79286 100644 --- a/src/paintings_pane.h +++ b/src/paintings_pane.h | |||
@@ -13,7 +13,8 @@ class PaintingsPane : public wxPanel { | |||
13 | public: | 13 | public: |
14 | explicit PaintingsPane(wxWindow* parent); | 14 | explicit PaintingsPane(wxWindow* parent); |
15 | 15 | ||
16 | void UpdateIndicators(); | 16 | void ResetIndicators(); |
17 | void UpdateIndicators(const std::vector<std::string>& paintings); | ||
17 | 18 | ||
18 | private: | 19 | private: |
19 | void OnClickRevealPaintings(wxCommandEvent& event); | 20 | void OnClickRevealPaintings(wxCommandEvent& event); |
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index f742d12..9a35eef 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp | |||
@@ -169,6 +169,8 @@ void SubwayMap::OnConnect() { | |||
169 | } | 169 | } |
170 | 170 | ||
171 | checked_paintings_.clear(); | 171 | checked_paintings_.clear(); |
172 | |||
173 | UpdateIndicators(); | ||
172 | } | 174 | } |
173 | 175 | ||
174 | void SubwayMap::UpdateIndicators() { | 176 | void SubwayMap::UpdateIndicators() { |
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index a697f9a..dc6c283 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp | |||
@@ -51,9 +51,8 @@ enum TrackerFrameIds { | |||
51 | }; | 51 | }; |
52 | 52 | ||
53 | wxDEFINE_EVENT(STATE_RESET, wxCommandEvent); | 53 | wxDEFINE_EVENT(STATE_RESET, wxCommandEvent); |
54 | wxDEFINE_EVENT(STATE_CHANGED, wxCommandEvent); | 54 | wxDEFINE_EVENT(STATE_CHANGED, StateChangedEvent); |
55 | wxDEFINE_EVENT(STATUS_CHANGED, wxCommandEvent); | 55 | wxDEFINE_EVENT(STATUS_CHANGED, wxCommandEvent); |
56 | wxDEFINE_EVENT(REDRAW_POSITION, wxCommandEvent); | ||
57 | wxDEFINE_EVENT(CONNECT_TO_AP, ApConnectEvent); | 56 | wxDEFINE_EVENT(CONNECT_TO_AP, ApConnectEvent); |
58 | 57 | ||
59 | TrackerFrame::TrackerFrame() | 58 | TrackerFrame::TrackerFrame() |
@@ -112,7 +111,6 @@ TrackerFrame::TrackerFrame() | |||
112 | Bind(STATE_RESET, &TrackerFrame::OnStateReset, this); | 111 | Bind(STATE_RESET, &TrackerFrame::OnStateReset, this); |
113 | Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); | 112 | Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); |
114 | Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); | 113 | Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); |
115 | Bind(REDRAW_POSITION, &TrackerFrame::OnRedrawPosition, this); | ||
116 | Bind(CONNECT_TO_AP, &TrackerFrame::OnConnectToAp, this); | 114 | Bind(CONNECT_TO_AP, &TrackerFrame::OnConnectToAp, this); |
117 | 115 | ||
118 | wxSize logicalSize = FromDIP(wxSize(1280, 728)); | 116 | wxSize logicalSize = FromDIP(wxSize(1280, 728)); |
@@ -173,15 +171,8 @@ void TrackerFrame::ResetIndicators() { | |||
173 | QueueEvent(new wxCommandEvent(STATE_RESET)); | 171 | QueueEvent(new wxCommandEvent(STATE_RESET)); |
174 | } | 172 | } |
175 | 173 | ||
176 | void TrackerFrame::UpdateIndicators(UpdateIndicatorsMode mode) { | 174 | void TrackerFrame::UpdateIndicators(StateUpdate state) { |
177 | auto evt = new wxCommandEvent(STATE_CHANGED); | 175 | QueueEvent(new StateChangedEvent(STATE_CHANGED, GetId(), std::move(state))); |
178 | evt->SetInt(static_cast<int>(mode)); | ||
179 | |||
180 | QueueEvent(evt); | ||
181 | } | ||
182 | |||
183 | void TrackerFrame::RedrawPosition() { | ||
184 | QueueEvent(new wxCommandEvent(REDRAW_POSITION)); | ||
185 | } | 176 | } |
186 | 177 | ||
187 | void TrackerFrame::OnAbout(wxCommandEvent &event) { | 178 | void TrackerFrame::OnAbout(wxCommandEvent &event) { |
@@ -250,7 +241,8 @@ void TrackerFrame::OnSettings(wxCommandEvent &event) { | |||
250 | GetTrackerConfig().track_position = dlg.GetTrackPosition(); | 241 | GetTrackerConfig().track_position = dlg.GetTrackPosition(); |
251 | GetTrackerConfig().Save(); | 242 | GetTrackerConfig().Save(); |
252 | 243 | ||
253 | UpdateIndicators(); | 244 | UpdateIndicators( |
245 | StateUpdate{.cleared_locations = true, .player_position = true}); | ||
254 | } | 246 | } |
255 | } | 247 | } |
256 | 248 | ||
@@ -304,7 +296,7 @@ void TrackerFrame::OnSashPositionChanged(wxSplitterEvent& event) { | |||
304 | void TrackerFrame::OnStateReset(wxCommandEvent &event) { | 296 | void TrackerFrame::OnStateReset(wxCommandEvent &event) { |
305 | tracker_panel_->UpdateIndicators(); | 297 | tracker_panel_->UpdateIndicators(); |
306 | achievements_pane_->UpdateIndicators(); | 298 | achievements_pane_->UpdateIndicators(); |
307 | paintings_pane_->UpdateIndicators(); | 299 | paintings_pane_->ResetIndicators(); |
308 | subway_map_->OnConnect(); | 300 | subway_map_->OnConnect(); |
309 | if (panels_panel_ != nullptr) { | 301 | if (panels_panel_ != nullptr) { |
310 | notebook_->DeletePage(notebook_->FindPage(panels_panel_)); | 302 | notebook_->DeletePage(notebook_->FindPage(panels_panel_)); |
@@ -313,19 +305,10 @@ void TrackerFrame::OnStateReset(wxCommandEvent &event) { | |||
313 | Refresh(); | 305 | Refresh(); |
314 | } | 306 | } |
315 | 307 | ||
316 | void TrackerFrame::OnStateChanged(wxCommandEvent &event) { | 308 | void TrackerFrame::OnStateChanged(StateChangedEvent &event) { |
317 | UpdateIndicatorsMode mode = static_cast<UpdateIndicatorsMode>(event.GetInt()); | 309 | const StateUpdate &state = event.GetState(); |
318 | 310 | ||
319 | if (mode == kUPDATE_ALL_INDICATORS) { | 311 | if (state.open_panels_tab) { |
320 | tracker_panel_->UpdateIndicators(); | ||
321 | achievements_pane_->UpdateIndicators(); | ||
322 | paintings_pane_->UpdateIndicators(); | ||
323 | subway_map_->UpdateIndicators(); | ||
324 | if (panels_panel_ != nullptr) { | ||
325 | panels_panel_->UpdateIndicators(); | ||
326 | } | ||
327 | Refresh(); | ||
328 | } else if (mode == kUPDATE_ONLY_PANELS) { | ||
329 | if (panels_panel_ == nullptr) { | 312 | if (panels_panel_ == nullptr) { |
330 | panels_panel_ = new TrackerPanel(notebook_); | 313 | panels_panel_ = new TrackerPanel(notebook_); |
331 | panels_panel_->SetPanelsMode(); | 314 | panels_panel_->SetPanelsMode(); |
@@ -335,25 +318,39 @@ void TrackerFrame::OnStateChanged(wxCommandEvent &event) { | |||
335 | if (notebook_->GetSelection() == 2) { | 318 | if (notebook_->GetSelection() == 2) { |
336 | Refresh(); | 319 | Refresh(); |
337 | } | 320 | } |
338 | } | ||
339 | } | ||
340 | |||
341 | void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { | ||
342 | SetStatusText(wxString::FromUTF8(GetStatusMessage())); | ||
343 | } | ||
344 | 321 | ||
345 | void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { | ||
346 | if (!GetTrackerConfig().track_position) { | ||
347 | return; | 322 | return; |
348 | } | 323 | } |
324 | |||
325 | if (!state.items.empty() || !state.paintings.empty() || | ||
326 | state.cleared_locations) { | ||
327 | tracker_panel_->UpdateIndicators(); | ||
328 | subway_map_->UpdateIndicators(); | ||
329 | if (panels_panel_ != nullptr) { | ||
330 | panels_panel_->UpdateIndicators(); | ||
331 | } | ||
332 | Refresh(); | ||
333 | } else if (state.player_position && GetTrackerConfig().track_position) { | ||
334 | if (notebook_->GetSelection() == 0) { | ||
335 | tracker_panel_->Refresh(); | ||
336 | } else if (notebook_->GetSelection() == 2) { | ||
337 | panels_panel_->Refresh(); | ||
338 | } | ||
339 | } | ||
349 | 340 | ||
350 | if (notebook_->GetSelection() == 0) { | 341 | if (state.achievements) { |
351 | tracker_panel_->Refresh(); | 342 | achievements_pane_->UpdateIndicators(); |
352 | } else if (notebook_->GetSelection() == 2) { | 343 | } |
353 | panels_panel_->Refresh(); | 344 | |
345 | if (!state.paintings.empty()) { | ||
346 | paintings_pane_->UpdateIndicators(state.paintings); | ||
354 | } | 347 | } |
355 | } | 348 | } |
356 | 349 | ||
350 | void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { | ||
351 | SetStatusText(wxString::FromUTF8(GetStatusMessage())); | ||
352 | } | ||
353 | |||
357 | void TrackerFrame::OnConnectToAp(ApConnectEvent &event) { | 354 | void TrackerFrame::OnConnectToAp(ApConnectEvent &event) { |
358 | AP_Connect(event.GetServer(), event.GetUser(), event.GetPass()); | 355 | AP_Connect(event.GetServer(), event.GetUser(), event.GetPass()); |
359 | } | 356 | } |
diff --git a/src/tracker_frame.h b/src/tracker_frame.h index 4f1f464..ff18e49 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h | |||
@@ -9,6 +9,7 @@ | |||
9 | 9 | ||
10 | #include <memory> | 10 | #include <memory> |
11 | 11 | ||
12 | #include "ap_state.h" | ||
12 | #include "icons.h" | 13 | #include "icons.h" |
13 | #include "updater.h" | 14 | #include "updater.h" |
14 | 15 | ||
@@ -44,17 +45,33 @@ class ApConnectEvent : public wxEvent { | |||
44 | std::string ap_pass_; | 45 | std::string ap_pass_; |
45 | }; | 46 | }; |
46 | 47 | ||
48 | struct StateUpdate { | ||
49 | std::vector<ItemState> items; | ||
50 | std::vector<std::string> paintings; | ||
51 | bool achievements = false; | ||
52 | bool open_panels_tab = false; | ||
53 | bool cleared_locations = false; | ||
54 | bool player_position = false; | ||
55 | }; | ||
56 | |||
57 | class StateChangedEvent : public wxEvent { | ||
58 | public: | ||
59 | StateChangedEvent(wxEventType eventType, int winid, StateUpdate state) | ||
60 | : wxEvent(winid, eventType), state_(std::move(state)) {} | ||
61 | |||
62 | const StateUpdate &GetState() const { return state_; } | ||
63 | |||
64 | virtual wxEvent *Clone() const { return new StateChangedEvent(*this); } | ||
65 | |||
66 | private: | ||
67 | StateUpdate state_; | ||
68 | }; | ||
69 | |||
47 | wxDECLARE_EVENT(STATE_RESET, wxCommandEvent); | 70 | wxDECLARE_EVENT(STATE_RESET, wxCommandEvent); |
48 | wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent); | 71 | wxDECLARE_EVENT(STATE_CHANGED, StateChangedEvent); |
49 | wxDECLARE_EVENT(STATUS_CHANGED, wxCommandEvent); | 72 | wxDECLARE_EVENT(STATUS_CHANGED, wxCommandEvent); |
50 | wxDECLARE_EVENT(REDRAW_POSITION, wxCommandEvent); | ||
51 | wxDECLARE_EVENT(CONNECT_TO_AP, ApConnectEvent); | 73 | wxDECLARE_EVENT(CONNECT_TO_AP, ApConnectEvent); |
52 | 74 | ||
53 | enum UpdateIndicatorsMode { | ||
54 | kUPDATE_ALL_INDICATORS = 0, | ||
55 | kUPDATE_ONLY_PANELS = 1, | ||
56 | }; | ||
57 | |||
58 | class TrackerFrame : public wxFrame { | 75 | class TrackerFrame : public wxFrame { |
59 | public: | 76 | public: |
60 | TrackerFrame(); | 77 | TrackerFrame(); |
@@ -63,8 +80,7 @@ class TrackerFrame : public wxFrame { | |||
63 | void UpdateStatusMessage(); | 80 | void UpdateStatusMessage(); |
64 | 81 | ||
65 | void ResetIndicators(); | 82 | void ResetIndicators(); |
66 | void UpdateIndicators(UpdateIndicatorsMode mode = kUPDATE_ALL_INDICATORS); | 83 | void UpdateIndicators(StateUpdate state); |
67 | void RedrawPosition(); | ||
68 | 84 | ||
69 | private: | 85 | private: |
70 | void OnExit(wxCommandEvent &event); | 86 | void OnExit(wxCommandEvent &event); |
@@ -80,9 +96,8 @@ class TrackerFrame : public wxFrame { | |||
80 | void OnSashPositionChanged(wxSplitterEvent &event); | 96 | void OnSashPositionChanged(wxSplitterEvent &event); |
81 | 97 | ||
82 | void OnStateReset(wxCommandEvent &event); | 98 | void OnStateReset(wxCommandEvent &event); |
83 | void OnStateChanged(wxCommandEvent &event); | 99 | void OnStateChanged(StateChangedEvent &event); |
84 | void OnStatusChanged(wxCommandEvent &event); | 100 | void OnStatusChanged(wxCommandEvent &event); |
85 | void OnRedrawPosition(wxCommandEvent &event); | ||
86 | void OnConnectToAp(ApConnectEvent &event); | 101 | void OnConnectToAp(ApConnectEvent &event); |
87 | 102 | ||
88 | std::unique_ptr<Updater> updater_; | 103 | std::unique_ptr<Updater> updater_; |