Add escape menu

This commit is contained in:
Nikita Lisitsa 2024-08-20 13:29:12 +03:00
parent 5419a816da
commit 83ef0dcac8

View file

@ -1219,13 +1219,10 @@ namespace gmtk
struct application
: app::application
{
application(options const &, context const &)
: seed_(make_seed())
, map_rng_{seed_, 0xf24130ddef6fb31full}
, item_rng_{seed_, 0xb9fc3979f9860bbdull}
, map_(start_menu_map())
application(options const &, context const & context)
: context_(context)
{
log::info() << "Starting seed: " << seed_;
context_.windowed(is_windowed_);
set_start_menu();
}
@ -1437,6 +1434,16 @@ namespace gmtk
{
time_speed_ = 3.f;
}
if (event.down && event.key == app::keycode::ESCAPE)
{
if (!in_start_menu_)
{
in_escape_menu_ ^= true;
if (in_escape_menu_)
set_escape_menu();
}
}
}
bool running() const override
@ -2121,7 +2128,7 @@ namespace gmtk
if (in_menu())
{
painter_.rect(view_box_, gfx::to_coloru8(gfx::color_4f{1.f, 1.f, 1.f, menu_transition_ * 0.5f}));
painter_.rect(view_box_, gfx::to_coloru8(gfx::color_4f{1.f, 1.f, 1.f, menu_transition_ * 0.75f}));
float button_width = pixel_size * 500.f;
float button_height = pixel_size * 64.f;
@ -2163,6 +2170,7 @@ namespace gmtk
bool running_ = true;
bool in_start_menu_ = true;
bool in_escape_menu_ = false;
float menu_transition_ = 1.f;
@ -2178,18 +2186,37 @@ namespace gmtk
bool in_menu() const
{
return in_start_menu_;
return in_start_menu_ || in_escape_menu_;
}
void start_campaign(bool /* challenge */)
bool is_challenge_mode_ = false;
void start_campaign(bool challenge, bool new_seed)
{
is_challenge_mode_ = challenge;
if (new_seed)
{
auto seed = make_seed();
log::info() << "New campaign seed: " << seed;
map_rng_ = {seed, 0xf24130ddef6fb31full};
item_rng_ = {seed, 0xb9fc3979f9860bbdull};
}
map_ = capmaign_map();
if (in_start_menu_)
{
view_transition_ = {view_stack_.back()};
view_stack_.pop_back();
}
else if (in_escape_menu_)
{
view_transition_ = {view_stack_.back()};
view_stack_.clear();
view_stack_.push_back({-1, {0, 0}});
}
in_start_menu_ = false;
in_escape_menu_ = false;
reset_state();
}
@ -2205,18 +2232,40 @@ namespace gmtk
void set_start_menu()
{
view_stack_.clear();
in_start_menu_ = true;
in_escape_menu_ = false;
map_ = start_menu_map();
if (!view_stack_.empty())
{
view_transition_ = {view_stack_.back()};
view_stack_.clear();
}
view_stack_.push_back({-1, {0, 0}});
view_stack_.push_back({0, {1, 1}});
menu_buttons_.clear();
menu_buttons_.push_back({"Campaign mode", [this]{ start_campaign(false); }});
menu_buttons_.push_back({"Challenge mode", [this]{ start_campaign(true); }});
menu_buttons_.push_back({"Campaign mode", [this]{ start_campaign(false, true); }});
menu_buttons_.push_back({"Challenge mode", [this]{ start_campaign(true, true); }});
menu_buttons_.push_back({"Sandbox mode", {}});
menu_buttons_.push_back({is_windowed_ ? "Windowed" : "Fullscreen", [this]{ is_windowed_ ^= true; context_.windowed(is_windowed_); }});
menu_buttons_.push_back({"Exit", [this]{ stop(); }});
}
std::uint64_t seed_;
void set_escape_menu()
{
menu_buttons_.clear();
menu_buttons_.push_back({"Continue", [this]{ in_escape_menu_ = false; }});
menu_buttons_.push_back({"Restart", [this]{ start_campaign(is_challenge_mode_, false); }});
menu_buttons_.push_back({"Main menu", [this]{ set_start_menu(); }});
menu_buttons_.push_back({is_windowed_ ? "Windowed" : "Fullscreen", [this]{ is_windowed_ ^= true; context_.windowed(is_windowed_); }});
menu_buttons_.push_back({"Exit", [this]{ stop(); }});
}
context const & context_;
bool is_windowed_ = false;
random::generator map_rng_;
random::generator item_rng_;
map map_;