+#define MAIN_CONTROL_NAME 0
+#define MAIN_CONTROL_LEVELS 1
+#define MAIN_CONTROL_SCORES 2
+#define MAIN_CONTROL_EDITOR 3
+#define MAIN_CONTROL_INFO 4
+#define MAIN_CONTROL_GAME 5
+#define MAIN_CONTROL_SETUP 6
+#define MAIN_CONTROL_QUIT 7
+#define MAIN_CONTROL_PREV_LEVEL 8
+#define MAIN_CONTROL_NEXT_LEVEL 9
+#define MAIN_CONTROL_CURRENT_LEVEL 10
+#define MAIN_CONTROL_FIRST_LEVEL 11
+#define MAIN_CONTROL_LAST_LEVEL 12
+#define MAIN_CONTROL_LEVELSET_INFO 13
+#define MAIN_CONTROL_LEVEL_INFO 14
+
+static char main_text_name[10];
+static char main_text_current_level[10];
+static char main_text_first_level[10];
+static char main_text_last_level[10];
+static char main_input_name[MAX_PLAYER_NAME_LEN + 1];
+
+static struct
+{
+ int nr;
+
+ struct Rect *pos_button;
+ int button_graphic;
+
+ struct Rect *pos_text;
+ char *text;
+ int font_text;
+
+ struct Rect *pos_input;
+ char *input;
+ int font_input;
+}
+main_controls[] =
+{
+ {
+ MAIN_CONTROL_NAME,
+ &menu.main.button.name, IMG_MENU_BUTTON,
+ &menu.main.text.name, main_text_name, FONT_MENU_1,
+ &menu.main.input.name, main_input_name, FONT_INPUT_1,
+ },
+ {
+ MAIN_CONTROL_LEVELS,
+ &menu.main.button.levels, IMG_MENU_BUTTON_ENTER_MENU,
+ &menu.main.text.levels, "Levelset", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_SCORES,
+ &menu.main.button.scores, IMG_MENU_BUTTON,
+ &menu.main.text.scores, "Hall Of Fame", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_EDITOR,
+ &menu.main.button.editor, IMG_MENU_BUTTON,
+ &menu.main.text.editor, "Level Creator", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_INFO,
+ &menu.main.button.info, IMG_MENU_BUTTON_ENTER_MENU,
+ &menu.main.text.info, "Info Screen", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_GAME,
+ &menu.main.button.game, IMG_MENU_BUTTON,
+ &menu.main.text.game, "Start Game", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_SETUP,
+ &menu.main.button.setup, IMG_MENU_BUTTON_ENTER_MENU,
+ &menu.main.text.setup, "Setup", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_QUIT,
+ &menu.main.button.quit, IMG_MENU_BUTTON,
+ &menu.main.text.quit, "Quit", FONT_MENU_1,
+ NULL, NULL, -1,
+ },
+#if 0
+ {
+ MAIN_CONTROL_PREV_LEVEL,
+ &menu.main.button.prev_level, IMG_MENU_BUTTON_PREV_LEVEL,
+ NULL, NULL, -1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_NEXT_LEVEL,
+ &menu.main.button.next_level, IMG_MENU_BUTTON_NEXT_LEVEL,
+ NULL, NULL, -1,
+ NULL, NULL, -1,
+ },
+#endif
+ {
+ MAIN_CONTROL_CURRENT_LEVEL,
+ NULL, -1,
+ &menu.main.text.current_level, main_text_current_level,FONT_VALUE_1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_FIRST_LEVEL,
+ NULL, -1,
+ &menu.main.text.first_level, main_text_first_level, FONT_TEXT_3,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_LAST_LEVEL,
+ NULL, -1,
+ &menu.main.text.last_level, main_text_last_level, FONT_TEXT_3,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_LEVELSET_INFO,
+ NULL, -1,
+ &menu.main.text.levelset_info, NULL, -1,
+ NULL, NULL, -1,
+ },
+ {
+ MAIN_CONTROL_LEVEL_INFO,
+ NULL, -1,
+ &menu.main.text.level_info, NULL, -1,
+ NULL, NULL, -1,
+ },
+
+ {
+ -1,
+ NULL, -1,
+ NULL, NULL, -1,
+ NULL, NULL, -1,
+ }
+};
+
+
+static void InitializeMainControls()
+{
+ boolean local_team_mode = (!options.network && setup.team_mode);
+ int i;
+
+ /* set main control text values to dynamically determined values */
+ sprintf(main_text_name, "%s", local_team_mode ? "Team:" : "Name:");
+ sprintf(main_text_current_level, "%s", int2str(level_nr, 3));
+ sprintf(main_text_first_level, "%03d", leveldir_current->first_level);
+ sprintf(main_text_last_level, "%03d", leveldir_current->last_level);
+ sprintf(main_input_name, "%s", setup.player_name);
+
+ /* set main control screen positions to dynamically determined values */
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ int nr = main_controls[i].nr;
+ struct Rect *pos_button = main_controls[i].pos_button;
+ struct Rect *pos_text = main_controls[i].pos_text;
+ struct Rect *pos_input = main_controls[i].pos_input;
+ char *text = main_controls[i].text;
+ char *input = main_controls[i].input;
+ int button_graphic = main_controls[i].button_graphic;
+ int font_text = main_controls[i].font_text;
+ int font_input = main_controls[i].font_input;
+
+ int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0);
+ int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0);
+ int font_input_width = (font_input != -1 ? getFontWidth(font_input) : 0);
+ int font_input_height = (font_input != -1 ? getFontHeight(font_input) : 0);
+ int text_chars = (text != NULL ? strlen(text) : 0);
+ int input_chars = (input != NULL ? strlen(input) : 0);
+
+ int button_width =
+ (button_graphic != -1 ? graphic_info[button_graphic].width : 0);
+ int button_height =
+ (button_graphic != -1 ? graphic_info[button_graphic].height : 0);
+ int text_width = font_text_width * text_chars;
+ int text_height = font_text_height;
+ int input_width = font_input_width * input_chars;
+ int input_height = font_input_height;
+
+ if (nr == MAIN_CONTROL_NAME)
+ {
+#if 0
+ if (menu.main.input.name.x == -1)
+ menu.main.input.name.x = menu.main.text.name.x + text_width;
+ if (menu.main.input.name.y == -1)
+ menu.main.input.name.y = menu.main.text.name.y;
+#endif
+
+ menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN;
+ menu.main.input.name.height = font_input_height;
+ }
+
+ if (pos_button != NULL)
+ {
+ if (pos_button->width == 0)
+ pos_button->width = button_width;
+ if (pos_button->height == 0)
+ pos_button->height = button_height;
+ }
+
+ if (pos_text != NULL)
+ {
+ if (pos_text->x == -1 && pos_button != NULL)
+ pos_text->x = pos_button->x + pos_button->width;
+ if (pos_text->y == -1 && pos_button != NULL)
+ pos_text->y = pos_button->y;
+
+ if (pos_text->width == -1)
+ pos_text->width = text_width;
+ if (pos_text->height == -1)
+ pos_text->height = text_height;
+ }
+
+ if (pos_input != NULL)
+ {
+ if (pos_input->x == -1 && pos_text != NULL)
+ pos_input->x = pos_text->x + pos_text->width;
+ if (pos_input->y == -1 && pos_text != NULL)
+ pos_input->y = pos_text->y;
+
+ if (pos_input->width == -1)
+ pos_input->width = input_width;
+ if (pos_input->height == -1)
+ pos_input->height = input_height;
+ }
+ }
+}
+
+static void DrawCursorAndText_Main(int pos, boolean active)
+{
+ int i;
+
+ for (i = 0; main_controls[i].nr != -1; i++)
+ {
+ if (main_controls[i].nr == pos)
+ {
+ struct Rect *pos_button = main_controls[i].pos_button;
+ struct Rect *pos_text = main_controls[i].pos_text;
+ char *text = main_controls[i].text;
+ int font_text = main_controls[i].font_text;
+ int button_graphic = main_controls[i].button_graphic;
+ int button_x = mSX + pos_button->x;
+ int button_y = mSY + pos_button->y;
+ int text_x = mSX + pos_text->x;
+ int text_y = mSY + pos_text->y;
+
+ if (active)
+ {
+ button_graphic = BUTTON_GRAPHIC_ACTIVE(button_graphic);
+ font_text = FONT_ACTIVE(font_text);
+ }
+
+ DrawBackground(button_x, button_y, pos_button->width, pos_button->height);
+ DrawGraphicThruMaskExt(drawto, button_x, button_y, button_graphic, 0);
+
+ DrawBackground(text_x, text_y, pos_text->width, pos_text->height);
+ DrawText(text_x, text_y, text, font_text);
+
+ break;
+ }
+ }
+}
+
+static boolean insideRect(struct Rect *rect, int x, int y)
+{
+ return (rect != NULL &&
+ x >= rect->x && x < rect->x + rect->width &&
+ y >= rect->y && y < rect->y + rect->height);
+}
+
+static void drawCursorExt(int xpos, int ypos, boolean active, int graphic)