diff --git a/CMakeLists.txt b/CMakeLists.txt index 6123a1b..42bf048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ set(SOURCES src/core.c src/display.c src/menus.c + src/calccity.c ) set(ASSETS) diff --git a/src/calccity.c b/src/calccity.c index 9908a5b..6af540a 100644 --- a/src/calccity.c +++ b/src/calccity.c @@ -5,417 +5,417 @@ const struct building buildings[41] = { // Menu 1 { - "TERRE", (unsigned char []){48, 49, 110, 111, 112, 113, 114, 120, 121, 122, 123, 124, 130, 131, 132, 133, 134}, 10, // cost {1, 1}, //size {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // stat {0, 0, 0}, // taxes - {0, 0, 0} // funds + {0, 0, 0}, // funds + "TERRE" }, { - "EAU", (unsigned char []){139}, 15, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "EAU" }, { - "FORET", (unsigned char []){76}, 15, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "FORET" }, { - "HABITATIONS TYPE 1", (unsigned char []){66}, 100, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "MAISONS TYPE 1" }, { - "HABITATIONS TYPE 2", (unsigned char []){67}, 150, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "MAISONS TYPE 2" }, { - "HABITATIONS TYPE 3", (unsigned char []){68}, 200, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "MAISONS TYPE 3" }, { - "BUREAUX TYPE 1", (unsigned char []){45}, 50, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "BUREAUX TYPE 1" }, { - "BUREAUX TYPE 2", (unsigned char []){46}, 100, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "BUREAUX TYPE 2" }, { - "BUREAUX TYPE 3", (unsigned char []){47}, 150, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "BUREAUX TYPE 3" }, { - "USINE TYPE 1", (unsigned char []){54}, 200, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "USINE TYPE 1" }, { - "USINE TYPE 2", (unsigned char []){55}, 300, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "USINE TYPE 2" }, { - "USINE TYPE 3", (unsigned char []){56}, 400, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "USINE TYPE 3" }, { - "FERME TYPE 1", (unsigned char []){9}, 50, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "FERME TYPE 1" }, { - "FERME TYPE 2", (unsigned char []){19}, 75, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "FERME TYPE 2" }, { - "FERME TYPE 3", (unsigned char []){44}, 100, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "FERME TYPE 3" }, // Menu 2 { - "ROUTE", (unsigned char []){80, 81, 82, 83, 90, 91, 92, 93, 100, 101, 102}, 10, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "ROUTE" }, { - "PORT", (unsigned char []){62, 63, 64, 65}, 500, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "PORT" }, { - "AEROPORT", (unsigned char []){0, 1, 2, 12}, 3500, {2, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "AEROPORT" }, { - "RAIL", (unsigned char []){84, 85, 86, 87, 94, 95, 96, 97, 104, 105, 106}, 50, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "RAIL" }, { - "CENTRALE ELECTRIQUE 1", (unsigned char []){71}, 500, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CENTRALE ELECTRIQUE 1" }, { - "CENTRALE ELECTRIQUE 2", (unsigned char []){72}, 1000, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CENTRALE ELECTRIQUE 2" }, { - "CENTALE NUCLEAIRE", (unsigned char []){50, 51, 60, 61}, 25000, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CENTALE NUCLEAIRE" }, { - "INCINERATEUR", (unsigned char []){3, 4, 13, 14}, 2500, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - } + "INCINERATEUR" + }, { - "STATION D'EPURATION", (unsigned char []){77}, 50, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "STATION D'EPURATION" }, { - "TERRAIN DE SPORT", (unsigned char []){78}, 250, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "TERRAIN DE SPORT" }, { - "AIRE DE JEUX", (unsigned char []){69}, 150, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "AIRE DE JEUX" }, { - "STADE", (unsigned char []){42, 43, 52, 53}, 10000, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "STADE" }, { - "CASERNE DE POLICE", (unsigned char []){70}, 250, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CASERNE DE POLICE" }, { - "CASERNE DE POMPIERS", (unsigned char []){58}, 250, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CASERNE DE POMPIERS" }, { - "HOPITAL", (unsigned char []){59}, 250, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "HOPITAL" }, { - "CENTRE ECOLOGIQUE", (unsigned char []){75}, 2500, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CENTRE ECOLOGIQUE" }, { - "ECOLE TYPE 1", (unsigned char []){73}, 250, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "ECOLE TYPE 1" }, { - "ECOLE TYPE 2", (unsigned char []){74}, 500, {1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "ECOLE TYPE 2" }, { - "UNIVERSITE", (unsigned char []){28, 29, 38, 39}, 2500, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "UNIVERSITE" }, { - "EGLISE ET CIMETIERE", (unsigned char []){10, 11, 20, 21}, 2500, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "EGLISE ET CIMETIERE" }, // Others buildings { - "IMMEUBLE"; (unsigned char []){5, 6, 15, 56}, 0, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - } + "IMMEUBLE" + }, { - "TOUR DE BUREAUX", (unsigned char []){7, 8, 17, 18}, 0, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "TOUR DE BUREAUX" }, { - "USINE", (unsigned char []){30, 31, 40, 41}, 0, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "USINE" }, { - "CASERNE DE POLICE", (unsigned char []){26, 27, 36, 37}, 0, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CASERNE DE POLICE" }, { - "CASERNE DE POMPIERS", (unsigned char []){22, 23, 32, 33}, 0, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "CASERNE DE POMPIERS" }, { - "HOPITAL", (unsigned char []){24, 25, 34, 35}, 0, {2, 2}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0}, - {0, 0, 0} + {0, 0, 0}, + "HOPITAL" }, }; \ No newline at end of file diff --git a/src/calccity.h b/src/calccity.h index 45f759c..9d26076 100644 --- a/src/calccity.h +++ b/src/calccity.h @@ -75,11 +75,9 @@ struct map struct building -{ - char *name; - +{ unsigned char *id; - int cost; + long unsigned int cost; unsigned char size[2]; /* @@ -116,11 +114,12 @@ struct building // police, firemen, education, heathcare unsigned int funds[4]; + char *name; }; #define ENGINE_TICK 100 -static const struct building buildings[41]; +extern const struct building buildings[41]; #endif /* _CALCCITY_H */ \ No newline at end of file diff --git a/src/core.c b/src/core.c index c3c4902..10c834d 100644 --- a/src/core.c +++ b/src/core.c @@ -153,7 +153,8 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick)); if (t >= 0) timer_start(t); - int end = 0, key = 0; + struct building building = {0}; + int end = 0, key = 0, build_mode = 0; while (!end) { @@ -161,15 +162,73 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map while (!tick) sleep(); tick = 0; - next_step(calccity); + if (!build_mode) next_step(calccity); dclear(C_WHITE); - main_display(calccity, camera, map, 1); + display_main(calccity, camera, map, 1); + if (build_mode) + { + 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); + } dupdate(); // Get and manage input key = rtc_key(); - end = keyboard_managment(calccity, camera, map, key); + end = keyboard_managment(camera, key); + + // Menu gestion + switch (key) + { + case KEY_F1: case KEY_F2: + exit_build_mode(camera, &build_mode); + + if (key == KEY_F1) building = menu_12(calccity, camera, map, &build_mode, 1); + if (key == KEY_F2) building = menu_12(calccity, camera, map, &build_mode, 2); + if (build_mode) + { + camera->cursor_size[0] = building.size[0] * 15; + camera->cursor_size[1] = building.size[1] * 15; + } + break; + + case KEY_F4: + menu_4(calccity); + break; + + case KEY_F5: + menu_5(calccity); + break; + + case KEY_F6: + end = menu_6(calccity); + break; + } + + if (build_mode) + { + // Build annulation + if (key == KEY_ALPHA) + exit_build_mode(camera, &build_mode); + + // Build validation + if (key == KEY_SHIFT && can_build(calccity, camera, map, &building)) + { + unsigned short loc_x = building.size[0] * floor(camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1)); + unsigned short loc_y = building.size[1] * floor(camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1)); + int index = 0; + 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->data[y][x] = building.id[index]; + index ++; + } + } + calccity->misc[0] -= building.cost; + } + + } } // Free timer @@ -177,7 +236,7 @@ void main_loop(struct calccity *calccity, struct camera *camera, struct map *map } -int keyboard_managment(struct calccity *calccity, struct camera *camera, struct map *map, const int key) +int keyboard_managment(struct camera *camera, const int key) { int end = 0; @@ -189,12 +248,12 @@ int keyboard_managment(struct calccity *calccity, struct camera *camera, struct break; case KEY_RIGHT: - if (camera->cursor_x < floor(120 / camera->cursor_size[0]) - 1) camera->cursor_x ++; + if (camera->cursor_x < 14) camera->cursor_x ++; else if (camera->x < 42) camera->x ++; break; case KEY_DOWN: - if (camera->cursor_y < floor(57 / camera->cursor_size[1]) - 1) camera->cursor_y ++; + if (camera->cursor_y < 6) camera->cursor_y ++; else if (camera->y < 46) camera->y ++; break; @@ -202,101 +261,52 @@ int keyboard_managment(struct calccity *calccity, struct camera *camera, struct if (camera->cursor_x > 0) camera->cursor_x --; else if (camera->x > 0) camera->x --; break; - - case KEY_F1: - int build_mode = 0; - struct building selected_building = menu_1(calccity, camera, map, &build_mode); - - if (build_mode == 1) - build(calccity, camera, map, &selected_building); - break; - - case KEY_F2: - break; - - case KEY_F4: - menu_4(calccity); - break; - - case KEY_F5: - menu_5(calccity); - break; - - case KEY_F6: - end = menu_6(calccity); - break; } return end; } -void build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building) +bool can_build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building) { - // Timer initialisation - static volatile int tick = 1; - int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick)); - if (t >= 0) timer_start(t); + unsigned short loc_x = building->size[0] * floor(camera->cursor_x / (floor(camera->cursor_size[0] / 8) + 1)); + unsigned short loc_y = building->size[1] * floor(camera->cursor_y / (floor(camera->cursor_size[1] / 8) + 1)); - // Adjust cursor size - camera->cursor_size[0] = building->size[0] * 15; - camera->cursor_size[1] = building->size[1] * 15; - camera->cursor_x = 1; - camera->cursor_y = 1; - - int key = 0, end = 0; - - while (!end) + // Not enougth money + if (calccity->misc[0] < building->cost) { - // Real-time clock system - while (!tick) sleep(); - tick = 0; + display_message("VOUS N'AVEZ PAS ASSEZ D'ARGENT POUR CONSTRUIRE."); + return false; + } - next_step(calccity); - dclear(C_WHITE); - main_display(calccity, camera, map, 1); + for (int y = loc_y; y < loc_y + building->size[1]; y ++) + { + for (int x = loc_x; x < loc_x + building->size[0]; x ++) + { + // Build on water + if (map->data[y][x] == 139) + { + display_message("VOUS NE POUVEZ PAS CONSTRUIRE SUR L'EAU."); + return false; + } - dprint_opt(4, 7, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "$%d %d,%d", building->cost, building->size[0], building->size[1]); - dprint_opt(4, 13, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%s", building->name); - dupdate(); + // Build on another building + if (map->data[y][x] != 48 && map->data[y][x] != 49 && map->data[y][x] < 110) + { + display_message("VOUS NE POUVEZ PAS CONSTRUIRE SUR BATIMENT EXISTANT."); + return false; + } - key = rtc_key(); - switch (key) - { - case KEY_UP: - if (camera->cursor_y > 0) camera->cursor_y --; - else if (camera->y > 0) camera->y --; - break; - - case KEY_RIGHT: - if (camera->cursor_x < floor(120 / camera->cursor_size[0]) - 1) camera->cursor_x ++; - else if (camera->x < 42) camera->x ++; - break; - - case KEY_DOWN: - if (camera->cursor_y < floor(57 / camera->cursor_size[1]) - 1) camera->cursor_y ++; - else if (camera->y < 46) camera->y ++; - break; - - case KEY_LEFT: - if (camera->cursor_x > 0) camera->cursor_x --; - else if (camera->x > 0) camera->x --; - break; - - case KEY_ALPHA: - end = 1; - break; - - case KEY_SHIFT: - end = 1; - break; } } - if (t >= 0) timer_stop(t); + return true; +} + +void exit_build_mode(struct camera *camera, int *build_mode) +{ + *build_mode = 0; camera->cursor_size[0] = 8; camera->cursor_size[1] = 8; - camera->cursor_x = 1; - camera->cursor_y = 1; } \ No newline at end of file diff --git a/src/core.h b/src/core.h index 8d33b79..0c78355 100644 --- a/src/core.h +++ b/src/core.h @@ -21,9 +21,12 @@ void next_step(struct calccity *calccity); void main_loop(struct calccity *calccity, struct camera *camera, struct map *map); // keyboard_managment : get the key, manage input and open menus -int keyboard_managment(struct calccity *calccity, struct camera *camera, struct map *map, const int key); +int keyboard_managment(struct camera *camera, const int key); -// build : manage the build -void build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building); +// can_build : test if the build is legit +bool can_build(struct calccity *calccity, struct camera *camera, struct map *map, struct building *building); + +// exit_build_mode : reset build mode and cusor +void exit_build_mode(struct camera *camera, int *build_mode); #endif /* _CORE_H */ \ No newline at end of file diff --git a/src/display.c b/src/display.c index 0b1d6c6..b72f820 100644 --- a/src/display.c +++ b/src/display.c @@ -16,7 +16,7 @@ void title_screen(void) } -void main_display(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor) +void display_main(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor) { // Display map display_large_map(calccity, camera, map); @@ -55,6 +55,30 @@ 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); + + // Cursor + if (disp_cursor) + { + + int offset_x = floor(camera->cursor_x / 2); + int offset_y = floor(camera->cursor_y / 2); + + drect_border(8 * camera->cursor_x - offset_x + 3, 8 * camera->cursor_y - offset_y, 8 * (camera->cursor_x + 1) - offset_x + 3, 8 * (camera->cursor_y + 1) - offset_y , C_WHITE, 1, C_BLACK); + + dline(8 * camera->cursor_x - offset_x + 6, 8 * camera->cursor_y - offset_y + 4, 8 * camera->cursor_x - offset_x + 8, 8 * camera->cursor_y - offset_y + 4, C_BLACK); + dline(8 * camera->cursor_x - offset_x + 7, 8 * camera->cursor_y - offset_y + 3, 8 * camera->cursor_x - offset_x + 7, 8 * camera->cursor_y - offset_y + 5, C_BLACK); + + 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)); + drect_border(x, y, x + camera->cursor_size[0], y + camera->cursor_size[1], C_NONE, 1, C_BLACK); + } + + } + // Functions keys dimage(3, 57, &img_fn_keys); @@ -63,18 +87,40 @@ void display_around(struct calccity *calccity, struct camera *camera, const int dline(3, 56, 123, 56, C_BLACK); dline(3, 0, 3, 56, C_BLACK); dline(123, 0, 123, 56, C_BLACK); - - // Date in the top-left corner - dprint_opt(4, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "%d-%d", calccity->month, calccity->year); - - // Cursor - if (disp_cursor) - { - int middle_x = floor(camera->cursor_size[0] / 2) + 3; - int middle_y = floor(camera->cursor_size[1] / 2); - drect_border(camera->cursor_size[0] * camera->cursor_x + 3, camera->cursor_size[1] * camera->cursor_y, camera->cursor_size[0] * camera->cursor_x + 3 + camera->cursor_size[0], camera->cursor_size[1] * camera->cursor_y + camera->cursor_size[1], C_WHITE, 1, C_BLACK); - dline(camera->cursor_size[0] * camera->cursor_x + middle_x - 1, camera->cursor_size[1] * camera->cursor_y + middle_y , camera->cursor_size[0] * camera->cursor_x + middle_x + 1, camera->cursor_size[1] * camera->cursor_y + middle_y , C_BLACK); - dline(camera->cursor_size[0] * camera->cursor_x + middle_x , camera->cursor_size[1] * camera->cursor_y + middle_y - 1, camera->cursor_size[0] * camera->cursor_x + middle_x , camera->cursor_size[1] * camera->cursor_y + middle_y + 1, C_BLACK); - } +} + + +void display_message(char* message) +{ + dclear(C_WHITE); + + drect(0, 0, 127, 6, C_BLACK); + dhline(0, C_BLACK); + dhline(63, C_BLACK); + dvline(0, C_BLACK); + dvline(127, C_BLACK); + dtext(42, 1, C_WHITE, "MESSAGE"); + + int total_offset = 0; + for (int i = 0; i < 5; i ++) + { + dtext_opt(3, 7 * i + 8, C_BLACK, C_WHITE, 0, 0, message + total_offset, 20); + + int offset = 0; + while (message[total_offset + offset] != '\0') offset += 1; + + if (!offset) break; + else if (offset > 20) total_offset += 20; + else total_offset += offset; + } + + dupdate(); + + int opt = GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA & ~GETKEY_REP_ARROWS; + int timeout = 0; + + int key = 0; + while (key != KEY_ALPHA) + key = getkey_opt(opt, &timeout).key; } diff --git a/src/display.h b/src/display.h index 8f146ce..2230ca6 100644 --- a/src/display.h +++ b/src/display.h @@ -8,7 +8,7 @@ void title_screen(void); // main_display : the general display function -void main_display(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor); +void display_main(struct calccity *calccity, struct camera *camera, struct map *map, const int disp_cursor); // display_large_map : display the current state of the large map void display_large_map(struct calccity *calccity, struct camera *camera, struct map *map); @@ -16,4 +16,7 @@ void display_large_map(struct calccity *calccity, struct camera *camera, struct // display_around : display the screen frame and cursor void display_around(struct calccity *calccity, struct camera *camera, const int disp_cursor); +// display_message : display the given message with lines breaks +void display_message(char* message); + #endif /* _DISPLAY_H */ \ No newline at end of file diff --git a/src/menus.c b/src/menus.c index 2a6cf0c..c375d2a 100644 --- a/src/menus.c +++ b/src/menus.c @@ -5,32 +5,35 @@ #include "menus.h" -struct building menu_1(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode) +struct building menu_12(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode, const int menu) { extern const bopti_image_t img_fn_1; - int key = 0, end = 0, x = 0, y = 0; + extern const bopti_image_t img_fn_2; + extern const struct building buildings[41]; - struct building default_building = { - .name = "TEST", - .id = (unsigned char []){0}, - .cost = 0, - .size = {1, 1}, - .stat = {0}, - .taxes = {0}, - .funds = {0} - }; + int key = 0, end = 0, x = 0, y = 0; while (!end) { dclear(C_WHITE); - main_display(calccity, camera, map, 0); - drect(3, 57, 19, 64, C_INVERT); - dimage(3, 11, &img_fn_1); - drect(9 * x + 4, 9 * y + 12, 9 * x + 4 + 7, 9 * y + 12 + 7, C_INVERT); + display_main(calccity, camera, map, 0); + + if (menu == 1) + { + drect(3, 57, 19, 64, C_INVERT); + dimage(3, 11, &img_fn_1); + drect(9 * x + 4, 9 * y + 12, 9 * x + 11, 9 * y + 19, C_INVERT); + } + else + { + drect(21, 57, 39, 64, C_INVERT); + dimage(20, 11, &img_fn_2); + drect(9 * x + 21, 9 * y + 12, 9 * x + 28, 9 * y + 19, C_INVERT); + + } dupdate(); key = rtc_key(); - switch (key) { case KEY_UP: @@ -46,7 +49,7 @@ struct building menu_1(struct calccity *calccity, struct camera *camera, struct break; case KEY_RIGHT: - if (x < 2) x ++; + if (x < (1 + menu)) x ++; break; case KEY_ALPHA: @@ -58,16 +61,22 @@ struct building menu_1(struct calccity *calccity, struct camera *camera, struct break; } } + if (end == 1) { *build_mode = 1; - return buildings[x + y * 3]; + if (menu == 1) + return buildings[x + y * 3]; + else + return buildings[15 + x + y * 4]; } else { *build_mode = 0; + struct building default_building = {0}; return default_building; } + } @@ -179,7 +188,7 @@ void menu_5(struct calccity *calccity) switch (i) { case 0: case 9: case 14: case 21: - values[i] = -1; + values[i] = 0; offset ++; break; diff --git a/src/menus.h b/src/menus.h index bfb02c9..470e358 100644 --- a/src/menus.h +++ b/src/menus.h @@ -4,8 +4,8 @@ #include "calccity.h" #include "core.h" -// menu_1 : building 1 -struct building menu_1(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode); +// menu_12 : buildings +struct building menu_12(struct calccity *calccity, struct camera *camera, struct map *map, int *build_mode, const int menu); // menu_4 : tax and funds void menu_4(struct calccity *calccity);