Minor changements

This commit is contained in:
Shadow15510 2022-06-24 13:06:30 +02:00
parent 70bce561ba
commit 7a0e19c00c
4 changed files with 53 additions and 16 deletions

View File

@ -68,6 +68,7 @@ struct camera
int cursor_x, cursor_y;
int cursor_size[2];
int display_name;
};

View File

@ -4,6 +4,7 @@
#include <gint/timer.h>
#include <gint/clock.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "core.h"
@ -189,11 +190,12 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
display_main(calccity, camera, map, 1);
if (build_mode >= 0)
{
char building_data[50];
sprintf(building_data, "%s:%d$", building.name, building.cost);
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);
dsize(building_data, NULL, &width, NULL);
drect(4, 6, 5 + width, 11, C_WHITE);
dprint_opt(5, 7, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, building_data);
}
dupdate();
@ -233,6 +235,9 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
if (build_mode >= 0)
{
if (camera->display_name)
camera->display_name = 0;
// Build annulation
if (key == KEY_ALPHA)
exit_build_mode(camera, &build_mode);
@ -283,6 +288,10 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map
}
}
// Exit build mode
if (build_mode != -1)
exit_build_mode(camera, &build_mode);
// Free timer
if (t >= 0) timer_stop(t);
}
@ -330,8 +339,14 @@ void keyboard_managment(struct camera *camera, const int key, const int build_mo
if (camera->x > 35) camera->x = 35;
if (camera->y > 43) camera->y = 43;
camera->zoom = 1;
camera->display_name = 0;
}
break;
case KEY_OPTN:
if (!camera->zoom)
camera->display_name = (camera->display_name + 1) % 2;
break;
}
}
@ -488,22 +503,22 @@ void update_stat(struct calccity *calccity, struct map *map)
// FUNDS : health
case 1:
calccity->stat[i] += floor(building.stat[i] * ((float)calccity->funds[3] / 100));
calccity->stat[i] += floor((building.stat[i] * calccity->funds[3]) / 100);
break;
// FUNDS : crime
case 6:
calccity->stat[i] += floor(building.stat[i] * ((float)calccity->funds[0] / 100));
calccity->stat[i] += floor((building.stat[i] * calccity->funds[0]) / 100);
break;
// FUNDS : firehazard
case 7:
calccity->stat[i] += floor(building.stat[i] * ((float)calccity->funds[1] / 100));
calccity->stat[i] += floor((building.stat[i] * calccity->funds[1]) / 100);
break;
// FUNDS : education
case 2:
calccity->stat[i] += floor(building.stat[i] * ((float)calccity->funds[2] / 100));
calccity->stat[i] += floor((building.stat[i] * calccity->funds[2]) / 100);
break;
// special calculation of the annual cost

View File

@ -23,12 +23,12 @@ void display_main(struct calccity *calccity, struct camera *camera, struct map *
if (camera->zoom == 0)
{
display_large_map(calccity, camera, map);
display_around(calccity, camera, disp_cursor);
display_around(calccity, camera, map, disp_cursor);
}
else
{
display_mini_map(camera, map);
display_around(calccity, camera, 0);
display_around(calccity, camera, map, 0);
}
}
@ -92,13 +92,33 @@ void display_mini_map(struct camera *camera, struct map *map)
}
}
void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor)
void display_around(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor)
{
extern const bopti_image_t img_fn_keys;
extern const struct building buildings[42];
// Date in the top-left corner and treasure
char up_data[25];
sprintf(up_data, "%d-%d %d$", calccity->month, calccity->year, calccity->misc[0]);
// Informations on top-left corner (time, treasure, building under cursor)
if (camera->display_name)
{
char id;
unsigned short loc_x = floor(camera->x + camera->cursor_x / 2);
unsigned short loc_y = floor(camera->y + camera->cursor_y / 2);
if (map->id[loc_y][loc_x] == -1)
id = get_reference_id(map->data[loc_y][loc_x]);
else
id = map->id[loc_y][loc_x];
char building_data[50];
sprintf(building_data, "%s", buildings[id].name);
int width;
dsize(building_data, NULL, &width, NULL);
drect(4, 6, 5 + width, 11, C_WHITE);
dprint_opt(5, 7, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, building_data);
}
char up_data[50];
sprintf(up_data, "%d-%d %d$", calccity->month, calccity->year, calccity->misc[0]);
int width;
dsize(up_data, NULL, &width, NULL);
drect(4, 1, 5 + width, 6, C_WHITE);
@ -119,7 +139,8 @@ void display_around(struct calccity *calccity, struct camera *camera, const int
if (camera->cursor_size[0] > 8 && camera->cursor_size[1] > 8)
{
unsigned short x = camera->cursor_size[0] * floor(camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1)) + 3;
unsigned short y = camera->cursor_size[1] * floor(camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
unsigned short y = camera->cursor_size[0] * floor(camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1));
drect_border(x, y, x + camera->cursor_size[0], y + camera->cursor_size[1], C_NONE, 1, C_BLACK);
}

View File

@ -17,7 +17,7 @@ void display_large_map(struct calccity *calccity, struct camera *camera, struct
void display_mini_map(struct camera *camera, struct map *map);
// display_around : display the screen frame and cursor
void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor);
void display_around(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor);
// display_message : display the given message with lines breaks
void display_message(char* message);