Improve UI and add detection of large buildings

This commit is contained in:
Shadow15510 2022-02-06 10:22:25 +01:00
parent 9dc5edeb3d
commit 2dc0988041
7 changed files with 120 additions and 32 deletions

View File

@ -8,4 +8,4 @@ calccity.png:
charset: print
grid.size: 5x6
grid.padding: 1
proportional: True
proportional: true

View File

@ -359,8 +359,8 @@ const struct building buildings[42] = {
// Others buildings
{
(char []){5, 6, 15, 56, -1},
0,
(char []){5, 6, 15, 16, -1},
200,
{2, 2},
{10000, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 150, 0, 0, 0, 0},
{0, 0, 0},
@ -370,7 +370,7 @@ const struct building buildings[42] = {
{
(char []){7, 8, 17, 18, -1},
0,
150,
{2, 2},
{0, 0, 0, 0, 5000, 0, 0, 30, 0, 0, 10000, 0, 0, 0, 0, 0, 100, 0, 300, 0, 0, 0, 0},
{-25, 0, 0},
@ -380,7 +380,7 @@ const struct building buildings[42] = {
{
(char []){30, 31, 40, 41, -1},
0,
400,
{2, 2},
{0, -200, 0, 0, 5000, 0, 0, 80, 0, 1000, 0, 5000, 5000, 0, 0, 0, 50, 0, 400, 0, 0, 0, 0},
{0, -6, 0},
@ -390,7 +390,7 @@ const struct building buildings[42] = {
{
(char []){26, 27, 36, 37, -1},
0,
250,
{2, 2},
{0, 0, 0, 0, 150, 0, -20000, 1, 0, 3, 0, 0, 0, 0, 0, 0, 20, 0, 110, 0, 0, 0, 0},
{0, 0, 0},
@ -400,7 +400,7 @@ const struct building buildings[42] = {
{
(char []){22, 23, 32, 33, -1},
0,
250,
{2, 2},
{0, 0, 0, 0, 150, 0, 0, -50000, 0, 1, 0, 0, 0, 0, 0, 0, 20, 0, 110, 0, 0, 0, 0},
{0, 0, 0},
@ -410,7 +410,7 @@ const struct building buildings[42] = {
{
(char []){24, 25, 34, 35, -1},
0,
250,
{2, 2},
{0, 50000, 0, 0, 250, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 100, 0, 0, 0, 0},
{0, 0, 0},

View File

@ -153,6 +153,8 @@ void next_step(struct calccity *calccity, struct map *map)
calccity->year ++;
}
}
// Disasters gestion soon™
}
@ -178,14 +180,17 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
display_main(calccity, camera, map, 1);
if (build_mode >= 0)
{
dprint_opt(4, 7, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "$%d", building.cost);
dprint_opt(4, 13, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%s", building.name);
int width;
dsize(building.name, NULL, &width, NULL);
drect(4, 6, 5 + width, 17, C_WHITE);
dprint_opt(5, 7, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "$%d", building.cost);
dprint_opt(5, 13, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%s", building.name);
}
dupdate();
// Get and manage input
key = rtc_key();
keyboard_managment(camera, key);
keyboard_managment(camera, key, build_mode);
// Menu gestion
switch (key)
@ -228,6 +233,18 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
{
unsigned short loc_x = building.size[0] * floor(camera->x + camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1));
unsigned short loc_y = building.size[1] * floor(camera->y + camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
if (build_mode == 5 || build_mode == 8 || build_mode == 11 || build_mode == 27 || build_mode == 28 || build_mode == 29)
{
building = large_building(map, build_mode, &loc_x, &loc_y);
for (int y = loc_y; y < loc_y + building.size[1]; y ++)
{
for (int x = loc_x; x < loc_x + building.size[0]; x ++)
map->id[y][x] = 0;
}
update_stat(calccity, map);
}
unsigned char index = 0;
for (int y = loc_y; y < loc_y + building.size[1]; y ++)
{
@ -250,7 +267,7 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
}
void keyboard_managment(struct camera *camera, const int key)
void keyboard_managment(struct camera *camera, const int key, const int build_mode)
{
switch (key)
{
@ -287,9 +304,12 @@ void keyboard_managment(struct camera *camera, const int key)
break;
case KEY_MINUS:
if (camera->x > 35) camera->x = 35;
if (camera->y > 43) camera->y = 43;
camera->zoom = 1;
if (build_mode == -1)
{
if (camera->x > 35) camera->x = 35;
if (camera->y > 43) camera->y = 43;
camera->zoom = 1;
}
break;
}
}
@ -341,22 +361,57 @@ void exit_build_mode(struct camera *camera, int *build_mode)
}
/*struct building get_building(const int id)
struct building large_building(struct map *map, const int build_mode, short unsigned int *loc_x, short unsigned int *loc_y)
{
extern const struct building buildings[42];
for (int i = 0; i < 42; i ++)
const short unsigned int Y[16] = {*loc_y - 1, *loc_y - 1, *loc_y, *loc_y, *loc_y - 1, *loc_y - 1, *loc_y, *loc_y, *loc_y, *loc_y, *loc_y + 1, *loc_y + 1, *loc_y, *loc_y, *loc_y + 1, *loc_y + 1};
const short unsigned int X[16] = {*loc_x - 1, *loc_x, *loc_x - 1, *loc_x, *loc_x, *loc_x + 1, *loc_x, *loc_x + 1, *loc_x - 1, *loc_x, *loc_x - 1, *loc_x, *loc_x, *loc_x + 1, *loc_x, *loc_x + 1};
for (int i = 0; i < 4; i ++)
{
for (int j = 0; buildings[i].id[j] != -1; j ++)
int check = 0;
for (int j = 0; j < 4; j ++)
{
if (buildings[i].id[j] == id)
return buildings[i];
short unsigned int y = Y[4 * i + j];
short unsigned int x = X[4 * i + j];
if (map->id[y][x] == build_mode) check ++;
}
if (check == 3)
{
*loc_x = X[4 * i];
*loc_y = Y[4 * i];
switch (build_mode)
{
case 5:
return buildings[35];
break;
case 8:
return buildings[36];
break;
case 11:
return buildings[37];
break;
case 27:
return buildings[38];
break;
case 28:
return buildings[39];
break;
case 29:
return buildings[40];
break;
}
}
}
struct building building = {0};
return building;
}*/
return buildings[build_mode];
}
void update_stat(struct calccity *calccity, struct map *map)

View File

@ -21,7 +21,7 @@ void next_step(struct calccity *calccity, struct map *map);
void main_loop(struct calccity *calccity, struct camera *camera, struct map *map);
// keyboard_managment : get the key, manage input and open menus
void keyboard_managment(struct camera *camera, const int key);
void keyboard_managment(struct camera *camera, const int key, const int build_mode);
// can_build : test if the build is legit
bool can_build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building);
@ -29,6 +29,9 @@ bool can_build(struct calccity *calccity, struct camera *camera, struct map *map
// exit_build_mode : reset build mode and cusor
void exit_build_mode(struct camera *camera, int *build_mode);
// large_building : detect large buildings and adjust the building's id
struct building large_building(struct map *map, const int build_mode, short unsigned int *loc_x, short unsigned int *loc_y);
// update_stat : compute the new stat with buildings
void update_stat(struct calccity *calccity, struct map *map);

View File

@ -96,7 +96,7 @@ void display_around(struct calccity *calccity, struct camera *camera, const int
extern const bopti_image_t img_fn_keys;
// Date in the top-left corner
dprint_opt(4, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%d-%d", calccity->month, calccity->year);
dprint_opt(5, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%d-%d", calccity->month, calccity->year);
// Cursor
if (disp_cursor)

View File

@ -5,7 +5,7 @@
#include "menus.h"
struct building menu_12(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode, const int menu)
struct building menu_12(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode, int menu)
{
extern const bopti_image_t img_fn_1;
extern const bopti_image_t img_fn_2;
@ -59,6 +59,33 @@ struct building menu_12(struct calccity *calccity, struct camera *camera, struct
case KEY_SHIFT:
end = 1;
break;
case KEY_F1:
menu = 1;
x = 0;
y = 0;
break;
case KEY_F2:
menu = 2;
x = 0;
y = 0;
break;
case KEY_F4:
menu_4(calccity);
end = 2;
break;
case KEY_F5:
menu_5(calccity);
end = 2;
break;
case KEY_F6:
menu_6(calccity);
end = 2;
break;
}
}
@ -246,10 +273,13 @@ void menu_5(struct calccity *calccity)
if (i + scroll == 0 || i + scroll == 10 || i + scroll == 15 || i + scroll == 22)
{
drect(5, 7 * i + 7, 127, 7 * i + 13, C_BLACK);
dtext(12, 7 * i + 8, C_WHITE, names[i + scroll]);
dtext(20, 7 * i + 8, C_WHITE, names[i + scroll]);
}
else
dprint(7, 7 * i + 8, C_BLACK, "%s %d", names[i + scroll], values[i + scroll]);
{
dprint(7, 7 * i + 8, C_BLACK, "%s", names[i + scroll]);
dprint(60, 7 * i + 8, C_BLACK, "%d", values[i + scroll]);
}
}
dupdate();
@ -307,7 +337,7 @@ int menu_6(struct calccity *calccity)
else
dtext(85, 16, C_BLACK, "off");
dprint(97, 23, C_BLACK, "%d%%", prcnt + 1);
dprint(85, 23, C_BLACK, "%d%%", prcnt + 1);
dtext(2, 9 + choice * 7, C_BLACK, ">");

View File

@ -5,7 +5,7 @@
#include "core.h"
// menu_12 : buildings
struct building menu_12(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode, const int menu);
struct building menu_12(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode, int menu);
// menu_4 : tax and funds
void menu_4(struct calccity *calccity);