Skip to content

Commit

Permalink
Fix text input on event editor
Browse files Browse the repository at this point in the history
  • Loading branch information
crudelios committed Nov 7, 2024
1 parent 9e84a22 commit a59b26a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/graphics/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ static void noop(void)
static void noop_input(const mouse *m, const hotkeys *h)
{}

static void noop_return(window_id from)
{}

static void increase_queue_index(void)
{
data.queue_index++;
Expand Down Expand Up @@ -91,14 +94,19 @@ void window_show(const window_type *window)
if (!data.current_window->handle_input) {
data.current_window->handle_input = noop_input;
}
if (!data.current_window->on_return) {
data.current_window->on_return = noop_return;
}
window_invalidate();
}

void window_go_back(void)
{
reset_input();
window_id from_id = window_get_id();
decrease_queue_index();
data.current_window = &data.window_queue[data.queue_index];
data.current_window->on_return(from_id);
window_invalidate();
}

Expand Down Expand Up @@ -146,12 +154,8 @@ void window_draw_underlying_window(void)
++data.underlying_windows_redrawing;
decrease_queue_index();
window_type *window_behind = &data.window_queue[data.queue_index];
if (window_behind->draw_background) {
window_behind->draw_background();
}
if (window_behind->draw_foreground) {
window_behind->draw_foreground();
}
window_behind->draw_background();
window_behind->draw_foreground();
increase_queue_index();
--data.underlying_windows_redrawing;
}
Expand Down
1 change: 1 addition & 0 deletions src/graphics/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef struct {
void (*draw_foreground)(void);
void (*handle_input)(const mouse *m, const hotkeys *h);
void (*get_tooltip)(tooltip_context *c);
void (*on_return)(window_id from);
} window_type;

/**
Expand Down
1 change: 1 addition & 0 deletions src/translation/english.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ static translation_string all_strings[] = {
{TR_EDITOR_SCENARIO_EVENTS_COUNT, "Total scenario events:" },
{TR_EDITOR_SCENARIO_EVENTS_CONDITIONS, "conditions" },
{TR_EDITOR_SCENARIO_EVENTS_ACTIONS, "actions" },
{TR_EDITOR_SCENARIO_EVENTS_SET_TO_GROUP, "Set selected to group..."},
{TR_EDITOR_SCENARIO_EVENTS_NO_GROUP, "No group"},
{TR_EDITOR_SCENARIO_EVENTS_GROUP, "Group "},
{TR_EDITOR_SCENARIO_EVENTS_NEW_GROUP, "New group"},
Expand Down
1 change: 1 addition & 0 deletions src/translation/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ typedef enum {
TR_EDITOR_SCENARIO_EVENTS_COUNT,
TR_EDITOR_SCENARIO_EVENTS_CONDITIONS,
TR_EDITOR_SCENARIO_EVENTS_ACTIONS,
TR_EDITOR_SCENARIO_EVENTS_SET_TO_GROUP,
TR_EDITOR_SCENARIO_EVENTS_NO_GROUP,
TR_EDITOR_SCENARIO_EVENTS_GROUP,
TR_EDITOR_SCENARIO_EVENTS_NEW_GROUP,
Expand Down
25 changes: 17 additions & 8 deletions src/window/editor/scenario_event_details.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ static void draw_background(void)
select_all_none_buttons[0].y + (20 - img->original.height) / 2, COLOR_MASK_NONE, SCALE_NONE);
}

// "Set selected to group..." option label
color_t color = data.conditions.selection_type == CHECKBOX_NO_SELECTION ? COLOR_FONT_LIGHT_GRAY : 0;
lang_text_draw_centered_colored(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_EVENTS_SET_TO_GROUP,
top_buttons[6].x, top_buttons[6].y + 5, top_buttons[6].width, FONT_SMALL_PLAIN, color);

// Condition grid box label
lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_CONDITION,
select_all_none_buttons[0].x + select_all_none_buttons[0].width + 6, conditions_grid_box.y - 20,
Expand Down Expand Up @@ -505,7 +510,7 @@ static void draw_background(void)
bottom_buttons[0].x, bottom_buttons[0].y + 6, bottom_buttons[0].width, FONT_NORMAL_BLACK);

// Delete selected button label
color_t color = data.conditions.selection_type == CHECKBOX_NO_SELECTION &&
color = data.conditions.selection_type == CHECKBOX_NO_SELECTION &&
data.actions.selection_type == CHECKBOX_NO_SELECTION ? COLOR_FONT_LIGHT_GRAY : COLOR_RED;
lang_text_draw_centered_colored(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_EVENTS_DELETE_SELECTED,
bottom_buttons[1].x, bottom_buttons[1].y + 6, bottom_buttons[1].width, FONT_NORMAL_PLAIN, color);
Expand Down Expand Up @@ -616,11 +621,6 @@ static void draw_foreground(void)
focus);
}

// "Set selected to group..." option label
color_t color = data.conditions.selection_type == CHECKBOX_NO_SELECTION ? COLOR_FONT_LIGHT_GRAY : 0;
text_draw_centered(string_from_ascii("Set selected to group..."), top_buttons[6].x, top_buttons[6].y + 5,
top_buttons[6].width, FONT_SMALL_PLAIN, color);

grid_box_draw(&conditions_grid_box);
grid_box_draw(&actions_grid_box);

Expand Down Expand Up @@ -675,6 +675,7 @@ static void set_repeat_times(int value)
static void button_repeat_times(const generic_button *button)
{
data.repeat_type = EVENT_REPEAT_TIMES;
stop_input();
window_numeric_input_bound_show(0, 0, button,
3, 1, 999, set_repeat_times);
}
Expand Down Expand Up @@ -702,6 +703,7 @@ static void button_repeat_between(const generic_button *button)
return;
}

stop_input();
window_numeric_input_bound_show(0, 0, button,
2, 1, 999, amount_type == REPEAT_MIN ? set_repeat_interval_min : set_repeat_interval_max);
}
Expand Down Expand Up @@ -796,7 +798,7 @@ static void button_set_selected_to_group(const generic_button *button)
if (data.conditions.selection_type == CHECKBOX_NO_SELECTION) {
return;
}

stop_input();
window_select_list_show_text(screen_dialog_offset_x(), screen_dialog_offset_y(), button,
(const uint8_t **) data.conditions.groups.names, data.conditions.groups.available,
set_selected_to_group);
Expand Down Expand Up @@ -854,6 +856,7 @@ static void button_delete_selected(const generic_button *button)
const uint8_t *title = lang_get_string(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_EVENTS_DELETE_SELECTED_CONFIRM_TITLE);
const uint8_t *text = lang_get_string(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_EVENTS_DELETE_SELECTED_CONFIRM_TEXT);
const uint8_t *check_text = lang_get_string(CUSTOM_TRANSLATION, TR_SAVE_DIALOG_OVERWRITE_FILE_DO_NOT_ASK_AGAIN);
stop_input();
window_popup_dialog_show_confirmation(title, text, check_text, delete_selected);
} else {
delete_selected(1, 1);
Expand Down Expand Up @@ -1025,14 +1028,20 @@ static void get_tooltip(tooltip_context *c)
}
}

static void on_return(window_id from)
{
start_input();
}

void window_editor_scenario_event_details_show(int event_id)
{
window_type window = {
WINDOW_EDITOR_SCENARIO_EVENT_DETAILS,
draw_background,
draw_foreground,
handle_input,
get_tooltip
get_tooltip,
on_return
};
init(event_id);
window_show(&window);
Expand Down

0 comments on commit a59b26a

Please sign in to comment.