1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-13 12:17:10 +00:00

Add support for pinning glyphs to a consistent spot in the HUD

This commit is contained in:
Joseph C. Sible
2025-10-05 13:20:44 -04:00
parent 8b7e82b460
commit d9050c9661
3 changed files with 45 additions and 6 deletions

View File

@@ -1207,6 +1207,14 @@ EX void initConfig() {
param_b(keybd_subdir_enabled, "keybd_subdir_enabled", 0)->editable("control the pushing direction with TAB", 'P')->help("If set, you control the off-heptagon pushing direction with TAB. Otherwise, you control it by rotating the screen.");
param_str(pinnedglyphs, "pinned_glyphs", "")
->set_standard_editor(true)
->editable("pinned glyphs",
"A list of glyphs to always sort at the front, "
"and reserve space for even when they're not being displayed.",
'p')
->set_reaction(updateglyphpinned);
param_enum(glyphsortorder, parameter_names("glyph_sort", "glyph sort order"), glyphsortorder)
->editable({
{"first on top", ""},

38
hud.cpp
View File

@@ -58,6 +58,8 @@ enum eGlyphsortorder {
#endif
EX eGlyphsortorder glyphsortorder;
EX string pinnedglyphs;
EX bool glyphpinned[int(ittypes) + int(motypes)];
int zero = 0;
@@ -80,6 +82,27 @@ int glyphorder[glyphs];
int glyphphase[glyphs];
int glyph_lastticks;
EX void updateglyphpinned() {
for(int i=0; i<glyphs; i++) glyphpinned[i] = false;
if(!pinnedglyphs.empty()) {
exp_parser ep;
ep.s = pinnedglyphs;
do {
int i = ep.iparse();
if(i >= 0 && i < glyphs) glyphpinned[i] = true;
} while(ep.eat(","));
}
}
EX void updatepinnedglyphs() {
std::stringstream ss;
for(int i=0; i<glyphs; i++) {
if(glyphpinned[i]) ss << i << ",";
}
pinnedglyphs = ss.str();
if(!pinnedglyphs.empty()) pinnedglyphs.pop_back();
}
void updatesort() {
for(int i=0; i<glyphs; i++) {
int ik = ikmerge(i);
@@ -123,6 +146,8 @@ int glyphcorner(int i) {
}
bool glyphsort(int i, int j) {
if(glyphpinned[i] != glyphpinned[j])
return glyphpinned[i] > glyphpinned[j];
if(subclass(i) != subclass(j))
return subclass(i) < subclass(j);
if(glyphsortorder == gsoFirstTop)
@@ -560,7 +585,7 @@ EX void drawStats() {
else if(cornermode) {
int bycorner[4];
for(int u=0; u<4; u++) bycorner[u] = 0;
for(int i=0; i<glyphs; i++) if(ikappear(i) && (glyphflags(i) & GLYPH_INSQUARE))
for(int i=0; i<glyphs; i++) if((ikappear(i) || glyphpinned[i]) && (glyphflags(i) & GLYPH_INSQUARE))
bycorner[glyphcorner(i)]++;
updatesort();
stable_sort(glyphorder, glyphorder+glyphs, glyphsort);
@@ -579,7 +604,7 @@ EX void drawStats() {
vector<int> glyphstoshow;
for(int i=0; i<glyphs; i++) {
int g = glyphorder[i];
if(ikappear(g) && (glyphflags(g) & GLYPH_INSQUARE) && glyphcorner(g) == cor)
if((ikappear(g) || glyphpinned[g]) && (glyphflags(g) & GLYPH_INSQUARE) && glyphcorner(g) == cor)
glyphstoshow.push_back(g);
}
for(int u=vid.fsize; u<vid.xres/2-s; u += s)
@@ -592,7 +617,8 @@ EX void drawStats() {
if(cor&1) cx = vid.xres-1-s-cx;
if(cor&2) cy = vid.yres-1-cy;
displayglyph2(cx, cy, s, glyphstoshow[next++]);
int g = glyphstoshow[next++];
if(ikappear(g)) displayglyph2(cx, cy, s, g);
}
break;
}
@@ -616,7 +642,7 @@ EX void drawStats() {
flagtype flag = portrait ? GLYPH_INPORTRAIT : GLYPH_INLANDSCAPE;
for(int i=0; i<glyphs; i++) if(ikappear(i))
for(int i=0; i<glyphs; i++) if(ikappear(i) || glyphpinned[i])
if(glyphflags(i) & flag)
maxbyclass[glyphclass(i)]++;
int buttonsize;
@@ -651,7 +677,7 @@ EX void drawStats() {
for(int i0=0; i0<glyphs; i0++) {
int i = glyphorder[i0];
if(!ikappear(i)) continue;
if(!ikappear(i) && !glyphpinned[i]) continue;
int z = glyphclass(i);
int imp = glyphflags(i);
if(!(imp & flag)) continue;
@@ -667,7 +693,7 @@ EX void drawStats() {
rowid[z]++; if(rowid[z] >= rows) rowid[z] = 0, colid[z]++;
displayglyph2(cx, cy, buttonsize, i);
if(ikappear(i)) displayglyph2(cx, cy, buttonsize, i);
}
}
}

View File

@@ -181,6 +181,11 @@ 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;
updatepinnedglyphs();
popScreen();
}});
if(cheater) {
dialog::helpToEdit(items[umod], 0, 200, 10, 10);
dialog::get_ne().reaction = [] () {