- Arreglat el problema

This commit is contained in:
2023-09-26 20:02:26 +02:00
parent e6cd1233e2
commit b0e4db1e8e
3 changed files with 21 additions and 12 deletions

View File

@@ -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 *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)); actor_t *act = (actor_t*)malloc(sizeof(actor_t));
act->name = std::string(name); strcpy(act->name, name.c_str());
act->bmp = std::string(bmp); strcpy(act->bmp, bmp.c_str());
act->pos = p; act->pos = p;
act->size = s; act->size = s;
act->surface = draw::loadSurface(bmp.c_str()); act->surface = draw::loadSurface(bmp.c_str());

View File

@@ -37,9 +37,9 @@ namespace actor
{ {
struct actor_t struct actor_t
{ {
std::string name; char name[16];
draw::surface *surface; draw::surface *surface;
std::string bmp; char bmp[16];
SDL_Rect bmp_rect; SDL_Rect bmp_rect;
SDL_Point bmp_offset; SDL_Point bmp_offset;

View File

@@ -64,6 +64,8 @@ void game::init()
int buffer_len=255; int buffer_len=255;
char buffer[buffer_len]; char buffer[buffer_len];
while(fgets(buffer, buffer_len, f)) { while(fgets(buffer, buffer_len, f)) {
auto len = strlen(buffer);
buffer[len-1]=0;
gifs.push_back(std::string(buffer)); 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}); //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<std::string> values) bool btn_opt2(const char* label, const int x, const int y, char *var, std::vector<std::string> values)
{ {
draw::print(label, x, y+3, 15, 0); draw::print(label, x, y+3, 15, 0);
int result = 0; int result = 0;
int pos = 0; int pos = 0;
while (var != values[pos]) std::string v = var;
while (pos < values.size() && v != values[pos])
{ {
pos++; pos++;
} }
if (pos==values.size()) pos = 0;
result = ui::button(var.c_str(), x+32, y, 56, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE); result = ui::button(var, x+32, y, 56, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE);
if (result) if (result)
{ {
pos++; if (pos==values.size()) pos=0; 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) 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(); act = actor::getSelected();
if (act) if (act)
{ {
btn_txt("NAME:", 330, 40, act->name.c_str()); btn_txt("NAME:", 330, 40, act->name);
btn_opt2("BMP:", 330, 55, act->bmp, gifs); 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); draw::print("RECT:", 330, 73, 15, 0);
btn_small(352, 70, act->bmp_rect.x, 0, 512); btn_small(352, 70, act->bmp_rect.x, 0, 512);
btn_small(369, 70, act->bmp_rect.y, 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) { } else if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) {
actor::select(act); 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++; line++;
} }
act = act->next; act = act->next;