PlayerController &GetPlayerController() noexcept { return input; }
ChunkReceiver &GetChunkReceiver() noexcept { return chunk_receiver; }
- void OnEnter() override;
+ void OnResume() override;
+ void OnPause() override;
+
+ void OnFocus() override;
+ void OnBlur() override;
void Handle(const SDL_Event &) override;
void Update(int dt) override;
}
}
-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) {
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 OnResume() override;
void OnPause() override;
+ void OnFocus() override;
+ void OnBlur() override;
+
void Handle(const SDL_Event &) override;
void Update(int dt) override;
void Render(Viewport &) override;
void SetInventorySlots(int num) { num_slots = num; }
+ void Lock();
+ void Unlock();
+
void HandlePress(const SDL_KeyboardEvent &);
void HandleRelease(const SDL_KeyboardEvent &);
void Handle(const SDL_MouseMotionEvent &);
int slot;
int num_slots;
+ bool locked;
+
};
}
, fwd(0)
, rev(0)
, slot(0)
-, num_slots(10) {
+, num_slots(10)
+, locked(false) {
}
+void Interface::Lock() {
+ fwd = glm::ivec3(0);
+ rev = glm::ivec3(0);
+ locked = true;
+}
+
+void Interface::Unlock() {
+ locked = false;
+}
void Interface::HandlePress(const SDL_KeyboardEvent &event) {
if (!config.input.keyboard) return;
}
void Interface::Handle(const SDL_MouseMotionEvent &event) {
- if (!config.input.mouse) return;
+ if (locked || !config.input.mouse) return;
player_ctrl.TurnHead(
event.yrel * config.input.pitch_sensitivity,
event.xrel * config.input.yaw_sensitivity);