-
Notifications
You must be signed in to change notification settings - Fork 224
/
replace_items_window.h
138 lines (112 loc) · 3.74 KB
/
replace_items_window.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#ifndef RME_REPLACE_ITEMS_WINDOW_H_
#define RME_REPLACE_ITEMS_WINDOW_H_
#include "main.h"
#include "common_windows.h"
#include "editor.h"
struct ReplacingItem
{
ReplacingItem() :
replaceId(0), withId(0), total(0), complete(false) { }
bool operator==(const ReplacingItem& other) const
{
return replaceId == other.replaceId && withId == other.withId;
}
uint16_t replaceId;
uint16_t withId;
uint32_t total;
bool complete;
};
// ============================================================================
// ReplaceItemsButton
class ReplaceItemsButton : public DCButton
{
public:
ReplaceItemsButton(wxWindow* parent);
~ReplaceItemsButton() { }
ItemGroup_t GetGroup() const;
uint16_t GetItemId() const { return m_id; }
void SetItemId(uint16_t id);
private:
uint16_t m_id;
};
// ============================================================================
// ReplaceItemsListBox
class ReplaceItemsListBox : public wxVListBox
{
public:
ReplaceItemsListBox(wxWindow* parent);
bool AddItem(const ReplacingItem& item);
void MarkAsComplete(const ReplacingItem& item, uint32_t total);
void RemoveSelected();
bool CanAdd(uint16_t replaceId, uint16_t withId) const;
void OnDrawItem(wxDC& dc, const wxRect& rect, size_t index) const;
wxCoord OnMeasureItem(size_t index) const;
const std::vector<ReplacingItem>& GetItems() const { return m_items; }
size_t GetCount() const { return m_items.size(); }
private:
std::vector<ReplacingItem> m_items;
wxBitmap m_arrow_bitmap;
wxBitmap m_flag_bitmap;
};
// ============================================================================
// ReplaceItemsDialog
struct ItemFinder
{
ItemFinder(uint16_t itemid, int32_t limit = -1) : itemid(itemid), limit(limit), exceeded(false) {}
void operator()(Map& map, Tile* tile, Item* item, long long done) {
if(exceeded)
return;
if(item->getID() == itemid) {
result.push_back(std::make_pair(tile, item));
if(limit > 0 && result.size() >= size_t(limit))
exceeded = true;
}
}
std::vector<std::pair<Tile*, Item*>> result;
private:
uint16_t itemid;
int32_t limit;
bool exceeded;
};
class ReplaceItemsDialog : public wxDialog
{
public:
ReplaceItemsDialog(wxWindow* parent, bool selectionOnly);
~ReplaceItemsDialog();
void OnListSelected(wxCommandEvent& event);
void OnReplaceItemClicked(wxMouseEvent& event);
void OnWithItemClicked(wxMouseEvent& event);
void OnAddButtonClicked(wxCommandEvent& event);
void OnRemoveButtonClicked(wxCommandEvent& event);
void OnExecuteButtonClicked(wxCommandEvent& event);
void OnCancelButtonClicked(wxCommandEvent& event);
private:
void UpdateWidgets();
ReplaceItemsListBox* list;
ReplaceItemsButton* replace_button;
ReplaceItemsButton* with_button;
wxGauge* progress;
wxStaticBitmap* arrow_bitmap;
wxButton* add_button;
wxButton* remove_button;
wxButton* execute_button;
wxButton* close_button;
bool selectionOnly;
};
#endif