From 3a8293df27bfbc403d42fae6bebe3bb0fb901734 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 9 Jul 2018 19:55:56 +0200 Subject: [PATCH] rogueviz:: tutorial, start/main menu, and welcome message done as hooks --- help.cpp | 2 ++ hyper.h | 4 +++- menus.cpp | 26 +++++++------------------- rogueviz.cpp | 39 +++++++++++++++++++++++++++++++++++++++ rogueviz.h | 1 - system.cpp | 14 ++++++-------- tour.cpp | 17 +++-------------- 7 files changed, 60 insertions(+), 43 deletions(-) diff --git a/help.cpp b/help.cpp index 461a1c39..32812e25 100644 --- a/help.cpp +++ b/help.cpp @@ -961,6 +961,7 @@ void gotoHelp(const string& h) { pushScreen(showHelp); if(help == "@") { +/* #if CAP_ROGUEVIZ if(rogueviz::on) { help = rogueviz::makehelp(); @@ -968,6 +969,7 @@ void gotoHelp(const string& h) { return; } #endif +*/ #if CAP_RUG if(rug::rugged) { diff --git a/hyper.h b/hyper.h index 44e8d396..58839874 100644 --- a/hyper.h +++ b/hyper.h @@ -1888,6 +1888,7 @@ namespace tour { void list(slide*); } + extern hookset *hooks_slide; }; #endif @@ -2019,7 +2020,7 @@ template int addHook(hookset*& m, int prio, const U& hook) return 0; } -extern purehookset hooks_frame, hooks_stats, clearmemory, hooks_config, hooks_tests, hooks_removecells, hooks_initgame, hooks_calcparam; +extern purehookset hooks_frame, hooks_stats, clearmemory, hooks_config, hooks_tests, hooks_removecells, hooks_initgame, hooks_calcparam, hooks_mainmenu, hooks_startmenu; template void callhooks(hookset *h, U... args) { if(h) for(auto& p: *h) p.second(args...); @@ -2039,6 +2040,7 @@ extern hookset *hooks_main; extern hookset *hooks_args; extern hookset *hooks_mark; extern hookset *hooks_nextland; +extern hookset *hooks_welcome_message; // hooks to extend HyperRogue with an external program // start compilation from another file which defines EXTRA_..., includes diff --git a/menus.cpp b/menus.cpp index 212c1108..907a8764 100644 --- a/menus.cpp +++ b/menus.cpp @@ -183,6 +183,8 @@ void showOverview() { // -- main menu -- +purehookset hooks_mainmenu; + void showMainMenu() { gamescreen(2); @@ -225,10 +227,6 @@ void showMainMenu() { if(inv::on) dialog::addItem(XLAT("inventory"), 'i'); -#if CAP_ROGUEVIZ - dialog::addItem(XLAT("rogueviz menu"), 'u'); -#endif - #if ISMOBILE==1 #if CAP_ACHIEVE dialog::addItem(XLAT("leaderboards/achievements"), '3'); @@ -238,6 +236,8 @@ void showMainMenu() { #if CAP_ANDROIDSHARE dialog::addItem("SHARE", 's'-96); #endif + + callhooks(hooks_mainmenu); if(!canmove) q = "review the scene"; else if(turncount > 0) q = "continue game"; @@ -289,9 +289,6 @@ void showMainMenu() { pushScreen(leader::showMenu); } #endif - #endif - #if CAP_ROGUEVIZ - else if(uni == 'u') pushScreen(rogueviz::showMenu); #endif else if(doexiton(sym, uni)) { popScreenAll(); @@ -586,6 +583,8 @@ bool showHalloween() { int daily_mode; +purehookset hooks_startmenu; + void showStartMenu() { if(!daily_mode) { daily_mode = hrand(10) + 1; @@ -682,11 +681,7 @@ void showStartMenu() { break; } -#if CAP_ROGUEVIZ && CAP_TOUR - dialog::addBreak(100); - dialog::addBigItem(XLAT("RogueViz"), 'r'); - dialog::addInfo(XLAT("see the visualizations")); -#endif + callhooks(hooks_startmenu); if(have_current_settings()) { dialog::addBreak(100); @@ -793,13 +788,6 @@ void showStartMenu() { popScreenAll(); pushScreen(daily::showMenu); } -#endif -#if CAP_ROGUEVIZ && CAP_TOUR - else if(uni == 'r') { - tour::slides = rogueviz::rvtour::rvslides; - popScreenAll(); - tour::start(); - } #endif else if(sym == 'm') { popScreen(); diff --git a/rogueviz.cpp b/rogueviz.cpp index 9d1a5799..0b30fb6c 100644 --- a/rogueviz.cpp +++ b/rogueviz.cpp @@ -2038,6 +2038,37 @@ slide rvslides[] = { } }; +int rvtour_hooks = + addHook(hooks_startmenu, 100, [] () { +#if CAP_TOUR + dialog::addBreak(100); + dialog::addBigItem(XLAT("RogueViz"), 'r'); + dialog::addInfo(XLAT("see the visualizations")); +#endif + dialog::add_action([] () { + tour::slides = rogueviz::rvtour::rvslides; + popScreenAll(); + tour::start(); + }); + }) + + addHook(hooks_slide, 100, [] (int mode) { + if(currentslide == 0 && slides == default_slides) { + slidecommand = "RogueViz presentation"; + if(mode == 1) + help += + "\n\nYour version of HyperRogue is compiled with RogueViz. " + "Press '5' to switch to the RogueViz slides. Watching the " + "common HyperRogue tutorial first is useful too, " + "as an introduction to hyperbolic geometry."; + if(mode == 4) { + slides = rogueviz::rvtour::rvslides; + while(tour::on) restart_game(rg::tour); + tour::start(); + } + } + }) + + 0; + } auto hooks = @@ -2053,6 +2084,14 @@ auto hooks = addHook(shmup::hooks_describe, 100, describe_monster) + addHook(shmup::hooks_turn, 100, turn) + addHook(shmup::hooks_kill, 100, activate) + + addHook(hooks_mainmenu, 100, [] () { + dialog::addItem(XLAT("rogueviz menu"), 'u'); + dialog::add_action([] () { pushScreen(rogueviz::showMenu); }); + }) + + addHook(hooks_welcome_message, 100, [] () { + if(rogueviz::on) addMessage(XLAT("Welcome to RogueViz!")); + return rogueviz::on; + }) + 0; }; diff --git a/rogueviz.h b/rogueviz.h index f639498e..cd32e81b 100644 --- a/rogueviz.h +++ b/rogueviz.h @@ -7,7 +7,6 @@ namespace rogueviz { void describe(cell *c); void drawExtra(); void close(); - void showMenu(); string makehelp(); void init(); diff --git a/system.cpp b/system.cpp index c07c38ba..e0bb3140 100644 --- a/system.cpp +++ b/system.cpp @@ -38,8 +38,11 @@ bool do_use_special_land() { (peace::on || tactic::on || geometry || gp::on || randomPatternsMode || yendor::on); } +hookset *hooks_welcome_message; + void welcomeMessage() { - if(tactic::trailer) return; + if(callhandlers(false, hooks_welcome_message)) return; + else if(tactic::trailer) return; #if CAP_TOUR else if(tour::on) return; // displayed by tour #endif @@ -67,13 +70,8 @@ void welcomeMessage() { addMessage(XLAT("Good luck in the elliptic plane!")); else if(sphere) addMessage(XLAT("Welcome to Spherogue!")); -#if CAP_ROGUEVIZ - else if(rogueviz::on) - addMessage(XLAT("Welcome to RogueViz!")); -#endif - else { - addMessage(XLAT("Welcome to HyperRogue!")); - } + else + addMessage(XLAT("Welcome to HyperRogue!")); if(do_use_special_land() || firstland != laIce) if(!daily::on) { auto lv = land_validity(specialland); diff --git a/tour.cpp b/tour.cpp index 16326493..1780bc60 100644 --- a/tour.cpp +++ b/tour.cpp @@ -48,6 +48,8 @@ function showland; string slidecommand; +hookset *hooks_slide; + void presentation(presmode mode) { cheater = 0; @@ -62,6 +64,7 @@ void presentation(presmode mode) { SHOWLAND(true); slides[currentslide].action(mode); + callhooks(hooks_slide, mode); } void slidehelp() { @@ -363,20 +366,6 @@ slide default_slides[] = { else clearMessages(); } SHOWLAND( l == laIce ); -#if CAP_ROGUEVIZ - slidecommand = "RogueViz presentation"; - if(mode == 1) - help += - "\n\nYour version of HyperRogue is compiled with RogueViz. " - "Press '5' to switch to the RogueViz slides. Watching the " - "common HyperRogue tutorial first is useful too, " - "as an introduction to hyperbolic geometry."; - if(mode == 4) { - slides = rogueviz::rvtour::rvslides; - while(tour::on) restart_game(rg::tour); - tour::start(); - } -#endif } }, {"Basics of gameplay", 11, LEGAL_ANY,