linije

Клон игре Color lines
git clone https://git.sr.ht/~strahinja/linije
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување f8a2f9ea65c22625a567ce157a54f852d360e4d6
родитељ ffed8d4efc94dbd3218767b9918f40fd4316331f
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Tue, 11 Aug 2026 12:27:50 +0000

Add DIM_{START,END}; prettify HOF dialog

Diffstat:
Mlinije.c | 63++++++++++++++++++++++++++++++++++++++++++++++++---------------
измењених датотека: 1, додавања: 48(+), брисања: 15(-)

diff --git a/linije.c b/linije.c @@ -37,17 +37,17 @@ #define BOLD_START '\1' #define BOLD_END '\2' #define CENTER_LINE '\3' +#define DIM_START '\4' +#define DIM_END '\2' +#define CELL_SCALE_FACTOR 2.0f #define BUFSIZE 4096 #define CELL_SIZE 20 #define DEFAULT_WIDTH 1280 #define DEFAULT_HEIGHT 720 -#define HELP_DIALOG_WIDTH 900 -#define HELP_DIALOG_HEIGHT 500 -#define HOF_DIALOG_WIDTH 900 -#define HOF_DIALOG_HEIGHT 470 -#define HOF_DIALOG_MAX_LINE_LEN 60 +#define HOF_DIALOG_MAX_LINE_LEN 80 // #define HOF_DIALOG_TEXT_ORIGIN_X 70 #define HOF_DIALOG_TEXT_ORIGIN_X 0 +#define HOF_STANDOUT_ENTRIES 3 #define GAME_OVER_DIALOG_WIDTH 270 #define GAME_OVER_DIALOG_HEIGHT 110 #define GRID_WIDTH 15 @@ -66,10 +66,18 @@ #define QUIT_MSGBOX_HEIGHT 150 #define TER12_WIDTH 6 #define TER12_HEIGHT 12 +#define TEXT_OPACITY_DIM 0.3f #define TEXT_OPACITY_NORMAL 0.6f #define TEXT_OPACITY_BOLD 1.0f +#define TEXT_SCALE_FACTOR 2.0f #define WIN_TITLE "Linije" +#define HELP_DIALOG_WIDTH TER12_WIDTH * 75 * TEXT_SCALE_FACTOR +#define HELP_DIALOG_HEIGHT TER12_HEIGHT * 20 * TEXT_SCALE_FACTOR +#define HOF_DIALOG_WIDTH \ + TER12_WIDTH*(HOF_DIALOG_MAX_LINE_LEN + 3) * TEXT_SCALE_FACTOR +#define HOF_DIALOG_HEIGHT TER12_HEIGHT * 19 * TEXT_SCALE_FACTOR + #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define INDEX(x, y) ((y) * GRID_WIDTH + (x)) @@ -136,11 +144,11 @@ const char* help_text[] = { "\1Alt+Enter\2 - Toggle fullscreen", "\1Ctrl+Q\2 - Exit", "", - "\1---\2", + "---", "", - "This program is licensed under the terms of GNU GPL v3 or (at your", - "option) any later version. Copyright (C) 2025-2026 Strahinya Radich.", - "See the file LICENSE for exact copyright and license details.", + "\4This program is licensed under the terms of GNU GPL v3 or (at your\2", + "\4option) any later version. Copyright (C) 2025-2026 Strahinya Radich.\2", + "\4See the file LICENSE for exact copyright and license details.\2", NULL }; @@ -1214,7 +1222,7 @@ init_state(struct State* state) init_animation(&state->animation); state->background = NULL; state->grid = NULL; - state->cell_scale_factor = 2.0f; + state->cell_scale_factor = CELL_SCALE_FACTOR; state->check_score = 1; assign_point_xyII(-1, -1, &state->dialog_dims); assign_point_xyII(0, 0, &state->dialog_text_origin); @@ -1251,7 +1259,7 @@ init_state(struct State* state) assign_point_xyIF(-1, -1, &state->selection_end); state->sprites = NULL; state->ter12_texture = NULL; - state->text_scale_factor = 2.0f; + state->text_scale_factor = TEXT_SCALE_FACTOR; state->window = NULL; } @@ -1481,6 +1489,7 @@ prepare_hof_dialog(struct State* state, const int show) static int hof_size = HI_SCORE_MAX + 2 + 2 + 1; char* dots = NULL; int i; + int hof_line_len = 0; assert(state != NULL); errno = 0; @@ -1517,9 +1526,26 @@ prepare_hof_dialog(struct State* state, const int show) repeat_char(&dots, '.', HOF_DIALOG_MAX_LINE_LEN - 4 - e->name_len - num_size(e->score) - 1); - snprintf(hof_text[HOF_SCORES_START_IDX + i], - HOF_DIALOG_MAX_LINE_LEN, "%2d. %s%s%lu", i + 1, e->name, - dots, e->score); + + /* +4 is the number of special characters (the number of visible + * characters remains HOF_DIALOG_MAX_LINE_LEN) */ + hof_line_len = HOF_DIALOG_MAX_LINE_LEN + 4; + + /* For the first HOF_STANDOUT_ENTRIES entries, the number of + * special characters increases by 1 */ + if (i < HOF_STANDOUT_ENTRIES) + hof_line_len++; + + snprintf(hof_text[HOF_SCORES_START_IDX + i], hof_line_len, + "\4%2d. %s%s\4%s\2%s%lu", i + 1, + i < HOF_STANDOUT_ENTRIES ? "\1" : "\2", e->name, dots, + i < HOF_STANDOUT_ENTRIES ? "\1" : "", e->score); + + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, + "HOF[%d] = \"%s\" (%ld [vis=%d])\n", i, + hof_text[HOF_SCORES_START_IDX + i], + strlen(hof_text[HOF_SCORES_START_IDX + i]), + strlen_visible(hof_text[HOF_SCORES_START_IDX + i])); } prepare_dialog(state, HOF_DIALOG_WIDTH, HOF_DIALOG_HEIGHT, @@ -1942,6 +1968,12 @@ render_text(struct State* state, const int x, const int y, const int font_width, pbuf++; continue; } + else if (*pbuf == DIM_START) + { + opacity = TEXT_OPACITY_DIM; + pbuf++; + continue; + } else break; @@ -2190,7 +2222,8 @@ strlen_visible(const char* s) ps = s; while (*ps) { - if (*ps != CENTER_LINE && *ps != BOLD_START && *ps != BOLD_END) + if (*ps != CENTER_LINE && *ps != BOLD_START && *ps != BOLD_END + && *ps != DIM_START) result++; ps++; }