Include and link physfs properly.
[tuxanci.git] / src / client / saveDialog.c
blob7a0c31684d4d3f9fc7952f9dd3a6df881d4b3e20
1 #include <stdlib.h>
2 #include <assert.h>
4 #include "main.h"
5 #include "list.h"
6 #include "tux.h"
7 #include "space.h"
8 #include "arena.h"
9 #include "net_multiplayer.h"
11 #include "interface.h"
12 #include "saveDialog.h"
13 #include "image.h"
14 #include "font.h"
15 #include "saveLoad.h"
16 #include "hotKey.h"
18 #include "widget.h"
19 #include "widget_label.h"
20 #include "widget_button.h"
21 #include "widget_textfield.h"
23 static image_t *g_background;
24 static bool_t activeSaveDialog;
26 static widget_t *widgetLabelMsg;
27 static widget_t *widgetTextFieldName;
29 static widget_t *widgetButtonSave;
30 static widget_t *widgetButtonBack;
32 static void switchTerm()
34 if (activeSaveDialog == TRUE) {
35 activeSaveDialog = FALSE;
36 hot_key_unregister(SDLK_ESCAPE);
37 } else {
38 activeSaveDialog = TRUE;
39 hot_key_register(SDLK_ESCAPE, switchTerm);
43 static void eventWidget(void *p)
45 widget_t *button;
47 button = (widget_t *) p;
49 if (button == widgetButtonSave) {
50 save_arena(text_field_get_text(widgetTextFieldName), arena_get_current());
51 switchTerm();
54 if (button == widgetButtonBack) {
55 switchTerm();
59 static void hotkey_saveDialog()
61 switchTerm();
64 void save_dialog_init()
66 activeSaveDialog = FALSE;
68 g_background = image_get(IMAGE_GROUP_BASE, "screen_main");
70 widgetLabelMsg = label_new(_("Save as:"), SAVE_DIALOG_LOCATIN_X + 20,
71 SAVE_DIALOG_LOCATIN_Y + 20,
72 WIDGET_LABEL_LEFT);
74 widgetTextFieldName = text_field_new("", WIDGET_TEXTFIELD_FILTER_ALPHANUM,
75 widgetLabelMsg->x + widgetLabelMsg->w + 10,
76 widgetLabelMsg->y);
78 widgetButtonSave = button_new(_("Save"), SAVE_DIALOG_LOCATIN_X + 20,
79 SAVE_DIALOG_LOCATIN_Y + 60,
80 eventWidget);
82 widgetButtonBack = button_new(_("Back"), SAVE_DIALOG_LOCATIN_X + 20 +
83 WIDGET_BUTTON_WIDTH + 20,
84 SAVE_DIALOG_LOCATIN_Y + 60,
85 eventWidget);
87 hot_key_register(SDLK_F2, hotkey_saveDialog);
90 bool_t save_dialog_is_active()
92 return activeSaveDialog;
95 void save_dialog_draw()
97 if (activeSaveDialog == FALSE) {
98 return;
101 image_draw(g_background, SAVE_DIALOG_LOCATIN_X,
102 SAVE_DIALOG_LOCATIN_Y,
103 SAVE_DIALOG_LOCATIN_X,
104 SAVE_DIALOG_LOCATIN_Y,
105 SAVE_DIALOG_SIZE_X,
106 SAVE_DIALOG_SIZE_Y);
108 label_draw(widgetLabelMsg);
109 text_field_draw(widgetTextFieldName);
110 button_draw(widgetButtonSave);
111 button_draw(widgetButtonBack);
114 void save_dialog_event()
116 if (activeSaveDialog == FALSE) {
117 return;
120 text_field_event(widgetTextFieldName);
121 button_event(widgetButtonSave);
122 button_event(widgetButtonBack);
126 void save_dialog_quit()
128 hot_key_unregister(SDLK_F2);
130 label_destroy(widgetLabelMsg);
131 text_field_destroy(widgetTextFieldName);
132 button_destroy(widgetButtonSave);
133 button_destroy(widgetButtonBack);