Repository navigation
Expand file tree
/
Copy pathproperties.cpp
More file actions
185 lines (163 loc) · 5.78 KB
/
Copy pathproperties.cpp
File metadata and controls
185 lines (163 loc) · 5.78 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "properties.h"
#include "csmap.h"
#include "FXMenuSeparatorEx.h"
FXProperties::FXProperties(FXComposite* p, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h)
: FXTreeList(p, tgt, sel, opts | TREELIST_SHOWS_LINES | TREELIST_SHOWS_BOXES, x, y, w, h)
{
}
FXTreeItem* FXProperties::makeItem(const FXString& label, datablock* block, const FXString* info)
{
FXTreeItem* item = new FXTreeItem(label);
if (block) {
FXProperty* popup = new FXProperty(label);
popup->block = block;
if (info) {
popup->info = *info;
}
item->setData(popup); // show "info" popup cmd
}
return item;
}
FXTreeItem* FXProperties::makeStringList(FXTreeItem* p, const FXString& label, const datablock& block)
{
FXTreeItem* node = appendItem(p, label);
node->setExpanded(true);
for (const datakey& key : block.data()) {
appendItem(node, key.value());
}
return node;
}
FXTreeItem* FXProperties::makeUnitList(FXTreeItem* p, const FXString& label, datablock::itor begin, datablock::itor end, key_type key, int value)
{
std::vector<FXTreeItem*> units;
for (datablock::itor block = begin; block != end && block->type() != block_type::TYPE_REGION; ++block)
{
if (block->type() == block_type::TYPE_UNIT) {
datablock* unitPtr = &*block;
if (unitPtr->valueInt(key) == value) {
units.push_back(makeItem(unitPtr->getLabel() + ": " + unitPtr->value(TYPE_NUMBER), unitPtr));
}
}
}
if (!units.empty()) {
FXTreeItem* node = appendItem(p, label);
node->setExpanded(true);
for (FXTreeItem* item : units) {
appendItem(node, item);
}
return node;
}
return nullptr;
}
void FXProperties::setMapFile(std::shared_ptr<datafile>& f)
{
mapFile = f;
}
long FXProperties::onMapChange(FXObject*, FXSelector, void* ptr)
{
datafile::SelectionState* pstate = (datafile::SelectionState*)ptr;
// any data changed, so need to update list?
if (selection.fileChange != pstate->fileChange)
{
selection.fileChange = pstate->fileChange;
// clear list and build a new one from data in this->files
//clearItems();
}
if (selection.selChange != pstate->selChange)
{
selection = *pstate;
makeItems();
}
return 0;
}
long FXProperties::onDoubleClicked(FXObject *sender, FXSelector sel, void *ptr)
{
if (!mapFile)
return 0;
FXTreeItem *item = static_cast<FXTreeItem*>(ptr);
if (item) {
FXProperty* prop = static_cast<FXProperty*>(item->getData());
if (prop) {
return getShell()->handle(this, FXSEL(SEL_COMMAND, ID_SETVALUE), prop->block);
}
}
return FXTreeList::onDoubleClicked(this, sel, ptr);
}
FXString FXProperties::weightToString(int prop)
{
int full = prop / 100;
int remain = prop % 100;
FXString result = FXStringVal(full);
if (remain >= 10) {
result += "." + FXStringVal(remain);
}
else if (remain > 0) {
result += ".0" + FXStringVal(remain);
}
return result;
}
static const wchar_t* coasts[] = { L"Nordwestk\u00fcste", L"Nordostk\u00fcste", L"Ostk\u00fcste", L"S\u00fcdostk\u00fcste", L"S\u00fcdwestk\u00fcste", L"Westk\u00fcste" };
FXString FXProperties::coastToString(int prop)
{
if (prop >= 0 && prop < 6) {
return FXString(coasts[prop]);
}
return FXString("Unbekannt");
}
long FXProperties::onPopup(FXObject* sender, FXSelector sel, void* ptr)
{
onRightBtnRelease(sender, sel, ptr);
// no datafile, no popup
if (!mapFile)
return 0;
// find item to create popup for
FXEvent* event = (FXEvent*)ptr;
FXTreeItem* item = getCursorItem();
if (!item) {
item = getItemAt(event->click_x, event->click_y);
}
if (item) {
FXProperty* popup = static_cast<FXProperty*>(item->getData());
if (popup) {
CSMap* csmap = static_cast<CSMap*>(getShell());
FXMenuPane pane(this);
FXMenuPane paneCascade(this);
if (popup->block) {
datablock* block = popup->block;
FXString label = block->getName();
if (label.length() <= 20) {
new FXMenuSeparatorEx(&pane, label);
}
else {
FXString str = label.left(17) + "...";
new FXMenuSeparatorEx(&pane, str);
}
if (block->type() == block_type::TYPE_UNIT) {
label.assign("&Zeige Einheit");
}
else if (block->type() == block_type::TYPE_SHIP) {
label.assign("Zeige &Schiff");
}
else if (block->type() == block_type::TYPE_BUILDING) {
label.assign(L"&Zeige Geb\u00e4ude");
}
if (!label.empty()) {
FXMenuCommand* command = new FXMenuCommand(&pane, label, nullptr, csmap, CSMap::ID_POPUP_GOTO);
command->setUserData(block);
}
csmap->addClipboardPane(&pane, block);
}
else {
const FXString& label = item->getText();
const FXString& info = popup->info;
FXMenuCommand* command = new FXMenuCommand(&pane, "&Kopieren", nullptr, csmap, CSMap::ID_POPUP_COPY_TEXT);
command->setUserData(const_cast<char*>(label.text()));
(new FXMenuCommand(&pane, "Zeige &Info", nullptr, csmap, CSMap::ID_POPUP_SHOW_INFO))->setUserData(const_cast<char*>(info.text()));
}
pane.create();
pane.popup(nullptr, event->root_x, event->root_y);
return getApp()->runModalWhileShown(&pane);
}
}
return 0;
}