dunger now saves player start position and cell size
[vrlugburz] / tools / dunger / src / main.c
index 5a23d71..6bc37a7 100644 (file)
@@ -6,6 +6,7 @@
 #include <drawtext.h>
 #include "level.h"
 #include "lview.h"
+#include "app.h"
 
 static int init(void);
 static void cleanup(void);
@@ -25,6 +26,8 @@ static void cb_save_ok(utk_event *ev, void *data);
 
 static void cb_cancel(utk_event *ev, void *data);
 
+static void cb_toolselect(utk_event *ev, void *data);
+
 static int parse_args(int argc, char **argv);
 
 
@@ -57,6 +60,8 @@ static utk_widget *cbox_newsz;
 
 static struct level lvl;
 
+static const char *opt_fname;
+
 
 int main(int argc, char **argv)
 {
@@ -125,6 +130,9 @@ static int init(void)
        utk_button(win, "New", 0, 0, cb_new, 0);
        utk_button(win, "Open ...", 0, 0, cb_open, 0);
        utk_button(win, "Save ...", 0, 0, cb_save, 0);
+       utk_label(win, "-- Tools --");
+       utk_radiobox(win, "Draw", 1, cb_toolselect, (void*)TOOL_DRAW);
+       utk_radiobox(win, "Player start", 0, cb_toolselect, (void*)TOOL_PSTART);
 
        uiwin_new = utk_window(uiroot, (win_width - 220) / 2, (win_height - 150) / 2,
                        220, 150, "New level");
@@ -141,9 +149,16 @@ static int init(void)
        utk_set_size(uiwin_new, utk_get_width(vbox) + pad * 2.0f, utk_get_height(vbox) + pad * 2.0f);
 
 
-       if(init_level(&lvl, 32, 32) == -1) {
-               fprintf(stderr, "failed to create level\n");
-               return -1;
+       if(opt_fname) {
+               if(load_level(&lvl, opt_fname) == -1) {
+                       fprintf(stderr, "failed to load level: %s\n", opt_fname);
+                       return -1;
+               }
+       } else {
+               if(init_level(&lvl, 32, 32) == -1) {
+                       fprintf(stderr, "failed to create level\n");
+                       return -1;
+               }
        }
        if(init_lview(&lvl) == -1) {
                return -1;
@@ -398,6 +413,14 @@ static void cb_cancel(utk_event *ev, void *data)
        uigrab = 0;
 }
 
+static void cb_toolselect(utk_event *ev, void *data)
+{
+       utk_widget *w = utk_event_widget(ev);
+       if(utk_is_checked(w)) {
+               tool = (intptr_t)data;
+       }
+}
+
 static int parse_args(int argc, char **argv)
 {
        int i;
@@ -420,8 +443,11 @@ static int parse_args(int argc, char **argv)
                                return -1;
                        }
                } else {
-                       fprintf(stderr, "unexpected argument: %s\n", argv[i]);
-                       return -1;
+                       if(opt_fname) {
+                               fprintf(stderr, "unexpected argument: %s\n", argv[i]);
+                               return -1;
+                       }
+                       opt_fname = argv[i];
                }
        }
        return 0;