From 99bc842c572f772d2159b36b981a92947a654c10 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 28 May 2024 15:09:00 +0200 Subject: [PATCH] generalized show_turns to menu_format --- config.cpp | 7 ++++--- graph.cpp | 7 ++++--- util.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/config.cpp b/config.cpp index 1f475b8f..6d4714a3 100644 --- a/config.cpp +++ b/config.cpp @@ -1160,8 +1160,9 @@ EX void initConfig() { param_i(min_cells_drawn, "min_cells_drawn"); - param_b(show_turns, "show_turns", false) - -> editable("show turn count", 'T'); + param_str(menu_format, "menu_format", "") + ->editable("menu format", "programmable menu key", 'T') + ->set_standard_editor(); param_i(menu_darkening, "menu_darkening", 2) -> editable(0, 8, 1, "menu map darkening", "A larger number means darker game map in the background. Set to 8 to disable the background.", 'd') -> set_sets([] { dialog::bound_low(0); dialog::bound_up(8); dialog::get_di().dialogflags |= sm::DARKEN; }); @@ -2439,7 +2440,7 @@ EX void configureInterface() { }; }); - add_edit(show_turns); + add_edit(menu_format); add_edit(menu_darkening); add_edit(centered_menus); add_edit(startanims::enabled); diff --git a/graph.cpp b/graph.cpp index 0c035d13..47e28d18 100644 --- a/graph.cpp +++ b/graph.cpp @@ -5673,7 +5673,8 @@ EX bool just_refreshing; EX int menu_darkening = 2; EX bool centered_menus = false; -EX bool show_turns = false; + +EX string menu_format = ""; EX void gamescreen() { @@ -5800,8 +5801,8 @@ EX void normalscreen() { cmode = sm::NORMAL | sm::DOTOUR | sm::CENTER; if(viewdists && show_distance_lists) cmode |= sm::SIDE | sm::MAYDARK; gamescreen(); drawStats(); - if(show_turns) - displayButton(vid.xres-8, vid.yres-vid.fsize, "t:" + its(turncount), 'v', 16); + if(menu_format != "") + displayButton(vid.xres-8, vid.yres-vid.fsize, eval_programmable_string(menu_format), 'v', 16); else if(nomenukey || ISMOBILE) ; #if CAP_TOUR diff --git a/util.cpp b/util.cpp index 642906c6..2ab2c18d 100644 --- a/util.cpp +++ b/util.cpp @@ -1029,6 +1029,39 @@ EX string read_file_as_string(string fname) { return buf; } +EX string eval_programmable_string(const string& fmt) { + try { + exp_parser ep; + ep.s = fmt; + string out; + while(ep.at < (int) fmt.size()) { + if(ep.eat("$(")) { + auto res = ep.parse(); + if(ep.eat(",")) { + int prec = ep.iparse(); + std::stringstream str; + str.precision(prec); + str << std::fixed; + if(prec) str << std::showpoint; + str << real(res); + if(imag(res)) str << "+i" << imag(res); + out += str.str(); + } + else { + out += fts(real(res)); + if(imag(res)) out += "+i" + fts(imag(res)); + } + ep.force_eat(")"); + } + else out += ep.eatchar(); + } + return out; + } + catch(hr_parse_exception& ex) { + return fmt; + } + } + EX void floyd_warshall(vector>& v) { int N = isize(v); for(int k=0; k