From 1af08ecf3ca8f36a15451e9876b32ce6cab8e201 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 10 Jun 2024 14:14:13 +0200 Subject: [PATCH] - Treballant en poder editar guay les propietats --- source/main.cpp | 25 +++++++++++++++---------- source/room.cpp | 5 +++++ source/room.h | 6 ++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 05acb0a..f34ec2a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -110,7 +110,7 @@ int sx=1, sy=0; if (sign) draw::draw(x,y,5,7,50,120); } -void btn(const char* label, const int x, const int y, int &var, int min, int max) +const bool btn(const char* label, const int x, const int y, int &var, int min, int max) { char buffer[100]; int result=0; @@ -119,11 +119,12 @@ void btn(const char* label, const int x, const int y, int &var, int min, int max if (result) { var=SDL_max(min, SDL_min(max, var-(result-2))); - room::editor::setWidth(var); + return true; } + return false; } -void btn_small(const int x, const int y, int &var, int min, int max, bool restrt=false) +const bool btn_small(const int x, const int y, int &var, int min, int max) { char buffer[100]; int result=0; @@ -131,8 +132,9 @@ void btn_small(const int x, const int y, int &var, int min, int max, bool restrt if (result) { var=SDL_max(min, SDL_min(max, var+result)); - if (restrt) restart(); + return true; } + return false; } void btn_check(const int x, const int y, const char* label, uint8_t &flags, const uint8_t value) @@ -312,25 +314,28 @@ bool game::loop() switch (section) { case 0: */ + bool change = false; draw::setViewport(0,0,100,240); draw::color(WHITE); draw::fillrect(0, 0, 100, 240); - btn("ROOM WIDTH:", 10, 40, room_w, 0, 3); - btn("ROOM HEIGHT:", 10, 55, room_h, 0, 3); + change |= btn("ROOM WIDTH:", 10, 40, room::editor::refWidth(), 0, 3); + change |= btn("ROOM HEIGHT:", 10, 55, room::editor::refHeight(), 0, 3); draw::print("DOORS:", 10, 80, 15, 0); - btn_small(32, 80, room_xn, -1, 5, true); - btn_small(49, 80, room_yp, -1, 5, true); - btn_small(66, 80, room_xp, -1, 5, true); - btn_small(83, 80, room_yn, -1, 5, true); + btn_small(32, 80, room::editor::refDoor(XN), -1, 5); + btn_small(49, 80, room_yp, -1, 5); + btn_small(66, 80, room_xp, -1, 5); + btn_small(83, 80, room_yn, -1, 5); btn("COLOR:", 10, 140, room_color, 5, 11); btn("FLOOR:", 10, 155, room_floor, 0, 5); btn("WALLS:", 10, 170, room_walls, 0, 5); btn("DOORS:", 10, 185, room_doors, 0, 4); btn("WDOORS:", 10, 200, room_walldoors, 0, 5); + + if (change) room::update(); /* break; case 1: diff --git a/source/room.cpp b/source/room.cpp index ffcb64b..7ffa048 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -337,6 +337,11 @@ namespace room namespace editor { + int &refWidth() { return inner_w; } + int &refHeight() { return inner_h; } + + uint8_t &refDoor(const int which) { return door_height[which]; } + void setWidth(const int value) { inner_w = value; update(); } void setHeight(const int value) { inner_h = value; update(); } void setDoor(const int which, const int value) { door_height[which] = value; update(); } diff --git a/source/room.h b/source/room.h index 2d1c68a..eb9ccb1 100644 --- a/source/room.h +++ b/source/room.h @@ -19,6 +19,7 @@ namespace room void init(); void load(const int room); //void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn, uint8_t col, uint8_t floor, uint8_t walls, uint8_t door, uint8_t doorwall); + void update(); void draw(); void draw2(); @@ -31,6 +32,11 @@ namespace room namespace editor { + int &refWidth(); + int &refHeight(); + + uint8_t &refDoor(const int which); + void setWidth(const int value); void setHeight(const int value); void setDoor(const int which, const int value);