From e3de3ba5162f7ddd5005911124d4333e140fd984 Mon Sep 17 00:00:00 2001 From: navewindre Date: Thu, 27 Nov 2025 17:19:02 +0100 Subject: bunch o stuff --- src/editor/view2d.cpp | 144 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) (limited to 'src/editor/view2d.cpp') diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp index 35fd208..1445cfc 100644 --- a/src/editor/view2d.cpp +++ b/src/editor/view2d.cpp @@ -1,12 +1,13 @@ #include #include "editor.h" #include "../render/gl_2d.h" - #include "../game/objlist.h" +#include "../game/world/bsp.h" const I32 EDITORVIEW_TITLE_OFFSET = 15; const I32 EDITORVIEW_GUTTERS_OFFSETX = 22; const I32 EDITORVIEW_GUTTERS_OFFSETY = 16; +const I32 EDITORVIEW_TOOLBAR_OFFSET = 20; F32 gui_editor_2dview_calc_scale( GUI_EDITOR_2DVIEW* view ) { WORLD_MAP* m = editor->map; @@ -337,13 +338,23 @@ void gui_editor_2dview_draw_fn( void* ptr ) { U32 offx = EDITORVIEW_GUTTERS_OFFSETX; U32 offy = EDITORVIEW_GUTTERS_OFFSETY; - gui_draw_push_clip( x + offx, y + offy, w - offx, h - offy ); + gui_draw_push_clip( x + offx, y + offy, w - offx, h - offy - EDITORVIEW_TOOLBAR_OFFSET ); gui_editor_2dview_draw_polygons( view, x + offx, y + offy ); gui_editor_2dview_draw_walls( view, x + offx, y + offy ); gui_editor_2dview_draw_sprites( view, x + offx, y + offy ); gui_editor_2dview_draw_player( view, x + offx, y + offy ); gui_editor_2dview_draw_origin( view, x + offx, y + offy ); gui_draw_pop_clip(); + + gui_draw_push_clip( x, y + 16, view->w, view->h ); + view->children.each( fn( GUI_BASE** childptr ) { + GUI_BASE* child = *childptr; + if( !child->enabled ) return; + + if( child->draw_fn ) child->draw_fn( child ); + else dlog( "gui_view_draw_fn(): child %p no draw_fn\n", child ); + } ); + gui_draw_pop_clip(); } U8 gui_editor_2dview_input_drag( GUI_EDITOR_2DVIEW* view, U8 mouse ) { @@ -876,11 +887,91 @@ void gui_editor_2dview_input_tool_draw( GUI_EDITOR_2DVIEW* view ) { } } +void gui_editor_view2d_delete_obj( GUI_EDITOR_2DVIEW* view ) { + void* it; + U8 type; + + if( view->curdrag && view->dragtype ) { + it = view->curdrag; + type = view->dragtype; + view->curdrag = 0; + view->dragtype = EDITOR_SELECT_NONE; + } else if( editor->gui.props->curselect ) { + it = editor->gui.props->curselect; + type = editor->gui.props->seltype; + view->curselect = 0; + view->seltype = EDITOR_SELECT_NONE; + } + else return; + + U8 cleared = 1; + switch( type ) { + case EDITOR_SELECT_POLY: { + I32 idx = editor->map->polygons.idx_of( (MAP_POLYGON*)it ); + if( idx != -1 ) + editor->map->polygons.erase( idx ); + } break; + case EDITOR_SELECT_WALL: { + I32 idx = editor->map->walls.idx_of( (MAP_WALL*)it ); + if( idx != -1 ) + editor->map->walls.erase( idx ); + }; break; + case EDITOR_SELECT_SPRITE: { + I32 idx = editor->map->sprites.idx_of( (MAP_SPRITE*)it ); + if( idx != -1 ) + editor->map->sprites.erase( idx ); + }; break; + case EDITOR_SELECT_PVERTEX: { + I32 vidx = -1, idx = editor->map->polygons.idx_where( fn( MAP_POLYGON* p ) { + vidx = p->vertices.idx_where( fn( MAP_VERTEX* v ) { + return v == it; + } ); + return vidx != -1; + } ); + + if( idx != -1 && vidx != -1 ) { + MAP_POLYGON* p = &editor->map->polygons[idx]; + if( p->vertices.size <= 3 ) { + editor->map->polygons.erase( idx ); + break; + } + editor->map->polygons[idx].vertices.erase( vidx ); + } + }; break; + case EDITOR_SELECT_WVERTEX: { + I32 idx = editor->map->walls.idx_where( fn( MAP_WALL* w ) { + return &w->end == it || &w->start == it; + } ); + + if( idx != -1 ) + editor->map->walls.erase( idx ); + }; break; + default: + cleared = 0; break; + } + + if( cleared && it == editor->gui.props->curselect ) { + gui_editor_propview_select( editor->gui.props, 0, 0 ); + } +} + +void gui_editor_2dview_key_input( GUI_EDITOR_2DVIEW* view ) { + static U8 del_held = 0; + if( kb_down( SDLK_DELETE ) && !input.mouselock ) { + if( !del_held ) + gui_editor_view2d_delete_obj( view ); + + del_held = 1; + } else del_held = 0; +} + void gui_editor_2dview_input_fn( void* ptr ) { GUI_EDITOR_2DVIEW* view = (GUI_EDITOR_2DVIEW*)ptr; if( !editor->map ) return; + gui_editor_2dview_key_input( view ); + I32 x = gui_relx( view ); I32 y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET; I32 w = view->w; @@ -902,6 +993,10 @@ void gui_editor_2dview_input_fn( void* ptr ) { if( view->heldoutbounds ) return; + gui_base_input_fn( view ); + if( my >= y + h - 18 ) + return; + switch( editor->tool ) { case EDITOR_TOOL_SELECT: return gui_editor_2dview_input_tool_select( view ); case EDITOR_TOOL_WALL: @@ -913,6 +1008,47 @@ void gui_editor_2dview_input_fn( void* ptr ) { } } +void update_view_settings( GAME_EDITOR* e ) { + GAME_EDITOR::EDITOR_GUI* egui = &e->gui; + + sprintf( egui->gridlabel->name, "grid: %1.2f", e->grid ); +} + +void grid_increment_cb( void* ) { + if( editor->grid < 16.f ) editor->grid *= 2.f; + update_view_settings( editor ); + + if( editor->propgrid ) + editor_update_properties_column( editor ); +} + +void grid_decrement_cb( void* ) { + if( editor->grid > 0.25f ) editor->grid *= 0.5f; + update_view_settings( editor ); + + if( editor->propgrid ) + editor_update_properties_column( editor ); +} + +void grid_propgrid_cb( void* ) { + editor_update_properties_column( editor ); +} + +void gui_editor_2dview_create_toolbar( GUI_EDITOR_2DVIEW* view ) { + GAME_EDITOR* e = editor; + I32 x = 150, y = view->h - 4; + + editor->gui.gridlabel = gui_label( x, y + 1, "grid: %1.2f", e->grid ); + x += 70; + gui_button( x, y, 18, 18, "+", grid_increment_cb ); + gui_button( x + 23, y, 18, 18, "-", grid_decrement_cb ); + x += 50; + GUI_CHECKBOX* check = gui_checkbox( x, y, "properties grid", &e->propgrid ); + check->cb = grid_propgrid_cb; + x += 120; + gui_checkbox( x, y, "wireframe", &e->wireframe ); +} + GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) { GUI_EDITOR_2DVIEW* view = new GUI_EDITOR_2DVIEW; view->x = x; @@ -934,5 +1070,9 @@ GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) { parent->children.push( view ); view->parent = parent; + gui_set_view( view ); + gui_editor_2dview_create_toolbar( view ); + gui_set_view( (GUI_VIEW*)parent ); + return view; } -- cgit v1.2.3