mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-07-25 12:12:48 +00:00
dialog:: file dialogs now use list
This commit is contained in:
parent
42a1615d0d
commit
3b5a5c01c5
82
dialogs.cpp
82
dialogs.cpp
@ -1360,20 +1360,14 @@ EX namespace dialog {
|
|||||||
void handleKeyFile(int sym, int uni);
|
void handleKeyFile(int sym, int uni);
|
||||||
|
|
||||||
EX void drawFileDialog() {
|
EX void drawFileDialog() {
|
||||||
displayfr(vid.xres/2, 30 + vid.fsize, 2, vid.fsize,
|
cmode = sm::NUMBER | dialogflags;
|
||||||
filecaption, forecolor, 8);
|
gamescreen();
|
||||||
|
init(filecaption);
|
||||||
|
|
||||||
string& cfile = *cfileptr;
|
string cfile = *cfileptr;
|
||||||
|
dialog::addItem(cfile, 0);
|
||||||
|
|
||||||
displayfr(vid.xres/2, 34 + vid.fsize * 2, 2, vid.fsize,
|
dialog::addBreak(100);
|
||||||
cfile, 0xFFFF00, 8);
|
|
||||||
|
|
||||||
displayColorButton(vid.xres*1/4, 38+vid.fsize * 3,
|
|
||||||
XLAT("F4 = extension"), SDLK_F4, 8, 0, editext ? 0xFF00FF : 0xFFFF00, editext ? 0x800080 : 0x808000);
|
|
||||||
displayButton(vid.xres*2/4, 38+vid.fsize * 3,
|
|
||||||
XLAT("Enter = choose"), SDLK_RETURN, 8);
|
|
||||||
displayButton(vid.xres*3/4, 38+vid.fsize * 3,
|
|
||||||
XLAT("Esc = cancel"), SDLK_ESCAPE, 8);
|
|
||||||
|
|
||||||
v.clear();
|
v.clear();
|
||||||
|
|
||||||
@ -1399,21 +1393,45 @@ EX namespace dialog {
|
|||||||
}
|
}
|
||||||
sort(v.begin(), v.end(), filecmp);
|
sort(v.begin(), v.end(), filecmp);
|
||||||
|
|
||||||
int q = v.size();
|
dialog::start_list(1500, 1500);
|
||||||
int percolumn = (vid.yres-38) / (vid.fsize+5) - 4;
|
for(auto& vv: v) {
|
||||||
int columns = 1 + (q-1) / percolumn;
|
dialog::addItem(vv.first, list_fake_key++);
|
||||||
|
dialog::lastItem().color = vv.second;
|
||||||
for(int i=0; i<q; i++) {
|
string vf = vv.first;
|
||||||
int x = 16 + (vid.xres * (i/percolumn)) / columns;
|
bool dir = vv.second == CDIR;
|
||||||
int y = 42 + vid.fsize * 4 + (vid.fsize+5) * (i % percolumn);
|
dialog::add_action([vf, dir] {
|
||||||
|
string& s(*cfileptr);
|
||||||
displayColorButton(x, y, v[i].first, 1000 + i, 0, 0, v[i].second, 0xFFFF00);
|
string where = "", what = s, whereparent = "../";
|
||||||
|
for(int i=0; i<isize(s); i++)
|
||||||
|
if(s[i] == '/') {
|
||||||
|
if(i >= 2 && s.substr(i-2,3) == "../")
|
||||||
|
whereparent = s.substr(0, i+1) + "../";
|
||||||
|
else
|
||||||
|
whereparent = where;
|
||||||
|
where = s.substr(0, i+1), what = s.substr(i+1);
|
||||||
}
|
}
|
||||||
|
if(vf == "../")
|
||||||
|
s = whereparent + what;
|
||||||
|
else if(dir)
|
||||||
|
s = where + vf + what;
|
||||||
|
else
|
||||||
|
s = where + vf;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dialog::end_list();
|
||||||
|
|
||||||
|
dialog::addBreak(100);
|
||||||
|
|
||||||
|
dialog::addBoolItem_action("extension", editext, SDLK_F4);
|
||||||
|
dialog::addItem("choose", SDLK_RETURN);
|
||||||
|
dialog::addItem("cancel", SDLK_ESCAPE);
|
||||||
|
dialog::display();
|
||||||
|
|
||||||
keyhandler = handleKeyFile;
|
keyhandler = handleKeyFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
EX void handleKeyFile(int sym, int uni) {
|
EX void handleKeyFile(int sym, int uni) {
|
||||||
|
handleNavigation(sym, uni);
|
||||||
string& s(*cfileptr);
|
string& s(*cfileptr);
|
||||||
int i = isize(s) - (editext?0:4);
|
int i = isize(s) - (editext?0:4);
|
||||||
|
|
||||||
@ -1425,34 +1443,12 @@ EX namespace dialog {
|
|||||||
popScreen();
|
popScreen();
|
||||||
if(!file_action()) pushScreen(drawFileDialog);
|
if(!file_action()) pushScreen(drawFileDialog);
|
||||||
}
|
}
|
||||||
else if(sym == SDLK_F4) {
|
|
||||||
editext = !editext;
|
|
||||||
}
|
|
||||||
else if(sym == SDLK_BACKSPACE && i) {
|
else if(sym == SDLK_BACKSPACE && i) {
|
||||||
s.erase(i-1, 1);
|
s.erase(i-1, 1);
|
||||||
}
|
}
|
||||||
else if(uni >= 32 && uni < 127) {
|
else if(uni >= 32 && uni < 127) {
|
||||||
s.insert(i, s0 + char(uni));
|
s.insert(i, s0 + char(uni));
|
||||||
}
|
}
|
||||||
else if(uni >= 1000 && uni <= 1000+isize(v)) {
|
|
||||||
string where = "", what = s, whereparent = "../";
|
|
||||||
for(int i=0; i<isize(s); i++)
|
|
||||||
if(s[i] == '/') {
|
|
||||||
if(i >= 2 && s.substr(i-2,3) == "../")
|
|
||||||
whereparent = s.substr(0, i+1) + "../";
|
|
||||||
else
|
|
||||||
whereparent = where;
|
|
||||||
where = s.substr(0, i+1), what = s.substr(i+1);
|
|
||||||
}
|
|
||||||
int i = uni - 1000;
|
|
||||||
if(v[i].first == "../") {
|
|
||||||
s = whereparent + what;
|
|
||||||
}
|
|
||||||
else if(v[i].second == CDIR)
|
|
||||||
s = where + v[i].first + what;
|
|
||||||
else
|
|
||||||
s = where + v[i].first;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user