diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-17 16:32:10 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-17 16:32:10 -0500 |
commit | 4fb25ff5efe48ca8f594ce5b5d2839cb244018a9 (patch) | |
tree | 39af3f845aa80cf5e199f98ee22efaa43969045e | |
parent | ad7c3e616fdc6f13812ec52675d226a19351494a (diff) | |
download | lingo-ap-tracker-4fb25ff5efe48ca8f594ce5b5d2839cb244018a9.tar.gz lingo-ap-tracker-4fb25ff5efe48ca8f594ce5b5d2839cb244018a9.tar.bz2 lingo-ap-tracker-4fb25ff5efe48ca8f594ce5b5d2839cb244018a9.zip |
Added solved panels over IPC
-rw-r--r-- | src/ipc_state.cpp | 32 | ||||
-rw-r--r-- | src/ipc_state.h | 3 | ||||
-rw-r--r-- | src/tracker_frame.cpp | 35 | ||||
-rw-r--r-- | src/tracker_frame.h | 7 | ||||
-rw-r--r-- | src/tracker_panel.cpp | 10 | ||||
-rw-r--r-- | src/tracker_panel.h | 2 |
6 files changed, 77 insertions, 12 deletions
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 @@ | |||
9 | #include <mutex> | 9 | #include <mutex> |
10 | #include <nlohmann/json.hpp> | 10 | #include <nlohmann/json.hpp> |
11 | #include <optional> | 11 | #include <optional> |
12 | #include <set> | ||
12 | #include <string> | 13 | #include <string> |
13 | #include <thread> | 14 | #include <thread> |
14 | #include <tuple> | 15 | #include <tuple> |
@@ -35,6 +36,7 @@ struct IPCState { | |||
35 | std::string game_ap_user; | 36 | std::string game_ap_user; |
36 | 37 | ||
37 | std::optional<std::tuple<int, int>> player_position; | 38 | std::optional<std::tuple<int, int>> player_position; |
39 | std::set<std::string> solved_panels; | ||
38 | 40 | ||
39 | int backoff_amount = 0; | 41 | int backoff_amount = 0; |
40 | 42 | ||
@@ -77,6 +79,12 @@ struct IPCState { | |||
77 | return player_position; | 79 | return player_position; |
78 | } | 80 | } |
79 | 81 | ||
82 | const std::set<std::string>& GetSolvedPanels() { | ||
83 | std::lock_guard state_guard(state_mutex); | ||
84 | |||
85 | return solved_panels; | ||
86 | } | ||
87 | |||
80 | private: | 88 | private: |
81 | void Thread() { | 89 | void Thread() { |
82 | for (;;) { | 90 | for (;;) { |
@@ -137,7 +145,17 @@ struct IPCState { | |||
137 | } | 145 | } |
138 | } | 146 | } |
139 | 147 | ||
140 | void OnConnect() { connected = true; } | 148 | void OnConnect() { |
149 | connected = true; | ||
150 | |||
151 | { | ||
152 | std::lock_guard state_guard(state_mutex); | ||
153 | |||
154 | slot_matches = false; | ||
155 | player_position = std::nullopt; | ||
156 | solved_panels.clear(); | ||
157 | } | ||
158 | } | ||
141 | 159 | ||
142 | void OnClose() { | 160 | void OnClose() { |
143 | connected = false; | 161 | connected = false; |
@@ -168,6 +186,14 @@ struct IPCState { | |||
168 | std::make_tuple<int, int>(msg["position"]["x"], msg["position"]["z"]); | 186 | std::make_tuple<int, int>(msg["position"]["x"], msg["position"]["z"]); |
169 | 187 | ||
170 | tracker_frame->RedrawPosition(); | 188 | tracker_frame->RedrawPosition(); |
189 | } else if (msg["cmd"] == "SolvePanels") { | ||
190 | std::lock_guard state_guard(state_mutex); | ||
191 | |||
192 | for (std::string panel : msg["panels"]) { | ||
193 | solved_panels.insert(std::move(panel)); | ||
194 | } | ||
195 | |||
196 | tracker_frame->UpdateIndicators(kUPDATE_ONLY_PANELS); | ||
171 | } | 197 | } |
172 | } | 198 | } |
173 | 199 | ||
@@ -229,3 +255,7 @@ bool IPC_IsConnected() { return GetState().IsConnected(); } | |||
229 | std::optional<std::tuple<int, int>> IPC_GetPlayerPosition() { | 255 | std::optional<std::tuple<int, int>> IPC_GetPlayerPosition() { |
230 | return GetState().GetPlayerPosition(); | 256 | return GetState().GetPlayerPosition(); |
231 | } | 257 | } |
258 | |||
259 | const std::set<std::string>& IPC_GetSolvedPanels() { | ||
260 | return GetState().GetSolvedPanels(); | ||
261 | } | ||
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 @@ | |||
2 | #define IPC_STATE_H_6B3B0958 | 2 | #define IPC_STATE_H_6B3B0958 |
3 | 3 | ||
4 | #include <optional> | 4 | #include <optional> |
5 | #include <set> | ||
5 | #include <string> | 6 | #include <string> |
6 | #include <tuple> | 7 | #include <tuple> |
7 | 8 | ||
@@ -17,4 +18,6 @@ bool IPC_IsConnected(); | |||
17 | 18 | ||
18 | std::optional<std::tuple<int, int>> IPC_GetPlayerPosition(); | 19 | std::optional<std::tuple<int, int>> IPC_GetPlayerPosition(); |
19 | 20 | ||
21 | const std::set<std::string>& IPC_GetSolvedPanels(); | ||
22 | |||
20 | #endif /* end of include guard: IPC_STATE_H_6B3B0958 */ | 23 | #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 @@ | |||
1 | #include "tracker_frame.h" | 1 | #include "tracker_frame.h" |
2 | 2 | ||
3 | #include <fmt/core.h> | ||
3 | #include <wx/aboutdlg.h> | 4 | #include <wx/aboutdlg.h> |
4 | #include <wx/choicebk.h> | 5 | #include <wx/choicebk.h> |
5 | #include <wx/filedlg.h> | 6 | #include <wx/filedlg.h> |
@@ -7,7 +8,6 @@ | |||
7 | #include <wx/stdpaths.h> | 8 | #include <wx/stdpaths.h> |
8 | #include <wx/webrequest.h> | 9 | #include <wx/webrequest.h> |
9 | 10 | ||
10 | #include <fmt/core.h> | ||
11 | #include <nlohmann/json.hpp> | 11 | #include <nlohmann/json.hpp> |
12 | #include <sstream> | 12 | #include <sstream> |
13 | 13 | ||
@@ -147,8 +147,11 @@ void TrackerFrame::ResetIndicators() { | |||
147 | QueueEvent(new wxCommandEvent(STATE_RESET)); | 147 | QueueEvent(new wxCommandEvent(STATE_RESET)); |
148 | } | 148 | } |
149 | 149 | ||
150 | void TrackerFrame::UpdateIndicators() { | 150 | void TrackerFrame::UpdateIndicators(UpdateIndicatorsMode mode) { |
151 | QueueEvent(new wxCommandEvent(STATE_CHANGED)); | 151 | auto evt = new wxCommandEvent(STATE_CHANGED); |
152 | evt->SetInt(static_cast<int>(mode)); | ||
153 | |||
154 | QueueEvent(evt); | ||
152 | } | 155 | } |
153 | 156 | ||
154 | void TrackerFrame::RedrawPosition() { | 157 | void TrackerFrame::RedrawPosition() { |
@@ -268,13 +271,27 @@ void TrackerFrame::OnStateReset(wxCommandEvent &event) { | |||
268 | } | 271 | } |
269 | 272 | ||
270 | void TrackerFrame::OnStateChanged(wxCommandEvent &event) { | 273 | void TrackerFrame::OnStateChanged(wxCommandEvent &event) { |
271 | tracker_panel_->UpdateIndicators(); | 274 | UpdateIndicatorsMode mode = static_cast<UpdateIndicatorsMode>(event.GetInt()); |
272 | achievements_pane_->UpdateIndicators(); | 275 | |
273 | subway_map_->UpdateIndicators(); | 276 | if (mode == kUPDATE_ALL_INDICATORS) { |
274 | if (panels_panel_ != nullptr) { | 277 | tracker_panel_->UpdateIndicators(); |
278 | achievements_pane_->UpdateIndicators(); | ||
279 | subway_map_->UpdateIndicators(); | ||
280 | if (panels_panel_ != nullptr) { | ||
281 | panels_panel_->UpdateIndicators(); | ||
282 | } | ||
283 | Refresh(); | ||
284 | } else if (mode == kUPDATE_ONLY_PANELS) { | ||
285 | if (panels_panel_ == nullptr) { | ||
286 | panels_panel_ = new TrackerPanel(notebook_); | ||
287 | panels_panel_->SetPanelsMode(); | ||
288 | notebook_->AddPage(panels_panel_, "Panels"); | ||
289 | } | ||
275 | panels_panel_->UpdateIndicators(); | 290 | panels_panel_->UpdateIndicators(); |
291 | if (notebook_->GetSelection() == 2) { | ||
292 | Refresh(); | ||
293 | } | ||
276 | } | 294 | } |
277 | Refresh(); | ||
278 | } | 295 | } |
279 | 296 | ||
280 | void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { | 297 | void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { |
@@ -284,6 +301,8 @@ void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { | |||
284 | void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { | 301 | void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { |
285 | if (notebook_->GetSelection() == 0) { | 302 | if (notebook_->GetSelection() == 0) { |
286 | tracker_panel_->Refresh(); | 303 | tracker_panel_->Refresh(); |
304 | } else if (notebook_->GetSelection() == 2) { | ||
305 | panels_panel_->Refresh(); | ||
287 | } | 306 | } |
288 | } | 307 | } |
289 | 308 | ||
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); | |||
18 | wxDECLARE_EVENT(STATUS_CHANGED, wxCommandEvent); | 18 | wxDECLARE_EVENT(STATUS_CHANGED, wxCommandEvent); |
19 | wxDECLARE_EVENT(REDRAW_POSITION, wxCommandEvent); | 19 | wxDECLARE_EVENT(REDRAW_POSITION, wxCommandEvent); |
20 | 20 | ||
21 | enum UpdateIndicatorsMode { | ||
22 | kUPDATE_ALL_INDICATORS = 0, | ||
23 | kUPDATE_ONLY_PANELS = 1, | ||
24 | }; | ||
25 | |||
21 | class TrackerFrame : public wxFrame { | 26 | class TrackerFrame : public wxFrame { |
22 | public: | 27 | public: |
23 | TrackerFrame(); | 28 | TrackerFrame(); |
@@ -25,7 +30,7 @@ class TrackerFrame : public wxFrame { | |||
25 | void UpdateStatusMessage(); | 30 | void UpdateStatusMessage(); |
26 | 31 | ||
27 | void ResetIndicators(); | 32 | void ResetIndicators(); |
28 | void UpdateIndicators(); | 33 | void UpdateIndicators(UpdateIndicatorsMode mode = kUPDATE_ALL_INDICATORS); |
29 | void RedrawPosition(); | 34 | void RedrawPosition(); |
30 | 35 | ||
31 | private: | 36 | 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) { | |||
51 | } | 51 | } |
52 | 52 | ||
53 | void TrackerPanel::UpdateIndicators() { | 53 | void TrackerPanel::UpdateIndicators() { |
54 | if (panels_mode_ && !savedata_path_) { | ||
55 | solved_panels_ = IPC_GetSolvedPanels(); | ||
56 | } | ||
57 | |||
54 | for (AreaIndicator &area : areas_) { | 58 | for (AreaIndicator &area : areas_) { |
55 | area.popup->UpdateIndicators(); | 59 | area.popup->UpdateIndicators(); |
56 | } | 60 | } |
@@ -58,8 +62,10 @@ void TrackerPanel::UpdateIndicators() { | |||
58 | Redraw(); | 62 | Redraw(); |
59 | } | 63 | } |
60 | 64 | ||
65 | void TrackerPanel::SetPanelsMode() { panels_mode_ = true; } | ||
66 | |||
61 | void TrackerPanel::SetSavedataPath(std::string savedata_path) { | 67 | void TrackerPanel::SetSavedataPath(std::string savedata_path) { |
62 | if (!panels_mode_) { | 68 | if (!savedata_path_) { |
63 | wxButton *refresh_button = | 69 | wxButton *refresh_button = |
64 | new wxButton(this, wxID_ANY, "Refresh", {15, 15}); | 70 | new wxButton(this, wxID_ANY, "Refresh", {15, 15}); |
65 | refresh_button->Bind(wxEVT_BUTTON, &TrackerPanel::OnRefreshSavedata, this); | 71 | refresh_button->Bind(wxEVT_BUTTON, &TrackerPanel::OnRefreshSavedata, this); |
@@ -216,7 +222,7 @@ void TrackerPanel::Redraw() { | |||
216 | if (panel.non_counting) { | 222 | if (panel.non_counting) { |
217 | has_unchecked = !AP_HasCheckedGameLocation(section.ap_location_id); | 223 | has_unchecked = !AP_HasCheckedGameLocation(section.ap_location_id); |
218 | } else { | 224 | } else { |
219 | has_unchecked = !solved_panels_.contains(panel.nodepath); | 225 | has_unchecked = !GetSolvedPanels().contains(panel.nodepath); |
220 | } | 226 | } |
221 | } | 227 | } |
222 | } else if (AP_IsLocationVisible(section.classification)) { | 228 | } 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 { | |||
19 | 19 | ||
20 | void UpdateIndicators(); | 20 | void UpdateIndicators(); |
21 | 21 | ||
22 | void SetPanelsMode(); | ||
23 | |||
22 | void SetSavedataPath(std::string savedata_path); | 24 | void SetSavedataPath(std::string savedata_path); |
23 | 25 | ||
24 | bool IsPanelsMode() const { return panels_mode_; } | 26 | bool IsPanelsMode() const { return panels_mode_; } |