- [NEW] Selecció de actors en l'editor amb el ratolí

This commit is contained in:
2024-07-11 08:25:34 +02:00
parent b794ebe608
commit c4cbda9b23
5 changed files with 185 additions and 166 deletions

View File

@@ -23,6 +23,13 @@ namespace actor
actor_t *picked = nullptr;
static bool room_changed = false;
int current_tag = 0;
void resetTag()
{
current_tag = 0;
}
actor_t *getFirst()
{
return first;
@@ -44,6 +51,7 @@ 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->tag = current_tag++;
strcpy(act->name, name.c_str());
strcpy(act->bmp, bmp.c_str());
act->pos = p;
@@ -65,6 +73,7 @@ namespace actor
actor_t *createEmptyActor()
{
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
act->tag = current_tag++;
act->pos = {0, 0, 0};
act->size = {8,8,8};
act->bmp_rect = {0,0,32,32};
@@ -991,6 +1000,7 @@ namespace actor
draw::pushSource();
draw::setSource(act->surface);
if (editor::isEditing() && (act==selected)) draw::swapcol(1, room::getColor(1)); // Si està seleccionat, que canvie de color
draw::stencil::set(act->tag);
draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip);
draw::swapcol(1, room::getColor(0)); // Tornem al color per defecte
draw::popSource();
@@ -1016,18 +1026,20 @@ namespace actor
}
act = act->next;
}
return nullptr;
}
/*
act = dirty;
actor_t *findByTag(const int tag)
{
actor_t *act = first;
while (act)
{
if (name == act->name)
if (tag == act->tag)
{
return act;
}
act = act->next;
}
*/
return nullptr;
}
@@ -1119,6 +1131,7 @@ namespace actor
void clear(const bool all)
{
resetTag();
actor_t *hero = nullptr;
actor_t *act = first;
while (act)
@@ -1127,25 +1140,10 @@ namespace actor
if (!all && (act->flags & FLAG_HERO)) {
hero = act;
} else {
//draw::freeSurface(act->surface);
free(act);
}
act = tmp;
}
/*
act = dirty;
while (act)
{
actor_t *tmp = act->next;
if (act->flags & FLAG_HERO) {
hero = act;
} else {
//draw::freeSurface(act->surface);
free(act);
}
act = tmp;
}
*/
if (picked)
{
free(picked);