X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fstandalone%2FMasterState.cpp;h=5ade4f1ed89a3f6009d19e54adb407c2d2c77a1e;hb=10a310869c61cc52046e165f36ac9639fe9d0c69;hp=49ee0fbf9214967d550b526a7fd59469a9646c05;hpb=f21a21b285c5b54e3abcc757c6715d22520dd190;p=blank.git diff --git a/src/standalone/MasterState.cpp b/src/standalone/MasterState.cpp index 49ee0fb..5ade4f1 100644 --- a/src/standalone/MasterState.cpp +++ b/src/standalone/MasterState.cpp @@ -36,6 +36,7 @@ MasterState::MasterState( , chunk_renderer(player.GetChunks()) , spawner(world, res.models, env.rng) , sky(env.loader.LoadCubeMap("skybox")) +, cli(world) , preload(env, chunk_loader, chunk_renderer) , unload(env, world.Chunks(), save) , chat(env, *this, *this) { @@ -67,19 +68,30 @@ MasterState::~MasterState() { void MasterState::OnResume() { if (spawn_index.MissingChunks() > 0) { env.state.Push(&preload); - } - if (config.input.mouse) { - env.window.GrabMouse(); + return; } if (spawn_player) { // TODO: spawn spawn_player = false; } hud.KeepMessages(false); + OnFocus(); } void MasterState::OnPause() { + OnBlur(); +} + +void MasterState::OnFocus() { + if (config.input.mouse) { + env.window.GrabMouse(); + } + interface.Unlock(); +} + +void MasterState::OnBlur() { env.window.ReleaseMouse(); + interface.Lock(); } @@ -88,6 +100,11 @@ void MasterState::Handle(const SDL_Event &event) { case SDL_KEYDOWN: // TODO: move to interface if (event.key.keysym.sym == SDLK_RETURN) { + chat.Clear(); + env.state.Push(&chat); + hud.KeepMessages(true); + } else if (event.key.keysym.sym == SDLK_SLASH) { + chat.Preset("/"); env.state.Push(&chat); hud.KeepMessages(true); } else { @@ -118,7 +135,8 @@ void MasterState::Handle(const SDL_Event &event) { } void MasterState::Update(int dt) { - input.Update(dt); + spawner.Update(dt); + world.Update(dt); if (input.BlockFocus()) { hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block); } else if (input.EntityFocus()) { @@ -128,8 +146,6 @@ void MasterState::Update(int dt) { } hud.Display(res.block_types[player.GetInventorySlot() + 1]); hud.Update(dt); - spawner.Update(dt); - world.Update(dt); chunk_loader.Update(dt); chunk_renderer.Update(dt); @@ -196,7 +212,12 @@ void MasterState::Exit() { } void MasterState::OnLineSubmit(const std::string &line) { - if (!line.empty()) { + if (line.empty()) { + return; + } + if (line[0] == '/' && line.size() > 1 && line[1] != '/') { + cli.Execute(player, line.substr(1)); + } else { hud.PostMessage(line); } }