From 3da6090320575f65fe9cbe58d276d47f990ecd2f Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 3 May 2019 12:11:40 +0200 Subject: [PATCH] dialog:: addBoolItem_action, addBoolItem_action_neg, addBoolItem_choice used when applicable --- config.cpp | 21 +++++++-------------- conformal.cpp | 12 ++++-------- crystal.cpp | 3 +-- dialogs.cpp | 7 ++++++- expansion.cpp | 3 +-- hyper.h | 5 +++++ mapeditor.cpp | 12 ++++-------- racing.cpp | 3 +-- rogueviz-flocking.cpp | 3 +-- rogueviz.cpp | 6 ++---- screenshot.cpp | 24 ++++++++---------------- textures.cpp | 30 ++++++++++-------------------- 12 files changed, 50 insertions(+), 79 deletions(-) diff --git a/config.cpp b/config.cpp index 00cfe45f..61a4e34a 100644 --- a/config.cpp +++ b/config.cpp @@ -859,11 +859,9 @@ void configureOther() { dialog::add_action([] {vid.steamscore = vid.steamscore^1; }); #endif - dialog::addBoolItem(XLAT("skip the start menu"), vid.skipstart, 'm'); - dialog::add_action([] { vid.skipstart = !vid.skipstart; }); + dialog::addBoolItem_action(XLAT("skip the start menu"), vid.skipstart, 'm'); - dialog::addBoolItem(XLAT("forget faraway cells"), memory_saving_mode, 'y'); - dialog::add_action([] { memory_saving_mode = !memory_saving_mode; }); + dialog::addBoolItem_action(XLAT("forget faraway cells"), memory_saving_mode, 'y'); if(CAP_AUDIO) { dialog::addSelItem(XLAT("background music volume"), its(musicvolume), 'b'); @@ -1284,8 +1282,7 @@ void show3D() { dialog::addBreak(50); #if CAP_RUG if(rug::rugged) { - dialog::addBoolItem(XLAT("3D monsters/walls on the surface"), rug::spatial_rug, 'S'); - dialog::add_action([] () { rug::spatial_rug = !rug::spatial_rug; }); + dialog::addBoolItem_action(XLAT("3D monsters/walls on the surface"), rug::spatial_rug, 'S'); } #endif dialog::addBoolItem(XLAT("configure TPP automatically"), pmodel == mdDisk && vid.camera_angle, 'T'); @@ -1394,8 +1391,7 @@ void show3D() { XLAT("Don't center on the player character.") ); if(DIM == 3) dialog::extra_options = [] () { - dialog::addBoolItem(XLAT("reduce if walls on the way"), vid.use_wall_radar, 'R'); - dialog::add_action([] () { vid.use_wall_radar = !vid.use_wall_radar; }); + dialog::addBoolItem_action(XLAT("reduce if walls on the way"), vid.use_wall_radar, 'R'); }; } else if(uni == 's') @@ -1709,11 +1705,9 @@ void configureMouse() { gamescreen(1); dialog::init(XLAT("mouse & touchscreen")); - dialog::addBoolItem(XLAT("reverse pointer control"), (vid.revcontrol), 'r'); - dialog::add_action([] {vid.revcontrol = !vid.revcontrol; }); + dialog::addBoolItem_action(XLAT("reverse pointer control"), (vid.revcontrol), 'r'); - dialog::addBoolItem(XLAT("draw circle around the target"), (vid.drawmousecircle), 'd'); - dialog::add_action([] { vid.drawmousecircle = !vid.drawmousecircle; }); + dialog::addBoolItem_action(XLAT("draw circle around the target"), (vid.drawmousecircle), 'd'); #if ISMOBILE dialog::addBoolItem(XLAT("targetting ranged Orbs long-click only"), (vid.shifttarget&2), 'i'); @@ -1723,8 +1717,7 @@ void configureMouse() { dialog::add_action([] {vid.shifttarget = vid.shifttarget^3; }); #if !ISMOBILE - dialog::addBoolItem(XLAT("quick mouse"), vid.quickmouse, 'M'); - dialog::add_action([] {vid.quickmouse = !vid.quickmouse; }); + dialog::addBoolItem_action(XLAT("quick mouse"), vid.quickmouse, 'M'); #endif dialog::addSelItem(XLAT("move by clicking on compass"), its(vid.mobilecompasssize), 'C'); diff --git a/conformal.cpp b/conformal.cpp index 18d9fe2b..a62972ed 100644 --- a/conformal.cpp +++ b/conformal.cpp @@ -826,8 +826,7 @@ namespace conformal { } if(pmodel == mdRotatedHyperboles) { - dialog::addBoolItem(XLAT("use atan to make it finite"), use_atan, 'x'); - dialog::add_action([] () { use_atan = !use_atan; }); + dialog::addBoolItem_action(XLAT("use atan to make it finite"), use_atan, 'x'); } if(pmodel == mdBall) { @@ -1023,12 +1022,9 @@ namespace conformal { dialog::dialogflags |= sm::CENTER; dialog::extra_options = [] () { dialog::addBreak(100); - dialog::addBoolItem("line animation only", conformal::do_rotate == 0, 'N'); - dialog::add_action([] () { conformal::do_rotate = 0; }); - dialog::addBoolItem("gravity lands", conformal::do_rotate == 1, 'G'); - dialog::add_action([] () { conformal::do_rotate = 1; }); - dialog::addBoolItem("all directional lands", conformal::do_rotate == 2, 'D'); - dialog::add_action([] () { conformal::do_rotate = 2; }); + dialog::addBoolItem_choice("line animation only", conformal::do_rotate, 0, 'N'); + dialog::addBoolItem_choice("gravity lands", conformal::do_rotate, 1, 'G'); + dialog::addBoolItem_choice("all directional lands", conformal::do_rotate, 2, 'D'); }; } else if(doexiton(sym, uni)) popScreen(); diff --git a/crystal.cpp b/crystal.cpp index edc90907..0ef1db29 100644 --- a/crystal.cpp +++ b/crystal.cpp @@ -1149,8 +1149,7 @@ void show() { dialog::addBoolItem(XLAT("4D double bitruncated"), ginf[gCrystal].vertex == 3, 'D'); dialog::add_action(dialog::add_confirmation([]() { set_crystal(8); set_variation(eVariation::bitruncated); set_variation(eVariation::bitruncated); start_game(); })); dialog::addBreak(50); - dialog::addBoolItem(XLAT("view coordinates in the cheat mode"), view_coordinates, 'v'); - dialog::add_action([]() { view_coordinates = !view_coordinates; }); + dialog::addBoolItem_action(XLAT("view coordinates in the cheat mode"), view_coordinates, 'v'); dialog::addSelItem(XLAT("compass probability"), fts(compass_probability), 'p'); dialog::add_action([]() { dialog::editNumber(compass_probability, 0, 1, 0.1, 1, XLAT("compass probability"), compass_help()); diff --git a/dialogs.cpp b/dialogs.cpp index 01cbece8..3b3a55b6 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -1087,10 +1087,15 @@ namespace dialog { dialog::display(); } - void addBoolItem_action(const string& s, bool& b, char c) { + void addBoolItem_action(const string& s, bool& b, char c) { dialog::addBoolItem(s, b, c); dialog::add_action([&b] { b = !b; }); } + + void addBoolItem_action_neg(const string& s, bool& b, char c) { + dialog::addBoolItem(s, !b, c); + dialog::add_action([&b] { b = !b; }); + } }; } diff --git a/expansion.cpp b/expansion.cpp index 987a5df2..16118bed 100644 --- a/expansion.cpp +++ b/expansion.cpp @@ -583,8 +583,7 @@ void viewdist_configure_dialog() { dialog::addSelItem(XLAT("number codes"), XLAT(ncnames[number_coding]), 'n'); dialog::add_action([] () { number_coding = eNumberCoding((number_coding + 1) % (mod_allowed() ? 4 : 2)); }); - dialog::addBoolItem(XLAT("color codes"), use_color_codes, 'u'); - dialog::add_action([] () { use_color_codes = !use_color_codes; }); + dialog::addBoolItem_action(XLAT("color codes"), use_color_codes, 'u'); dialog::addSelItem(XLAT("display distances from"), its(first_distance), 'd'); dialog::add_action([] () { diff --git a/hyper.h b/hyper.h index 09bcf853..9955cfea 100644 --- a/hyper.h +++ b/hyper.h @@ -1974,6 +1974,11 @@ namespace dialog { void add_action_push(const reaction_t& action); void addBoolItem_action(const string& s, bool& b, char c); + void addBoolItem_action_neg(const string& s, bool& b, char c); + template void addBoolItem_choice(const string& s, T& b, T val, char c) { + addBoolItem(s, b == val, c); + add_action([&b, val] { b = val; }); + } string view_edited_string(); void start_editing(string& s); diff --git a/mapeditor.cpp b/mapeditor.cpp index 93ee366f..de116647 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -2108,21 +2108,17 @@ namespace mapeditor { dialog::init(XLAT("Map settings")); - dialog::addBoolItem(XLAT("disable wandering monsters"), !gen_wandering, 'w'); - dialog::add_action([] () { gen_wandering = !gen_wandering; }); + dialog::addBoolItem_action_neg(XLAT("disable wandering monsters"), gen_wandering, 'w'); if(gen_wandering) { - dialog::addBoolItem(XLAT("disable ghost timer"), !timerghost, 'g'); - dialog::add_action([] () { timerghost = !timerghost; }); + dialog::addBoolItem_action_neg(XLAT("disable ghost timer"), timerghost, 'g'); } else dialog::addBreak(100); - dialog::addBoolItem(XLAT("simple pattern generation"), reptilecheat, 'p'); - dialog::add_action([] () { reptilecheat = !reptilecheat; }); + dialog::addBoolItem_action(XLAT("simple pattern generation"), reptilecheat, 'p'); dialog::addInfo(XLAT("(e.g. pure Reptile pattern)")); - dialog::addBoolItem(XLAT("safety generation"), safety, 's'); - dialog::add_action([] () { safety = !safety; }); + dialog::addBoolItem_action(XLAT("safety generation"), safety, 's'); dialog::addInfo(XLAT("(no treasure, no dangers)")); dialog::addBoolItem(XLAT("god mode"), autocheat, 'G'); diff --git a/racing.cpp b/racing.cpp index f3d8e26d..55551b58 100644 --- a/racing.cpp +++ b/racing.cpp @@ -1018,8 +1018,7 @@ void race_projection() { dialog::addItem(XLAT("configure the projection"), 'p'); dialog::add_action_push(race_projection); - dialog::addBoolItem(XLAT("guiding line"), guiding, 'g'); - dialog::add_action([] () { guiding = !guiding; }); + dialog::addBoolItem_action(XLAT("guiding line"), guiding, 'g'); dialog::addItem(shmup::player_count_name(playercfg), 'n'); dialog::add_action([/*this*/] () { diff --git a/rogueviz-flocking.cpp b/rogueviz-flocking.cpp index de9fb544..5ff04aff 100644 --- a/rogueviz-flocking.cpp +++ b/rogueviz-flocking.cpp @@ -422,8 +422,7 @@ namespace flocking { hr::showquotients = true; dialog::add_action(runGeometryExperiments); - dialog::addBoolItem("draw forces", draw_lines, 'l'); - dialog::add_action([] () { draw_lines = !draw_lines; }); + dialog::addBoolItem_action("draw forces", draw_lines, 'l'); dialog::addSelItem("follow", follow_names[follow], 'f'); dialog::add_action([] () { follow++; follow %= 3; }); diff --git a/rogueviz.cpp b/rogueviz.cpp index 630baa27..47321b88 100644 --- a/rogueviz.cpp +++ b/rogueviz.cpp @@ -1959,10 +1959,8 @@ void configure_edge_display() { } dialog::addBreak(100); if(among(kind, kSAG, kKohonen, kSpiral)) { - dialog::addBoolItem("color/alpha", mode == 0, '1'); - dialog::add_action([] () { mode = 0; }); - dialog::addBoolItem(s3, mode == 1, '2'); - dialog::add_action([] () { mode = 1; }); + dialog::addBoolItem_choice("color/alpha", mode, 0, '1'); + dialog::addBoolItem_choice(s3, mode, 1, '2'); } else mode = 0; diff --git a/screenshot.cpp b/screenshot.cpp index 59eb5d49..c2538957 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -414,8 +414,7 @@ void menu() { dialog::addSelItem(XLAT("supersampling"), its(shot_aa), 's'); dialog::add_action([] { shot_aa *= 2; if(shot_aa > 16) shot_aa = 1; }); } - dialog::addBoolItem(XLAT("transparent"), transparent, 't'); - dialog::add_action([] { transparent = !transparent; }); + dialog::addBoolItem_action(XLAT("transparent"), transparent, 't'); dialog::addSelItem(XLAT("gamma"), fts(gamma), 'g'); dialog::add_action([] { dialog::editNumber(gamma, 0, 2, .1, .5, XLAT("gamma"), "higher value = darker"); }); @@ -423,11 +422,9 @@ void menu() { dialog::addSelItem(XLAT("brightness"), fts(fade), 'b'); dialog::add_action([] { dialog::editNumber(fade, 0, 2, .1, 1, XLAT("brightness"), "higher value = lighter"); }); - dialog::addBoolItem(XLAT("disable the HUD"), hide_hud, 'h'); - dialog::add_action([] { hide_hud = !hide_hud; }); + dialog::addBoolItem_action(XLAT("disable the HUD"), hide_hud, 'h'); - dialog::addBoolItem(XLAT("hide the player"), !mapeditor::drawplayer, 'H'); - dialog::add_action([] { mapeditor::drawplayer = !mapeditor::drawplayer; }); + dialog::addBoolItem_action_neg(XLAT("hide the player"), mapeditor::drawplayer, 'H'); dialog::addItem(XLAT("colors & aura"), 'c'); dialog::add_action_push(show_color_dialog); @@ -796,19 +793,14 @@ void show() { }; }); } - dialog::addBoolItem(XLAT("no movement animation"), ma == maNone, '0'); - dialog::add_action([] () { ma = maNone; }); - dialog::addBoolItem(XLAT("translation"), ma == maTranslation, '1'); - dialog::add_action([] () { ma = maTranslation; }); - dialog::addBoolItem(XLAT("rotation"), ma == maRotation, '2'); - dialog::add_action([] () { ma = maRotation; }); + dialog::addBoolItem_choice(XLAT("no movement animation"), ma, maNone, '0'); + dialog::addBoolItem_choice(XLAT("translation"), ma, maTranslation, '1'); + dialog::addBoolItem_choice(XLAT("rotation"), ma, maRotation, '2'); if(hyperbolic) { - dialog::addBoolItem(XLAT("parabolic"), ma == maParabolic, '3'); - dialog::add_action([] () { ma = maParabolic; }); + dialog::addBoolItem_choice(XLAT("parabolic"), ma, maParabolic, '3'); } if(among(pmodel, mdJoukowsky, mdJoukowskyInverted)) { - dialog::addBoolItem(XLAT("joukowsky_anim"), joukowsky_anim, 'j'); - dialog::add_action([] () { joukowsky_anim = !joukowsky_anim; }); + dialog::addBoolItem_action(XLAT("joukowsky_anim"), joukowsky_anim, 'j'); } if(among(pmodel, mdJoukowsky, mdJoukowskyInverted)) { animator(XLAT("Möbius transformations"), skiprope_rotation, 'S'); diff --git a/textures.cpp b/textures.cpp index 458ac499..435bd8d0 100644 --- a/textures.cpp +++ b/textures.cpp @@ -1147,19 +1147,19 @@ void showMenu() { dialog::addItem(XLAT("select the texture's pattern"), 'r'); dialog::addItem(XLAT("enable the texture"), 't'); dialog::addItem(XLAT("cancel the texture"), 'T'); - dialog::addBoolItem(XLAT("move the model"), panstate == tpsModel, 'm'); - dialog::addBoolItem(XLAT("move the texture"), panstate == tpsMove, 'a'); - dialog::addBoolItem(XLAT("zoom/scale the texture"), panstate == tpsScale, 'x'); - dialog::addBoolItem(XLAT("zoom/scale the model"), panstate == tpsZoom, 'z'); - dialog::addBoolItem(XLAT("projection"), panstate == tpsProjection, 'p'); - dialog::addBoolItem(XLAT("affine transformations"), panstate == tpsAffine, 'y'); + dialog::addBoolItem_choice(XLAT("move the model"), panstate, tpsModel, 'm'); + dialog::addBoolItem_choice(XLAT("move the texture"), panstate, tpsMove, 'a'); + dialog::addBoolItem_choice(XLAT("zoom/scale the texture"), panstate, tpsScale, 'x'); + dialog::addBoolItem_choice(XLAT("zoom/scale the model"), panstate, tpsZoom, 'z'); + dialog::addBoolItem_choice(XLAT("projection"), panstate, tpsProjection, 'p'); + dialog::addBoolItem_choice(XLAT("affine transformations"), panstate, tpsAffine, 'y'); dialog::addBoolItem(XLAT("magic"), false, 'A'); dialog::addBreak(50); - dialog::addBoolItem(XLAT("select master cells"), panstate == tpsCell, 'C'); - dialog::addBoolItem(XLAT("select master triangles"), panstate == tpsTriangle, 'X'); - dialog::addBoolItem(XLAT("fine tune vertices"), panstate == tpsTune, 'F'); + dialog::addBoolItem_choice(XLAT("select master cells"), panstate, tpsCell, 'C'); + dialog::addBoolItem_choice(XLAT("select master triangles"), panstate, tpsTriangle, 'X'); + dialog::addBoolItem_choice(XLAT("fine tune vertices"), panstate, tpsTune, 'F'); dialog::addColorItem(XLAT("grid color (master)"), config.master_color, 'M'); dialog::addColorItem(XLAT("grid color (copy)"), config.slave_color, 'K'); @@ -1183,8 +1183,7 @@ void showMenu() { dialog::addColorItem(XLAT("mesh color"), config.mesh_color, 'm'); dialog::addSelItem(XLAT("color alpha"), its(config.color_alpha), 'c'); dialog::addSelItem(XLAT("precision"), its(config.gsplits), 'P'); - dialog::addBoolItem(XLAT("aura from texture"), texture_aura, 'a'); - dialog::add_action([] () { texture_aura = !texture_aura; }); + dialog::addBoolItem_action(XLAT("aura from texture"), texture_aura, 'a'); #if CAP_EDIT if(DIM == 2) dialog::addItem(XLAT("edit the texture"), 'e'); #endif @@ -1212,15 +1211,6 @@ void showMenu() { } } - else if(uni == 'm' && config.tstate == tsAdjusting) panstate = tpsModel; - else if(uni == 'a' && config.tstate == tsAdjusting) panstate = tpsMove; - else if(uni == 'x' && config.tstate == tsAdjusting) panstate = tpsScale; - else if(uni == 'y' && config.tstate == tsAdjusting) panstate = tpsAffine; - else if(uni == 'z' && config.tstate == tsAdjusting) panstate = tpsZoom; - else if(uni == 'p' && config.tstate == tsAdjusting) panstate = tpsProjection; - else if(uni == 'C' && config.tstate == tsAdjusting) panstate = tpsCell; - else if(uni == 'X' && config.tstate == tsAdjusting) panstate = tpsTriangle; - else if(uni == 'F' && config.tstate == tsAdjusting) panstate = tpsTune; else if(uni == 'A' && config.tstate == tsAdjusting) pushScreen(showMagicMenu);