- Acabat el editor de templates

This commit is contained in:
2024-09-19 20:23:53 +02:00
parent 241ae1bd8e
commit 16914932ec
5 changed files with 222 additions and 179 deletions

View File

@@ -23,8 +23,11 @@ namespace modules
char name[13];
uint32_t time = 0;
char actor_cut[13];
void init()
{
actor_cut[0] = 0;
current_category = 0;
edit_mode = EDITING_NORMAL;
//for (int i=0; i<templates.size(); ++i) if (templates[i] != nullptr) actor::remove(templates[i]);
@@ -62,6 +65,17 @@ namespace modules
if (edit_mode == EDITING_NORMAL)
{
if (input::keyPressed(SDL_SCANCODE_V) && actor_cut[0]!=0)
{
actor::actor_t *act = actor::templates::getByName(actor_cut);
if (act)
{
act->template_category = current_category;
actor::templates::save();
}
actor_cut[0] = 0;
}
draw::cls(2);
int x=0, y=0;
@@ -82,15 +96,22 @@ namespace modules
draw::print(category.c_str(), 11+((40-category.size()*4)/2)+x*40, 3, LIGHT+WHITE, BLACK);
x++;
}
const int hovered_actor = ((input::mouseX()-10)/65) + ((input::mouseY()-14)/40) * 8;
x = 0;
int i = 0;
auto actors = actor::templates::getByCategory(categories[current_category].c_str());
if (input::keyPressed(SDL_SCANCODE_X) && (hovered_actor < actors.size())) strcpy(actor_cut, actors[hovered_actor].name);
for (auto actor : actors)
{
draw::swapcol(1, TEAL);
draw::swapcol(1, strcmp(actor.name, actor_cut)==0 ? BLUE : TEAL);
actor::drawAt(&actor, 10+x*65, 14+y*40);
draw::print(actor.name, 10+(x*65), (y*40)+44, LIGHT+WHITE, BLACK);
draw::print(actor.name, 10+(x*65), (y*40)+44, i==hovered_actor ? YELLOW : LIGHT+WHITE, BLACK);
x++; if (x==8) { x=0;y++; }
i++;
}
draw::render();
@@ -101,10 +122,9 @@ namespace modules
if (input::mouseClk(1))
{
if (input::mouseX()>12) {
const int clicked = ((input::mouseX()-10)/65) + ((input::mouseY()-14)/40) * 8;
if (clicked<=actors.size()) {
actor::actor_t *new_act = actor::duplicate(&actors[clicked]);
if (input::mouseY()>12) {
if (hovered_actor<=actors.size()) {
actor::actor_t *new_act = actor::duplicate(&actors[hovered_actor]);
actor::setUniqueName(new_act);
actor::setDirty(new_act, true);
actor::select(new_act);
@@ -113,17 +133,21 @@ namespace modules
return false;
}
} else {
edit_mode = EDITING_CATEGORY_NAME;
init_text_edit();
if (input::mouseX()<12) {
edit_mode = EDITING_CATEGORY_NAME;
init_text_edit();
} else {
current_category = (input::mouseX()-11)/40;
}
}
}
else if (input::mouseClk(3))
{
if (input::mouseX()>12) {
const int clicked = ((input::mouseX()-10)/65) + ((input::mouseY()-14)/40) * 8;
if (clicked<=actors.size()) {
actor_edited = actor::templates::getByName(actors[clicked].name);
edit_mode = EDITING_CATEGORY_NAME;
if (hovered_actor<=actors.size()) {
actor_edited = actor::templates::getByName(actors[hovered_actor].name);
edit_mode = EDITING_ACTOR_NAME;
init_text_edit();
}
}
}
@@ -136,7 +160,7 @@ namespace modules
draw::rect(217+10,106+15,66,11);
draw::print(name, 217+12, 106+17, BLACK, 0);
if (SDL_GetTicks()-time < 500) draw::print("_", 217+12+strlen(name)*4, 106+17, BLACK, 0);
if (SDL_GetTicks()-time >= 500) time = SDL_GetTicks();
if (SDL_GetTicks()-time >= 1000) time = SDL_GetTicks();
draw::render();
int result = input::getKeyPressed();
@@ -144,7 +168,16 @@ namespace modules
if (result)
{
const int len = strlen(name);
if (result == SDL_SCANCODE_BACKSPACE) {
if (result == SDL_SCANCODE_RETURN) {
if (edit_mode==EDITING_CATEGORY_NAME) {
actor::templates::newCategory(name);
edit_mode = EDITING_NORMAL;
} else {
strcpy(actor_edited->name, name);
edit_mode = EDITING_NORMAL;
}
actor::templates::save();
} else if (result == SDL_SCANCODE_BACKSPACE) {
if (len>0) name[len-1] = 0;
} else {
if (len<15) {
@@ -152,7 +185,6 @@ namespace modules
name[len+1] = 0;
}
}
return true;
}
}