summaryrefslogtreecommitdiff
path: root/src/editor/toolview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor/toolview.cpp')
-rw-r--r--src/editor/toolview.cpp169
1 files changed, 166 insertions, 3 deletions
diff --git a/src/editor/toolview.cpp b/src/editor/toolview.cpp
index 56e55f2..25c308d 100644
--- a/src/editor/toolview.cpp
+++ b/src/editor/toolview.cpp
@@ -1,5 +1,6 @@
#include "editor.h"
#include "../util/string.h"
+#include "../game/object.h"
const U32 TOOLVIEW_TITLE_OFFSET = 15;
const I32 TOOLVIEW_INNER_X = 10;
@@ -7,6 +8,8 @@ const I32 TOOLVIEW_INNER_PAD = 20;
const I32 TOOLVIEW_ROW_HEIGHT = 20;
const I32 TOOLVIEW_ROW_GAP = 4;
const I32 TOOLVIEW_WALL_SHAPE_LIST_HEIGHT = 54;
+const I32 TOOLVIEW_OBJECT_TYPE_LIST_HEIGHT = 36;
+const I32 TOOLVIEW_ENTITY_CLASS_LIST_HEIGHT = 54;
const I32 TOOLVIEW_SCROLL_STEP = 20;
const I32 TOOLVIEW_SCROLLBAR_W = 8;
const I32 TOOLVIEW_SCROLLBAR_MIN_H = 18;
@@ -116,6 +119,48 @@ void gui_editor_toolview_wallshape_select_cb( void* ptr ) {
gui_editor_toolview_queue_refresh( view );
}
+void gui_editor_toolview_objecttype_dropdown_toggle_cb( void* ptr ) {
+ GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
+ GUI_EDITOR_TOOLVIEW* view = gui_editor_toolview_from_item_child( btn );
+ if( !view )
+ return;
+
+ view->objecttype_dropdown_open = !view->objecttype_dropdown_open;
+ view->entclass_dropdown_open = 0;
+ gui_editor_toolview_queue_refresh( view );
+}
+
+void gui_editor_toolview_objecttype_select_cb( void* ptr ) {
+ GUI_LIST* list = (GUI_LIST*)ptr;
+ GUI_EDITOR_TOOLVIEW* view = gui_editor_toolview_from_item_child( list );
+ if( !view )
+ return;
+
+ view->objecttype_dropdown_open = 0;
+ view->entclass_dropdown_open = 0;
+ gui_editor_toolview_queue_refresh( view );
+}
+
+void gui_editor_toolview_entclass_dropdown_toggle_cb( void* ptr ) {
+ GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
+ GUI_EDITOR_TOOLVIEW* view = gui_editor_toolview_from_item_child( btn );
+ if( !view )
+ return;
+
+ view->entclass_dropdown_open = !view->entclass_dropdown_open;
+ gui_editor_toolview_queue_refresh( view );
+}
+
+void gui_editor_toolview_entclass_select_cb( void* ptr ) {
+ GUI_LIST* list = (GUI_LIST*)ptr;
+ GUI_EDITOR_TOOLVIEW* view = gui_editor_toolview_from_item_child( list );
+ if( !view )
+ return;
+
+ view->entclass_dropdown_open = 0;
+ gui_editor_toolview_queue_refresh( view );
+}
+
I32 gui_editor_toolview_create_wallshape_dropdown( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
static LIST<GUI_LIST_ENTRY> shape_entries{};
if( !shape_entries.size ) {
@@ -162,6 +207,102 @@ I32 gui_editor_toolview_create_wallshape_dropdown( GUI_EDITOR_TOOLVIEW* view, I3
return y;
}
+I32 gui_editor_toolview_create_objecttype_dropdown( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
+ static LIST<GUI_LIST_ENTRY> object_entries{};
+ if( !object_entries.size ) {
+ GUI_LIST_ENTRY sprite{};
+ sprite.val = EDITOR_OBJECT_SPRITE;
+ strcpy( sprite.title, "sprite" );
+ object_entries.push( sprite );
+
+ GUI_LIST_ENTRY entity{};
+ entity.val = EDITOR_OBJECT_ENTITY;
+ strcpy( entity.title, "entity" );
+ object_entries.push( entity );
+ }
+
+ const char* object_name = editor->tool.objecttype == EDITOR_OBJECT_ENTITY ? "entity" : "sprite";
+ char dropdown_title[64];
+ sprintf( dropdown_title, "kind: %s v", object_name );
+
+ gui_button(
+ TOOLVIEW_INNER_X,
+ y,
+ view->w - TOOLVIEW_INNER_PAD,
+ TOOLVIEW_ROW_HEIGHT,
+ dropdown_title,
+ gui_editor_toolview_objecttype_dropdown_toggle_cb
+ );
+
+ y += TOOLVIEW_ROW_HEIGHT + TOOLVIEW_ROW_GAP;
+ if( !view->objecttype_dropdown_open )
+ return y;
+
+ GUI_LIST* object_type = gui_list(
+ TOOLVIEW_INNER_X,
+ y,
+ view->w - TOOLVIEW_INNER_PAD,
+ TOOLVIEW_OBJECT_TYPE_LIST_HEIGHT,
+ "object type",
+ &object_entries,
+ &editor->tool.objecttype
+ );
+
+ object_type->cb = gui_editor_toolview_objecttype_select_cb;
+ y += TOOLVIEW_OBJECT_TYPE_LIST_HEIGHT + TOOLVIEW_ROW_GAP;
+ return y;
+}
+
+I32 gui_editor_toolview_create_entclass_dropdown( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
+ static LIST<GUI_LIST_ENTRY> entclass_entries{};
+ if( !entclass_entries.size ) {
+ GUI_LIST_ENTRY trigger{};
+ trigger.val = OBJCLASS_TRIGGER;
+ strcpy( trigger.title, "trigger" );
+ entclass_entries.push( trigger );
+
+ GUI_LIST_ENTRY player{};
+ player.val = OBJCLASS_PLAYER;
+ strcpy( player.title, "player" );
+ entclass_entries.push( player );
+
+ GUI_LIST_ENTRY npc{};
+ npc.val = OBJCLASS_BASENPC;
+ strcpy( npc.title, "base_npc" );
+ entclass_entries.push( npc );
+ }
+
+ char dropdown_title[64];
+ sprintf( dropdown_title, "class: %s v", obj_classid_to_name( editor->tool.entclass ) );
+
+ gui_button(
+ TOOLVIEW_INNER_X,
+ y,
+ view->w - TOOLVIEW_INNER_PAD,
+ TOOLVIEW_ROW_HEIGHT,
+ dropdown_title,
+ gui_editor_toolview_entclass_dropdown_toggle_cb
+ );
+
+ y += TOOLVIEW_ROW_HEIGHT + TOOLVIEW_ROW_GAP;
+ if( !view->entclass_dropdown_open )
+ return y;
+
+ GUI_LIST* entclass = gui_list(
+ TOOLVIEW_INNER_X,
+ y,
+ view->w - TOOLVIEW_INNER_PAD,
+ TOOLVIEW_ENTITY_CLASS_LIST_HEIGHT,
+ "entity class",
+ &entclass_entries,
+ (I32*)&editor->tool.entclass
+ );
+
+ entclass->cb = gui_editor_toolview_entclass_select_cb;
+ y += TOOLVIEW_ENTITY_CLASS_LIST_HEIGHT + TOOLVIEW_ROW_GAP;
+ return y;
+}
+
I32 gui_editor_toolview_create_poly_sides_input( GUI_EDITOR_TOOLVIEW* view, I32 y ) {
return gui_editor_toolview_create_float_input(
view,
@@ -204,11 +345,10 @@ I32 gui_editor_toolview_create_placement_height_input( GUI_EDITOR_TOOLVIEW* view
void gui_editor_toolview_get_title( GUI_EDITOR_TOOLVIEW* view, char* out ) {
switch( editor->tool.type ) {
- case EDITOR_TOOL_ENT: memcpy( out, "tool: entity", 12 ); break;
+ case EDITOR_TOOL_OBJECT: memcpy( out, "tool: object", 12 ); break;
case EDITOR_TOOL_WALL: memcpy( out, "tool: wall", 10 ); break;
case EDITOR_TOOL_POLY: memcpy( out, "tool: polygon", 14 ); break;
case EDITOR_TOOL_SELECT: memcpy( out, "tool: select", 12 ); break;
- case EDITOR_TOOL_SPRITE: memcpy( out, "tool: sprite", 12 ); break;
default: memcpy( out, "tool: none", 10 ); break;
}
}
@@ -243,6 +383,27 @@ void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view ) {
y = gui_editor_toolview_create_poly_sides_input( view, y );
y = gui_editor_toolview_create_placement_height_input( view, y );
}
+ else if( editor->tool.type == EDITOR_TOOL_OBJECT ) {
+ y = gui_editor_toolview_create_objecttype_dropdown( view, y );
+ if( view->objecttype_dropdown_open ) {
+ view->content_h = y + 6;
+ gui_editor_toolview_clamp_scroll( view );
+ gui_set_view( oldview );
+ return;
+ }
+
+ if( editor->tool.objecttype == EDITOR_OBJECT_ENTITY ) {
+ y = gui_editor_toolview_create_entclass_dropdown( view, y );
+ if( view->entclass_dropdown_open ) {
+ view->content_h = y + 6;
+ gui_editor_toolview_clamp_scroll( view );
+ gui_set_view( oldview );
+ return;
+ }
+ }
+
+ y = gui_editor_toolview_create_placement_height_input( view, y );
+ }
view->content_h = y + 6;
gui_editor_toolview_clamp_scroll( view );
@@ -279,7 +440,7 @@ void gui_editor_toolview_draw_fn( void* ptr ) {
I32 w = view->w;
I32 h = view->h;
- gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, "contextual tool options" );
+ gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, "tool options" );
y += TOOLVIEW_TITLE_OFFSET;
CLR col = gui_is_fg_window( view )? ui_clr.border : ui_clr.border_inactive;
@@ -341,6 +502,8 @@ GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ) {
view->draw_fn = gui_editor_toolview_draw_fn;
view->input_fn = gui_editor_toolview_input_fn;
view->wallshape_dropdown_open = 0;
+ view->objecttype_dropdown_open = 0;
+ view->entclass_dropdown_open = 0;
view->scroll = 0;
view->content_h = 0;