mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-11-14 20:57:10 +00:00
Make pinned glyphs sort in the order they were pinned in
This commit is contained in:
18
hud.cpp
18
hud.cpp
@@ -60,7 +60,8 @@ enum eGlyphsortorder {
|
||||
|
||||
EX eGlyphsortorder glyphsortorder;
|
||||
EX string pinnedglyphs;
|
||||
EX bool glyphpinned[int(ittypes) + int(motypes)];
|
||||
EX vector<int> revglyphpinned;
|
||||
EX unsigned glyphpinned[int(ittypes) + int(motypes)];
|
||||
|
||||
int zero = 0;
|
||||
|
||||
@@ -84,14 +85,19 @@ int glyphphase[glyphs];
|
||||
int glyph_lastticks;
|
||||
|
||||
EX void updateglyphpinned() {
|
||||
for(int i=0; i<glyphs; i++) glyphpinned[i] = false;
|
||||
revglyphpinned.clear();
|
||||
for(int i=0; i<glyphs; i++) glyphpinned[i] = 0;
|
||||
if(!pinnedglyphs.empty()) {
|
||||
unsigned n = 0;
|
||||
exp_parser ep;
|
||||
ep.s = pinnedglyphs;
|
||||
do {
|
||||
try {
|
||||
int i = ep.iparse();
|
||||
if(i >= 0 && i < glyphs) glyphpinned[i] = true;
|
||||
if(i >= 0 && i < glyphs) {
|
||||
revglyphpinned.push_back(i);
|
||||
glyphpinned[i] = ++n;
|
||||
}
|
||||
}
|
||||
catch(hr_parse_exception&) {
|
||||
continue;
|
||||
@@ -102,8 +108,8 @@ EX void updateglyphpinned() {
|
||||
|
||||
EX void updatepinnedglyphs() {
|
||||
std::stringstream ss;
|
||||
for(int i=0; i<glyphs; i++) {
|
||||
if(glyphpinned[i]) ss << i << ",";
|
||||
for(auto& i: revglyphpinned) {
|
||||
ss << i << ",";
|
||||
}
|
||||
pinnedglyphs = ss.str();
|
||||
if(!pinnedglyphs.empty()) pinnedglyphs.pop_back();
|
||||
@@ -153,7 +159,7 @@ int glyphcorner(int i) {
|
||||
|
||||
bool glyphsort(int i, int j) {
|
||||
if(glyphpinned[i] != glyphpinned[j])
|
||||
return glyphpinned[i] > glyphpinned[j];
|
||||
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
|
||||
if(subclass(i) != subclass(j))
|
||||
return subclass(i) < subclass(j);
|
||||
if(glyphsortorder == gsoFirstTop)
|
||||
|
||||
@@ -184,7 +184,14 @@ EX void showOverview() {
|
||||
else if(udiv == 2 && umod < ittypes) {
|
||||
gotoHelp(generateHelpForItem(eItem(umod)));
|
||||
help_extensions.push_back(help_extension{'p', glyphpinned[umod] ? XLAT("unpin from HUD") : XLAT("pin to HUD"), [umod] () {
|
||||
glyphpinned[umod] ^= true;
|
||||
if(glyphpinned[umod]) {
|
||||
revglyphpinned.erase(std::remove_if(revglyphpinned.begin(), revglyphpinned.end(), [umod] (int x) { return x == umod; }), revglyphpinned.end());
|
||||
glyphpinned[umod] = 0;
|
||||
}
|
||||
else {
|
||||
revglyphpinned.push_back(umod);
|
||||
glyphpinned[umod] = revglyphpinned.size();
|
||||
}
|
||||
updatepinnedglyphs();
|
||||
popScreen();
|
||||
}});
|
||||
|
||||
Reference in New Issue
Block a user