]> git.localhorst.tv Git - blank.git/blobdiff - src/standalone/MasterState.cpp
centralize entity controllers
[blank.git] / src / standalone / MasterState.cpp
index 91ee4826682fbdaca890b76d3c1c8bb0c3ab4929..81017f78603cea89bca967d440089e7c26876e05 100644 (file)
@@ -67,26 +67,37 @@ 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();
 }
 
 
 void MasterState::Handle(const SDL_Event &event) {
        switch (event.type) {
                case SDL_KEYDOWN:
-                       // TODO: move to interface?
+                       // TODO: move to interface
                        if (event.key.keysym.sym == SDLK_RETURN) {
                                env.state.Push(&chat);
                                hud.KeepMessages(true);
@@ -118,7 +129,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 +140,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 +206,9 @@ void MasterState::Exit() {
 }
 
 void MasterState::OnLineSubmit(const std::string &line) {
-       hud.PostMessage(line);
+       if (!line.empty()) {
+               hud.PostMessage(line);
+       }
 }
 
 }