Browse Source

Delay enabling input in menus to prevent accidental double clicks

master
C. J. Howard 2 years ago
parent
commit
0e9a3a8845
7 changed files with 32 additions and 12 deletions
  1. +3
    -0
      src/game/menu.hpp
  2. +5
    -2
      src/game/states/controls-menu.cpp
  3. +5
    -2
      src/game/states/graphics-menu.cpp
  4. +5
    -2
      src/game/states/language-menu.cpp
  5. +4
    -2
      src/game/states/main-menu.cpp
  6. +5
    -2
      src/game/states/options-menu.cpp
  7. +5
    -2
      src/game/states/sound-menu.cpp

+ 3
- 0
src/game/menu.hpp View File

@ -25,6 +25,9 @@
namespace game { namespace game {
namespace menu { namespace menu {
/// Delay, in seconds, to when menu input should be activated.
static constexpr float input_delay = 0.01f;
/// RGBA color of active menu items. /// RGBA color of active menu items.
static constexpr float4 active_color{1.0f, 1.0f, 1.0f, 1.0f}; static constexpr float4 active_color{1.0f, 1.0f, 1.0f, 1.0f};

+ 5
- 2
src/game/states/controls-menu.cpp View File

@ -26,6 +26,7 @@
#include "render/passes/clear-pass.hpp" #include "render/passes/clear-pass.hpp"
#include "debug/logger.hpp" #include "debug/logger.hpp"
#include "game/menu.hpp" #include "game/menu.hpp"
#include "animation/timeline.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -103,8 +104,10 @@ void enter(game::context* ctx)
// Set menu back callback // Set menu back callback
ctx->menu_back_callback = select_back_callback; ctx->menu_back_callback = select_back_callback;
// Setup menu controls
game::menu::setup_controls(ctx);
// Schedule menu control setup
timeline* timeline = ctx->timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
} }
void exit(game::context* ctx) void exit(game::context* ctx)

+ 5
- 2
src/game/states/graphics-menu.cpp View File

@ -25,6 +25,7 @@
#include "debug/logger.hpp" #include "debug/logger.hpp"
#include "game/fonts.hpp" #include "game/fonts.hpp"
#include "game/menu.hpp" #include "game/menu.hpp"
#include "animation/timeline.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -304,8 +305,10 @@ void enter(game::context* ctx)
// Set menu back callback // Set menu back callback
ctx->menu_back_callback = select_back_callback; ctx->menu_back_callback = select_back_callback;
// Setup menu controls
game::menu::setup_controls(ctx);
// Schedule menu control setup
timeline* timeline = ctx->timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
} }
void exit(game::context* ctx) void exit(game::context* ctx)

+ 5
- 2
src/game/states/language-menu.cpp View File

@ -25,6 +25,7 @@
#include "debug/logger.hpp" #include "debug/logger.hpp"
#include "game/fonts.hpp" #include "game/fonts.hpp"
#include "game/menu.hpp" #include "game/menu.hpp"
#include "animation/timeline.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -158,8 +159,10 @@ void enter(game::context* ctx)
// Set menu back callback // Set menu back callback
ctx->menu_back_callback = select_back_callback; ctx->menu_back_callback = select_back_callback;
// Setup menu controls
game::menu::setup_controls(ctx);
// Schedule menu control setup
timeline* timeline = ctx->timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
} }
void exit(game::context* ctx) void exit(game::context* ctx)

+ 4
- 2
src/game/states/main-menu.cpp View File

@ -148,8 +148,10 @@ void enter(game::context* ctx)
// Set menu back callback // Set menu back callback
ctx->menu_back_callback = menu_back_callback; ctx->menu_back_callback = menu_back_callback;
// Setup menu controls
game::menu::setup_controls(ctx);
// Schedule menu control setup
timeline* timeline = ctx->timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
} }
void exit(game::context* ctx) void exit(game::context* ctx)

+ 5
- 2
src/game/states/options-menu.cpp View File

@ -28,6 +28,7 @@
#include "animation/ease.hpp" #include "animation/ease.hpp"
#include "animation/animation.hpp" #include "animation/animation.hpp"
#include "animation/animator.hpp" #include "animation/animator.hpp"
#include "animation/timeline.hpp"
#include "application.hpp" #include "application.hpp"
#include "scene/text.hpp" #include "scene/text.hpp"
#include "render/passes/clear-pass.hpp" #include "render/passes/clear-pass.hpp"
@ -132,8 +133,10 @@ void enter(game::context* ctx)
// Set menu back callback // Set menu back callback
ctx->menu_back_callback = select_back_callback; ctx->menu_back_callback = select_back_callback;
// Setup menu controls
game::menu::setup_controls(ctx);
// Schedule menu control setup
timeline* timeline = ctx->timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
} }
void exit(game::context* ctx) void exit(game::context* ctx)

+ 5
- 2
src/game/states/sound-menu.cpp View File

@ -24,6 +24,7 @@
#include "render/passes/clear-pass.hpp" #include "render/passes/clear-pass.hpp"
#include "debug/logger.hpp" #include "debug/logger.hpp"
#include "game/menu.hpp" #include "game/menu.hpp"
#include "animation/timeline.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -214,8 +215,10 @@ void enter(game::context* ctx)
// Set menu back callback // Set menu back callback
ctx->menu_back_callback = select_back_callback; ctx->menu_back_callback = select_back_callback;
// Setup menu controls
game::menu::setup_controls(ctx);
// Schedule menu control setup
timeline* timeline = ctx->timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
} }
void exit(game::context* ctx) void exit(game::context* ctx)

Loading…
Cancel
Save