summaryrefslogtreecommitdiff
path: root/src/editor/gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor/gui.cpp')
-rw-r--r--src/editor/gui.cpp255
1 files changed, 255 insertions, 0 deletions
diff --git a/src/editor/gui.cpp b/src/editor/gui.cpp
new file mode 100644
index 0000000..71ce113
--- /dev/null
+++ b/src/editor/gui.cpp
@@ -0,0 +1,255 @@
+#include "editor.h"
+#include "../game/world/bsp.h"
+
+void gui_editorwindow_draw_fn( void* ptr ) {
+ GUI_EDITORWINDOW* wnd = (GUI_EDITORWINDOW*)ptr;
+
+ CLR clr = gui_is_fg_window( wnd )? ui_clr.border : ui_clr.border_inactive;
+ gui_draw_frect( wnd->x, wnd->y, wnd->w, wnd->h, clr );
+ gui_draw_frect( wnd->x + 1, wnd->y + 1, wnd->w - 2, wnd->h - 2, ui_clr.bg );
+
+ wnd->children.each( fn( GUI_BASE** ptr ) {
+ GUI_BASE* it = *ptr;
+ if( !it->enabled ) return;
+
+ if( it->draw_fn ) it->draw_fn( it );
+ else dlog( "gui_editorwindow_draw_fn(): child %p has no draw_fn", it );
+ } );
+}
+
+GUI_EDITORWINDOW* gui_editorwindow_create( I32 w, I32 h ) {
+ GUI_EDITORWINDOW* wnd = new GUI_EDITORWINDOW;
+ wnd->x = 0;
+ wnd->y = 0;
+ wnd->w = w;
+ wnd->h = h;
+ wnd->locked = 1;
+ wnd->draw_fn = gui_editorwindow_draw_fn;
+ strcpy( wnd->name, "EDITORWINDOW" );
+
+ _gui.windows.push( wnd );
+ gui_set_window( wnd );
+
+ gui_set_view( 0 );
+ gui_view( 1, 1, w - 2, h - 2 );
+ return wnd;
+}
+
+GUI_EDITORWINDOW* gui_editorwindow( I32 w, I32 h ) {
+ GUI_EDITORWINDOW* wnd = gui_editorwindow_create( w, h );
+
+ gui_title( "ray2Dscape (level editor)" );
+
+ GAME_EDITOR* e = editor;
+ LIST<GUI_LIST_ENTRY>* map_list = editor_get_map_list( e );
+
+ gui_list( wnd->w / 2 - 100, 40, 200, 200, "map list", map_list, &editor->gui.map_select );
+ gui_button( wnd->w / 2 - 100, 260, 95, 25, "new map", editor_new_map_cb );
+ gui_button( wnd->w / 2 + 5, 260, 95, 25, "load map", editor_load_map_cb );
+ return wnd;
+}
+
+void editor_update_active_tool_label( GAME_EDITOR* e ) {
+ char lstr[256];
+ switch( e->tool ) {
+ case EDITOR_TOOL_SELECT:
+ sprintf( lstr, "current tool: select" ); break;
+ case EDITOR_TOOL_WALL:
+ sprintf( lstr, "current tool: wall" ); break;
+ case EDITOR_TOOL_POLY:
+ sprintf( lstr, "current tool: polygon" ); break;
+ case EDITOR_TOOL_SPRITE:
+ sprintf( lstr, "current tool: sprite" ); break;
+ case EDITOR_TOOL_ENT:
+ sprintf( lstr, "current tool: entity" ); break;
+ default:
+ sprintf( lstr, "current tool: none" ); break;
+ }
+
+ strcpy( e->gui.toollabel->name, lstr );
+}
+
+void editor_update_properties_column( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+ gui_editor_propview_update( egui->props );
+}
+
+void editor_create_properties_column( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+ gui_button( 10, 10, 145, 20, "back", pfn( void* ) { editor_close( editor ); } );
+ gui_button( 165, 10, 145, 20, "save", pfn( void* ) { editor_save_map( editor ); } );
+
+ egui->props = gui_editor_propview( 10, 38, 300, 460 );
+ gui_editor_propview_select( egui->props, e->map, EDITOR_SELECT_ORIGIN );
+}
+
+void editor_create_game_view_column( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+ I32 x = 320, y = 10;
+
+ gui_button( x, y, 229, 20, "2d view", pfn( void* ptr ) {
+ editor->gui.v3d->enabled = 0;
+ editor->gui.v2d->enabled = 1;
+ } );
+
+ gui_button( x + 239, y, 229, 20, "3d view", pfn( void* ptr ) {
+ editor->gui.v3d->enabled = 1;
+ editor->gui.v2d->enabled = 0;
+ } );
+
+ y += 28;
+ egui->v2d = gui_editor_2dview( x, y, 468, 370 );
+ egui->v3d = gui_editor_3dview( x, y, 468, 370 );
+ egui->v2d->enabled = 0;
+ egui->v3d->enabled = 1;
+}
+
+void settool( U8 t ) { editor->tool = t; editor_update_active_tool_label( editor ); }
+void editor_create_tools_row( GAME_EDITOR* e ) {
+ I32 x = 10, y = 520;
+
+ e->gui.toollabel = gui_label( x, y, "current tool: none" );
+ y += 16;
+ gui_button( x, y, 80, 20, "none", pfn( void* ) { settool( EDITOR_TOOL_NONE ); } ); x += 90;
+ gui_button( x, y, 80, 20, "select", pfn( void* ) { settool( EDITOR_TOOL_SELECT ); } ); x += 90;
+ gui_button( x, y, 80, 20, "wall", pfn( void* ) { settool( EDITOR_TOOL_WALL ); } ); x += 90;
+
+ x = 10; y += 28;
+ gui_button( x, y, 80, 20, "polygon", pfn( void* ) { settool( EDITOR_TOOL_POLY ); } ); x += 90;
+ gui_button( x, y, 80, 20, "sprite", pfn( void* ) { settool( EDITOR_TOOL_SPRITE ); } ); x += 90;
+ gui_button( x, y, 80, 20, "entity", pfn( void* ) { settool( EDITOR_TOOL_ENT ); } ); x += 90;
+ editor_update_active_tool_label( e );
+}
+
+void editor_update_view_settings( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+
+ sprintf( egui->gridlabel->name, "grid size: %1.2f", e->grid );
+}
+
+void editor_grid_increment_cb( void* ) {
+ if( editor->grid < 16.f ) editor->grid *= 2.f;
+ editor_update_view_settings( editor );
+
+ if( editor->propgrid )
+ editor_update_properties_column( editor );
+}
+
+void editor_grid_decrement_cb( void* ) {
+ if( editor->grid > 0.25f ) editor->grid *= 0.5f;
+ editor_update_view_settings( editor );
+
+ if( editor->propgrid )
+ editor_update_properties_column( editor );
+}
+
+void editor_grid_propgrid_cb( void* ) {
+ editor_update_properties_column( editor );
+}
+
+void editor_create_view_settings_row( GAME_EDITOR* e ) {
+ I32 x = 320, y = 426;
+
+ gui_label( x, y, "view settings:" ); x += 95;
+ editor->gui.gridlabel = gui_label( x, y, "grid size: %1.2f", e->grid );
+ x += 95;
+ gui_button( x, y, 20, 20, "+", editor_grid_increment_cb );
+ gui_button( x + 25, y, 20, 20, "-", editor_grid_decrement_cb );
+ x += 55;
+ GUI_CHECKBOX* check = gui_checkbox( x, y, "properties grid", &e->propgrid );
+ check->cb = editor_grid_propgrid_cb;
+ x += 120;
+ gui_checkbox( x, y, "wireframe", &e->wireframe );
+
+ x = 320;
+ y = 440;
+ gui_button( x, y, 100, 20, "compile bsp", pfn( void* b ) {
+ if( editor->map->bsp )
+ bsp_free( editor->map->bsp );
+ editor->map->bsp = bsp_build_map( editor->map );
+ } ); x += 110;
+
+ gui_checkbox( x, y, "draw bsp", &e->drawbsp );
+}
+
+void editor_create_map_view( GAME_EDITOR* e ) {
+ if( !e->map ) {
+ dlog( "editor_create_map_views() : no map loaded\n" );
+ return;
+ }
+
+ GUI_EDITORWINDOW* w = e->wnd;
+ w->children.each( fn( GUI_BASE** ptr ) {
+ gui_free( *ptr );
+ } );
+ w->children.clear();
+
+ gui_set_window( w );
+ gui_set_view( 0 );
+
+ gui_view( 1, 1, w->w - 2, w->h - 2 );
+
+ editor_create_properties_column( e );
+ editor_create_game_view_column( e );
+ editor_create_tools_row( e );
+ editor_create_view_settings_row( e );
+}
+
+void close_new_map_popup( void* ) {
+ gui_push_callback( pfn( void* ) {
+ GUI_WINDOW* popup = editor->gui.new_map_popup;
+ if( !popup )
+ return;
+
+ gui_free( popup );
+ editor->gui.new_map_popup = 0;
+ } );
+}
+
+void editor_new_map_cb( void* ptr ) {
+ if( editor->gui.new_map_popup ) return;
+
+ GUI_WINDOW* cwnd = gui_get_window();
+ GUI_VIEW* view = gui_get_view();
+
+ I32 wx = 250;
+ I32 wy = 140;
+ I32 ww = 300;
+ I32 wh = 200;
+
+ editor->gui.new_map_popup = gui_window( wx, wy, ww, wh );
+ gui_title( "new map" );
+ GUI_TEXTBOX* tb = gui_textbox( 10, 20, ww - 20, 20, "name", 32 );
+ tb->active = 1;
+
+ gui_button( ww - 50 - 70, wh - 20 - 10, 50, 20, "ok", pfn( void* ptr ) {
+ GUI_BUTTON* btn = (GUI_BUTTON*)ptr;
+ GUI_TEXTBOX* name = (GUI_TEXTBOX*)gui_find_node( btn->parent, "name" );
+ if( !name )
+ return;
+
+ editor_new_map( editor, name->value );
+ close_new_map_popup( 0 );
+ } );
+
+ gui_button( ww - 50 - 10, wh - 20 - 10, 50, 20, "cancel", close_new_map_popup );
+
+ gui_set_window( cwnd );
+ gui_set_view( view );
+}
+
+void editor_load_map_cb( void* ptr ) {
+ GUI_LIST* list = (GUI_LIST*)gui_find_node( editor->wnd, "map list" );
+
+ GUI_LIST_ENTRY* e = gui_list_get_selected( list );
+ if( !e )
+ return;
+
+ char full_path[256];
+ sprintf( full_path, "../assets/maps/%s", e->title );
+
+ if( editor->map )
+ editor_close( editor );
+
+ editor_load_map( editor, full_path );
+}