1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#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_create_view_settings_row( GAME_EDITOR* e ) {
I32 x = 320, y = 426;
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 );
}
|