From 4fb25ff5efe48ca8f594ce5b5d2839cb244018a9 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 17 Dec 2024 16:32:10 -0500 Subject: Added solved panels over IPC --- src/ipc_state.cpp | 32 +++++++++++++++++++++++++++++++- src/ipc_state.h | 3 +++ src/tracker_frame.cpp | 35 +++++++++++++++++++++++++++-------- src/tracker_frame.h | 7 ++++++- src/tracker_panel.cpp | 10 ++++++++-- src/tracker_panel.h | 2 ++ 6 files changed, 77 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ipc_state.cpp b/src/ipc_state.cpp index 18f318f..c0bdc9b 100644 --- a/src/ipc_state.cpp +++ b/src/ipc_state.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ struct IPCState { std::string game_ap_user; std::optional> player_position; + std::set solved_panels; int backoff_amount = 0; @@ -77,6 +79,12 @@ struct IPCState { return player_position; } + const std::set& GetSolvedPanels() { + std::lock_guard state_guard(state_mutex); + + return solved_panels; + } + private: void Thread() { for (;;) { @@ -137,7 +145,17 @@ struct IPCState { } } - void OnConnect() { connected = true; } + void OnConnect() { + connected = true; + + { + std::lock_guard state_guard(state_mutex); + + slot_matches = false; + player_position = std::nullopt; + solved_panels.clear(); + } + } void OnClose() { connected = false; @@ -168,6 +186,14 @@ struct IPCState { std::make_tuple(msg["position"]["x"], msg["position"]["z"]); tracker_frame->RedrawPosition(); + } else if (msg["cmd"] == "SolvePanels") { + std::lock_guard state_guard(state_mutex); + + for (std::string panel : msg["panels"]) { + solved_panels.insert(std::move(panel)); + } + + tracker_frame->UpdateIndicators(kUPDATE_ONLY_PANELS); } } @@ -229,3 +255,7 @@ bool IPC_IsConnected() { return GetState().IsConnected(); } std::optional> IPC_GetPlayerPosition() { return GetState().GetPlayerPosition(); } + +const std::set& IPC_GetSolvedPanels() { + return GetState().GetSolvedPanels(); +} diff --git a/src/ipc_state.h b/src/ipc_state.h index be71673..a6bdc36 100644 --- a/src/ipc_state.h +++ b/src/ipc_state.h @@ -2,6 +2,7 @@ #define IPC_STATE_H_6B3B0958 #include +#include #include #include @@ -17,4 +18,6 @@ bool IPC_IsConnected(); std::optional> IPC_GetPlayerPosition(); +const std::set& IPC_GetSolvedPanels(); + #endif /* end of include guard: IPC_STATE_H_6B3B0958 */ diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index a06e46b..d0fd5a6 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp @@ -1,5 +1,6 @@ #include "tracker_frame.h" +#include #include #include #include @@ -7,7 +8,6 @@ #include #include -#include #include #include @@ -147,8 +147,11 @@ void TrackerFrame::ResetIndicators() { QueueEvent(new wxCommandEvent(STATE_RESET)); } -void TrackerFrame::UpdateIndicators() { - QueueEvent(new wxCommandEvent(STATE_CHANGED)); +void TrackerFrame::UpdateIndicators(UpdateIndicatorsMode mode) { + auto evt = new wxCommandEvent(STATE_CHANGED); + evt->SetInt(static_cast(mode)); + + QueueEvent(evt); } void TrackerFrame::RedrawPosition() { @@ -268,13 +271,27 @@ void TrackerFrame::OnStateReset(wxCommandEvent &event) { } void TrackerFrame::OnStateChanged(wxCommandEvent &event) { - tracker_panel_->UpdateIndicators(); - achievements_pane_->UpdateIndicators(); - subway_map_->UpdateIndicators(); - if (panels_panel_ != nullptr) { + UpdateIndicatorsMode mode = static_cast(event.GetInt()); + + if (mode == kUPDATE_ALL_INDICATORS) { + tracker_panel_->UpdateIndicators(); + achievements_pane_->UpdateIndicators(); + subway_map_->UpdateIndicators(); + if (panels_panel_ != nullptr) { + panels_panel_->UpdateIndicators(); + } + Refresh(); + } else if (mode == kUPDATE_ONLY_PANELS) { + if (panels_panel_ == nullptr) { + panels_panel_ = new TrackerPanel(notebook_); + panels_panel_->SetPanelsMode(); + notebook_->AddPage(panels_panel_, "Panels"); + } panels_panel_->UpdateIndicators(); + if (notebook_->GetSelection() == 2) { + Refresh(); + } } - Refresh(); } void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { @@ -284,6 +301,8 @@ void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { if (notebook_->GetSelection() == 0) { tracker_panel_->Refresh(); + } else if (notebook_->GetSelection() == 2) { + panels_panel_->Refresh(); } } diff --git a/src/tracker_frame.h b/src/tracker_frame.h index ab59ffb..9d18dc7 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h @@ -18,6 +18,11 @@ wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent); wxDECLARE_EVENT(STATUS_CHANGED, wxCommandEvent); wxDECLARE_EVENT(REDRAW_POSITION, wxCommandEvent); +enum UpdateIndicatorsMode { + kUPDATE_ALL_INDICATORS = 0, + kUPDATE_ONLY_PANELS = 1, +}; + class TrackerFrame : public wxFrame { public: TrackerFrame(); @@ -25,7 +30,7 @@ class TrackerFrame : public wxFrame { void UpdateStatusMessage(); void ResetIndicators(); - void UpdateIndicators(); + void UpdateIndicators(UpdateIndicatorsMode mode = kUPDATE_ALL_INDICATORS); void RedrawPosition(); private: diff --git a/src/tracker_panel.cpp b/src/tracker_panel.cpp index 2f2d596..04b970c 100644 --- a/src/tracker_panel.cpp +++ b/src/tracker_panel.cpp @@ -51,6 +51,10 @@ TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { } void TrackerPanel::UpdateIndicators() { + if (panels_mode_ && !savedata_path_) { + solved_panels_ = IPC_GetSolvedPanels(); + } + for (AreaIndicator &area : areas_) { area.popup->UpdateIndicators(); } @@ -58,8 +62,10 @@ void TrackerPanel::UpdateIndicators() { Redraw(); } +void TrackerPanel::SetPanelsMode() { panels_mode_ = true; } + void TrackerPanel::SetSavedataPath(std::string savedata_path) { - if (!panels_mode_) { + if (!savedata_path_) { wxButton *refresh_button = new wxButton(this, wxID_ANY, "Refresh", {15, 15}); refresh_button->Bind(wxEVT_BUTTON, &TrackerPanel::OnRefreshSavedata, this); @@ -216,7 +222,7 @@ void TrackerPanel::Redraw() { if (panel.non_counting) { has_unchecked = !AP_HasCheckedGameLocation(section.ap_location_id); } else { - has_unchecked = !solved_panels_.contains(panel.nodepath); + has_unchecked = !GetSolvedPanels().contains(panel.nodepath); } } } else if (AP_IsLocationVisible(section.classification)) { diff --git a/src/tracker_panel.h b/src/tracker_panel.h index e1f515d..822d181 100644 --- a/src/tracker_panel.h +++ b/src/tracker_panel.h @@ -19,6 +19,8 @@ class TrackerPanel : public wxPanel { void UpdateIndicators(); + void SetPanelsMode(); + void SetSavedataPath(std::string savedata_path); bool IsPanelsMode() const { return panels_mode_; } -- cgit 1.4.1