Implemented contextual menu to re-enter sound sourece filename

dev
Shariq Shah 6 years ago
parent 187fe1fa01
commit a5f9184a4e
  1. 66
      src/game/editor.c
  2. 1
      todo.txt

@ -65,12 +65,6 @@ enum Editor_Axis
EDITOR_AXIS_YZ, EDITOR_AXIS_YZ,
}; };
static struct
{
bool diffuse_texture;
bool sound_source;
} Popup_States;
static struct Debug_Variable* debug_vars_list = NULL; static struct Debug_Variable* debug_vars_list = NULL;
static int* empty_indices = NULL; static int* empty_indices = NULL;
static int window_flags = NK_WINDOW_BORDER | static int window_flags = NK_WINDOW_BORDER |
@ -164,9 +158,6 @@ void editor_init(struct Editor* editor)
event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release); event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release);
editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.symbres", MAT_UNSHADED); editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.symbres", MAT_UNSHADED);
Popup_States.diffuse_texture = false;
Popup_States.sound_source = false;
} }
void editor_init_camera(struct Editor* editor, struct Hashmap* cvars) void editor_init_camera(struct Editor* editor, struct Hashmap* cvars)
@ -1224,11 +1215,6 @@ void editor_entity_select(struct Editor* editor, struct Entity* entity)
editor->selected_entity = entity; editor->selected_entity = entity;
transform_copy(editor->cursor_entity, editor->selected_entity, false); transform_copy(editor->cursor_entity, editor->selected_entity, false);
} }
//Reset all popups
Popup_States.diffuse_texture = false;
Popup_States.sound_source = false;
log_message("Popups reset");
} }
void editor_tool_reset(struct Editor* editor) void editor_tool_reset(struct Editor* editor)
@ -1796,28 +1782,46 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
volume = nk_propertyf(context, "Volume", 0.f, volume, 10.f, 0.5f, 0.1f); volume = nk_propertyf(context, "Volume", 0.f, volume, 10.f, 0.5f, 0.1f);
sound_source_instance_volume_set(sound, sound_source->source_instance, volume); sound_source_instance_volume_set(sound, sound_source->source_instance, volume);
nk_layout_row_dynamic(context, 30, 2); nk_layout_row_dynamic(context, row_height, 2);
static char sound_source_filename_buffer[MAX_FILENAME_LEN]; static char sound_source_filename_buffer[MAX_FILENAME_LEN];
strncpy(sound_source_filename_buffer, sound_source->source_buffer->filename, MAX_FILENAME_LEN); static bool sound_source_filename_copied = false;
if(!sound_source_filename_copied)
{
strncpy(sound_source_filename_buffer, sound_source->source_buffer->filename, MAX_FILENAME_LEN);
sound_source_filename_copied = true;
}
nk_label(context, "File", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "File", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
int edit_flags = NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD | NK_EDIT_SIG_ENTER; struct nk_rect sound_source_filename_bounds = nk_widget_bounds(context);
int edit_state = nk_edit_string_zero_terminated(context, edit_flags, sound_source_filename_buffer, MAX_FILENAME_LEN, NULL); nk_button_label(context, sound_source->source_buffer->filename);
if(edit_state & NK_EDIT_COMMITED) if(nk_input_is_mouse_hovering_rect(context, sound_source_filename_bounds))
nk_tooltip(context, "Right-click to change");
if(nk_contextual_begin(context, 0, nk_vec2(200, 120), sound_source_filename_bounds))
{ {
if(strncmp(sound_source_filename_buffer, sound_source->source_buffer->filename, MAX_FILENAME_LEN) != 0) nk_layout_row_dynamic(context, 28, 1);
int edit_flags = NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD | NK_EDIT_SIG_ENTER;
int edit_state = nk_edit_string_zero_terminated(context, edit_flags, sound_source_filename_buffer, MAX_FILENAME_LEN, NULL);
nk_layout_row_dynamic(context, row_height, 1);
if(edit_state & NK_EDIT_COMMITED || nk_button_label(context, "OK"))
{ {
struct Sound_Source_Buffer* new_source_buffer = sound_source_create(sound, sound_source_filename_buffer, ST_WAV_STREAM); if(strncmp(sound_source_filename_buffer, sound_source->source_buffer->filename, MAX_FILENAME_LEN) != 0)
if(new_source_buffer)
{ {
sound_source_stop_all(sound, sound_source->source_buffer); struct Sound_Source_Buffer* new_source_buffer = sound_source_create(sound, sound_source_filename_buffer, ST_WAV_STREAM);
sound_source_instance_destroy(sound, sound_source->source_instance); if(new_source_buffer)
sound_source->source_instance = sound_source_instance_create(sound, new_source_buffer, true); {
sound_source->source_buffer = new_source_buffer; sound_source_stop_all(sound, sound_source->source_buffer);
sound_source->base.transform.is_modified = true; // Fake a transformation so that post-update the new sound source position is updated sound_source_instance_destroy(sound, sound_source->source_instance);
if(playing) sound_source->source_instance = sound_source_instance_create(sound, new_source_buffer, true);
sound_source_instance_play(sound, sound_source->source_instance); sound_source->source_buffer = new_source_buffer;
sound_source->base.transform.is_modified = true; // Fake a transformation so that post-update the new sound source position is updated
if(playing)
sound_source_instance_play(sound, sound_source->source_instance);
}
} }
sound_source_filename_copied = false;
nk_contextual_close(context);
} }
nk_contextual_end(context);
} }
nk_tree_pop(context); nk_tree_pop(context);
@ -1831,7 +1835,7 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
struct Static_Mesh* mesh = (struct Static_Mesh*)entity; struct Static_Mesh* mesh = (struct Static_Mesh*)entity;
if(nk_tree_push(context, NK_TREE_TAB, "Static Mesh", NK_MAXIMIZED)) if(nk_tree_push(context, NK_TREE_TAB, "Static Mesh", NK_MAXIMIZED))
{ {
nk_layout_row_dynamic(context, 30, 2); nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Geometry", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Geometry", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
static char geometry_filename_buffer[MAX_FILENAME_LEN]; static char geometry_filename_buffer[MAX_FILENAME_LEN];
@ -1845,7 +1849,7 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
} }
struct nk_rect geometry_name_bounds = nk_widget_bounds(context); struct nk_rect geometry_name_bounds = nk_widget_bounds(context);
nk_label(context, geometry->filename, NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_button_label(context, geometry->filename);
if(nk_input_is_mouse_hovering_rect(context, geometry_name_bounds)) if(nk_input_is_mouse_hovering_rect(context, geometry_name_bounds))
nk_tooltip(context, "Right-click to change"); nk_tooltip(context, "Right-click to change");

@ -325,3 +325,4 @@ Done:
* Fixed issue of partial matches returning incorrect hashmap values * Fixed issue of partial matches returning incorrect hashmap values
* Implemented Static Mesh property viewing/editing in editor * Implemented Static Mesh property viewing/editing in editor
* Implemented contextual menu for re-entering diffuse texture name * Implemented contextual menu for re-entering diffuse texture name
* Implemented contextual menus for entering geometry and sound source names

Loading…
Cancel
Save