static float uiscale = 1.0f;
#define UISPLIT 150
-int splitx;
+static int splitx;
#define FONTSZ 16
static struct dtx_font *uifont;
static utk_widget *uigrab;
static utk_widget *cbox_newsz;
-static struct level *lvl;
+static struct level lvl;
int main(int argc, char **argv)
utk_set_size(uiwin_new, utk_get_width(vbox) + pad * 2.0f, utk_get_height(vbox) + pad * 2.0f);
- if(!(lvl = create_level(32, 32))) {
+ if(init_level(&lvl, 32, 32) == -1) {
fprintf(stderr, "failed to create level\n");
return -1;
}
- if(init_lview(lvl) == -1) {
+ if(init_lview(&lvl) == -1) {
return -1;
}
static void cleanup(void)
{
destroy_lview();
- free_level(lvl);
+ destroy_level(&lvl);
dtx_close_font(uifont);
utk_close(uiroot);
}
{
static int levsz[] = {16, 24, 32};
int sz;
- struct level *newlvl;
+ struct level newlvl;
sz = levsz[utk_get_selected(cbox_newsz)];
- if(!(newlvl = create_level(sz, sz))) {
+ if(init_level(&newlvl, sz, sz) == -1) {
utk_message_dialog("failed to create new level", UTK_MSG_TYPE_ERROR,
UTK_MSG_BN_OK, cb_cancel, 0);
return;
}
- free_level(lvl);
+ destroy_level(&lvl);
destroy_lview();
lvl = newlvl;
- init_lview(newlvl);
+ init_lview(&lvl);
utk_hide(uiwin_new);
uigrab = 0;
static void cb_open_ok(utk_event *ev, void *data)
{
+ char *errmsg = 0;
+ const char *path;
+
utk_widget *dlg = utk_event_widget(ev);
- printf("selected: %s\n", utk_file_dialog_file(dlg));
+ path = utk_file_dialog_path(dlg);
+ printf("selected: %s\n", path);
+ if(load_level(&lvl, path) == -1) {
+ errmsg = alloca(strlen(path) + 32);
+ sprintf(errmsg, "Failed to load level: %s", path);
+ }
utk_destroy_window(dlg);
if(uigrab == dlg) uigrab = 0;
+
+ if(errmsg) {
+ uigrab = utk_message_dialog(errmsg, UTK_MSG_TYPE_ERROR, UTK_MSG_BN_OK, cb_cancel, 0);
+ }
}
static void cb_save(utk_event *ev, void *data)
static void cb_save_ok(utk_event *ev, void *data)
{
+ char *errmsg = 0;
+ const char *path;
+
utk_widget *dlg = utk_event_widget(ev);
- printf("selected: %s\n", utk_file_dialog_file(dlg));
+ path = utk_file_dialog_path(dlg);
+ printf("selected: %s\n", path);
+ if(save_level(&lvl, path) == -1) {
+ errmsg = alloca(strlen(path) + 32);
+ sprintf(errmsg, "Failed to save level file: %s", path);
+ }
utk_destroy_window(dlg);
if(uigrab == dlg) uigrab = 0;
+
+ if(errmsg) {
+ uigrab = utk_message_dialog(errmsg, UTK_MSG_TYPE_ERROR, UTK_MSG_BN_OK, cb_cancel, 0);
+ }
}
static void cb_cancel(utk_event *ev, void *data)