| 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 |
#include "mission_options.h" |
| 29 |
|
| 30 |
#include "nk_window.h" |
| 31 |
|
| 32 |
#define WIDTH 800 |
| 33 |
#define HEIGHT 200 |
| 34 |
#define ROW_HEIGHT 25 |
| 35 |
|
| 36 |
typedef struct |
| 37 |
{ |
| 38 |
Mission *m; |
| 39 |
char Title[256]; |
| 40 |
char Description[1024]; |
| 41 |
char MusicFilename[256]; |
| 42 |
EditorResult result; |
| 43 |
} MissionOptionsData; |
| 44 |
|
| 45 |
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data); |
| 46 |
static void CheckTextChanged( |
| 47 |
char **dst, const char *src, EditorResult *result); |
| 48 |
EditorResult EditMissionOptions(EventHandlers *handlers, Mission *m) |
| 49 |
{ |
| 50 |
NKWindowConfig cfg; |
| 51 |
memset(&cfg, 0, sizeof cfg); |
| 52 |
cfg.Title = "Mission Options"; |
| 53 |
cfg.Size = svec2i(WIDTH, HEIGHT); |
| 54 |
color_t bg = {41, 26, 26, 255}; |
| 55 |
cfg.BG = bg; |
| 56 |
cfg.Handlers = handlers; |
| 57 |
cfg.Draw = Draw; |
| 58 |
|
| 59 |
NKWindowInit(&cfg); |
| 60 |
|
| 61 |
MissionOptionsData data; |
| 62 |
memset(&data, 0, sizeof data); |
| 63 |
data.m = m; |
| 64 |
if (m->Title) |
| 65 |
{ |
| 66 |
strcpy(data.Title, m->Title); |
| 67 |
} |
| 68 |
if (m->Description) |
| 69 |
{ |
| 70 |
strcpy(data.Description, m->Description); |
| 71 |
} |
| 72 |
if (m->Music.Type == MUSIC_SRC_DYNAMIC && m->Music.Data.Filename) |
| 73 |
{ |
| 74 |
strcpy(data.MusicFilename, m->Music.Data.Filename); |
| 75 |
} |
| 76 |
cfg.DrawData = &data; |
| 77 |
|
| 78 |
NKWindow(cfg); |
| 79 |
|
| 80 |
CheckTextChanged(&m->Title, data.Title, &data.result); |
| 81 |
CheckTextChanged(&m->Description, data.Description, &data.result); |
| 82 |
if (m->Music.Type == MUSIC_SRC_DYNAMIC) |
| 83 |
{ |
| 84 |
CheckTextChanged(&m->Music.Data.Filename, data.MusicFilename, &data.result); |
| 85 |
} |
| 86 |
else |
| 87 |
{ |
| 88 |
CFREE(m->Music.Data.Filename); |
| 89 |
CSTRDUP(m->Music.Data.Filename, ""); |
| 90 |
} |
| 91 |
return data.result; |
| 92 |
} |
| 93 |
static void CheckTextChanged(char **dst, const char *src, EditorResult *result) |
| 94 |
{ |
| 95 |
if (*dst == NULL || strcmp(src, *dst) != 0) |
| 96 |
{ |
| 97 |
CFREE(*dst); |
| 98 |
CSTRDUP(*dst, src); |
| 99 |
*result = EDITOR_RESULT_CHANGED; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
static bool Draw(SDL_Window *win, struct nk_context *ctx, void *data) |
| 104 |
{ |
| 105 |
UNUSED(win); |
| 106 |
bool changed = false; |
| 107 |
MissionOptionsData *mData = data; |
| 108 |
|
| 109 |
if (nk_begin( |
| 110 |
ctx, "", nk_rect(0, 0, WIDTH, HEIGHT), |
| 111 |
NK_WINDOW_BORDER)) |
| 112 |
{ |
| 113 |
nk_layout_row_dynamic(ctx, ROW_HEIGHT, 1); |
| 114 |
DrawTextbox(ctx, mData->Title, 256, "Title", NK_EDIT_FIELD); |
| 115 |
nk_layout_row_dynamic(ctx, ROW_HEIGHT * 3, 1); |
| 116 |
DrawTextbox(ctx, mData->Description, 1024, "Description", NK_EDIT_BOX); |
| 117 |
nk_layout_row_dynamic(ctx, ROW_HEIGHT, 1); |
| 118 |
bool dynamicMusic = mData->m->Music.Type == MUSIC_SRC_DYNAMIC; |
| 119 |
if (DrawCheckbox(ctx, "Custom Music", NULL, &dynamicMusic)) |
| 120 |
{ |
| 121 |
changed = true; |
| 122 |
mData->m->Music.Type = dynamicMusic ? MUSIC_SRC_DYNAMIC : MUSIC_SRC_GENERAL; |
| 123 |
} |
| 124 |
if (dynamicMusic) |
| 125 |
{ |
| 126 |
DrawTextbox(ctx, mData->MusicFilename, 256, "Music Filename", NK_EDIT_FIELD); |
| 127 |
} |
| 128 |
if (DrawCheckbox( |
| 129 |
ctx, "Persist weapons & ammo", |
| 130 |
"Whether weapons picked up and extra ammo are " |
| 131 |
"available in this mission", |
| 132 |
&mData->m->WeaponPersist)) |
| 133 |
{ |
| 134 |
changed = true; |
| 135 |
} |
| 136 |
if (DrawCheckbox( |
| 137 |
ctx, "Skip debrief", |
| 138 |
"Skip the end-of-mission summary screen", |
| 139 |
&mData->m->SkipDebrief)) |
| 140 |
{ |
| 141 |
changed = true; |
| 142 |
} |
| 143 |
nk_end(ctx); |
| 144 |
} |
| 145 |
if (changed) |
| 146 |
{ |
| 147 |
mData->result = EDITOR_RESULT_CHANGED; |
| 148 |
} |
| 149 |
return true; |
| 150 |
} |