X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=44163f6cc17b74b9cb548b3bd93242e6028b6a90;hb=dbd214ac278019c20c883cbb76456b0b0fddc063;hp=fd4fbee8bad7c3b68362bb4950cebd2ecf2a3406;hpb=fcb9cdbbb01dbe4a86981e1529df451d7d5e8256;p=blank.git diff --git a/src/client/client.cpp b/src/client/client.cpp index fd4fbee..44163f6 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -60,7 +60,8 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) , chunk_renderer(player.GetChunks()) , loop_timer(16) , sky(master.GetEnv().loader.LoadCubeMap("skybox")) -, update_status() { +, update_status() +, chat(master.GetEnv(), *this, *this) { if (!save.Exists()) { save.Write(master.GetWorldConf()); } @@ -86,7 +87,13 @@ void InteractiveState::OnEnter() { void InteractiveState::Handle(const SDL_Event &event) { switch (event.type) { case SDL_KEYDOWN: - interface.HandlePress(event.key); + // TODO: move to interface + if (event.key.keysym.sym == SDLK_RETURN) { + master.GetEnv().state.Push(&chat); + hud.KeepMessages(true); + } else { + interface.HandlePress(event.key); + } break; case SDL_KEYUP: interface.HandleRelease(event.key); @@ -147,7 +154,9 @@ void InteractiveState::Update(int dt) { } void InteractiveState::Render(Viewport &viewport) { - viewport.WorldPosition(player.GetEntity().Transform(player.GetEntity().ChunkCoords())); + viewport.WorldPosition( + player.GetEntity().Transform(player.GetEntity().ChunkCoords()) + * player.GetEntity().GetModel().EyesTransform()); if (master.GetConfig().video.world) { chunk_renderer.Render(viewport); world.Render(viewport); @@ -263,6 +272,12 @@ void InteractiveState::Handle(const Packet::BlockUpdate &pack) { } } +void InteractiveState::Handle(const Packet::Message &pack) { + string msg; + pack.ReadMessage(msg); + hud.PostMessage(msg); +} + void InteractiveState::SetAudio(bool b) { master.GetConfig().audio.enabled = b; if (b) { @@ -304,6 +319,10 @@ void InteractiveState::Exit() { master.Quit(); } +void InteractiveState::OnLineSubmit(const string &line) { + master.GetClient().SendMessage(1, 0, line); +} + MasterState::MasterState( Environment &env, @@ -456,5 +475,15 @@ void MasterState::On(const Packet::BlockUpdate &pack) { state->Handle(pack); } +void MasterState::On(const Packet::Message &pack) { + if (state) { + state->Handle(pack); + } else { + string msg; + pack.ReadMessage(msg); + cout << "got message before interface was created: " << msg << endl; + } +} + } }