diff --git a/source/jutil.cpp b/source/jutil.cpp index 7abc6a0..8f2c1c5 100644 --- a/source/jutil.cpp +++ b/source/jutil.cpp @@ -1,7 +1,7 @@ #include "jutil.h" #include #include - +#include namespace util { int stringToInt(const char *value, std::vector strings, std::vector values) @@ -23,4 +23,14 @@ namespace util if (a==nullptr || b==nullptr) return false; return (strcmp(a,b)==0); } + + const uint8_t scancode_to_char(const uint8_t scancode) + { + if (scancode == SDL_SCANCODE_0 || scancode == SDL_SCANCODE_KP_0) return '0'; + if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19; + if (scancode >= SDL_SCANCODE_KP_1 && scancode <= SDL_SCANCODE_KP_9) return scancode-40; + if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61; + //if (scancode == SDL_SCANCODE_MINUS) return '-'; + return '-'; + } } \ No newline at end of file diff --git a/source/jutil.h b/source/jutil.h index 7caeb7e..5615b57 100644 --- a/source/jutil.h +++ b/source/jutil.h @@ -1,9 +1,11 @@ #pragma once #include - +#include namespace util { int stringToInt(const char *value, std::vector strings, std::vector values); const bool strcomp(const char *a, const char* b); + + const uint8_t scancode_to_char(const uint8_t scancode); } \ No newline at end of file diff --git a/source/m_editor_templates.cpp b/source/m_editor_templates.cpp index 32fef44..bd43be1 100644 --- a/source/m_editor_templates.cpp +++ b/source/m_editor_templates.cpp @@ -6,59 +6,157 @@ #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; + //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() { - 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; - draw::cls(2); - - //draw::stencil::enable(); - //draw::stencil::clear(255); - - int x=0, y=0; - - for (int i=0; iname, (x*65), (y*40)+30, LIGHT+WHITE, BLACK); - x++; if (x==8) { x=0;y++; } - } + draw::cls(2); - draw::render(); + int x=0, y=0; - if (input::mouseClk(1)) { - //const int clicked = draw::stencil::query(input::mouseX(), input::mouseY()); - const int clicked = (input::mouseX()/65) + (input::mouseY()/40) * 8; - if (clicked<=actor::templates::size()) { - actor::actor_t *new_act = actor::duplicate(actor::templates::get(clicked)); - actor::setUniqueName(new_act); - actor::setDirty(new_act, true); - actor::select(new_act); - room::editor::modify(); + draw::color(BLUE); + draw::fillrect(8, 0, 512, 11); - return false; + 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; } diff --git a/source/m_game.cpp b/source/m_game.cpp index 0d5e471..c115b48 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -6,6 +6,7 @@ #include "jgame.h" #include "console.h" #include "editor.h" +#include "jutil.h" namespace modules { @@ -155,15 +156,6 @@ namespace modules return false; } - const uint8_t scancode_to_char(const uint8_t scancode) - { - if (scancode == SDL_SCANCODE_0) return '0'; - if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19; - if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61; - //if (scancode == SDL_SCANCODE_MINUS) return '-'; - return '-'; - } - const bool btn_txt(const char* label, const int x, const int y, char *var) { //draw::print(label, x, y+3, PAPER, 0); @@ -177,7 +169,7 @@ namespace modules if (len>0) var[len-1] = 0; } else { if (len<15) { - var[len] = scancode_to_char(result); + var[len] = util::scancode_to_char(result); var[len+1] = 0; } }