diff options
| author | aura <nw@moneybot.cc> | 2026-08-13 00:51:36 +0200 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-08-13 00:51:36 +0200 |
| commit | a266df321b19558764565f3b433aa997004a5f42 (patch) | |
| tree | 9d4dd1b4a6a4c21348fe222e28e21a858561b8ee | |
| parent | 17c07b5f884453130d8be3a6d91d730d80d4f8ae (diff) | |
| -rw-r--r-- | src/editor/editor.h | 17 | ||||
| -rw-r--r-- | src/editor/toolview.cpp | 17 | ||||
| -rw-r--r-- | src/editor/view2d.cpp | 96 |
3 files changed, 116 insertions, 14 deletions
diff --git a/src/editor/editor.h b/src/editor/editor.h index 682ccc8..642138f 100644 --- a/src/editor/editor.h +++ b/src/editor/editor.h @@ -19,13 +19,20 @@ enum EditorTools_t { enum EditorWallShape_t { EDITOR_WALLSHAPE_LINE = 0, - EDITOR_WALLSHAPE_POLYGON = 1, - EDITOR_WALLSHAPE_PATH = 2 + EDITOR_WALLSHAPE_POLYGON, + EDITOR_WALLSHAPE_PATH, + EDITOR_WALLSHAPE_MAX +}; + +constexpr const char* EDITOR_WALLSHAPE_NAMES[] = { + "line", + "polygon", + "path" }; enum EditorPolyShape_t { EDITOR_POLYSHAPE_DRAG = 0, - EDITOR_POLYSHAPE_PATH = 1 + EDITOR_POLYSHAPE_PATH }; enum EditorSelectType_t { @@ -293,6 +300,10 @@ struct GUI_EDITOR_2DVIEW : GUI_VIEW { VEC2 poly_end; VEC3 pending_object_pos; + VEC3 draw_lastpos; + VEC3 draw_startpos; + U8 draw_started; + I32 pending_wall_undo_idx; I32 pending_object_undo_idx; U8 pending_object_undo_type; diff --git a/src/editor/toolview.cpp b/src/editor/toolview.cpp index 6bbaa3a..3a9aa9d 100644 --- a/src/editor/toolview.cpp +++ b/src/editor/toolview.cpp @@ -164,18 +164,15 @@ void gui_editor_toolview_entclass_select_cb( void* ptr ) { I32 gui_editor_toolview_create_wallshape_dropdown( GUI_EDITOR_TOOLVIEW* view, I32 y ) { static LIST<GUI_LIST_ENTRY> shape_entries{}; if( !shape_entries.size ) { - GUI_LIST_ENTRY line{}; - line.val = EDITOR_WALLSHAPE_LINE; - strcpy( line.title, "line" ); - shape_entries.push( line ); - - GUI_LIST_ENTRY polygon{}; - polygon.val = EDITOR_WALLSHAPE_POLYGON; - strcpy( polygon.title, "polygon" ); - shape_entries.push( polygon ); + for( U32 i = 0; i < EDITOR_WALLSHAPE_MAX; ++i ) { + GUI_LIST_ENTRY entry{}; + entry.val = i; + strcpy( entry.title, EDITOR_WALLSHAPE_NAMES[i] ); + shape_entries.push( entry ); + } } - const char* shape_name = editor->tool.wallshape == EDITOR_WALLSHAPE_POLYGON ? "polygon" : "line"; + const char* shape_name = EDITOR_WALLSHAPE_NAMES[editor->tool.wallshape]; char dropdown_title[64]; sprintf( dropdown_title, "shape: %s v", shape_name ); diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp index 7a7ea3e..bfeed1d 100644 --- a/src/editor/view2d.cpp +++ b/src/editor/view2d.cpp @@ -674,7 +674,6 @@ void gui_editor_2dview_draw_entities( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) { } void gui_editor_2dview_draw_player( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) { - if( !objl->pl ) return; @@ -714,6 +713,44 @@ void gui_editor_2dview_draw_object_preview( GUI_EDITOR_2DVIEW* view ) { ); } +void gui_editor_2dview_draw_wallpath_preview( GUI_EDITOR_2DVIEW* view ) { + if( !view->draw_started ) + return; + + I32 mx, my; + gui_cursor_pos( &mx, &my ); + + VEC2 world = gui_editor_2dview_screen_to_world( view, mx, my ); + F32 depth = gui_editor_2dview_placement_z(); + VEC3 wp3 = gui_editor_2dview_plane_to_world3( world, depth ); + gui_editor_2dview_snap_plane( &wp3 ); + + VEC2 start = gui_editor_2dview_world3_to_screen( view, view->draw_lastpos ); + VEC2 end = gui_editor_2dview_world3_to_screen( view, wp3 ); + + F32 deg = vec_angle( start, end ); + F32 len = vec_dist( start, end ); + + for( F32 dash = 0; dash < len; dash += 8.f ) { + VEC2 p1 = start + m_radial_offset( deg, dash ); + VEC2 p2 = start + m_radial_offset( deg, dash + 6.f ); + + gui_draw_line( p1.x, p1.y, p2.x, p2.y, CLR::CYAN() ); + } +} + + +void gui_editor_2dview_draw_polypath_preview( GUI_EDITOR_2DVIEW* view ) { + +} + +void gui_editor_2dview_draw_path_preview( GUI_EDITOR_2DVIEW* view ) { + switch( editor->tool.type ) { + case EDITOR_TOOL_WALL: return gui_editor_2dview_draw_wallpath_preview( view ); + case EDITOR_TOOL_POLY: return gui_editor_2dview_draw_polypath_preview( view ); + } +} + void gui_editor_2dview_draw_origin( GUI_EDITOR_2DVIEW* view, I32 x, I32 y ) { WORLD_MAP* m = editor->map; @@ -764,6 +801,7 @@ void gui_editor_2dview_draw_fn( void* ptr ) { gui_editor_2dview_draw_player( view, x + offx, y + offy ); gui_editor_2dview_draw_origin( view, x + offx, y + offy ); gui_editor_2dview_draw_poly_preview( view ); + gui_editor_2dview_draw_path_preview( view ); gui_editor_2dview_draw_object_preview( view ); gui_draw_pop_clip(); @@ -1362,6 +1400,59 @@ void gui_editor_2dview_input_tool_wall_shape( GUI_EDITOR_2DVIEW* view ) { } +void gui_editor_2dview_input_tool_wall_path( GUI_EDITOR_2DVIEW* view ) { + U8 m1 = gui_mbutton_down( 0 ); + if( !m1 ) { + view->held = 0; + return; + } + + if( view->held ) + return; + + view->held = 1; + I32 mx, my; + gui_cursor_pos( &mx, &my ); + + VEC2 world = gui_editor_2dview_screen_to_world( view, mx, my ); + F32 depth = gui_editor_2dview_placement_z(); + VEC3 wp3 = gui_editor_2dview_plane_to_world3( world, depth ); + + gui_editor_2dview_snap_plane( &wp3 ); + if( !view->draw_started ) { + view->draw_startpos = wp3; + view->draw_lastpos = wp3; + view->draw_started = 1; + } else { + if( wp3 != view->draw_lastpos ) { + MAP_WALL neww; + neww.start = view->draw_lastpos; + neww.end = wp3; + neww.end.z = gui_editor_2dview_wall_height(); + neww.propid = 0; + + + I32 idx = editor->map->walls.size; + editor->map->walls.push( neww ); + editor_undo_record_create_walls( editor, idx, 1 ); + gui_editor_2dview_check_bounds_preserve_view( view ); + gui_editor_propview_update( editor->gui.props ); + // TODO : creating objects within level + // causes a crash due to stale pointer in + // editor properties on list reallocation + // fixme + } + + if( wp3 == view->draw_startpos || wp3 == view->draw_lastpos ) { + view->draw_lastpos = view->draw_startpos = {}; + view->draw_started = 0; + return; + } + } + + view->draw_lastpos = wp3; +} + void gui_editor_2dview_input_tool_wall_line( GUI_EDITOR_2DVIEW* view ) { U8 m1 = gui_mbutton_down( 0 ); if( !m1 ) { @@ -1404,6 +1495,7 @@ void gui_editor_2dview_input_tool_wall_line( GUI_EDITOR_2DVIEW* view ) { view->oldmy = my; view->mremainx = 0.0; view->mremainy = 0.0; + gui_editor_propview_update( editor->gui.props ); return; } @@ -1416,6 +1508,7 @@ void gui_editor_2dview_input_tool_wall_line( GUI_EDITOR_2DVIEW* view ) { void gui_editor_2dview_input_tool_wall( GUI_EDITOR_2DVIEW* view ) { switch( editor->tool.wallshape ) { + case EDITOR_WALLSHAPE_PATH: return gui_editor_2dview_input_tool_wall_path( view ); case EDITOR_WALLSHAPE_POLYGON: return gui_editor_2dview_input_tool_wall_shape( view ); default: return gui_editor_2dview_input_tool_wall_line( view ); } @@ -1514,6 +1607,7 @@ void gui_editor_2dview_input_tool_draw( GUI_EDITOR_2DVIEW* view ) { U8 m2 = !m1 && gui_mbutton_down( 1 ); if( gui_editor_2dview_input_drag( view, m2 ) ) { + view->draw_started = 0; return; } |
