|
@@ -16,6 +16,8 @@
|
16
|
16
|
#include "Window.h"
|
17
|
17
|
#include "Menu.h"
|
18
|
18
|
|
|
19
|
+// TODO
|
|
20
|
+// Going up to / leads to the current working directory
|
19
|
21
|
|
20
|
22
|
Menu::Menu() {
|
21
|
23
|
mVisible = false;
|
|
@@ -43,11 +45,16 @@ Menu::~Menu() {
|
43
|
45
|
}
|
44
|
46
|
|
45
|
47
|
int Menu::initialize() {
|
|
48
|
+ return initialize(Folder(getOpenRaider().mPakDir));
|
|
49
|
+}
|
|
50
|
+
|
|
51
|
+int Menu::initialize(Folder folder) {
|
46
|
52
|
if (mapFolder != nullptr)
|
47
|
53
|
delete mapFolder;
|
48
|
|
- mapFolder = new Folder(getOpenRaider().mPakDir);
|
|
54
|
+ mapFolder = new Folder(folder);
|
|
55
|
+ mMin = mCursor = 0;
|
49
|
56
|
|
50
|
|
- mapFolder->executeRemoveRecursiveItems([](File &f) {
|
|
57
|
+ mapFolder->executeRemoveFiles([](File &f) {
|
51
|
58
|
// Filter files based on file name
|
52
|
59
|
if ((f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
|
53
|
60
|
&& (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
|
|
@@ -67,6 +74,9 @@ int Menu::initialize() {
|
67
|
74
|
return false; // keep file on list
|
68
|
75
|
});
|
69
|
76
|
|
|
77
|
+ if ((mapFolder->fileCount() + mapFolder->folderCount()) > 0)
|
|
78
|
+ mCursor = 1; // Don't select ".." by default
|
|
79
|
+
|
70
|
80
|
return 0;
|
71
|
81
|
}
|
72
|
82
|
|
|
@@ -93,83 +103,71 @@ void Menu::display() {
|
93
|
103
|
mainText.x = (getWindow().getWidth() / 2) - ((unsigned int)(mainText.w / 2));
|
94
|
104
|
getFont().writeString(mainText);
|
95
|
105
|
|
96
|
|
- if ((mapFolder == nullptr) || (mapFolder->countRecursiveItems() == 0)) {
|
97
|
|
- getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, RED, "No maps found! See README.md");
|
98
|
|
- return;
|
99
|
|
- } else {
|
100
|
|
- // Estimate displayable number of items
|
101
|
|
- int items = (getWindow().getHeight() - 60) / 25;
|
102
|
|
-
|
103
|
|
- // Select which part of the list to show
|
104
|
|
- long min, max;
|
105
|
|
- if (((long)mCursor - (items / 2)) > 0)
|
106
|
|
- min = mCursor - (items / 2);
|
107
|
|
- else
|
108
|
|
- min = 0;
|
109
|
|
-
|
110
|
|
- if ((mCursor + (items / 2)) < (long)mapFolder->countRecursiveItems())
|
111
|
|
- max = mCursor + (items / 2);
|
112
|
|
- else
|
113
|
|
- max = (long)mapFolder->countRecursiveItems();
|
114
|
|
-
|
115
|
|
- while ((max - min) < items) {
|
116
|
|
- if (min > 0)
|
117
|
|
- min--;
|
118
|
|
- else if (max < ((int)mapFolder->countRecursiveItems()))
|
119
|
|
- max++;
|
120
|
|
- else
|
121
|
|
- break;
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- mMin = min;
|
|
106
|
+ // Estimate displayable number of items
|
|
107
|
+ int items = (getWindow().getHeight() - 60) / 25;
|
125
|
108
|
|
126
|
|
- for (long i = 0; i < (max - min); i++) {
|
127
|
|
- const char *map = mapFolder->getRecursiveItemName((unsigned long)(i + min)).c_str();
|
128
|
|
- getFont().drawText(25, (unsigned int)(50 + (25 * i)), 0.75f,
|
129
|
|
- ((i + min) == mCursor) ? RED : BLUE, "%s", map);
|
|
109
|
+ // Print list of "..", folders, files
|
|
110
|
+ for (long i = mMin; (i < (mMin + items))
|
|
111
|
+ && (i < (mapFolder->folderCount() + mapFolder->fileCount() + 1)); i++) {
|
|
112
|
+ if (i == 0) {
|
|
113
|
+ getFont().drawText(25, 50, 0.75f, (mCursor == i) ? RED : BLUE, "..");
|
|
114
|
+ } else {
|
|
115
|
+ getFont().drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
|
|
116
|
+ (mCursor == i) ? RED : BLUE, "%s",
|
|
117
|
+ ((i - 1) < mapFolder->folderCount()) ?
|
|
118
|
+ (mapFolder->getFolder(i - 1).getName() + "/").c_str()
|
|
119
|
+ : mapFolder->getFile(i - 1 - mapFolder->folderCount()).getName().c_str());
|
130
|
120
|
}
|
131
|
121
|
}
|
132
|
122
|
}
|
133
|
123
|
|
134
|
124
|
void Menu::play() {
|
135
|
|
- char *tmp = bufferString("load %s", mapFolder->getRecursiveItemName((unsigned long)mCursor).c_str());
|
136
|
|
- if (getOpenRaider().command(tmp) == 0) {
|
137
|
|
- setVisible(false);
|
|
125
|
+ if (mCursor == 0) {
|
|
126
|
+ if (initialize(mapFolder->getParent().getPath()) != 0) {
|
|
127
|
+ //! \todo Display something if an error occurs
|
|
128
|
+ }
|
|
129
|
+ } else if ((mCursor - 1) < mapFolder->folderCount()) {
|
|
130
|
+ if (initialize(mapFolder->getFolder(mCursor - 1).getPath()) != 0) {
|
|
131
|
+ //! \todo Display something if an error occurs
|
|
132
|
+ }
|
138
|
133
|
} else {
|
139
|
|
- //! \todo Display something if an error occurs
|
|
134
|
+ char *tmp = bufferString("load %s",
|
|
135
|
+ mapFolder->getFile((unsigned long)mCursor - 1 - mapFolder->folderCount()).getPath().c_str());
|
|
136
|
+ if (getOpenRaider().command(tmp) == 0) {
|
|
137
|
+ setVisible(false);
|
|
138
|
+ } else {
|
|
139
|
+ //! \todo Display something if an error occurs
|
|
140
|
+ }
|
|
141
|
+ delete [] tmp;
|
140
|
142
|
}
|
141
|
|
- delete [] tmp;
|
142
|
143
|
}
|
143
|
144
|
|
144
|
145
|
void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
|
145
|
146
|
if (!pressed)
|
146
|
147
|
return;
|
147
|
148
|
|
|
149
|
+ assert(mapFolder != nullptr);
|
|
150
|
+ int items = (getWindow().getHeight() - 60) / 25;
|
|
151
|
+
|
148
|
152
|
if (key == upKey) {
|
149
|
153
|
if (mCursor > 0)
|
150
|
154
|
mCursor--;
|
151
|
155
|
else
|
152
|
|
- mCursor = (long)mapFolder->countRecursiveItems() - 1;
|
|
156
|
+ mCursor = (long)(mapFolder->folderCount() + mapFolder->fileCount());
|
153
|
157
|
} else if (key == downKey) {
|
154
|
|
- if (mCursor < (long)(mapFolder->countRecursiveItems() - 1))
|
|
158
|
+ if (mCursor < (long)(mapFolder->folderCount() + mapFolder->fileCount()))
|
155
|
159
|
mCursor++;
|
156
|
160
|
else
|
157
|
161
|
mCursor = 0;
|
158
|
|
- } else if (key == rightKey) {
|
159
|
|
- long i = 10;
|
160
|
|
- if (mCursor > (long)(mapFolder->countRecursiveItems() - 11))
|
161
|
|
- i = ((long)mapFolder->countRecursiveItems()) - 1 - mCursor;
|
162
|
|
- while (i-- > 0)
|
163
|
|
- handleKeyboard(downKey, true);
|
164
|
|
- } else if (key == leftKey) {
|
165
|
|
- long i = 10;
|
166
|
|
- if (mCursor < 10)
|
167
|
|
- i = mCursor;
|
168
|
|
- while (i-- > 0)
|
169
|
|
- handleKeyboard(upKey, true);
|
170
|
162
|
} else if (key == enterKey) {
|
171
|
163
|
play();
|
172
|
164
|
}
|
|
165
|
+
|
|
166
|
+ if (mCursor > (mMin + items - 1)) {
|
|
167
|
+ mMin = mCursor - items + 1;
|
|
168
|
+ } else if (mCursor < mMin) {
|
|
169
|
+ mMin = mCursor;
|
|
170
|
+ }
|
173
|
171
|
}
|
174
|
172
|
|
175
|
173
|
void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
|
|
@@ -187,3 +185,25 @@ void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton butto
|
187
|
185
|
}
|
188
|
186
|
}
|
189
|
187
|
|
|
188
|
+void Menu::handleMouseScroll(int xrel, int yrel) {
|
|
189
|
+ assert((xrel != 0) || (yrel != 0));
|
|
190
|
+ assert(mapFolder != nullptr);
|
|
191
|
+ int items = (getWindow().getHeight() - 60) / 25;
|
|
192
|
+
|
|
193
|
+ if ((mapFolder->folderCount() + mapFolder->fileCount() + 1) > items) {
|
|
194
|
+ if (yrel < 0) {
|
|
195
|
+ if (mMin < (mapFolder->folderCount() + mapFolder->fileCount() + 1 - items))
|
|
196
|
+ mMin++;
|
|
197
|
+ } else if (yrel > 0) {
|
|
198
|
+ if (mMin > 0)
|
|
199
|
+ mMin--;
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ if (mCursor < mMin) {
|
|
203
|
+ mCursor = mMin;
|
|
204
|
+ } else if (mCursor > (mMin + items - 1)) {
|
|
205
|
+ mCursor = mMin + items - 1;
|
|
206
|
+ }
|
|
207
|
+ }
|
|
208
|
+}
|
|
209
|
+
|