summaryrefslogtreecommitdiff
path: root/src/editor/editor.h
blob: cd42a4ed8df50e83a5e46694bce4107290572dec (plain)
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
#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;
const I32 EDITOR_POLY_SIDES_MAX = 32;

enum EditorTools_t {
  EDITOR_TOOL_NONE,
  EDITOR_TOOL_SELECT,
  EDITOR_TOOL_WALL,
  EDITOR_TOOL_POLY,
  EDITOR_TOOL_SPRITE,
  EDITOR_TOOL_ENT
};

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
};

struct GAME_EDITOR_TOOL {
  U8 type;

  /* shapes */
  I32 wallshape;
  F32 polysides;
  F32 wallheight;
  F32 placementheight;
  GL_TEX2D* tex;

  /* entity */
  U32 entclass;
  void* entprops;
};

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{};
  } gui;


  U8 wireframe{};
  GAME_EDITOR_TOOL tool;
  F32 grid{};
  U8  propgrid{};
  F32 spritesize{};
  U8 drawbsp{};

  LIST<GUI_LIST_ENTRY> map_list{};
};

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 LIST<GUI_LIST_ENTRY>* 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 );

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;
};

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;
};

struct GUI_EDITOR_TEXTUREPICKER : GUI_WINDOW {
  struct GL_TEX2D** target;
  struct GL_TEX2D* curselect;

  I32 scrolloff;

  LIST<FILE_ENTRY> files;
  LIST<struct GL_TEX2D*> textures;
  I32 scrollheight;

  U32 rowcount;
  char search[256];

  U32 curload;
  U8  loaded;

  GL_TEX2D* heldselect;
  GUI_LABEL* densitylabel;

  GUI_CALLBACK cb;
};

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;