X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=26e0e0df748c64cd70f0807ae00e90b4bb7d1dbf;hb=10a310869c61cc52046e165f36ac9639fe9d0c69;hp=8b532633ab0cd85dc2926f2dbda72eb3ed7762e3;hpb=f21a21b285c5b54e3abcc757c6715d22520dd190;p=blank.git diff --git a/src/client/client.cpp b/src/client/client.cpp index 8b53263..26e0e0d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -80,8 +80,24 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) } } -void InteractiveState::OnEnter() { - master.GetEnv().window.GrabMouse(); +void InteractiveState::OnResume() { + OnFocus(); +} + +void InteractiveState::OnPause() { + OnBlur(); +} + +void InteractiveState::OnFocus() { + if (master.GetConfig().input.mouse) { + master.GetEnv().window.GrabMouse(); + } + interface.Unlock(); +} + +void InteractiveState::OnBlur() { + master.GetEnv().window.ReleaseMouse(); + interface.Lock(); } void InteractiveState::Handle(const SDL_Event &event) { @@ -89,6 +105,11 @@ void InteractiveState::Handle(const SDL_Event &event) { case SDL_KEYDOWN: // TODO: move to interface if (event.key.keysym.sym == SDLK_RETURN) { + chat.Clear(); + master.GetEnv().state.Push(&chat); + hud.KeepMessages(true); + } else if (event.key.keysym.sym == SDLK_SLASH) { + chat.Preset("/"); master.GetEnv().state.Push(&chat); hud.KeepMessages(true); } else { @@ -119,20 +140,10 @@ void InteractiveState::Handle(const SDL_Event &event) { } void InteractiveState::Update(int dt) { - input.Update(dt); - if (input.BlockFocus()) { - hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block); - } else if (input.EntityFocus()) { - hud.FocusEntity(*input.EntityFocus().entity); - } else { - hud.FocusNone(); - } - hud.Display(res.block_types[player.GetInventorySlot() + 1]); loop_timer.Update(dt); master.Update(dt); chunk_receiver.Update(dt); - hud.Update(dt); int world_dt = 0; while (loop_timer.HitOnce()) { world.Update(loop_timer.Interval()); @@ -141,9 +152,18 @@ void InteractiveState::Update(int dt) { } chunk_renderer.Update(dt); + if (input.BlockFocus()) { + hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block); + } else if (input.EntityFocus()) { + hud.FocusEntity(*input.EntityFocus().entity); + } else { + hud.FocusNone(); + } if (world_dt > 0) { input.PushPlayerUpdate(world_dt); } + hud.Display(res.block_types[player.GetInventorySlot() + 1]); + hud.Update(dt); glm::mat4 trans = player.GetEntity().Transform(player.GetEntity().ChunkCoords()); glm::vec3 dir(trans * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));