Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ set(WIDGET_FILES
${PROJECT_SOURCE_DIR}/src/widget/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/collapsed/sidebar.c
${PROJECT_SOURCE_DIR}/src/widget/sidebar/expanded/sidebar.c
${PROJECT_SOURCE_DIR}/src/widget/sidebar/advanced/sidebar.c
src/widget/sidebar/advanced/advisors/info.c
${PROJECT_SOURCE_DIR}/src/widget/sidebar/city.c
${PROJECT_SOURCE_DIR}/src/widget/sidebar/common.c
${PROJECT_SOURCE_DIR}/src/widget/sidebar/editor.c
Expand Down
57 changes: 19 additions & 38 deletions src/city/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "map/grid.h"
#include "map/image.h"
#include "widget/minimap.h"
#include "widget/sidebar/city.h"

#define TILE_WIDTH_PIXELS 60
#define TILE_HEIGHT_PIXELS 30
Expand All @@ -22,7 +23,6 @@ static const int Y_DIRECTION_FOR_ORIENTATION[] = {1, -1, -1, 1};
static struct {
int screen_width;
int screen_height;
int sidebar_collapsed;
int orientation;
int scale;
struct {
Expand All @@ -43,6 +43,7 @@ static struct {
} selected_tile;
} data;


static int view_to_grid_offset_lookup[VIEW_X_MAX][VIEW_Y_MAX];

static void check_camera_boundaries(void)
Expand Down Expand Up @@ -580,35 +581,28 @@ void city_view_rotate_right(void)
check_camera_boundaries();
}

static void set_viewport(int x_offset, int y_offset, int width, int height)
static void set_viewport(void)
{
data.viewport.x = x_offset;
data.viewport.y = y_offset;
const int sidebar_width = widget_sidebar_city_get_width() - 2;
const int width = data.screen_width - sidebar_width;
const int height = data.screen_height - TOP_MENU_HEIGHT;

data.viewport.x = 0;
data.viewport.y = TOP_MENU_HEIGHT;
data.viewport.width_pixels = width - 2;
data.viewport.height_pixels = height;
data.viewport.height_pixels = data.screen_height - TOP_MENU_HEIGHT;

data.viewport.width_tiles = calc_adjust_with_percentage(width, data.scale) / TILE_WIDTH_PIXELS;
data.viewport.height_tiles = calc_adjust_with_percentage(height, data.scale) / HALF_TILE_HEIGHT_PIXELS;
}

static void set_viewport_with_sidebar(void)
{
set_viewport(0, TOP_MENU_HEIGHT, data.screen_width - 160, data.screen_height - TOP_MENU_HEIGHT);
}

static void set_viewport_without_sidebar(void)
{
set_viewport(0, TOP_MENU_HEIGHT, data.screen_width - 40, data.screen_height - TOP_MENU_HEIGHT);
}

void city_view_set_scale(int scale)
{
scale = calc_bound(scale, 50, city_view_get_max_scale());
data.scale = scale;
if (data.sidebar_collapsed) {
set_viewport_without_sidebar();
} else {
set_viewport_with_sidebar();
}

set_viewport();

check_camera_boundaries();
graphics_renderer()->update_scale(scale);
}
Expand All @@ -617,11 +611,7 @@ void city_view_set_viewport(int screen_width, int screen_height)
{
data.screen_width = screen_width;
data.screen_height = screen_height;
if (data.sidebar_collapsed) {
set_viewport_without_sidebar();
} else {
set_viewport_with_sidebar();
}
set_viewport();
check_camera_boundaries();
}

Expand All @@ -639,26 +629,17 @@ void city_view_get_viewport_size_tiles(int *width, int *height)
*height = data.viewport.height_tiles;
}

int city_view_is_sidebar_collapsed(void)
{
return data.sidebar_collapsed;
}

void city_view_start_sidebar_toggle(void)
{
set_viewport_without_sidebar();
set_viewport();
check_camera_boundaries();
}

void city_view_toggle_sidebar(void)
{
if (data.sidebar_collapsed) {
data.sidebar_collapsed = 0;
set_viewport_with_sidebar();
} else {
data.sidebar_collapsed = 1;
set_viewport_without_sidebar();
}
//data.sidebar_collapsed = !data.sidebar_collapsed;

set_viewport();
check_camera_boundaries();
}

Expand Down
4 changes: 0 additions & 4 deletions src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ int game_init_editor(void)
game_file_editor_clear_data();
game_file_editor_create_scenario(2);

if (city_view_is_sidebar_collapsed()) {
city_view_toggle_sidebar();
}

editor_set_active(1);
window_editor_map_show();
return 1;
Expand Down
16 changes: 16 additions & 0 deletions src/graphics/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "assets/assets.h"
#include "core/image.h"

#include <math.h>

#include "graphics/renderer.h"
#include "graphics/screen.h"

Expand All @@ -28,6 +31,19 @@ void image_draw_silhouette(int image_id, int x, int y, color_t color, float scal

}

void image_draw_scaled_from_corner(const int image_id, const int x, const int y, const color_t color,
const int draw_scale_percent)
{
const float obj_draw_scale = 100.0f / (float)draw_scale_percent;

// The draw_image function divides x and y by scale internally.
// Multiply here to cancel (invert) that effect.
const int inverting_scale_x = (int)lroundf((float)x * obj_draw_scale);
const int inverting_scale_y = (int)lroundf((float)y * obj_draw_scale);

image_draw(image_id, inverting_scale_x, inverting_scale_y, color, obj_draw_scale);
}

void image_draw_scaled_centered(int image_id, int x, int y, color_t color, int draw_scale_percent)
{
float obj_draw_scale = 100.0f / draw_scale_percent;
Expand Down
1 change: 1 addition & 0 deletions src/graphics/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ void image_blend_footprint_color(int x, int y, color_t color, float scale);
void image_draw_isometric_top(int image_id, int x, int y, color_t color_mask, float scale);
void image_draw_isometric_top_from_draw_tile(int image_id, int x, int y, color_t color_mask, float scale);
void image_draw_set_isometric_top_from_draw_tile(int image_id, int x, int y, color_t color_mask, float scale);
void image_draw_scaled_from_corner(int image_id, int x, int y, color_t color, int draw_scale_percent);

#endif // GRAPHICS_IMAGE_H
6 changes: 4 additions & 2 deletions src/graphics/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <string.h>
#include <time.h>

#include "widget/sidebar/city.h"

#define TILE_X_SIZE 60
#define TILE_Y_SIZE 30
#define IMAGE_HEIGHT_CHUNK (TILE_Y_SIZE * 15)
Expand Down Expand Up @@ -300,7 +302,7 @@ static void create_full_city_screenshot(void)
graphics_set_clip_rectangle(0, TOP_MENU_HEIGHT, canvas_width, IMAGE_HEIGHT_CHUNK);
int viewport_x, viewport_y, viewport_width, viewport_height;
city_view_get_viewport(&viewport_x, &viewport_y, &viewport_width, &viewport_height);
city_view_set_viewport(canvas_width + (city_view_is_sidebar_collapsed() ? 42 : 162),
city_view_set_viewport(canvas_width + widget_sidebar_city_get_width(),
IMAGE_HEIGHT_CHUNK + TOP_MENU_HEIGHT);
int current_height = base_height;
while ((size = image_request_rows()) != 0) {
Expand All @@ -325,7 +327,7 @@ static void create_full_city_screenshot(void)
}
current_height += IMAGE_HEIGHT_CHUNK;
}
city_view_set_viewport(viewport_width + (city_view_is_sidebar_collapsed() ? 42 : 162), viewport_height + TOP_MENU_HEIGHT);
city_view_set_viewport(viewport_width + widget_sidebar_city_get_width(), viewport_height + TOP_MENU_HEIGHT);
city_view_set_scale(old_scale);
config_set(CONFIG_UI_DRAW_CLOUD_SHADOWS, draw_cloud_shadows);
graphics_reset_clip_rectangle();
Expand Down
7 changes: 6 additions & 1 deletion src/widget/city.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "city.h"
#include "sidebar/city.h"

#include "building/construction.h"
#include "building/properties.h"
Expand Down Expand Up @@ -185,6 +186,7 @@ static void draw_construction_buttons(void)
city_view_get_viewport(&x, &y, &width, &height);
int x_offset = width - 4 * BLOCK_SIZE;
int y_offset = 40;

if (((sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED) || !mouse_get()->is_touch) && width < 680)
&& game_state_is_paused()) {
y_offset = 100;
Expand All @@ -201,6 +203,7 @@ static void draw_construction_buttons(void)

if ((mouse_get()->is_touch || config_get(CONFIG_UI_ALWAYS_SHOW_ROTATION_BUTTONS)) &&
building_construction_can_rotate()) {

if (!sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED)) {
x_offset = 4 * BLOCK_SIZE + 8;
} else {
Expand Down Expand Up @@ -256,6 +259,7 @@ static int is_rotate_backward_button(int x, int y)
int city_x, city_y, width, height;
city_view_get_viewport(&city_x, &city_y, &width, &height);

//TODO: config
int sidebar_pause_button = sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED);
int x_offset = sidebar_pause_button ? 16 : 4 * BLOCK_SIZE + 4;
int y_offset = sidebar_pause_button && width < 680 && game_state_is_paused() ? 84 : 24;
Expand All @@ -268,6 +272,7 @@ static int is_rotate_forward_button(int x, int y)
int city_x, city_y, width, height;
city_view_get_viewport(&city_x, &city_y, &width, &height);

//TODO: config
int sidebar_pause_button = sidebar_extra_is_information_displayed(SIDEBAR_EXTRA_DISPLAY_GAME_SPEED);
int x_offset = sidebar_pause_button ? 4 * BLOCK_SIZE + 4 : 7 * BLOCK_SIZE + 4;
int y_offset = sidebar_pause_button && width < 680 && game_state_is_paused() ? 84 : 24;
Expand Down Expand Up @@ -715,7 +720,7 @@ void widget_city_handle_input_military(const mouse *m, const hotkeys *h, int leg
{
map_tile *tile = &data.current_tile;
update_city_view_coords(m->x, m->y, tile);
if (!city_view_is_sidebar_collapsed() && widget_minimap_handle_mouse(m)) {
if (!widget_sidebar_is_collapsed() && widget_minimap_handle_mouse(m)) {
return;
}
scroll_map(m);
Expand Down
Loading