mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-11-25 09:54:48 +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 eGlyphsortorder glyphsortorder;
|
||||||
EX string pinnedglyphs;
|
EX string pinnedglyphs;
|
||||||
EX bool glyphpinned[int(ittypes) + int(motypes)];
|
EX vector<int> revglyphpinned;
|
||||||
|
EX unsigned glyphpinned[int(ittypes) + int(motypes)];
|
||||||
|
|
||||||
int zero = 0;
|
int zero = 0;
|
||||||
|
|
||||||
@@ -84,14 +85,19 @@ int glyphphase[glyphs];
|
|||||||
int glyph_lastticks;
|
int glyph_lastticks;
|
||||||
|
|
||||||
EX void updateglyphpinned() {
|
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()) {
|
if(!pinnedglyphs.empty()) {
|
||||||
|
unsigned n = 0;
|
||||||
exp_parser ep;
|
exp_parser ep;
|
||||||
ep.s = pinnedglyphs;
|
ep.s = pinnedglyphs;
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
int i = ep.iparse();
|
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&) {
|
catch(hr_parse_exception&) {
|
||||||
continue;
|
continue;
|
||||||
@@ -102,8 +108,8 @@ EX void updateglyphpinned() {
|
|||||||
|
|
||||||
EX void updatepinnedglyphs() {
|
EX void updatepinnedglyphs() {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for(int i=0; i<glyphs; i++) {
|
for(auto& i: revglyphpinned) {
|
||||||
if(glyphpinned[i]) ss << i << ",";
|
ss << i << ",";
|
||||||
}
|
}
|
||||||
pinnedglyphs = ss.str();
|
pinnedglyphs = ss.str();
|
||||||
if(!pinnedglyphs.empty()) pinnedglyphs.pop_back();
|
if(!pinnedglyphs.empty()) pinnedglyphs.pop_back();
|
||||||
@@ -153,7 +159,7 @@ int glyphcorner(int i) {
|
|||||||
|
|
||||||
bool glyphsort(int i, int j) {
|
bool glyphsort(int i, int j) {
|
||||||
if(glyphpinned[i] != glyphpinned[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))
|
if(subclass(i) != subclass(j))
|
||||||
return subclass(i) < subclass(j);
|
return subclass(i) < subclass(j);
|
||||||
if(glyphsortorder == gsoFirstTop)
|
if(glyphsortorder == gsoFirstTop)
|
||||||
|
|||||||
@@ -184,7 +184,14 @@ EX void showOverview() {
|
|||||||
else if(udiv == 2 && umod < ittypes) {
|
else if(udiv == 2 && umod < ittypes) {
|
||||||
gotoHelp(generateHelpForItem(eItem(umod)));
|
gotoHelp(generateHelpForItem(eItem(umod)));
|
||||||
help_extensions.push_back(help_extension{'p', glyphpinned[umod] ? XLAT("unpin from HUD") : XLAT("pin to HUD"), [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();
|
updatepinnedglyphs();
|
||||||
popScreen();
|
popScreen();
|
||||||
}});
|
}});
|
||||||
|
|||||||
Reference in New Issue
Block a user