Fixed bugs with input events routed to the wrong gui context

dev
Shariq Shah 6 years ago
parent c1454e2a8d
commit b9abcf481d
  1. 2
      src/common/version.h
  2. 4
      src/game/console.c
  3. 6
      src/game/game.c
  4. 8
      src/game/gui.c
  5. 7
      src/game/gui_game.c
  6. 5
      src/system/sound.c
  7. 1
      src/system/sound.h
  8. 3
      todo.txt

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */ /* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1 #define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 334 #define SYMMETRY_VERSION_REVISION 335
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -84,11 +84,11 @@ void console_toggle(struct Console* console)
} }
} }
void console_update(struct Console* console, struct Gui* gui_state, float dt) void console_update(struct Console* console, struct Gui* gui, float dt)
{ {
if(!console->visible) return; if(!console->visible) return;
struct nk_context* context = &gui_state->context; struct nk_context* context = &gui->context;
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
int win_width = 0, win_height = 0; int win_width = 0, win_height = 0;

@ -75,7 +75,7 @@ bool game_init(struct Window* window, struct Hashmap* cvars)
game_state->scene = calloc(1, sizeof(*game_state->scene)); game_state->scene = calloc(1, sizeof(*game_state->scene));
game_state->console = calloc(1, sizeof(*game_state->console)); game_state->console = calloc(1, sizeof(*game_state->console));
game_state->editor = calloc(1, sizeof(*game_state->editor)); game_state->editor = calloc(1, sizeof(*game_state->editor));
game_state->gui_editor = calloc(1, sizeof(*game_state->gui_editor)); game_state->gui_editor = calloc(1, sizeof(*game_state->gui_editor));
game_state->gui_game = calloc(1, sizeof(*game_state->gui_game)); game_state->gui_game = calloc(1, sizeof(*game_state->gui_game));
game_state->event_manager = calloc(1, sizeof(*game_state->event_manager)); game_state->event_manager = calloc(1, sizeof(*game_state->event_manager));
game_state->sound = calloc(1, sizeof(*game_state->sound)); game_state->sound = calloc(1, sizeof(*game_state->sound));
@ -589,10 +589,12 @@ void game_update(float dt, bool* window_should_close)
if(game_state->game_mode == GAME_MODE_PAUSE) if(game_state->game_mode == GAME_MODE_PAUSE)
{ {
game_state->game_mode = GAME_MODE_GAME; game_state->game_mode = GAME_MODE_GAME;
sound_pause_all(game_state->sound, false);
} }
else if(game_state->game_mode == GAME_MODE_GAME) else if(game_state->game_mode == GAME_MODE_GAME)
{ {
game_state->game_mode = GAME_MODE_PAUSE; game_state->game_mode = GAME_MODE_PAUSE;
sound_pause_all(game_state->sound, true);
input_mouse_mode_set(MM_NORMAL); input_mouse_mode_set(MM_NORMAL);
int width = 0, height = 0; int width = 0, height = 0;
window_get_drawable_size(game_state_get()->window, &width, &height); window_get_drawable_size(game_state_get()->window, &width, &height);
@ -602,7 +604,7 @@ void game_update(float dt, bool* window_should_close)
//game_debug(dt); //game_debug(dt);
//game_debug_gui(dt); //game_debug_gui(dt);
console_update(game_state->console, game_state->gui_editor, dt); console_update(game_state->console, game_state->game_mode == GAME_MODE_EDITOR ? game_state->gui_editor : game_state->gui_game, dt);
scene_update(game_state->scene, dt); scene_update(game_state->scene, dt);
if(game_state->game_mode == GAME_MODE_EDITOR) if(game_state->game_mode == GAME_MODE_EDITOR)
{ {

@ -345,7 +345,7 @@ void gui_on_mousebutton(const struct Event* event)
int x = event->mousebutton.x; int x = event->mousebutton.x;
int y = event->mousebutton.y; int y = event->mousebutton.y;
int down = event->type == EVT_MOUSEBUTTON_PRESSED ? 1 : 0; int down = event->type == EVT_MOUSEBUTTON_PRESSED ? 1 : 0;
struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game; struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context;
if(button == MSB_LEFT) nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down); if(button == MSB_LEFT) nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
if(button == MSB_MIDDLE) nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down); if(button == MSB_MIDDLE) nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down);
@ -359,7 +359,7 @@ void gui_on_mousemotion(const struct Event* event)
int y = event->mousemotion.y; int y = event->mousemotion.y;
int xrel = event->mousemotion.xrel; int xrel = event->mousemotion.xrel;
int yrel = event->mousemotion.yrel; int yrel = event->mousemotion.yrel;
struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game; struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context;
if(ctx->input.mouse.grabbed) if(ctx->input.mouse.grabbed)
{ {
@ -375,7 +375,7 @@ void gui_on_mousemotion(const struct Event* event)
void gui_on_textinput(const struct Event* event) void gui_on_textinput(const struct Event* event)
{ {
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game; struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context;
nk_glyph glyph; nk_glyph glyph;
memcpy(glyph, event->text_input.text, NK_UTF_SIZE); memcpy(glyph, event->text_input.text, NK_UTF_SIZE);
nk_input_glyph(ctx, glyph); nk_input_glyph(ctx, glyph);
@ -386,7 +386,7 @@ void gui_on_mousewheel(const struct Event* event)
int x = event->mousewheel.x; int x = event->mousewheel.x;
int y = event->mousewheel.y; int y = event->mousewheel.y;
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game; struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context;
nk_input_scroll(ctx, nk_vec2(x, y)); nk_input_scroll(ctx, nk_vec2(x, y));
} }

@ -1,6 +1,7 @@
#include "gui_game.h" #include "gui_game.h"
#include "gui.h" #include "gui.h"
#include "game.h" #include "game.h"
#include "../common/log.h"
#include "../system/platform.h" #include "../system/platform.h"
static void gui_game_pause_menu(struct nk_context* context); static void gui_game_pause_menu(struct nk_context* context);
@ -45,6 +46,12 @@ void gui_game_pause_menu(struct nk_context* context)
{ {
nk_layout_row_dynamic(context, 30, 1); nk_layout_row_dynamic(context, 30, 1);
nk_label(context, "Hello from the Pause Menu!", NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Hello from the Pause Menu!", NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE);
if(nk_button_label(context, "Button"))
{
log_message("Pressed!");
}
nk_end(context); nk_end(context);
} }
} }

@ -63,6 +63,11 @@ void sound_listener_update(struct Sound* sound)
up.x, up.y, up.z); // Up up.x, up.y, up.z); // Up
} }
void sound_pause_all(struct Sound* sound, bool pause)
{
Soloud_setPauseAll(sound->soloud_context, pause);
}
void sound_listener_set(struct Sound* sound, struct Entity* listener) void sound_listener_set(struct Sound* sound, struct Entity* listener)
{ {
sound->listener = listener; sound->listener = listener;

@ -51,6 +51,7 @@ void sound_master_volume_set(struct Sound* sound, float volume);
void sound_listener_set(struct Sound* sound, struct Entity* listener); void sound_listener_set(struct Sound* sound, struct Entity* listener);
void sound_update_3d(struct Sound* sound); void sound_update_3d(struct Sound* sound);
void sound_listener_update(struct Sound* sound); void sound_listener_update(struct Sound* sound);
void sound_pause_all(struct Sound* sound, bool pause);
void sound_source_instance_update_position(struct Sound* sound, uint source_instance, vec3 abs_pos); void sound_source_instance_update_position(struct Sound* sound, uint source_instance, vec3 abs_pos);
uint sound_source_instance_create(struct Sound* sound, struct Sound_Source_Buffer* source, bool is3d); uint sound_source_instance_create(struct Sound* sound, struct Sound_Source_Buffer* source, bool is3d);

@ -1,4 +1,5 @@
Todo: Todo:
- Allow switching to editor mode when game is in pause mode
- Implement flag for ignoring collisions with certain entities - Implement flag for ignoring collisions with certain entities
- Implement separate property window for player related variables that can be shown in the editor similar to renderer settings etc - Implement separate property window for player related variables that can be shown in the editor similar to renderer settings etc
- Implement game gui either with a separate nuklear context or as part of existing context - Implement game gui either with a separate nuklear context or as part of existing context
@ -404,3 +405,5 @@ Done:
* Fix crash where if entity selected in editor is deleted in game mode and then returning to editor mode causes a crash * Fix crash where if entity selected in editor is deleted in game mode and then returning to editor mode causes a crash
* Add "Select Parent" button to property inspector * Add "Select Parent" button to property inspector
* Remove ODE completely * Remove ODE completely
* Fixed console not working in game mode
* Pause sound when game is in pause mode
Loading…
Cancel
Save