- [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);

View File

@@ -100,8 +100,12 @@ namespace actor
int inner_x;
int inner_y;
int tag;
};
void resetTag();
// Torna el primer actor de la llista
actor_t *getFirst();
@@ -140,6 +144,8 @@ namespace actor
actor_t *find(std::string name);
actor_t *findByTag(const int tag);
actor_t *find_at(const int x, const int y, const int z);
actor_t *get_collision(actor_t *act);

View File

@@ -22,7 +22,9 @@ namespace modules
::game::setUpdateTicks(64);
actor::templates::load();
if (editor::isDevMode()) {
if (editor::isDevMode())
{
draw::stencil::init();
FILE* f = fopen("data/gifs.txt", "r");
int buffer_len=255;
@@ -287,11 +289,24 @@ namespace modules
if (editor::isDevMode()) draw::setViewport(100,0,320,240);
room::draw();
draw::stencil::enable();
draw::stencil::clear(255);
actor::draw(actor::getFirst());
draw::stencil::disable();
room::draw2();
draw::swapcol(1, WHITE+LIGHT);
actor::draw(actor::getPicked(), false);
if (editor::isDevMode() && input::mouseBtn(1))
{
const uint8_t val = draw::stencil::query(input::mouseX(), input::mouseY());
if (val != 255)
{
actor::select(actor::findByTag(val));
section = SECTION_ACTOR;
}
}
const int col1 = room::getColor(1);
const int col2 = room::getColor(2);
const int col3 = room::getColor(3);