#pragma once #include "../gui/base.h" #include "../util/file.h" #include "../game/world/map.h" const F32 EDITOR_DEFAULT_SPRITE_SIZE = 32.f; const F32 EDITOR_DEFAULT_POLY_SIDES = 6.f; const F32 EDITOR_DEFAULT_WALL_HEIGHT = 80.f; const F32 EDITOR_DEFAULT_PLACEMENT_HEIGHT = 0.f; const I32 EDITOR_POLY_SIDES_MIN = 3; enum EditorTools_t { EDITOR_TOOL_NONE, EDITOR_TOOL_SELECT, EDITOR_TOOL_WALL, EDITOR_TOOL_POLY, EDITOR_TOOL_OBJECT }; enum EditorWallShape_t { EDITOR_WALLSHAPE_LINE = 0, EDITOR_WALLSHAPE_POLYGON = 1 }; enum EditorSelectType_t { EDITOR_SELECT_NONE, EDITOR_SELECT_WALL, EDITOR_SELECT_POLY, EDITOR_SELECT_WVERTEX, // wall vertex EDITOR_SELECT_PVERTEX, // polygon vertex EDITOR_SELECT_SPRITE, EDITOR_SELECT_ENT, EDITOR_SELECT_ORIGIN, EDITOR_SELECT_SURFPROPS }; enum EditorUndoType_t { EDITOR_UNDO_NONE = 0, EDITOR_UNDO_CREATE_WALLS = 1, EDITOR_UNDO_CREATE_POLY = 2, EDITOR_UNDO_CREATE_SPRITES = 3, EDITOR_UNDO_CREATE_ENTITIES = 4 }; enum EditorInfoBoxType_t { EDITOR_INFOBOX_ASSETS = 1, EDITOR_INFOBOX_STATUS = 2 }; enum EditorViewMode_t { EDITOR_VIEWMODE_2D = 0, EDITOR_VIEWMODE_3D = 1, EDITOR_VIEWMODE_SIM = 2 }; enum Editor2DViewType_t { EDITOR_2DVIEW_TOP_DOWN = 0, EDITOR_2DVIEW_SIDE_ELEVATION = 1, EDITOR_2DVIEW_FRONT_ELEVATION = 2 }; enum EditorObjectType_t { EDITOR_OBJECT_SPRITE = 0, EDITOR_OBJECT_ENTITY = 1 }; typedef void( *EDITOR_CONTEXTMENU_CALLBACK )( void* data ); struct EDITOR_CONTEXTMENU_ITEM; typedef U8( *EDITOR_CONTEXTMENU_ENABLED_CALLBACK )( EDITOR_CONTEXTMENU_ITEM* item ); struct EDITOR_CONTEXTMENU_ITEM { char text[64]{}; void* data{}; EDITOR_CONTEXTMENU_CALLBACK cb{}; EDITOR_CONTEXTMENU_ENABLED_CALLBACK enabled_cb{}; U8 enabled{1}; LIST items{}; }; struct GAME_EDITOR; typedef void( *EDITOR_GRID_DEP_CALLBACK )( GAME_EDITOR* e ); struct GAME_EDITOR_TOOL { U8 type; /* shapes */ I32 wallshape; F32 polysides; F32 wallheight; F32 placementheight; GL_TEX2D* tex; /* entity */ U32 entclass; void* entprops; I32 objecttype; }; struct GAME_EDITOR { GAME_DATA* game; struct WORLD_MAP* map; struct GUI_EDITORWINDOW* wnd; struct EDITOR_GUI { struct GUI_WINDOW* new_map_popup; struct GUI_EDITOR_2DVIEW* v2d; struct GUI_EDITOR_3DVIEW* v3d; struct GUI_LABEL* gridlabel; struct GUI_EDITOR_PROPVIEW* props; struct GUI_EDITOR_TOOLVIEW* tool; I32 map_select{}; I32 props_w{300}; I32 props_h{300}; I32 view_h{370}; GUI_VIEW* assets{}; GUI_VIEW* status{}; I32 assets_scroll{}; I32 view_mode{}; I32 view2d_type{}; struct GUI_EDITOR_CONTEXTMENU* contextmenu{}; GUI_BASE* header_toolbar{}; GUI_LABEL* header_viewtype_label{}; GUI_BUTTON* header_back{}; GUI_BUTTON* header_mode_2d{}; GUI_BUTTON* header_mode_3d{}; GUI_BUTTON* header_mode_sim{}; GUI_BASE* header_viewtype{}; } gui; U8 wireframe{}; GAME_EDITOR_TOOL tool; F32 grid{}; U8 propgrid{}; F32 spritesize{}; U8 drawbsp{}; struct GRID_DEPENDENCY { void* tag{}; EDITOR_GRID_DEP_CALLBACK cb{}; }; LIST grid_dependencies{}; LIST map_list{}; struct EDITOR_UNDO_ACTION { U8 type{}; I32 start_idx{}; LIST walls{}; LIST polys{}; LIST sprites{}; LIST entities{}; }; LIST undo_actions{}; LIST redo_actions{}; }; struct EDITOR_LAYOUT { I32 left_x; I32 left_w; I32 right_x; I32 right_w; I32 top_y; I32 props_y; I32 props_h; I32 assets_y; I32 assets_h; I32 view_y; I32 view_h; I32 tool_y; I32 tool_h; I32 tool_btn_x; I32 tool_btn_y; I32 tool_btn_w; I32 tool_btn_step; I32 tool_panel_x; I32 tool_panel_w; I32 tool_panel_h; I32 status_x; I32 status_y; I32 status_w; I32 status_h; }; extern GAME_EDITOR* editor_create( struct GAME_DATA* game ); extern void editor_destroy( GAME_EDITOR* editor ); extern STAT editor_load_map( GAME_EDITOR* e, const char* mapname ); extern STAT editor_save_map( GAME_EDITOR* e ); extern STAT editor_new_map( GAME_EDITOR* e, const char* mapname ); extern STAT editor_close( GAME_EDITOR* e ); extern void editor_clear_gui_state_refs( GAME_EDITOR* e ); extern void editor_resize( GAME_EDITOR* e, I32 w, I32 h ); extern void editor_register_grid_dependency( GAME_EDITOR* e, void* tag, EDITOR_GRID_DEP_CALLBACK cb ); extern void editor_notify_grid_change( GAME_EDITOR* e ); extern LIST* editor_get_map_list( GAME_EDITOR* e ); extern void editor_load_map_cb( void* ); extern void editor_new_map_cb( void* ); extern void editor_create_map_view( GAME_EDITOR* e ); extern void editor_update_properties_column( GAME_EDITOR* e ); extern const char* editor_tool_name(); extern void editor_set_view_mode( I32 mode ); extern void editor_undo_clear( GAME_EDITOR* e ); extern void editor_undo_record_create_walls( GAME_EDITOR* e, I32 start_idx, I32 count ); extern void editor_undo_record_create_poly( GAME_EDITOR* e, I32 start_idx ); extern void editor_undo_record_create_sprite( GAME_EDITOR* e, I32 start_idx ); extern void editor_undo_record_create_entity( GAME_EDITOR* e, I32 start_idx ); extern U8 editor_undo( GAME_EDITOR* e ); extern U8 editor_redo( GAME_EDITOR* e ); extern void editor_show_contextmenu( I32 x, I32 y, LIST* items, const char* title = 0 ); extern void editor_hide_contextmenu(); extern U8 editor_contextmenu_open(); extern void editor_contextmenu_set_item( EDITOR_CONTEXTMENU_ITEM* item, const char* text, EDITOR_CONTEXTMENU_CALLBACK cb = 0, void* data = 0, EDITOR_CONTEXTMENU_ENABLED_CALLBACK enabled_cb = 0 ); struct GUI_EDITORWINDOW : GUI_WINDOW {}; struct GUI_EDITOR_3DVIEW : GUI_VIEW { U8 heldoutbounds; }; struct GUI_EDITOR_2DVIEW : GUI_VIEW { F32 scale; F32 posx, posy; I32 moffx, moffy; F32 voffx, voffy; U8 dragheld; U8 held; U8 heldoutbounds; I32 oldmx, oldmy; F32 mremainx, mremainy; void* curselect; U8 seltype; void* curdrag; U8 dragtype; U8 dragmoved; U8 poly_drag; VEC2 poly_start; VEC2 poly_end; VEC3 pending_object_pos; I32 pending_wall_undo_idx; I32 pending_object_undo_idx; U8 pending_object_undo_type; }; struct GUI_EDITOR_PROPVIEW : GUI_VIEW { void* curselect; U8 seltype; GUI_VIEW* itemview; }; struct GUI_EDITOR_TOOLVIEW : GUI_VIEW { GUI_VIEW* itemview; U8 wallshape_dropdown_open; U8 objecttype_dropdown_open; U8 entclass_dropdown_open; I32 scroll; I32 content_h; }; struct GUI_EDITOR_TEXTUREPICKER : GUI_WINDOW { struct GL_TEX2D** target; struct GL_TEX2D* curselect; I32 scrolloff; LIST files; LIST textures; I32 scrollheight; U32 rowcount; char search[256]; U32 curload; U8 loaded; GL_TEX2D* heldselect; GUI_LABEL* densitylabel; GUI_CALLBACK cb; }; struct GUI_EDITOR_INFOBOX : GUI_VIEW { U8 type{}; }; struct GUI_EDITOR_VIEWTYPE_SEGMENT : GUI_BASE { U8 held{}; I32 held_seg{-1}; }; struct GUI_EDITOR_CONTEXTMENU : GUI_BASE { LIST* items{}; U8 initheld{1}; U8 held{}; I32 held_idx{-1}; char title[64]{}; }; struct GUI_EDITOR_TOOLBAR : GUI_BASE { U8 held{}; I32 held_root{-1}; I32 active_root{-1}; LIST entries{}; }; extern GUI_EDITORWINDOW* gui_editorwindow( I32 w, I32 h ); extern GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ); extern GUI_EDITOR_3DVIEW* gui_editor_3dview( I32 x, I32 y, I32 w, I32 h ); extern GUI_EDITOR_PROPVIEW* gui_editor_propview( I32 x, I32 y, I32 w, I32 h ); extern void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* e, void* what, U8 seltype ); extern void gui_editor_propview_update( GUI_EDITOR_PROPVIEW* e ); extern GUI_EDITOR_TOOLVIEW* gui_editor_toolview( I32 x, I32 y, I32 w, I32 h ); extern void gui_editor_toolview_update( GUI_EDITOR_TOOLVIEW* view ); extern GUI_EDITOR_TEXTUREPICKER* gui_editor_texturepicker( I32 x, I32 y, I32 w, I32 h, GL_TEX2D** target ); extern GAME_EDITOR* editor;