Skip to content

Commit 33330c9

Browse files
committed
Make pinned glyphs sort in the order they were pinned in
1 parent 718fbcd commit 33330c9

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

hud.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ enum eGlyphsortorder {
6060

6161
EX eGlyphsortorder glyphsortorder;
6262
EX string pinnedglyphs;
63-
EX bool glyphpinned[int(ittypes) + int(motypes)];
63+
EX vector<int> revglyphpinned;
64+
EX unsigned glyphpinned[int(ittypes) + int(motypes)];
6465

6566
int zero = 0;
6667

@@ -84,14 +85,19 @@ int glyphphase[glyphs];
8485
int glyph_lastticks;
8586

8687
EX void updateglyphpinned() {
87-
for(int i=0; i<glyphs; i++) glyphpinned[i] = false;
88+
revglyphpinned.clear();
89+
for(int i=0; i<glyphs; i++) glyphpinned[i] = 0;
8890
if(!pinnedglyphs.empty()) {
91+
unsigned n = 0;
8992
exp_parser ep;
9093
ep.s = pinnedglyphs;
9194
do {
9295
try {
9396
int i = ep.iparse();
94-
if(i >= 0 && i < glyphs) glyphpinned[i] = true;
97+
if(i >= 0 && i < glyphs) {
98+
revglyphpinned.push_back(i);
99+
glyphpinned[i] = ++n;
100+
}
95101
}
96102
catch(hr_parse_exception&) {
97103
continue;
@@ -102,8 +108,8 @@ EX void updateglyphpinned() {
102108

103109
EX void updatepinnedglyphs() {
104110
std::stringstream ss;
105-
for(int i=0; i<glyphs; i++) {
106-
if(glyphpinned[i]) ss << i << ",";
111+
for(auto& i: revglyphpinned) {
112+
ss << i << ",";
107113
}
108114
pinnedglyphs = ss.str();
109115
if(!pinnedglyphs.empty()) pinnedglyphs.pop_back();
@@ -153,7 +159,7 @@ int glyphcorner(int i) {
153159

154160
bool glyphsort(int i, int j) {
155161
if(glyphpinned[i] != glyphpinned[j])
156-
return glyphpinned[i] > glyphpinned[j];
162+
return glyphpinned[i] - 1 < glyphpinned[j] - 1; // We subtract 1 from both sides to make 0 wrap around, so that it compares greater than any positive value
157163
if(subclass(i) != subclass(j))
158164
return subclass(i) < subclass(j);
159165
if(glyphsortorder == gsoFirstTop)

menus.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,14 @@ EX void showOverview() {
184184
else if(udiv == 2 && umod < ittypes) {
185185
gotoHelp(generateHelpForItem(eItem(umod)));
186186
help_extensions.push_back(help_extension{'p', glyphpinned[umod] ? XLAT("unpin from HUD") : XLAT("pin to HUD"), [umod] () {
187-
glyphpinned[umod] ^= true;
187+
if(glyphpinned[umod]) {
188+
revglyphpinned.erase(std::remove_if(revglyphpinned.begin(), revglyphpinned.end(), [umod] (int x) { return x == umod; }), revglyphpinned.end());
189+
glyphpinned[umod] = 0;
190+
}
191+
else {
192+
revglyphpinned.push_back(umod);
193+
glyphpinned[umod] = revglyphpinned.size();
194+
}
188195
updatepinnedglyphs();
189196
popScreen();
190197
}});

0 commit comments

Comments
 (0)