about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-05-21 13:16:25 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-05-21 13:16:25 -0400
commitbb12ecd88fe16e4009b0d8927c5653d72972e284 (patch)
tree69e2e23b43605ffa24fe2c64251a1fab8ff0dfd7 /src
parent0e69963e29fd7e3f9e4bdf876246c400d2f07f19 (diff)
downloadlingo-ap-tracker-bb12ecd88fe16e4009b0d8927c5653d72972e284.tar.gz
lingo-ap-tracker-bb12ecd88fe16e4009b0d8927c5653d72972e284.tar.bz2
lingo-ap-tracker-bb12ecd88fe16e4009b0d8927c5653d72972e284.zip
Show list of achievements on the side
Diffstat (limited to 'src')
-rw-r--r--src/achievements_pane.cpp33
-rw-r--r--src/achievements_pane.h22
-rw-r--r--src/ap_state.cpp46
-rw-r--r--src/ap_state.h2
-rw-r--r--src/game_data.cpp7
-rw-r--r--src/game_data.h1
-rw-r--r--src/tracker_frame.cpp13
-rw-r--r--src/tracker_frame.h2
8 files changed, 122 insertions, 4 deletions
diff --git a/src/achievements_pane.cpp b/src/achievements_pane.cpp new file mode 100644 index 0000000..8ec3727 --- /dev/null +++ b/src/achievements_pane.cpp
@@ -0,0 +1,33 @@
1#include "achievements_pane.h"
2
3#include "ap_state.h"
4#include "game_data.h"
5
6AchievementsPane::AchievementsPane(wxWindow* parent)
7 : wxListView(parent, wxID_ANY) {
8 AppendColumn("Achievement");
9
10 for (int panel_id : GD_GetAchievementPanels()) {
11 achievement_names_.push_back(GD_GetPanel(panel_id).achievement_name);
12 }
13
14 std::sort(std::begin(achievement_names_), std::end(achievement_names_));
15
16 for (int i = 0; i < achievement_names_.size(); i++) {
17 InsertItem(i, achievement_names_.at(i));
18 }
19
20 SetColumnWidth(0, wxLIST_AUTOSIZE);
21
22 UpdateIndicators();
23}
24
25void AchievementsPane::UpdateIndicators() {
26 for (int i = 0; i < achievement_names_.size(); i++) {
27 if (AP_HasAchievement(achievement_names_.at(i))) {
28 SetItemTextColour(i, *wxBLACK);
29 } else {
30 SetItemTextColour(i, *wxRED);
31 }
32 }
33}
diff --git a/src/achievements_pane.h b/src/achievements_pane.h new file mode 100644 index 0000000..ac88cac --- /dev/null +++ b/src/achievements_pane.h
@@ -0,0 +1,22 @@
1#ifndef ACHIEVEMENTS_PANE_H_C320D0B8
2#define ACHIEVEMENTS_PANE_H_C320D0B8
3
4#include <wx/wxprec.h>
5
6#ifndef WX_PRECOMP
7#include <wx/wx.h>
8#endif
9
10#include <wx/listctrl.h>
11
12class AchievementsPane : public wxListView {
13 public:
14 explicit AchievementsPane(wxWindow* parent);
15
16 void UpdateIndicators();
17
18 private:
19 std::vector<std::string> achievement_names_;
20};
21
22#endif /* end of include guard: ACHIEVEMENTS_PANE_H_C320D0B8 */ \ No newline at end of file
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 8a3aaf9..0f2246b 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -45,8 +45,11 @@ struct APState {
45 bool connected = false; 45 bool connected = false;
46 bool has_connection_result = false; 46 bool has_connection_result = false;
47 47
48 std::list<std::string> tracked_data_storage_keys;
49
48 std::map<int64_t, int> inventory; 50 std::map<int64_t, int> inventory;
49 std::set<int64_t> checked_locations; 51 std::set<int64_t> checked_locations;
52 std::map<std::string, bool> data_storage;
50 53
51 std::map<std::tuple<int, int>, int64_t> ap_id_by_location_id; 54 std::map<std::tuple<int, int>, int64_t> ap_id_by_location_id;
52 std::map<std::string, int64_t> ap_id_by_item_name; 55 std::map<std::string, int64_t> ap_id_by_item_name;
@@ -78,6 +81,11 @@ struct APState {
78 } 81 }
79 }).detach(); 82 }).detach();
80 83
84 for (int panel_id : GD_GetAchievementPanels()) {
85 tracked_data_storage_keys.push_back(
86 "Achievement|" + GD_GetPanel(panel_id).achievement_name);
87 }
88
81 initialized = true; 89 initialized = true;
82 } 90 }
83 91
@@ -104,6 +112,7 @@ struct APState {
104 112
105 inventory.clear(); 113 inventory.clear();
106 checked_locations.clear(); 114 checked_locations.clear();
115 data_storage.clear();
107 door_shuffle_mode = kNO_DOORS; 116 door_shuffle_mode = kNO_DOORS;
108 color_shuffle = false; 117 color_shuffle = false;
109 painting_shuffle = false; 118 painting_shuffle = false;
@@ -162,6 +171,31 @@ struct APState {
162 RefreshTracker(); 171 RefreshTracker();
163 }); 172 });
164 173
174 apclient->set_retrieved_handler(
175 [this](const std::map<std::string, nlohmann::json>& data) {
176 for (const auto& [key, value] : data) {
177 if (value.is_boolean()) {
178 data_storage[key] = value.get<bool>();
179 TrackerLog("Data storage " + key + " retrieved as " +
180 (value.get<bool>() ? "true" : "false"));
181 }
182 }
183
184 RefreshTracker();
185 });
186
187 apclient->set_set_reply_handler([this](const std::string& key,
188 const nlohmann::json& value,
189 const nlohmann::json&) {
190 if (value.is_boolean()) {
191 data_storage[key] = value.get<bool>();
192 TrackerLog("Data storage " + key + " set to " +
193 (value.get<bool>() ? "true" : "false"));
194
195 RefreshTracker();
196 }
197 });
198
165 apclient->set_slot_connected_handler([this]( 199 apclient->set_slot_connected_handler([this](
166 const nlohmann::json& slot_data) { 200 const nlohmann::json& slot_data) {
167 tracker_frame->SetStatusMessage("Connected to Archipelago!"); 201 tracker_frame->SetStatusMessage("Connected to Archipelago!");
@@ -187,6 +221,9 @@ struct APState {
187 has_connection_result = true; 221 has_connection_result = true;
188 222
189 RefreshTracker(); 223 RefreshTracker();
224
225 apclient->Get(tracked_data_storage_keys);
226 apclient->SetNotify(tracked_data_storage_keys);
190 }); 227 });
191 228
192 apclient->set_slot_refused_handler( 229 apclient->set_slot_refused_handler(
@@ -325,6 +362,11 @@ struct APState {
325 } 362 }
326 } 363 }
327 364
365 bool HasAchievement(const std::string& name) {
366 std::string key = "Achievement|" + name;
367 return data_storage.count(key) && data_storage.at(key);
368 }
369
328 void RefreshTracker() { 370 void RefreshTracker() {
329 TrackerLog("Refreshing display..."); 371 TrackerLog("Refreshing display...");
330 372
@@ -386,3 +428,7 @@ const std::map<std::string, std::string> AP_GetPaintingMapping() {
386int AP_GetMasteryRequirement() { return GetState().mastery_requirement; } 428int AP_GetMasteryRequirement() { return GetState().mastery_requirement; }
387 429
388bool AP_IsReduceChecks() { return GetState().reduce_checks; } 430bool AP_IsReduceChecks() { return GetState().reduce_checks; }
431
432bool AP_HasAchievement(const std::string& achievement_name) {
433 return GetState().HasAchievement(achievement_name);
434}
diff --git a/src/ap_state.h b/src/ap_state.h index f0dcadb..a9edd9e 100644 --- a/src/ap_state.h +++ b/src/ap_state.h
@@ -32,4 +32,6 @@ int AP_GetMasteryRequirement();
32 32
33bool AP_IsReduceChecks(); 33bool AP_IsReduceChecks();
34 34
35bool AP_HasAchievement(const std::string& achievement_name);
36
35#endif /* end of include guard: AP_STATE_H_664A4180 */ 37#endif /* end of include guard: AP_STATE_H_664A4180 */
diff --git a/src/game_data.cpp b/src/game_data.cpp index f21bc3d..351f515 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -177,11 +177,10 @@ struct GameData {
177 } 177 }
178 178
179 if (panel_it.second["achievement"]) { 179 if (panel_it.second["achievement"]) {
180 panel_obj.achievement = panel_it.second["achievement"].as<bool>(); 180 panel_obj.achievement = true;
181 panel_obj.achievement_name = panel_it.second["achievement"].as<std::string>();
181 182
182 if (panel_obj.achievement) { 183 achievement_panels_.push_back(panel_id);
183 achievement_panels_.push_back(panel_id);
184 }
185 } 184 }
186 185
187 if (panel_it.second["exclude_reduce"]) { 186 if (panel_it.second["exclude_reduce"]) {
diff --git a/src/game_data.h b/src/game_data.h index 7348809..672d8a4 100644 --- a/src/game_data.h +++ b/src/game_data.h
@@ -29,6 +29,7 @@ struct Panel {
29 bool check = false; 29 bool check = false;
30 bool exclude_reduce = false; 30 bool exclude_reduce = false;
31 bool achievement = false; 31 bool achievement = false;
32 std::string achievement_name;
32}; 33};
33 34
34struct ProgressiveRequirement { 35struct ProgressiveRequirement {
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index 0308886..49f947f 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp
@@ -1,10 +1,12 @@
1#include "tracker_frame.h" 1#include "tracker_frame.h"
2 2
3#include <wx/choicebk.h>
3#include <wx/webrequest.h> 4#include <wx/webrequest.h>
4 5
5#include <nlohmann/json.hpp> 6#include <nlohmann/json.hpp>
6#include <sstream> 7#include <sstream>
7 8
9#include "achievements_pane.h"
8#include "ap_state.h" 10#include "ap_state.h"
9#include "connection_dialog.h" 11#include "connection_dialog.h"
10#include "tracker_config.h" 12#include "tracker_config.h"
@@ -50,8 +52,18 @@ TrackerFrame::TrackerFrame()
50 Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); 52 Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this);
51 Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); 53 Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this);
52 54
55 wxChoicebook *choicebook = new wxChoicebook(this, wxID_ANY);
56 achievements_pane_ = new AchievementsPane(this);
57 choicebook->AddPage(achievements_pane_, "Achievements");
58
53 tracker_panel_ = new TrackerPanel(this); 59 tracker_panel_ = new TrackerPanel(this);
54 60
61 wxBoxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL);
62 top_sizer->Add(choicebook, wxSizerFlags().Expand().Proportion(1));
63 top_sizer->Add(tracker_panel_, wxSizerFlags().Expand().Proportion(3));
64
65 SetSizerAndFit(top_sizer);
66
55 if (!GetTrackerConfig().asked_to_check_for_updates) { 67 if (!GetTrackerConfig().asked_to_check_for_updates) {
56 GetTrackerConfig().asked_to_check_for_updates = true; 68 GetTrackerConfig().asked_to_check_for_updates = true;
57 69
@@ -113,6 +125,7 @@ void TrackerFrame::OnCheckForUpdates(wxCommandEvent &event) {
113 125
114void TrackerFrame::OnStateChanged(wxCommandEvent &event) { 126void TrackerFrame::OnStateChanged(wxCommandEvent &event) {
115 tracker_panel_->UpdateIndicators(); 127 tracker_panel_->UpdateIndicators();
128 achievements_pane_->UpdateIndicators();
116 Refresh(); 129 Refresh();
117} 130}
118 131
diff --git a/src/tracker_frame.h b/src/tracker_frame.h index f3470fd..85cc7c3 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h
@@ -7,6 +7,7 @@
7#include <wx/wx.h> 7#include <wx/wx.h>
8#endif 8#endif
9 9
10class AchievementsPane;
10class TrackerPanel; 11class TrackerPanel;
11 12
12wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent); 13wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent);
@@ -32,6 +33,7 @@ class TrackerFrame : public wxFrame {
32 void CheckForUpdates(bool manual); 33 void CheckForUpdates(bool manual);
33 34
34 TrackerPanel *tracker_panel_; 35 TrackerPanel *tracker_panel_;
36 AchievementsPane *achievements_pane_;
35}; 37};
36 38
37#endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */ 39#endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */