mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-08 06:59:55 +00:00
naming modes
This commit is contained in:
parent
94c02b5082
commit
93dcc68acb
1
hud.cpp
1
hud.cpp
@ -719,6 +719,7 @@ EX void drawStats() {
|
|||||||
}
|
}
|
||||||
string vers = VER;
|
string vers = VER;
|
||||||
if(true) {
|
if(true) {
|
||||||
|
if(modename.count(current_modecode)) vers == " '" + modename[current_modecode] + "' ";
|
||||||
vers += mode_description();
|
vers += mode_description();
|
||||||
if(peace::on) vers += " peace";
|
if(peace::on) vers += " peace";
|
||||||
if(racing::on) vers += " racing";
|
if(racing::on) vers += " racing";
|
||||||
|
10
menus.cpp
10
menus.cpp
@ -487,6 +487,8 @@ EX string custom_welcome;
|
|||||||
|
|
||||||
string customfile = "custom.hrm";
|
string customfile = "custom.hrm";
|
||||||
|
|
||||||
|
string name_to_edit;
|
||||||
|
|
||||||
EX void show_custom() {
|
EX void show_custom() {
|
||||||
cmode = sm::SIDE | sm::MAYDARK;
|
cmode = sm::SIDE | sm::MAYDARK;
|
||||||
gamescreen();
|
gamescreen();
|
||||||
@ -506,6 +508,14 @@ EX void show_custom() {
|
|||||||
dialog::edit_string(custom_welcome, "custom welcome message", "");
|
dialog::edit_string(custom_welcome, "custom welcome message", "");
|
||||||
});
|
});
|
||||||
dialog::addBreak(100);
|
dialog::addBreak(100);
|
||||||
|
auto m = at_or_null(modename, current_modecode);
|
||||||
|
dialog::addSelItem("name custom mode", m ? *m : "", 'N');
|
||||||
|
dialog::add_action([] {
|
||||||
|
name_to_edit = modename[current_modecode];
|
||||||
|
dialog::edit_string(name_to_edit, "name custom mode", "");
|
||||||
|
dialog::get_di().reaction_final = [] { update_modename(name_to_edit); };
|
||||||
|
});
|
||||||
|
|
||||||
dialog::addItem("save custom mode", 'S');
|
dialog::addItem("save custom mode", 'S');
|
||||||
dialog::add_action([] {
|
dialog::add_action([] {
|
||||||
dialog::openFileDialog(customfile, XLAT("file to save:"), ".hrm", [] () {
|
dialog::openFileDialog(customfile, XLAT("file to save:"), ".hrm", [] () {
|
||||||
|
11
system.cpp
11
system.cpp
@ -171,6 +171,8 @@ EX void initgame() {
|
|||||||
DEBBI(DF_INIT, ("initGame"));
|
DEBBI(DF_INIT, ("initGame"));
|
||||||
callhooks(hooks_initgame);
|
callhooks(hooks_initgame);
|
||||||
|
|
||||||
|
modecode();
|
||||||
|
|
||||||
if(!safety) fix_land_structure_choice();
|
if(!safety) fix_land_structure_choice();
|
||||||
|
|
||||||
if(multi::players < 1 || multi::players > MAXPLAYER)
|
if(multi::players < 1 || multi::players > MAXPLAYER)
|
||||||
@ -1227,6 +1229,11 @@ EX void loadsave() {
|
|||||||
while(s != "" && s.back() < 32) s.pop_back();
|
while(s != "" && s.back() < 32) s.pop_back();
|
||||||
load_modecode_line(s);
|
load_modecode_line(s);
|
||||||
}
|
}
|
||||||
|
if(buf[0] == 'N' && buf[1] == 'A') {
|
||||||
|
string s = buf;
|
||||||
|
while(s != "" && s.back() < 32) s.pop_back();
|
||||||
|
load_modename_line(s);
|
||||||
|
}
|
||||||
if(buf[0] == 'H' && buf[1] == 'y') {
|
if(buf[0] == 'H' && buf[1] == 'y') {
|
||||||
if(fscanf(f, "%9999s", buf) <= 0) break;
|
if(fscanf(f, "%9999s", buf) <= 0) break;
|
||||||
sc.ver = buf;
|
sc.ver = buf;
|
||||||
@ -1834,6 +1841,7 @@ EX void save_mode_to_file(const string& fname) {
|
|||||||
println(f, modheader);
|
println(f, modheader);
|
||||||
println(f, s);
|
println(f, s);
|
||||||
if(custom_welcome != "") println(f, "CMSG ", custom_welcome);
|
if(custom_welcome != "") println(f, "CMSG ", custom_welcome);
|
||||||
|
if(modename.count(current_modecode)) println(f, "NAME ", modename[current_modecode]);
|
||||||
|
|
||||||
for(auto& ap: allowed_params) {
|
for(auto& ap: allowed_params) {
|
||||||
auto& s = params[ap];
|
auto& s = params[ap];
|
||||||
@ -1851,10 +1859,12 @@ EX void load_mode_from_file(const string& fname) {
|
|||||||
shstream ss;
|
shstream ss;
|
||||||
ss.s = from_hexstring(hex + "00");
|
ss.s = from_hexstring(hex + "00");
|
||||||
custom_welcome = "";
|
custom_welcome = "";
|
||||||
|
string custom_name = "";
|
||||||
while(true) {
|
while(true) {
|
||||||
string s = scanline_noblank(f);
|
string s = scanline_noblank(f);
|
||||||
if(s == "") break;
|
if(s == "") break;
|
||||||
else if(s.substr(0, 5) == "CMSG ") custom_welcome = s.substr(5);
|
else if(s.substr(0, 5) == "CMSG ") custom_welcome = s.substr(5);
|
||||||
|
else if(s.substr(0, 5) == "NAME ") custom_name = s.substr(5);
|
||||||
else {
|
else {
|
||||||
auto pos = s.find("=");
|
auto pos = s.find("=");
|
||||||
if(pos != string::npos) {
|
if(pos != string::npos) {
|
||||||
@ -1870,6 +1880,7 @@ EX void load_mode_from_file(const string& fname) {
|
|||||||
}
|
}
|
||||||
stop_game();
|
stop_game();
|
||||||
load_mode_data_with_zero(ss);
|
load_mode_data_with_zero(ss);
|
||||||
|
if(custom_name != "") { modecode(); update_modename(custom_name); }
|
||||||
start_game();
|
start_game();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
yendor.cpp
36
yendor.cpp
@ -1141,9 +1141,11 @@ EX modecode_t get_identify(modecode_t xc) {
|
|||||||
/** handle cases where the encoding changed in the new version */
|
/** handle cases where the encoding changed in the new version */
|
||||||
EX string expected_modecode;
|
EX string expected_modecode;
|
||||||
|
|
||||||
|
EX modecode_t current_modecode;
|
||||||
|
|
||||||
EX modecode_t modecode(int mode) {
|
EX modecode_t modecode(int mode) {
|
||||||
modecode_t x = legacy_modecode();
|
modecode_t x = legacy_modecode();
|
||||||
if(x != UNKNOWN) return x;
|
if(x != UNKNOWN) return current_modecode = x;
|
||||||
|
|
||||||
xcheat = (cheater ? 1 : 0);
|
xcheat = (cheater ? 1 : 0);
|
||||||
shstream ss;
|
shstream ss;
|
||||||
@ -1181,7 +1183,7 @@ EX modecode_t modecode(int mode) {
|
|||||||
fprintf(f, "MODE %d %s\n", next, s.c_str());
|
fprintf(f, "MODE %d %s\n", next, s.c_str());
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return next;
|
return current_modecode = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
EX void load_modecode_line(string s) {
|
EX void load_modecode_line(string s) {
|
||||||
@ -1199,6 +1201,26 @@ EX void load_modecode_line(string s) {
|
|||||||
code_for[nover] = code;
|
code_for[nover] = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EX void load_modename_line(string s) {
|
||||||
|
int code = atoi(&s[5]);
|
||||||
|
int pos = 5;
|
||||||
|
while(s[pos] != ' ' && s[pos]) pos++;
|
||||||
|
if(!s[pos]) { modename.erase(get_identify(code)); return; }
|
||||||
|
pos++;
|
||||||
|
modename[get_identify(code)] = s.substr(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
EX void update_modename(string newname) {
|
||||||
|
string old = modename.count(current_modecode) ? modename[current_modecode] : "";
|
||||||
|
if(old == newname) return;
|
||||||
|
if(newname == "") modename.erase(current_modecode);
|
||||||
|
else modename[current_modecode] = newname;
|
||||||
|
FILE *f = fopen(scorefile.c_str(), "at");
|
||||||
|
if(!f) return;
|
||||||
|
fprintf(f, "NAME %d %s\n", current_modecode, newname.c_str());
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
EX namespace peace {
|
EX namespace peace {
|
||||||
|
|
||||||
EX bool on = false;
|
EX bool on = false;
|
||||||
@ -1420,7 +1442,8 @@ void mode_screen_for_current() {
|
|||||||
cmode = sm::SIDE | sm::MAYDARK;
|
cmode = sm::SIDE | sm::MAYDARK;
|
||||||
gamescreen();
|
gamescreen();
|
||||||
|
|
||||||
auto mc = modecode();
|
modecode();
|
||||||
|
auto& mc = current_modecode;
|
||||||
dialog::init(XLAT("recorded mode %1", its(mc)), iinf[itOrbYendor].color, 150, 100);
|
dialog::init(XLAT("recorded mode %1", its(mc)), iinf[itOrbYendor].color, 150, 100);
|
||||||
dialog::addInfo(mode_description1());
|
dialog::addInfo(mode_description1());
|
||||||
|
|
||||||
@ -1490,11 +1513,14 @@ EX string mode_to_search;
|
|||||||
int gscore(modecode_t xc) { if(!qty_scores_for.count(xc)) return 0; return qty_scores_for[xc]; }
|
int gscore(modecode_t xc) { if(!qty_scores_for.count(xc)) return 0; return qty_scores_for[xc]; }
|
||||||
int gscoreall(modecode_t xc) { return gscore(xc) * 100 + tactic::compute_tscore(xc) * 10 + yendor::compute_tscore(xc); }
|
int gscoreall(modecode_t xc) { return gscore(xc) * 100 + tactic::compute_tscore(xc) * 10 + yendor::compute_tscore(xc); }
|
||||||
string gdisplay(modecode_t xc) {
|
string gdisplay(modecode_t xc) {
|
||||||
if(mode_description_of.count(xc)) return mode_description_of[xc];
|
string out = "";
|
||||||
else return "(mode " + its(xc) + ")";
|
if(modename.count(xc)) out = modename[xc] + ": ";
|
||||||
|
if(mode_description_of.count(xc)) return out + mode_description_of[xc];
|
||||||
|
else return out + "(mode " + its(xc) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
EX vector<modecode_t> mode_list;
|
EX vector<modecode_t> mode_list;
|
||||||
|
EX map<modecode_t, string> modename;
|
||||||
|
|
||||||
EX void prepare_custom() {
|
EX void prepare_custom() {
|
||||||
scores::load_only();
|
scores::load_only();
|
||||||
|
Loading…
Reference in New Issue
Block a user