#include "m_editor_templates.h" #include "jdraw.h" #include "jinput.h" #include "misc.h" #include #include "actor.h" #include #include "room.h" #include "jutil.h" #define EDITING_NORMAL 0 #define EDITING_CATEGORY_NAME 1 #define EDITING_ACTOR_NAME 2 namespace modules { namespace editor_templates { //std::vector templates; int current_category; int edit_mode = EDITING_NORMAL; actor::actor_t *actor_edited = nullptr; char name[13]; uint32_t time = 0; void init() { current_category = 0; edit_mode = EDITING_NORMAL; //for (int i=0; iname); draw::print("ACTOR NAME:", 227, 110, LIGHT+WHITE, PAPER); } } bool loop() { if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false; if (edit_mode == EDITING_NORMAL) { draw::cls(2); int x=0, y=0; draw::color(BLUE); draw::fillrect(8, 0, 512, 11); auto categories = actor::templates::getCategories(); draw::color(GREEN); draw::fillrect(0, 0, 11, 11); draw::print("+", 4, 3, WHITE, BLACK); for (auto category : categories) { if (current_category == x) { draw::color(BLACK); draw::fillrect(11+x*40, 0, 40, 11); } draw::print(category.c_str(), 11+((40-category.size()*4)/2)+x*40, 3, LIGHT+WHITE, BLACK); x++; } x = 0; auto actors = actor::templates::getByCategory(categories[current_category].c_str()); for (auto actor : actors) { draw::swapcol(1, TEAL); actor::drawAt(&actor, 10+x*65, 14+y*40); draw::print(actor.name, 10+(x*65), (y*40)+44, LIGHT+WHITE, BLACK); x++; if (x==8) { x=0;y++; } } draw::render(); current_category += input::mouseWheel(); if (current_category < 0) current_category = categories.size()-1; if (current_category >= categories.size()) current_category = 0; 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]); actor::setUniqueName(new_act); actor::setDirty(new_act, true); actor::select(new_act); room::editor::modify(); return false; } } else { edit_mode = EDITING_CATEGORY_NAME; init_text_edit(); } } 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; } } } } else { draw::color(LIGHT+WHITE); draw::fillrect(217+10,106+15,66,11); draw::color(BLACK); 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(); draw::render(); int result = input::getKeyPressed(); if (result) { const int len = strlen(name); if (result == SDL_SCANCODE_BACKSPACE) { if (len>0) name[len-1] = 0; } else { if (len<15) { name[len] = util::scancode_to_char(result); name[len+1] = 0; } } return true; } } return true; } } }