Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to file dialog window #629

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ set(GAME_FILES
${PROJECT_SOURCE_DIR}/src/game/file.c
${PROJECT_SOURCE_DIR}/src/game/file_editor.c
${PROJECT_SOURCE_DIR}/src/game/file_io.c
${PROJECT_SOURCE_DIR}/src/game/file_minimap.c
${PROJECT_SOURCE_DIR}/src/game/game.c
${PROJECT_SOURCE_DIR}/src/game/mission.c
${PROJECT_SOURCE_DIR}/src/game/orientation.c
Expand Down Expand Up @@ -465,7 +466,6 @@ set(WIDGET_FILES
${PROJECT_SOURCE_DIR}/src/widget/map_editor.c
${PROJECT_SOURCE_DIR}/src/widget/map_editor_tool.c
${PROJECT_SOURCE_DIR}/src/widget/minimap.c
${PROJECT_SOURCE_DIR}/src/widget/scenario_minimap.c
${PROJECT_SOURCE_DIR}/src/widget/top_menu.c
${PROJECT_SOURCE_DIR}/src/widget/top_menu_editor.c
${PROJECT_SOURCE_DIR}/src/widget/sidebar/city.c
Expand Down
6 changes: 6 additions & 0 deletions src/building/building.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ building *building_get(int id)
return &all_buildings[id];
}

void building_get_from_buffer(buffer *buf, int id, building *b)
{
buffer_set(buf, 128 * id);
building_state_load_from_buffer(buf, b);
}

building *building_main(building *b)
{
for (int guard = 0; guard < 9; guard++) {
Expand Down
2 changes: 2 additions & 0 deletions src/building/building.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ typedef struct {

building *building_get(int id);

void building_get_from_buffer(buffer *buf, int id, building *b);

building *building_main(building *b);

building *building_next(building *b);
Expand Down
8 changes: 8 additions & 0 deletions src/city/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,11 @@ void city_data_load_state(buffer *main, buffer *faction, buffer *faction_unknown

load_entry_exit(entry_exit_xy, entry_exit_grid_offset);
}

void city_data_load_basic_info(buffer *main, int *population, int *treasury)
{
buffer_skip(main, 18080);
*treasury = buffer_read_i32(main);
buffer_skip(main, 20);
*population = buffer_read_i32(main);
}
2 changes: 2 additions & 0 deletions src/city/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ void city_data_save_state(buffer *main, buffer *faction, buffer *faction_unknown
void city_data_load_state(buffer *main, buffer *faction, buffer *faction_unknown, buffer *graph_order,
buffer *entry_exit_xy, buffer *entry_exit_grid_offset);

void city_data_load_basic_info(buffer *main, int *population, int *treasury);

#endif // CITY_DATA_H
32 changes: 32 additions & 0 deletions src/city/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "map/image.h"
#include "widget/minimap.h"

#include <string.h>

#define TILE_WIDTH_PIXELS 60
#define TILE_HEIGHT_PIXELS 30
#define HALF_TILE_WIDTH_PIXELS 30
Expand Down Expand Up @@ -172,6 +174,36 @@ void city_view_reset_orientation(void)
calculate_lookup();
}

void city_view_set_custom_lookup(int start_offset, int width, int height, int border_size)
{
reset_lookup();

int start_x = border_size / 2;
int end_x = GRID_SIZE - start_x;
int start_y = (start_offset - start_x) / GRID_SIZE;
int end_y = start_y + height;

int x_view_start = VIEW_X_MAX - 1 - start_y;
int y_view_start = 1 + start_y;

for (int y = start_y; y < end_y; y++) {
int x_view = x_view_start + start_x;
int y_view = y_view_start + start_x;
for (int x = start_x; x < end_x; x++) {
view_to_grid_offset_lookup[x_view / 2][y_view] = x + GRID_SIZE * y;
x_view++;
y_view++;
}
x_view_start--;
y_view_start++;
}
}

void city_view_restore_lookup(void)
{
calculate_lookup();
}

void city_view_get_camera(int *x, int *y)
{
*x = data.camera.tile.x;
Expand Down
3 changes: 3 additions & 0 deletions src/city/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ int city_view_orientation(void);

void city_view_reset_orientation(void);

void city_view_set_custom_lookup(int start_offset, int width, int height, int border_size);
void city_view_restore_lookup(void);

void city_view_get_camera(int *x, int *y);
void city_view_get_camera_absolute(int *x_abs, int *y_abs);
void city_view_get_pixel_offset(int *x, int *y);
Expand Down
44 changes: 24 additions & 20 deletions src/game/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,40 @@ static void initialize_scenario_data(const uint8_t *scenario_name)
game_state_unpause();
}

static void load_empire_data(int is_custom_scenario, int empire_id)
{
empire_load(is_custom_scenario, empire_id);
scenario_distant_battle_set_roman_travel_months();
scenario_distant_battle_set_enemy_travel_months();
}

static int load_scenario_data(const char *scenario_file)
{
if (!game_file_io_read_scenario(scenario_file)) {
return 0;
}

trade_prices_reset();
load_empire_data(1, scenario_empire_id());
city_view_reset_orientation();
return 1;
}


static int load_custom_scenario(const uint8_t *scenario_name, const char *scenario_file)
{
if (!file_exists(scenario_file, NOT_LOCALIZED)) {
return 0;
}

clear_scenario_data();
game_file_load_scenario_data(scenario_file);
if (!load_scenario_data(scenario_file)) {
return 0;
}
initialize_scenario_data(scenario_name);
return 1;
}

static void load_empire_data(int is_custom_scenario, int empire_id)
{
empire_load(is_custom_scenario, empire_id);
scenario_distant_battle_set_roman_travel_months();
scenario_distant_battle_set_enemy_travel_months();
}

static void initialize_saved_game(void)
{
load_empire_data(scenario_is_custom(), scenario_empire_id());
Expand Down Expand Up @@ -332,21 +347,10 @@ int game_file_start_scenario(const char *scenario_file)
uint8_t scenario_name[FILE_NAME_MAX];
encoding_from_utf8(scenario_file, scenario_name, FILE_NAME_MAX);
file_remove_extension(scenario_name);
scenario_set_custom(2);
return start_scenario(scenario_name, scenario_file);
}

int game_file_load_scenario_data(const char *scenario_file)
{
if (!game_file_io_read_scenario(scenario_file)) {
return 0;
}

trade_prices_reset();
load_empire_data(1, scenario_empire_id());
city_view_reset_orientation();
return 1;
}

int game_file_load_saved_game(const char *filename)
{
if (!game_file_io_read_saved_game(filename, 0)) {
Expand Down
7 changes: 0 additions & 7 deletions src/game/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ int game_file_start_scenario_by_name(const uint8_t *scenario_name);
*/
int game_file_start_scenario(const char *scenario_file);

/**
* Load scenario data only, without starting it
* @param scenario_file File to load
* @return Boolean true on success, false on failure
*/
int game_file_load_scenario_data(const char *scenario_file);

/**
* Load saved game
* @param filename File to load
Expand Down
Loading
Loading