From b0e4db1e8e723ac8de67f831c2cd98ed83b531d8 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Tue, 26 Sep 2023 20:02:26 +0200 Subject: [PATCH] - Arreglat el problema --- source/actor.cpp | 4 ++-- source/actor.h | 4 ++-- source/main.cpp | 25 +++++++++++++++++-------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/actor.cpp b/source/actor.cpp index 9a1b1bd..f63be46 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -27,8 +27,8 @@ namespace actor actor_t *create(std::string name, vec3_t p, vec3_t s, std::string bmp, SDL_Rect r, SDL_Point o) { actor_t *act = (actor_t*)malloc(sizeof(actor_t)); - act->name = std::string(name); - act->bmp = std::string(bmp); + strcpy(act->name, name.c_str()); + strcpy(act->bmp, bmp.c_str()); act->pos = p; act->size = s; act->surface = draw::loadSurface(bmp.c_str()); diff --git a/source/actor.h b/source/actor.h index a7f0a72..f2d0fe3 100644 --- a/source/actor.h +++ b/source/actor.h @@ -37,9 +37,9 @@ namespace actor { struct actor_t { - std::string name; + char name[16]; draw::surface *surface; - std::string bmp; + char bmp[16]; SDL_Rect bmp_rect; SDL_Point bmp_offset; diff --git a/source/main.cpp b/source/main.cpp index aae3d7e..aff86ae 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -64,6 +64,8 @@ void game::init() int buffer_len=255; char buffer[buffer_len]; while(fgets(buffer, buffer_len, f)) { + auto len = strlen(buffer); + buffer[len-1]=0; gifs.push_back(std::string(buffer)); } //actor::actor_t *hero = actor::create("HERO", {16,32,8}, {8,8,12}, "test.gif", {0,32,20,32}, {-6,38}); @@ -168,22 +170,26 @@ void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vec } } -void btn_opt2(const char* label, const int x, const int y, std::string &var, std::vector values) +bool btn_opt2(const char* label, const int x, const int y, char *var, std::vector values) { draw::print(label, x, y+3, 15, 0); int result = 0; int pos = 0; - while (var != values[pos]) + std::string v = var; + while (pos < values.size() && v != values[pos]) { pos++; } - - result = ui::button(var.c_str(), x+32, y, 56, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE); + if (pos==values.size()) pos = 0; + + result = ui::button(var, x+32, y, 56, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE); if (result) { pos++; if (pos==values.size()) pos=0; - var = values[pos]; + strcpy(var,values[pos].c_str()); + return true; } + return false; } void btn_txt(const char* label, const int x, const int y, const char *var) @@ -267,8 +273,11 @@ bool game::loop() act = actor::getSelected(); if (act) { - btn_txt("NAME:", 330, 40, act->name.c_str()); - btn_opt2("BMP:", 330, 55, act->bmp, gifs); + btn_txt("NAME:", 330, 40, act->name); + if (btn_opt2("BMP:", 330, 55, act->bmp, gifs)) { + draw::freeSurface(act->surface); + act->surface = draw::loadSurface(act->bmp); + } draw::print("RECT:", 330, 73, 15, 0); btn_small(352, 70, act->bmp_rect.x, 0, 512); btn_small(369, 70, act->bmp_rect.y, 0, 512); @@ -319,7 +328,7 @@ bool game::loop() } else if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) { actor::select(act); } - draw::print(act->name.c_str(), 332, 42+line*9, WHITE, BLACK); + draw::print(act->name, 332, 42+line*9, WHITE, BLACK); line++; } act = act->next;