#include "editor_gui_internal.h" #include "../game.h" void gui_editorwindow_draw_fn( void* ptr ) { GUI_EDITORWINDOW* wnd = (GUI_EDITORWINDOW*)ptr; editor_raise_header_toolbar( editor ); GUI_BASE* toolbar = ( editor && editor->map ) ? editor->gui.header_toolbar : 0; GUI_EDITOR_TOOLBAR* tbar = (GUI_EDITOR_TOOLBAR*)toolbar; U8 menu_open = editor_toolbar_menu_open( tbar ); F32 saved_mx = input.mouse.pos.x; F32 saved_my = input.mouse.pos.y; if( menu_open ) { editor_menu_hover_mask_active = 1; editor_menu_hover_real_x = (I32)saved_mx; editor_menu_hover_real_y = (I32)saved_my; input.mouse.pos.x = -100000.f; input.mouse.pos.y = -100000.f; } else { editor_menu_hover_mask_active = 0; } 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 ); } ); input.mouse.pos.x = saved_mx; input.mouse.pos.y = saved_my; editor_menu_hover_mask_active = 0; } static void gui_editorwindow_input_fn( void* ptr ) { GUI_EDITORWINDOW* wnd = (GUI_EDITORWINDOW*)ptr; editor_raise_header_toolbar( editor ); GUI_BASE* toolbar = ( editor && editor->map ) ? editor->gui.header_toolbar : 0; if( toolbar && toolbar->enabled && toolbar->input_fn ) toolbar->input_fn( toolbar ); GUI_EDITOR_TOOLBAR* tbar = (GUI_EDITOR_TOOLBAR*)toolbar; if( editor_toolbar_menu_open( tbar ) ) return; wnd->children.each( fn( GUI_BASE** childptr ) { GUI_BASE* child = *childptr; if( !child || child == toolbar || !child->enabled || !child->input_fn ) return; child->input_fn( child ); } ); } GUI_EDITORWINDOW* gui_editorwindow_create( I32 w, I32 h ) { GUI_EDITORWINDOW* wnd = new GUI_EDITORWINDOW; wnd->x = 0; wnd->y = 0; wnd->xbound = wnd->w = w; wnd->ybound = wnd->h = h; wnd->locked = 1; wnd->draw_fn = gui_editorwindow_draw_fn; wnd->input_fn = gui_editorwindow_input_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 ); GAME_EDITOR* e = editor; LIST* map_list = editor_get_map_list( e ); gui_list( wnd->w / 2 - 100, EDITOR_LAYOUT_CONTENT_Y, 200, 200, "map list", map_list, &editor->gui.map_select ); gui_button( wnd->w / 2 - 100, EDITOR_LAYOUT_CONTENT_Y + 220, 95, 25, "new map", editor_new_map_cb ); gui_button( wnd->w / 2 + 5, EDITOR_LAYOUT_CONTENT_Y + 220, 95, 25, "load map", editor_load_map_cb ); return wnd; } 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; egui->props = gui_editor_propview( 10, EDITOR_LAYOUT_CONTENT_Y, 300, 460 ); gui_editor_propview_select( egui->props, e->map, EDITOR_SELECT_ORIGIN ); } void editor_create_auxiliary_panels( GAME_EDITOR* e ) { GAME_EDITOR::EDITOR_GUI* egui = &e->gui; egui->assets = gui_editor_infobox( 10, EDITOR_LAYOUT_CONTENT_Y + 310, 300, 180, EDITOR_INFOBOX_ASSETS, "EDITOR_ASSETS_VIEW" ); egui->status = gui_editor_infobox( 10, 568, 780, EDITOR_LAYOUT_STATUS_H, EDITOR_INFOBOX_STATUS, "EDITOR_STATUS_VIEW" ); } void editor_update_toolview( GAME_EDITOR* e ) { GAME_EDITOR::EDITOR_GUI* egui = &e->gui; gui_editor_toolview_update( egui->tool ); } void settool( U8 t ) { editor->tool.type = t; if( editor->gui.v2d ) editor->gui.v2d->poly_drag = 0; if( editor->gui.tool ) editor_update_toolview( editor ); } const char* editor_tool_name() { switch( editor->tool.type ) { case EDITOR_TOOL_SELECT: return "select"; case EDITOR_TOOL_WALL: return "wall"; case EDITOR_TOOL_POLY: return "poly"; case EDITOR_TOOL_SPRITE: return "sprite"; case EDITOR_TOOL_ENT: return "ent"; default: return "none"; } } static U8 EDITOR_TOOL_BUTTON_TYPES[] = { EDITOR_TOOL_NONE, EDITOR_TOOL_SELECT, EDITOR_TOOL_WALL, EDITOR_TOOL_POLY, EDITOR_TOOL_SPRITE, EDITOR_TOOL_ENT }; static void settool_btn_cb( void* ptr ) { GUI_BUTTON* btn = (GUI_BUTTON*)ptr; if( !btn || !btn->extra ) return; settool( *(U8*)btn->extra ); } void editor_create_toolview_column( GAME_EDITOR* e ) { GAME_EDITOR::EDITOR_GUI* egui = &e->gui; I32 x = 320; I32 y = EDITOR_LAYOUT_CONTENT_Y + EDITOR_LAYOUT_VIEW_DEFAULT_H + EDITOR_LAYOUT_VIEW_TOOL_GAP + EDITOR_LAYOUT_TOOL_BTN_TOP_GAP; I32 off = 23; const char* labels[] = { "none", "select", "wall", "poly", "sprite", "ent" }; for( U32 i = 0; i < sizeof( labels ) / sizeof( labels[0] ); ++i ) { GUI_BUTTON* btn = gui_button( x, y, 45, 20, labels[i], settool_btn_cb ); btn->extra = &EDITOR_TOOL_BUTTON_TYPES[i]; y += off; } egui->tool = gui_editor_toolview( 370, y - EDITOR_LAYOUT_TOOL_BTN_TOP_GAP, 300, 150 ); gui_editor_toolview_update( egui->tool ); } void editor_create_game_view_column( GAME_EDITOR* e ) { GAME_EDITOR::EDITOR_GUI* egui = &e->gui; I32 x = 320, y = EDITOR_LAYOUT_CONTENT_Y; egui->v2d = gui_editor_2dview( x, y, 468, 370 ); egui->v3d = gui_editor_3dview( x, y, 468, 370 ); egui->v2d->enabled = 1; egui->v3d->enabled = 0; } 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(); editor_clear_gui_state_refs( e ); e->gui.view2d_type = EDITOR_2DVIEW_TOP_DOWN; e->gui.view_mode = EDITOR_VIEWMODE_2D; gui_set_window( w ); gui_set_view( 0 ); gui_view( 1, 1, w->w - 2, w->h - 2 ); editor_create_header_controls( e ); editor_create_properties_column( e ); editor_create_toolview_column( e ); editor_create_game_view_column( e ); editor_create_auxiliary_panels( e ); editor_layout_map_view( e ); } void editor_resize( GAME_EDITOR* e, I32 w, I32 h ) { if( !e || !e->wnd ) return; w = max( 1, w ); h = max( 1, h ); GUI_EDITORWINDOW* wnd = e->wnd; if( wnd->w == w && wnd->h == h ) return; editor_set_bounds( wnd, 0, 0, w, h ); editor_resize_base_view( wnd ); if( e->map ) editor_layout_map_view( e ); else editor_layout_start_menu( e ); if( !e->gui.new_map_popup ) return; GUI_WINDOW* popup = e->gui.new_map_popup; if( popup->x > w - 5 ) popup->x = w - 5; if( popup->x + popup->w < 5 ) popup->x = 5 - popup->w; if( popup->y > h - 5 ) popup->y = h - 5; if( popup->y + popup->h < 5 ) popup->y = 5 - popup->h; } 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 ); }