Skip to content

Commit

Permalink
Start refining custom variables UI
Browse files Browse the repository at this point in the history
  • Loading branch information
crudelios committed Dec 19, 2024
1 parent 50ba1e9 commit d05afb7
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/graphics/grid_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void grid_box_request_refresh(grid_box_type *grid_box)
grid_box->refresh_requested = 1;
}

static unsigned int get_actual_width(const grid_box_type *grid_box)
unsigned int grid_box_get_usable_width(const grid_box_type *grid_box)
{
unsigned int width = grid_box->width;
if (width <= 2 * BLOCK_SIZE) {
Expand Down Expand Up @@ -110,7 +110,7 @@ void grid_box_draw(grid_box_type *grid_box)
}
grid_box->refresh_requested = 0;

unsigned int width = get_actual_width(grid_box);
unsigned int width = grid_box_get_usable_width(grid_box);
unsigned int inner_padding = 0;

if (grid_box->draw_inner_panel) {
Expand Down Expand Up @@ -152,7 +152,7 @@ void grid_box_draw(grid_box_type *grid_box)
static int determine_focus(grid_box_type *grid_box, int x, int y)
{
unsigned int inner_padding = grid_box->draw_inner_panel ? BLOCK_SIZE / 2 : 0;
unsigned int width = get_actual_width(grid_box);
unsigned int width = grid_box_get_usable_width(grid_box);
unsigned int old_position = grid_box->focus.position;
if (x < grid_box->x + inner_padding || x >= grid_box->x + width - inner_padding ||
y < grid_box->y + inner_padding || y >= grid_box->y + grid_box->height - inner_padding) {
Expand Down Expand Up @@ -224,7 +224,7 @@ void grid_box_handle_tooltip(const grid_box_type *grid_box, tooltip_context *c)
return;
}
unsigned int inner_padding = grid_box->draw_inner_panel ? BLOCK_SIZE : 0;
unsigned int width = (get_actual_width(grid_box) - inner_padding) / grid_box->num_columns;
unsigned int width = (grid_box_get_usable_width(grid_box) - inner_padding) / grid_box->num_columns;
grid_box_item item = {
.width = width - grid_box->item_margin.horizontal,
.height = grid_box->item_height,
Expand Down
1 change: 1 addition & 0 deletions src/graphics/grid_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void grid_box_init(grid_box_type *grid_box, unsigned int total_items);
void grid_box_update_total_items(grid_box_type *grid_box, unsigned int total_items);
unsigned int grid_box_get_total_items(const grid_box_type *grid_box);
void grid_box_draw(grid_box_type *grid_box);
unsigned int grid_box_get_usable_width(const grid_box_type *grid_box);
int grid_box_handle_input(grid_box_type *grid_box, const mouse *m, int in_dialog);
void grid_box_handle_tooltip(const grid_box_type *grid_box, tooltip_context *c);
void grid_box_show_index(grid_box_type *grid_box, unsigned int index);
Expand Down
2 changes: 1 addition & 1 deletion src/translation/english.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_VICTORY, "Select victory message"},
{TR_EDITOR_SCENARIO_DESELECT_VICTORY, "Remove victory message"},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Custom variables" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Maximum possible variables" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Total variables:" },
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TITLE, "Unable to change custom variable"},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TEXT, "The custom variable is being used by at least one event.\n\nRemove the custom variable from the event to be able to change its name or to delete it."},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_EVENT_ID, "Earliest event ID where variable is used: "},
Expand Down
1 change: 0 additions & 1 deletion src/translation/french.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_VICTORY, "Choisir message de victoire"},
{TR_EDITOR_SCENARIO_DESELECT_VICTORY, "Retirer message de victoire"},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Variables perso." },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Variables possibles max." },
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TITLE, "Impossible de modifier la variable perso."},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TEXT, "La variable perso. est utilisée par au moins un autre événement.\n\nSupprimez cette variable dans l'événement pour pouvoir modifier son nom ou l'effacer."},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_EVENT_ID, "ID événement où la variable est utilisée : "},
Expand Down
1 change: 0 additions & 1 deletion src/translation/german.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_CUSTOM_MESSAGES_EXPORT_FULL, "Benutzerdefinierte Nachrichten exportieren" },
{TR_EDITOR_CUSTOM_MESSAGES_IMPORT_FULL, "Benutzerdefinierte Nachrichten importieren" },
{TR_EDITOR_CUSTOM_MESSAGES_TITLE, "Benutzerdef. Nachrichten" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Maximal mögliche Variablen" },
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Benutzerdefinierte Variablen" },
{TR_EDITOR_DELETE, "Löschen"},
{TR_EDITOR_DELETED, "Gelöscht"},
Expand Down
1 change: 0 additions & 1 deletion src/translation/greek.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_INTRO, "Επιλέξτε εισαγωγή σεναρίου"},
{TR_EDITOR_SCENARIO_DESELECT_INTRO, "Αποεπιλογή εισαγωγής σεναρίου"},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Προσαρμοσμένες μεταβλητές" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Μέγιστες δυνατές μεταβλητές" },
{TR_EDITOR_GRID_OFFSET, "αντιστάθμιση" },
{TR_PARAMETER_TYPE_CHECK, "Έλεγχος συγκρίσεων"},
{TR_PARAMETER_TYPE_MIN_MAX_NUMBER_MIN, "Ελάχιστο"},
Expand Down
1 change: 0 additions & 1 deletion src/translation/italian.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_VICTORY, "Scegli il messaggio di vittoria"},
{TR_EDITOR_SCENARIO_DESELECT_VICTORY, "Rimuovi il messaggio di vittoria"},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Variabili personalizzate" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Massime variabili possibili" },
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TITLE, "Impossibile cambiare la variabile personalizzata"},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TEXT, "La variabile personalizzata è usata almeno da un evento.\n\nRimuovi la variabile dal relativo evento per poterne cambiare il nome o rimuoverla."},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_EVENT_ID, "ID del primo evento dove la variabile è usata: "},
Expand Down
1 change: 0 additions & 1 deletion src/translation/korean.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_INTRO, "Select scenario intro"},
{TR_EDITOR_SCENARIO_DESELECT_INTRO, "Deselect scenario intro"},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Custom variables" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Maximum possible variables" },
{TR_EDITOR_GRID_OFFSET, " offset" },
{TR_PARAMETER_TYPE_CHECK, "Comparison check"},
{TR_PARAMETER_TYPE_MIN_MAX_NUMBER_MIN, "Minimum"},
Expand Down
1 change: 0 additions & 1 deletion src/translation/polish.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_CUSTOM_MESSAGES_EXPORT_FULL, "Eksportuj niestandardowe wiadomości" },
{TR_EDITOR_CUSTOM_MESSAGES_IMPORT_FULL, "Importuj niestandardowe wiadomości" },
{TR_EDITOR_CUSTOM_MESSAGES_TITLE, "Niestandardowe wiadomości" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Maksymalne możliwe zmienne" },
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Zmienne niestandardowe" },
{TR_EDITOR_DELETE, "Usuń"},
{TR_EDITOR_DELETED, "Usunięte"},
Expand Down
2 changes: 1 addition & 1 deletion src/translation/portuguese.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ static translation_string all_strings[] = {
{TR_EDITOR_CUSTOM_MESSAGES_EXPORT_FULL, "Exportar mensagens personalizadas" },
{TR_EDITOR_CUSTOM_MESSAGES_IMPORT_FULL, "Importar mensagens personalizadas" },
{TR_EDITOR_CUSTOM_MESSAGES_TITLE, "Mensagens personalizadas" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Máximo de variáveis permitidas" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Total de variáveis:" },
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Variáveis personalizadas" },
{TR_EDITOR_DELETE, "Apagar"},
{TR_EDITOR_DELETED, "Apagado"},
Expand Down
1 change: 0 additions & 1 deletion src/translation/russian.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_VICTORY, "Выберите сообщение о победе"},
{TR_EDITOR_SCENARIO_DESELECT_VICTORY, "Удалить сообщение о победе "},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Переменные" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Макс. возможных переменных" },
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TITLE, "Невозможно изменить переменную"},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TEXT, "Переменная используется уже минимум одним событием.\n\nУдалите переменную из события, чтобы иметь возможность изменить ее имя или удалить."},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_EVENT_ID, "ID самого раннего события c переменной: "},
Expand Down
1 change: 0 additions & 1 deletion src/translation/spanish.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_SELECT_VICTORY, "Selecciona mensaje de victoria"},
{TR_EDITOR_SCENARIO_DESELECT_VICTORY, "Quitar mensaje de victoria"},
{TR_EDITOR_CUSTOM_VARIABLES_TITLE, "Variables personalizadas" },
{TR_EDITOR_CUSTOM_VARIABLES_COUNT, "Variables máximas posibles" },
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TITLE, "No se puede cambiar la variable personalizada"},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_TEXT, "La variable personalizada está siendo utilizada por al menos un evento.\n\nElimine la variable personalizada del evento para poder cambiar su nombre o eliminarla."},
{TR_EDITOR_CUSTOM_VARIABLE_UNABLE_TO_CHANGE_EVENT_ID, "ID del evento más antiguo en el que se utiliza la variable: "},
Expand Down
57 changes: 37 additions & 20 deletions src/window/editor/custom_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "window/plain_message_dialog.h"
#include "window/text_input.h"

#define WIDTH_VALUE_BUTTON 96
#define VALUE_BUTTON_WIDTH 120

static void button_edit_variable(unsigned int index, unsigned int mouse_x, unsigned int mouse_y);
static void button_new_variable(const generic_button *button);
Expand All @@ -43,13 +43,13 @@ static struct {
} data;

static generic_button new_variable_button = {
195, 340, 250, 25, button_new_variable
195, 410, 250, 25, button_new_variable
};

static grid_box_type variable_buttons = {
.x = 10,
.y = 146,
.width = 35 * BLOCK_SIZE,
.x = 26,
.y = 108,
.width = 38 * BLOCK_SIZE,
.height = 19 * BLOCK_SIZE,
.num_columns = 1,
.item_height = 30,
Expand Down Expand Up @@ -99,15 +99,26 @@ static void draw_background(void)

outer_panel_draw(16, 16, 40, 30);

text_draw_centered(translation_for(TR_EDITOR_CUSTOM_VARIABLES_TITLE), 48, 58, 640, FONT_LARGE_BLACK, 0);
text_draw_label_and_number(translation_for(TR_EDITOR_CUSTOM_VARIABLES_COUNT), data.custom_variables_in_use, "",
48, 106, FONT_NORMAL_PLAIN, COLOR_BLACK);
text_draw_centered(translation_for(TR_EDITOR_CUSTOM_VARIABLES_TITLE), 0, 32, 640, FONT_LARGE_BLACK, 0);
text_draw_label_and_number_centered(translation_for(TR_EDITOR_CUSTOM_VARIABLES_COUNT), data.custom_variables_in_use, "",
0, 70, 640, FONT_NORMAL_BLACK, 0);

lang_text_draw_centered(13, 3, 48, 450, 640, FONT_NORMAL_BLACK);

text_draw_centered(string_from_ascii("New custom variable"), new_variable_button.x, new_variable_button.y + 4,
text_draw_centered(string_from_ascii("New custom variable"), new_variable_button.x, new_variable_button.y + 8,
new_variable_button.width, FONT_NORMAL_BLACK, 0);

int base_x = variable_buttons.x;

text_draw_centered(string_from_ascii("ID"), base_x, 96, 40, FONT_SMALL_PLAIN, 0);
text_draw(string_from_ascii("Name"), base_x + 40, 96, FONT_SMALL_PLAIN, 0);

if (!data.callback) {
int value_x_offset = grid_box_get_usable_width(&variable_buttons) - VALUE_BUTTON_WIDTH;
text_draw(string_from_ascii("Initial value"), base_x + value_x_offset, 96, FONT_SMALL_PLAIN, 0);
}

lang_text_draw_centered(13, 3, 48, 450, 640, FONT_NORMAL_BLACK);

graphics_reset_dialog();

grid_box_request_refresh(&variable_buttons);
Expand All @@ -117,25 +128,30 @@ static void draw_variable_button(const grid_box_item *item)
{
unsigned int id = data.custom_variable_ids[item->index];
const uint8_t *name = scenario_custom_variable_get_name(id);
//int value = scenario_custom_variable_get_value(id);
int value_button_x_offset = item->width - WIDTH_VALUE_BUTTON;
int value = scenario_custom_variable_get_value(id);
int name_button_width = item->width - 32;

if (!data.callback) {
name_button_width -= VALUE_BUTTON_WIDTH + 4;
}

button_border_draw(item->x, item->y, item->width, item->height,
item->is_focused && item->mouse.x < value_button_x_offset);
text_draw_label_and_number(0, id, "", item->x, item->y + 12, FONT_NORMAL_GREEN, COLOR_MASK_NONE);
text_draw_number_centered(id, item->x, item->y + 8, 32, FONT_NORMAL_BLACK);

button_border_draw(item->x + 32, item->y, name_button_width, item->height,
item->is_focused && item->mouse.x >= 32 && item->mouse.x < name_button_width);

if (name && *name) {
text_draw(name, item->x + 52, item->y + 12, FONT_NORMAL_GREEN, COLOR_MASK_NONE);
text_draw(name, item->x + 40, item->y + 8, FONT_NORMAL_BLACK, COLOR_MASK_NONE);
}

if (data.callback) {
return;
}
// large_label_draw(buttons[j + 1].x, buttons[j + 1].y, buttons[j + 1].width / BLOCK_SIZE,
// data.focus_button_id == j + 2 ? 1 : 0);

// text_draw_number(data.list[i]->value, ' ', "", buttons[j + 1].x, buttons[j + 1].y + 8,
// FONT_NORMAL_GREEN, COLOR_MASK_NONE);
button_border_draw(item->x + name_button_width + 36, item->y, VALUE_BUTTON_WIDTH, item->height,
item->is_focused && item->mouse.x >= name_button_width + 36);

text_draw_number(value, ' ', "", item->x + name_button_width + 44, item->y + 8, FONT_NORMAL_BLACK, COLOR_MASK_NONE);
}


Expand Down Expand Up @@ -243,6 +259,7 @@ static void button_new_variable(const generic_button *button)
}
populate_list();
grid_box_update_total_items(&variable_buttons, data.custom_variables_in_use);
window_request_refresh();
}

static void handle_input(const mouse *m, const hotkeys *h)
Expand Down

0 comments on commit d05afb7

Please sign in to comment.