From: Holger Schemel Date: Mon, 4 Feb 2019 20:59:07 +0000 (+0100) Subject: added options for alignment of selection lists on setup sub-screens X-Git-Tag: 4.1.2.0~33 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=dc0d3a4edd8a5b989f6fcd89e48a77b4ca590df4;p=rocksndiamonds.git added options for alignment of selection lists on setup sub-screens This adds two new "graphicsinfo.conf" options that are a bit special: - menu.list.SETUP[CHOOSE_OTHER].align - menu.list.SETUP[CHOOSE_OTHER].valign These new options can be used for horizontal and vertical alignment of selection lists on setup sub-screens (which cannot be adjusted individually like the other setup screens using "menu.draw_xoffset" and "menu.draw_yoffset"). Values are as usual: "left", "center" and "right" for ".align" and "top", "middle", "bottom" for ".valign" (with "left" and "top" being the default values). --- diff --git a/build-scripts/create_element_defs.pl b/build-scripts/create_element_defs.pl index 91ea130d..bd8cd46d 100755 --- a/build-scripts/create_element_defs.pl +++ b/build-scripts/create_element_defs.pl @@ -2406,8 +2406,8 @@ sub print_image_config_vars $var =~ s/\.draw_order$/.sort_priority/; $var =~ s/\.font_[a-z]+$/.font_alt/; - $var =~ s/\.INFO\[([A-Z]+)\]$/_info\[GFX_SPECIAL_ARG_INFO_$1\]/; - $var =~ s/\.SETUP\[([A-Z0-9_]+)\]$/_setup\[GFX_SPECIAL_ARG_SETUP_$1\]/; + $var =~ s/\.INFO\[([A-Z]+)\](.*)$/_info\[GFX_SPECIAL_ARG_INFO_$1\]$2/; + $var =~ s/\.SETUP\[([A-Z0-9_]+)\](.*)$/_setup\[GFX_SPECIAL_ARG_SETUP_$1\]$2/; $var =~ s/\.([A-Z]+)$/\[GFX_SPECIAL_ARG_$1\]/; $var =~ s/\.([A-Z]+)\./\[GFX_SPECIAL_ARG_$1\]./; diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 1fa9a01e..14d7272b 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -7797,6 +7797,9 @@ struct ConfigInfo image_config[] = { "menu.scrollbar_xoffset", "0" }, + { "menu.list.SETUP[CHOOSE_OTHER].align", "left" }, + { "menu.list.SETUP[CHOOSE_OTHER].valign", "top" }, + { "menu.list_size", "-1" }, { "menu.list_size.LEVELS", "-1" }, { "menu.list_size.LEVELNR", "-1" }, diff --git a/src/main.h b/src/main.h index 13cec3fb..9e1e04dd 100644 --- a/src/main.h +++ b/src/main.h @@ -2757,6 +2757,8 @@ struct MenuInfo int scrollbar_xoffset; + struct MenuPosInfo list_setup[NUM_SPECIAL_GFX_SETUP_ARGS]; + int list_size[NUM_SPECIAL_GFX_ARGS]; int list_size_info[NUM_SPECIAL_GFX_INFO_ARGS]; diff --git a/src/screens.c b/src/screens.c index c8bc6e66..5195cacd 100644 --- a/src/screens.c +++ b/src/screens.c @@ -523,6 +523,9 @@ static struct ValueTextInfo grid_sizes_list[] = { -1, NULL }, }; +static int align_xoffset = 0; +static int align_yoffset = 0; + #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \ (s) <= GAME_MODE_SETUP ? (s) : \ (s) == GAME_MODE_PSEUDO_TYPENAME ? \ @@ -579,6 +582,9 @@ static struct ValueTextInfo grid_sizes_list[] = #define mSX (SX + DRAW_XOFFSET(game_status)) #define mSY (SY + DRAW_YOFFSET(game_status)) +#define amSX (mSX + align_xoffset) +#define amSY (mSY + align_yoffset) + #define NUM_MENU_ENTRIES_ON_SCREEN (menu.list_size[game_status] > 2 ? \ menu.list_size[game_status] : \ MAX_MENU_ENTRIES_ON_SCREEN) @@ -1364,8 +1370,8 @@ static void clearMenuListArea(void) static void drawCursorExt(int xpos, int ypos, boolean active, int graphic) { static int cursor_array[MAX_LEV_FIELDY]; - int x = mSX + TILEX * xpos; - int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos); + int x = amSX + TILEX * xpos; + int y = amSY + TILEY * (MENU_SCREEN_START_YPOS + ypos); if (xpos == 0) { @@ -3990,6 +3996,51 @@ void HandleTypeName(int newxpos, Key key) // tree menu functions // ============================================================================ +static int getAlignXOffsetFromTreeInfo(TreeInfo *ti) +{ + if (game_status != GAME_MODE_SETUP || + DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER) + return 0; + + int max_text_size = 0; + TreeInfo *node; + + for (node = getTreeInfoFirstGroupEntry(ti); node != NULL; node = node->next) + max_text_size = MAX(max_text_size, strlen(node->name)); + + int num_entries = numTreeInfoInGroup(ti); + boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN); + int text_width = max_text_size * getFontWidth(FONT_TEXT_1); + int button_width = SC_MENUBUTTON_XSIZE; + int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset; + int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE); + int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].align; + int x = ALIGNED_XPOS(0, screen_width, align) * -1; + int align_xoffset_raw = ALIGNED_XPOS(x, button_width + text_width, align); + int align_xoffset = MAX(0, align_xoffset_raw); + + return align_xoffset; +} + +static int getAlignYOffsetFromTreeInfo(TreeInfo *ti) +{ + if (game_status != GAME_MODE_SETUP || + DRAW_MODE_SETUP(setup_mode) != SETUP_MODE_CHOOSE_OTHER) + return 0; + + int num_entries = numTreeInfoInGroup(ti); + int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN); + int font_height = getFontHeight(FONT_TEXT_1); + int text_height = font_height * num_page_entries; + int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN; + int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign; + int y = ALIGNED_YPOS(0, page_height, align) * -1; + int align_yoffset_raw = ALIGNED_YPOS(y, text_height, align); + int align_yoffset = MAX(0, align_yoffset_raw); + + return align_yoffset; +} + static void DrawChooseTree(TreeInfo **ti_ptr) { int fade_mask = REDRAW_FIELD; @@ -4061,10 +4112,10 @@ static void drawChooseTreeList(int first_entry, int num_page_entries, int entry_pos = first_entry + i; int xpos = MENU_SCREEN_START_XPOS; int ypos = MENU_SCREEN_START_YPOS + i; - int startx = mSX + xpos * 32; - int starty = mSY + ypos * 32; + int startx = amSX + xpos * 32; + int starty = amSY + ypos * 32; int startx_text = startx + font_xoffset; - int endx_text = mSX + screen_width; + int endx_text = amSX + screen_width; int max_text_size = endx_text - startx_text; int max_buffer_len = max_text_size / getFontWidth(font_nr); char buffer[max_buffer_len + 1]; @@ -4144,6 +4195,9 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, int num_entries = numTreeInfoInGroup(ti); int entry_pos = posTreeInfo(ti); + align_xoffset = getAlignXOffsetFromTreeInfo(ti); + align_yoffset = getAlignYOffsetFromTreeInfo(ti); + if (ti->cl_first == -1) { // only on initialization @@ -4228,8 +4282,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, if (mx || my) // mouse input { - x = (mx - mSX) / 32; - y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS; + x = (mx - amSX) / 32; + y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS; } else if (dx || dy) // keyboard or scrollbar/scrollbutton input { @@ -8068,6 +8122,9 @@ void ConfigureVirtualButtons(void) void DrawSetupScreen(void) { + align_xoffset = 0; + align_yoffset = 0; + if (setup_mode == SETUP_MODE_INPUT) DrawSetupScreen_Input(); else if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED)