diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-08 14:46:22 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-03-08 14:46:22 -0500 |
commit | 97f02b39ba00ebefdb309750826dd13e0c8c1ccf (patch) | |
tree | a28721785eaf006044f4782be02d1c9b46d8cc3a /src | |
parent | f8f55976533ac3b77bb8d31697ba2f1e54a994c1 (diff) | |
download | lingo-ap-tracker-97f02b39ba00ebefdb309750826dd13e0c8c1ccf.tar.gz lingo-ap-tracker-97f02b39ba00ebefdb309750826dd13e0c8c1ccf.tar.bz2 lingo-ap-tracker-97f02b39ba00ebefdb309750826dd13e0c8c1ccf.zip |
Added items pane
Diffstat (limited to 'src')
-rw-r--r-- | src/items_pane.cpp | 145 | ||||
-rw-r--r-- | src/items_pane.h | 33 | ||||
-rw-r--r-- | src/tracker_frame.cpp | 9 | ||||
-rw-r--r-- | src/tracker_frame.h | 2 |
4 files changed, 189 insertions, 0 deletions
diff --git a/src/items_pane.cpp b/src/items_pane.cpp new file mode 100644 index 0000000..055eec0 --- /dev/null +++ b/src/items_pane.cpp | |||
@@ -0,0 +1,145 @@ | |||
1 | #include "items_pane.h" | ||
2 | |||
3 | #include <map> | ||
4 | |||
5 | namespace { | ||
6 | |||
7 | enum SortInstruction { | ||
8 | SI_NONE = 0, | ||
9 | SI_ASC = 1 << 0, | ||
10 | SI_DESC = 1 << 1, | ||
11 | SI_NAME = 1 << 2, | ||
12 | SI_AMOUNT = 1 << 3, | ||
13 | SI_ORDER = 1 << 4, | ||
14 | }; | ||
15 | |||
16 | inline SortInstruction operator|(SortInstruction lhs, SortInstruction rhs) { | ||
17 | return static_cast<SortInstruction>(static_cast<int>(lhs) | | ||
18 | static_cast<int>(rhs)); | ||
19 | } | ||
20 | |||
21 | template <typename T> | ||
22 | int ItemCompare(const T& lhs, const T& rhs, bool ascending) { | ||
23 | if (lhs < rhs) { | ||
24 | return ascending ? -1 : 1; | ||
25 | } else if (lhs > rhs) { | ||
26 | return ascending ? 1 : -1; | ||
27 | } else { | ||
28 | return 0; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | int wxCALLBACK RowCompare(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData) { | ||
33 | const ItemState& lhs = *reinterpret_cast<const ItemState*>(item1); | ||
34 | const ItemState& rhs = *reinterpret_cast<const ItemState*>(item2); | ||
35 | SortInstruction instruction = static_cast<SortInstruction>(sortData); | ||
36 | |||
37 | bool ascending = (instruction & SI_ASC) != 0; | ||
38 | if ((instruction & SI_NAME) != 0) { | ||
39 | return ItemCompare(lhs.name, rhs.name, ascending); | ||
40 | } else if ((instruction & SI_AMOUNT) != 0) { | ||
41 | return ItemCompare(lhs.amount, rhs.amount, ascending); | ||
42 | } else if ((instruction & SI_ORDER) != 0) { | ||
43 | return ItemCompare(lhs.index, rhs.index, ascending); | ||
44 | } else { | ||
45 | return 0; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | } // namespace | ||
50 | |||
51 | ItemsPane::ItemsPane(wxWindow* parent) | ||
52 | : wxListView(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, | ||
53 | wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES) { | ||
54 | AppendColumn("Item", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE_USEHEADER); | ||
55 | AppendColumn("Amount", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE_USEHEADER); | ||
56 | AppendColumn("Order", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE_USEHEADER); | ||
57 | |||
58 | Bind(wxEVT_LIST_COL_CLICK, &ItemsPane::OnColClick, this); | ||
59 | Bind(wxEVT_DPI_CHANGED, &ItemsPane::OnDPIChanged, this); | ||
60 | } | ||
61 | |||
62 | void ItemsPane::ResetIndicators() { | ||
63 | DeleteAllItems(); | ||
64 | items_.clear(); | ||
65 | } | ||
66 | |||
67 | void ItemsPane::UpdateIndicators(const std::vector<ItemState>& items) { | ||
68 | std::map<std::string, ItemState> items_by_name; | ||
69 | |||
70 | for (const ItemState& item : items) { | ||
71 | items_by_name[item.name] = item; | ||
72 | } | ||
73 | |||
74 | for (int i = 0; i < GetItemCount(); i++) { | ||
75 | std::string item_name = GetItemText(i).utf8_string(); | ||
76 | auto it = items_by_name.find(item_name); | ||
77 | |||
78 | if (it != items_by_name.end()) { | ||
79 | SetItem(i, 1, std::to_string(it->second.amount)); | ||
80 | SetItem(i, 2, std::to_string(it->second.index)); | ||
81 | |||
82 | *reinterpret_cast<ItemState*>(GetItemData(i)) = it->second; | ||
83 | |||
84 | items_by_name.erase(item_name); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | for (const auto& [name, item] : items_by_name) { | ||
89 | int i = InsertItem(GetItemCount(), name); | ||
90 | SetItem(i, 1, std::to_string(item.amount)); | ||
91 | SetItem(i, 2, std::to_string(item.index)); | ||
92 | |||
93 | auto item_ptr = std::make_unique<ItemState>(item); | ||
94 | SetItemPtrData(i, reinterpret_cast<wxUIntPtr>(item_ptr.get())); | ||
95 | items_.push_back(std::move(item_ptr)); | ||
96 | } | ||
97 | |||
98 | SetColumnWidth(0, wxLIST_AUTOSIZE); | ||
99 | SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER); | ||
100 | SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER); | ||
101 | |||
102 | if (GetSortIndicator() != -1) { | ||
103 | DoSort(GetSortIndicator(), IsAscendingSortIndicator()); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | void ItemsPane::OnColClick(wxListEvent& event) { | ||
108 | int col = event.GetColumn(); | ||
109 | if (col == -1) { | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | bool ascending = GetUpdatedAscendingSortIndicator(col); | ||
114 | |||
115 | DoSort(col, ascending); | ||
116 | } | ||
117 | |||
118 | void ItemsPane::OnDPIChanged(wxDPIChangedEvent& event) { | ||
119 | SetColumnWidth(0, wxLIST_AUTOSIZE); | ||
120 | SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER); | ||
121 | SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER); | ||
122 | |||
123 | event.Skip(); | ||
124 | } | ||
125 | |||
126 | void ItemsPane::DoSort(int col, bool ascending) { | ||
127 | SortInstruction instruction = SI_NONE; | ||
128 | if (ascending) { | ||
129 | instruction = instruction | SI_ASC; | ||
130 | } else { | ||
131 | instruction = instruction | SI_DESC; | ||
132 | } | ||
133 | |||
134 | if (col == 0) { | ||
135 | instruction = instruction | SI_NAME; | ||
136 | } else if (col == 1) { | ||
137 | instruction = instruction | SI_AMOUNT; | ||
138 | } else if (col == 2) { | ||
139 | instruction = instruction | SI_ORDER; | ||
140 | } | ||
141 | |||
142 | if (SortItems(RowCompare, instruction)) { | ||
143 | ShowSortIndicator(col, ascending); | ||
144 | } | ||
145 | } | ||
diff --git a/src/items_pane.h b/src/items_pane.h new file mode 100644 index 0000000..aa09c49 --- /dev/null +++ b/src/items_pane.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef ITEMS_PANE_H_EB637EE3 | ||
2 | #define ITEMS_PANE_H_EB637EE3 | ||
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 | |||
12 | #include <memory> | ||
13 | #include <vector> | ||
14 | |||
15 | #include "ap_state.h" | ||
16 | |||
17 | class ItemsPane : public wxListView { | ||
18 | public: | ||
19 | explicit ItemsPane(wxWindow* parent); | ||
20 | |||
21 | void ResetIndicators(); | ||
22 | void UpdateIndicators(const std::vector<ItemState>& items); | ||
23 | |||
24 | private: | ||
25 | void OnColClick(wxListEvent& event); | ||
26 | void OnDPIChanged(wxDPIChangedEvent& event); | ||
27 | |||
28 | void DoSort(int col, bool ascending); | ||
29 | |||
30 | std::vector<std::unique_ptr<ItemState>> items_; | ||
31 | }; | ||
32 | |||
33 | #endif /* end of include guard: ITEMS_PANE_H_EB637EE3 */ | ||
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index dc6c283..0ab043d 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "connection_dialog.h" | 17 | #include "connection_dialog.h" |
18 | #include "ipc_dialog.h" | 18 | #include "ipc_dialog.h" |
19 | #include "ipc_state.h" | 19 | #include "ipc_state.h" |
20 | #include "items_pane.h" | ||
20 | #include "paintings_pane.h" | 21 | #include "paintings_pane.h" |
21 | #include "settings_dialog.h" | 22 | #include "settings_dialog.h" |
22 | #include "subway_map.h" | 23 | #include "subway_map.h" |
@@ -123,6 +124,9 @@ TrackerFrame::TrackerFrame() | |||
123 | achievements_pane_ = new AchievementsPane(choicebook); | 124 | achievements_pane_ = new AchievementsPane(choicebook); |
124 | choicebook->AddPage(achievements_pane_, "Achievements"); | 125 | choicebook->AddPage(achievements_pane_, "Achievements"); |
125 | 126 | ||
127 | items_pane_ = new ItemsPane(choicebook); | ||
128 | choicebook->AddPage(items_pane_, "Items"); | ||
129 | |||
126 | paintings_pane_ = new PaintingsPane(choicebook); | 130 | paintings_pane_ = new PaintingsPane(choicebook); |
127 | choicebook->AddPage(paintings_pane_, "Paintings"); | 131 | choicebook->AddPage(paintings_pane_, "Paintings"); |
128 | 132 | ||
@@ -296,6 +300,7 @@ void TrackerFrame::OnSashPositionChanged(wxSplitterEvent& event) { | |||
296 | void TrackerFrame::OnStateReset(wxCommandEvent &event) { | 300 | void TrackerFrame::OnStateReset(wxCommandEvent &event) { |
297 | tracker_panel_->UpdateIndicators(); | 301 | tracker_panel_->UpdateIndicators(); |
298 | achievements_pane_->UpdateIndicators(); | 302 | achievements_pane_->UpdateIndicators(); |
303 | items_pane_->ResetIndicators(); | ||
299 | paintings_pane_->ResetIndicators(); | 304 | paintings_pane_->ResetIndicators(); |
300 | subway_map_->OnConnect(); | 305 | subway_map_->OnConnect(); |
301 | if (panels_panel_ != nullptr) { | 306 | if (panels_panel_ != nullptr) { |
@@ -342,6 +347,10 @@ void TrackerFrame::OnStateChanged(StateChangedEvent &event) { | |||
342 | achievements_pane_->UpdateIndicators(); | 347 | achievements_pane_->UpdateIndicators(); |
343 | } | 348 | } |
344 | 349 | ||
350 | if (!state.items.empty()) { | ||
351 | items_pane_->UpdateIndicators(state.items); | ||
352 | } | ||
353 | |||
345 | if (!state.paintings.empty()) { | 354 | if (!state.paintings.empty()) { |
346 | paintings_pane_->UpdateIndicators(state.paintings); | 355 | paintings_pane_->UpdateIndicators(state.paintings); |
347 | } | 356 | } |
diff --git a/src/tracker_frame.h b/src/tracker_frame.h index ff18e49..e7a3958 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "updater.h" | 14 | #include "updater.h" |
15 | 15 | ||
16 | class AchievementsPane; | 16 | class AchievementsPane; |
17 | class ItemsPane; | ||
17 | class PaintingsPane; | 18 | class PaintingsPane; |
18 | class SubwayMap; | 19 | class SubwayMap; |
19 | class TrackerPanel; | 20 | class TrackerPanel; |
@@ -106,6 +107,7 @@ class TrackerFrame : public wxFrame { | |||
106 | wxNotebook *notebook_; | 107 | wxNotebook *notebook_; |
107 | TrackerPanel *tracker_panel_; | 108 | TrackerPanel *tracker_panel_; |
108 | AchievementsPane *achievements_pane_; | 109 | AchievementsPane *achievements_pane_; |
110 | ItemsPane *items_pane_; | ||
109 | PaintingsPane *paintings_pane_; | 111 | PaintingsPane *paintings_pane_; |
110 | SubwayMap *subway_map_; | 112 | SubwayMap *subway_map_; |
111 | TrackerPanel *panels_panel_ = nullptr; | 113 | TrackerPanel *panels_panel_ = nullptr; |