Skip to content

Commit

Permalink
Improve UI for unlimited requests
Browse files Browse the repository at this point in the history
  • Loading branch information
crudelios committed Aug 1, 2024
1 parent cc2ba87 commit d7033d2
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/scenario/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void scenario_editor_create(int map_size)
init_point(&scenario.herd_points[i]);
}

scenario_request_init();
scenario_request_clear_all();

for (int i = 0; i < MAX_INVASIONS; i++) {
scenario.invasions[i].from = 8;
Expand Down
22 changes: 10 additions & 12 deletions src/scenario/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#define REQUESTS_ARRAY_SIZE_STEP 16
#define MAX_ORIGINAL_REQUESTS 20

#define REQUESTS_STRUCT_SIZE_ORIGINAL ((7 * sizeof(int16_t)) + (6 * sizeof(uint8_t)))
#define REQUESTS_STRUCT_SIZE_CURRENT (REQUESTS_STRUCT_SIZE_ORIGINAL + REQUESTS_DESCRIPTION_SIZE)
#define REQUESTS_STRUCT_SIZE_CURRENT ((7 * sizeof(int16_t)) + (6 * sizeof(uint8_t)))

static array(scenario_request) requests;

Expand Down Expand Up @@ -67,11 +66,17 @@ void scenario_request_init(void)
if (request->resource != RESOURCE_NONE) {
request->month = (random_byte() & 7) + 2;
request->months_to_comply = 12 * request->deadline_years;

}
}
}

int scenario_request_new(void)
{
scenario_request *request;
array_new_item(requests, 0, request);
return request ? request->id : -1;
}

static void process_request(scenario_request *request)
{
if (!request->resource || request->state > REQUEST_STATE_DISPATCHED_LATE) {
Expand Down Expand Up @@ -318,8 +323,6 @@ static void request_save(buffer *list, const scenario_request *request)
buffer_write_i16(list, request->extension_months_to_comply);
buffer_write_i16(list, request->extension_disfavor);
buffer_write_i16(list, request->ignored_disfavor);

buffer_write_raw(list, request->description, REQUESTS_DESCRIPTION_SIZE);
}

void scenario_request_save_state(buffer *list)
Expand All @@ -336,7 +339,7 @@ void scenario_request_save_state(buffer *list)
}
}

static void request_load(buffer *list, scenario_request *request, int has_description)
static void request_load(buffer *list, scenario_request *request)
{
request->year = buffer_read_i16(list);
request->resource = resource_remap(buffer_read_i16(list));
Expand All @@ -351,9 +354,6 @@ static void request_load(buffer *list, scenario_request *request, int has_descri
request->extension_months_to_comply = buffer_read_i16(list);
request->extension_disfavor = buffer_read_i16(list);
request->ignored_disfavor = buffer_read_i16(list);
if (has_description) {
buffer_read_raw(list, request->description, REQUESTS_DESCRIPTION_SIZE);
}
}

void scenario_request_load_state(buffer *list)
Expand All @@ -366,16 +366,14 @@ void scenario_request_load_state(buffer *list)
&array_size,
&struct_size);

int has_description = struct_size != REQUESTS_STRUCT_SIZE_ORIGINAL;

if (!array_init(requests, REQUESTS_ARRAY_SIZE_STEP, new_request, request_in_use) ||
!array_expand(requests, array_size)) {
log_error("Error creating requests array. The game will probably crash.", 0, 0);
}

for (int i = 0; i < array_size; i++) {
scenario_request *request = array_advance(requests);
request_load(list, request, has_description);
request_load(list, request);
}

array_trim(requests);
Expand Down
5 changes: 2 additions & 3 deletions src/scenario/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "core/buffer.h"

#define REQUESTS_DESCRIPTION_SIZE 25

#define REQUESTS_DEFAULT_DEADLINE_YEARS 5
#define REQUESTS_DEFAULT_FAVOUR 8
#define REQUESTS_DEFAULT_MONTHS_TO_COMPLY 24
Expand Down Expand Up @@ -35,7 +33,6 @@ typedef struct {
int extension_months_to_comply;
int extension_disfavor;
int ignored_disfavor;
uint8_t description[REQUESTS_DESCRIPTION_SIZE];
} scenario_request;

typedef enum {
Expand All @@ -49,6 +46,8 @@ void scenario_request_clear_all(void);

void scenario_request_init(void);

int scenario_request_new(void);

void scenario_request_process(void);

void scenario_request_dispatch(int id);
Expand Down
1 change: 1 addition & 0 deletions src/translation/english.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ static translation_string all_strings[] = {
{TR_FIGURE_TYPE_ARMORY_CARTPUSHER, "Armory deliveryman"},
{TR_TOOLTIP_BUTTON_CAN_GO_TO_ADVISORS, "Display the relevant advisor for this building." },
{TR_FIGURE_ENEMY_CATAPULT, "Catapult"},
{TR_EDITOR_NEW_REQUEST, "New request"},
};

void translation_english(const translation_string **strings, int *num_strings)
Expand Down
1 change: 1 addition & 0 deletions src/translation/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@ typedef enum {
TR_FIGURE_TYPE_ARMORY_CARTPUSHER,
TR_TOOLTIP_BUTTON_CAN_GO_TO_ADVISORS,
TR_FIGURE_ENEMY_CATAPULT,
TR_EDITOR_NEW_REQUEST,
TRANSLATION_MAX_KEY
} translation_key;

Expand Down
2 changes: 1 addition & 1 deletion src/window/editor/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void draw_foreground(void)

lang_text_draw(44, 40, 32, 165, FONT_NORMAL_BLACK);
button_border_draw(212, 156, 250, 30, data.focus_button_id == 3);
lang_text_draw_centered(44, 19, 212, 165, 250, FONT_NORMAL_BLACK);
lang_text_draw_centered(44, 14, 212, 165, 250, FONT_NORMAL_BLACK);

lang_text_draw(44, 41, 32, 205, FONT_NORMAL_BLACK);
button_border_draw(212, 196, 250, 30, data.focus_button_id == 4);
Expand Down
89 changes: 48 additions & 41 deletions src/window/editor/edit_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ static void button_ignored_disfavor(int param1, int param2);
static void button_delete(int param1, int param2);
static void button_save(int param1, int param2);

static generic_button buttons[] = {
{30, 152, 60, 25, button_year, button_none},
{330, 152, 80, 25, button_amount, button_none},
{430, 152, 100, 25, button_resource, button_none},
{70, 190, 140, 25, button_deadline_years, button_none},
{400, 190, 80, 25, button_favor, button_none},
{400, 230, 80, 25, button_extension_months, button_none},
{400, 270, 80, 25, button_extension_disfavor, button_none},
{400, 310, 80, 25, button_ignored_disfavor, button_none},
{10, 350, 250, 25, button_delete, button_none},
{300, 350, 100, 25, button_save, button_none}
};

static struct {
int id;
scenario_request request;
unsigned int focus_button_id;
resource_type avaialble_resources[RESOURCE_MAX];
} data;

static generic_button buttons[] = {
{30, 186, 60, 25, button_year, button_none},
{330, 186, 80, 25, button_amount, button_none},
{430, 186, 100, 25, button_resource, button_none},
{70, 224, 140, 25, button_deadline_years, button_none},
{400, 224, 80, 25, button_favor, button_none},
{400, 264, 80, 25, button_extension_months, button_none},
{400, 304, 80, 25, button_extension_disfavor, button_none},
{400, 344, 80, 25, button_ignored_disfavor, button_none},
{110, 384, 250, 25, button_delete, button_none},
{400, 384, 100, 25, button_save, button_none}
};

static void init(int id)
{
data.id = id;
Expand All @@ -66,44 +66,51 @@ static void draw_foreground(void)
graphics_in_dialog();

outer_panel_draw(0, 100, 38, 20);
lang_text_draw(44, 21, 14, 114, FONT_LARGE_BLACK);
lang_text_draw_centered(44, 21, 14, 114, 580, FONT_LARGE_BLACK);

int width = text_get_number_width(data.request.id, 0, "", FONT_NORMAL_BLACK);
width += lang_text_get_width(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_EVENT_ID, FONT_NORMAL_BLACK);
int base_x = (580 - width) / 2 + 14;

width = lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_SCENARIO_EVENT_ID, base_x, 154, FONT_NORMAL_BLACK);
text_draw_number(data.request.id, 0, "", base_x + width, 154, FONT_NORMAL_BLACK, 0);

button_border_draw(30, 152, 60, 25, data.focus_button_id == 1);
text_draw_number_centered_prefix(data.request.year, '+', 30, 158, 60, FONT_NORMAL_BLACK);
lang_text_draw_year(scenario_property_start_year() + data.request.year, 110, 158, FONT_NORMAL_BLACK);
button_border_draw(30, 186, 60, 25, data.focus_button_id == 1);
text_draw_number_centered_prefix(data.request.year, '+', 30, 192, 60, FONT_NORMAL_BLACK);
lang_text_draw_year(scenario_property_start_year() + data.request.year, 110, 192, FONT_NORMAL_BLACK);

lang_text_draw(44, 72, 250, 158, FONT_NORMAL_BLACK);
button_border_draw(330, 152, 80, 25, data.focus_button_id == 2);
text_draw_number_centered(data.request.amount, 330, 158, 80, FONT_NORMAL_BLACK);
lang_text_draw(44, 72, 250, 192, FONT_NORMAL_BLACK);
button_border_draw(330, 186, 80, 25, data.focus_button_id == 2);
text_draw_number_centered(data.request.amount, 330, 192, 80, FONT_NORMAL_BLACK);

button_border_draw(430, 152, 100, 25, data.focus_button_id == 3);
text_draw_centered(resource_get_data(data.request.resource)->text, 430, 158, 100, FONT_NORMAL_BLACK, COLOR_MASK_NONE);
button_border_draw(430, 186, 100, 25, data.focus_button_id == 3);
text_draw_centered(resource_get_data(data.request.resource)->text, 430, 192, 100, FONT_NORMAL_BLACK, COLOR_MASK_NONE);

lang_text_draw(44, 24, 40, 196, FONT_NORMAL_BLACK);
button_border_draw(70, 190, 140, 25, data.focus_button_id == 4);
lang_text_draw_amount(8, 8, data.request.deadline_years, 80, 196, FONT_NORMAL_BLACK);
lang_text_draw(44, 24, 40, 230, FONT_NORMAL_BLACK);
button_border_draw(70, 224, 140, 25, data.focus_button_id == 4);
lang_text_draw_amount(8, 8, data.request.deadline_years, 80, 230, FONT_NORMAL_BLACK);

lang_text_draw(44, 73, 300, 196, FONT_NORMAL_BLACK);
button_border_draw(400, 190, 80, 25, data.focus_button_id == 5);
text_draw_number_centered_prefix(data.request.favor, '+', 400, 196, 80, FONT_NORMAL_BLACK);
lang_text_draw(44, 73, 300, 230, FONT_NORMAL_BLACK);
button_border_draw(400, 224, 80, 25, data.focus_button_id == 5);
text_draw_number_centered_prefix(data.request.favor, '+', 400, 230, 80, FONT_NORMAL_BLACK);

lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_FAVOUR_EXTENSION_MONTHS, 70, 236, FONT_NORMAL_BLACK);
button_border_draw(400, 230, 80, 25, data.focus_button_id == 6);
text_draw_number_centered_prefix(data.request.extension_months_to_comply, '+', 400, 236, 80, FONT_NORMAL_BLACK);
lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_FAVOUR_EXTENSION_MONTHS, 70, 270, FONT_NORMAL_BLACK);
button_border_draw(400, 264, 80, 25, data.focus_button_id == 6);
text_draw_number_centered_prefix(data.request.extension_months_to_comply, '+', 400, 270, 80, FONT_NORMAL_BLACK);

lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_FAVOUR_DISFAVOR, 70, 276, FONT_NORMAL_BLACK);
button_border_draw(400, 270, 80, 25, data.focus_button_id == 7);
text_draw_number_centered_prefix(data.request.extension_disfavor, '-', 400, 276, 80, FONT_NORMAL_BLACK);
lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_FAVOUR_DISFAVOR, 70, 310, FONT_NORMAL_BLACK);
button_border_draw(400, 304, 80, 25, data.focus_button_id == 7);
text_draw_number_centered_prefix(data.request.extension_disfavor, '-', 400, 310, 80, FONT_NORMAL_BLACK);

lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_FAVOUR_IGNORED, 70, 316, FONT_NORMAL_BLACK);
button_border_draw(400, 310, 80, 25, data.focus_button_id == 8);
text_draw_number_centered_prefix(data.request.ignored_disfavor, '-', 400, 316, 80, FONT_NORMAL_BLACK);
lang_text_draw(CUSTOM_TRANSLATION, TR_EDITOR_FAVOUR_IGNORED, 70, 350, FONT_NORMAL_BLACK);
button_border_draw(400, 344, 80, 25, data.focus_button_id == 8);
text_draw_number_centered_prefix(data.request.ignored_disfavor, '-', 400, 350, 80, FONT_NORMAL_BLACK);

button_border_draw(300, 350, 100, 25, data.focus_button_id == 10);
lang_text_draw_centered(18, 3, 300, 356, 100, FONT_NORMAL_BLACK);
button_border_draw(400, 384, 100, 25, data.focus_button_id == 10);
lang_text_draw_centered(18, 3, 400, 390, 100, FONT_NORMAL_BLACK);

button_border_draw(10, 350, 250, 25, data.focus_button_id == 9);
lang_text_draw_centered(44, 25, 10, 356, 250, FONT_NORMAL_BLACK);
button_border_draw(110, 384, 250, 25, data.focus_button_id == 9);
lang_text_draw_centered(44, 25, 110, 390, 250, FONT_NORMAL_BLACK);

graphics_reset_dialog();
}
Expand Down
Loading

0 comments on commit d7033d2

Please sign in to comment.