mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 13:07:16 +00:00
custom mode manager and custom welcome messages
This commit is contained in:
parent
66a79fe2cd
commit
afd4a3f4e3
55
menus.cpp
55
menus.cpp
@ -472,6 +472,59 @@ EX void show_chaos() {
|
||||
dialog::display();
|
||||
}
|
||||
|
||||
EX string custom_welcome;
|
||||
|
||||
string customfile = "custom.hrm";
|
||||
|
||||
EX void show_custom() {
|
||||
cmode = sm::SIDE | sm::MAYDARK;
|
||||
gamescreen();
|
||||
dialog::init(XLAT("custom mode"));
|
||||
|
||||
if(custom_welcome != "") {
|
||||
dialog::addInfo("custom welcome message:");
|
||||
dialog::addInfo(custom_welcome);
|
||||
dialog::addItem("edit", '/');
|
||||
}
|
||||
else {
|
||||
dialog::addItem("custom welcome message", '/');
|
||||
}
|
||||
dialog::add_action([] () {
|
||||
dialog::edit_string(custom_welcome, "custom welcome message", "");
|
||||
});
|
||||
dialog::addBreak(100);
|
||||
dialog::addItem("save custom mode", 's');
|
||||
dialog::add_action([] {
|
||||
dialog::openFileDialog(customfile, XLAT("file to save:"), ".hrm", [] () {
|
||||
try {
|
||||
save_mode_to_file(customfile);
|
||||
addMessage(XLAT("Mode saved to %1", customfile));
|
||||
return true;
|
||||
}
|
||||
catch(hstream_exception& e) {
|
||||
addMessage(XLAT("Failed to save mode to %1", customfile));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
dialog::addItem("load custom mode", 'l');
|
||||
dialog::add_action([] {
|
||||
dialog::openFileDialog(customfile, XLAT("file to load:"), ".hrm", [] () {
|
||||
try {
|
||||
load_mode_from_file(customfile);
|
||||
addMessage(XLAT("Loaded mode from %1", customfile));
|
||||
return true;
|
||||
}
|
||||
catch(hstream_exception& e) {
|
||||
addMessage(XLAT("Failed to load mode from %1", customfile));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
dialog::addBack();
|
||||
dialog::display();
|
||||
}
|
||||
|
||||
EX void mode_higlights() {
|
||||
cmode = sm::NOSCR;
|
||||
gamescreen();
|
||||
@ -751,6 +804,8 @@ EX void showChangeMode() {
|
||||
dialog::addBreak(50);
|
||||
dialog::addItem(XLAT("highlights & achievements"), 'h');
|
||||
dialog::add_action_push(mode_higlights);
|
||||
dialog::addItem(XLAT("custom mode manager"), 'm');
|
||||
dialog::add_action_push(show_custom);
|
||||
|
||||
dialog::addBack();
|
||||
dialog::display();
|
||||
|
12
system.cpp
12
system.cpp
@ -80,7 +80,8 @@ EX hookset<bool()> hooks_welcome_message;
|
||||
EX void welcomeMessage() {
|
||||
if(callhandlers(false, hooks_welcome_message)) return;
|
||||
if(nohelp == 1) return;
|
||||
if(embedded_plane) return IPF(welcomeMessage());
|
||||
if(custom_welcome != "") addMessage(custom_welcome);
|
||||
else if(embedded_plane) return IPF(welcomeMessage());
|
||||
#if CAP_TOUR
|
||||
else if(tour::on) return; // displayed by tour
|
||||
#endif
|
||||
@ -1796,17 +1797,26 @@ EX void save_mode_to_file(const string& fname) {
|
||||
save_mode_data(ss);
|
||||
string s = as_hexstring(ss.s);
|
||||
fhstream f(fname, "w");
|
||||
if(!f.f) throw hstream_exception();
|
||||
println(f, modheader);
|
||||
println(f, s);
|
||||
if(custom_welcome != "") println(f, "CMSG ", custom_welcome);
|
||||
}
|
||||
|
||||
EX void load_mode_from_file(const string& fname) {
|
||||
fhstream f(fname, "r");
|
||||
if(!f.f) throw hstream_exception();
|
||||
string header = scanline(f);
|
||||
if(header[0] != '#') throw hstream_exception();
|
||||
string hex = scanline(f);
|
||||
shstream ss;
|
||||
ss.s = from_hexstring(hex + "00");
|
||||
custom_welcome = "";
|
||||
while(true) {
|
||||
string s = scanline(f);
|
||||
if(s == "") break;
|
||||
if(s.substr(0, 5) == "CMSG ") custom_welcome = s.substr(5);
|
||||
}
|
||||
stop_game();
|
||||
load_mode_data_with_zero(ss);
|
||||
start_game();
|
||||
|
Loading…
Reference in New Issue
Block a user