diff --git a/data/templates.txt b/data/templates.txt index 892f470..f0581f3 100644 --- a/data/templates.txt +++ b/data/templates.txt @@ -1,6 +1,6 @@ category{ - name: default + name: DEFAULT actor{ name: BOX @@ -85,18 +85,168 @@ category{ } actor{ - name: P-TIMER - bmp: objectes.gif - bmp-rect: 96 0 24 32 - bmp-offset: -4 34 - pos: 8 40 8 - size: 4 4 4 - anim-cycle: SEQ - anim-wait: 2 - flags: SPECIAL + name: FINESTRA + bmp: altres.gif + bmp-rect: 0 75 20 33 + bmp-offset: 0 39 + pos: 15 23 4 + size: 1 1 9 movement: CW } + actor{ + name: EXPLOSION + bmp: caixes.gif + bmp-rect: 0 160 18 22 + bmp-offset: -7 24 + pos: 32 32 0 + size: 8 8 4 + anim-cycle: SEQ + flags: ANIMATED + movement: CW + } + + actor{ + name: GAT-NEGRE + bmp: gat.gif + bmp-rect: 0 0 24 28 + bmp-offset: -4 32 + pos: 8 8 0 + size: 8 8 8 + orient: XP + anim-wait: 2 + flags: MOVING ANIMATED ORIENTABLE + movement: CW + } + + actor{ + name: CUADRO + bmp: altres.gif + bmp-rect: 66 75 18 32 + bmp-offset: 0 39 + pos: 14 23 6 + size: 1 1 9 + orient: YP + flags: ORIENTABLE + movement: CW + } + + actor{ + name: ROOMBA + bmp: caixes.gif + bmp-rect: 160 0 32 32 + bmp-offset: 0 34 + pos: 32 32 0 + size: 8 8 2 + orient: XN + flags: REACTIVE MOVING DEADLY + react-mask: XP XN YP YN ZP ZN + movement: CCW + } + + actor{ + name: WC + bmp: altres.gif + bmp-rect: 105 0 21 33 + bmp-offset: -4 36 + pos: 8 8 0 + size: 8 8 8 + movement: CW + } + + actor{ + name: MANCUERNA + bmp: altres.gif + bmp-rect: 106 33 17 14 + bmp-offset: -6 20 + pos: 24 25 0 + size: 6 4 2 + movement: CW + } + +} + +category{ + name: MOBLES + + actor{ + name: SOFA + bmp: altres.gif + bmp-rect: 0 0 48 40 + bmp-offset: 0 32 + pos: 0 0 0 + size: 16 8 6 + movement: CW + } + + actor{ + name: LLIT + bmp: altres.gif + bmp-rect: 48 0 57 47 + bmp-offset: 11 32 + pos: 8 8 0 + size: 16 16 8 + movement: CW + } + + actor{ + name: KALLAX + bmp: altres.gif + bmp-rect: 0 48 24 27 + bmp-offset: 0 31 + pos: 0 0 0 + size: 8 4 8 + movement: CW + } + + actor{ + name: MESITA + bmp: caixes.gif + bmp-rect: 0 64 32 32 + bmp-offset: 0 32 + pos: 0 16 0 + size: 8 8 4 + movement: CW + } + + actor{ + name: LAMPARA + bmp: altres.gif + bmp-rect: 128 0 20 41 + bmp-offset: -6 45 + pos: 1 41 0 + size: 6 6 16 + movement: CW + } + + actor{ + name: CADIRA + bmp: caixes.gif + bmp-rect: 64 96 20 32 + bmp-offset: -8 40 + pos: 8 51 0 + size: 5 4 8 + orient: YP + movement: CW + } + + actor{ + name: PILA + bmp: caixes.gif + bmp-rect: 160 96 32 32 + bmp-offset: 0 32 + pos: 24 8 0 + size: 8 8 8 + orient: YP + flags: ORIENTABLE + movement: CW + } + +} + +category{ + name: PARTS + actor{ name: P-FILTER bmp: objectes.gif @@ -163,160 +313,15 @@ category{ } actor{ - name: SOFA - bmp: altres.gif - bmp-rect: 0 0 48 40 - bmp-offset: 0 32 - pos: 0 0 0 - size: 16 8 6 - movement: CW - } - - actor{ - name: LLIT - bmp: altres.gif - bmp-rect: 48 0 57 47 - bmp-offset: 11 32 - pos: 8 8 0 - size: 16 16 8 - movement: CW - } - - actor{ - name: KALLAX-A - bmp: altres.gif - bmp-rect: 0 48 24 27 - bmp-offset: 0 31 - pos: 0 0 0 - size: 8 4 8 - movement: CW - } - - actor{ - name: FINESTRA - bmp: altres.gif - bmp-rect: 0 75 20 33 - bmp-offset: 0 39 - pos: 15 23 4 - size: 1 1 9 - movement: CW - } - - actor{ - name: EXPLOSION - bmp: caixes.gif - bmp-rect: 0 160 18 22 - bmp-offset: -7 24 - pos: 32 32 0 - size: 8 8 4 + name: P-TIMER + bmp: objectes.gif + bmp-rect: 96 0 24 32 + bmp-offset: -4 34 + pos: 8 40 8 + size: 4 4 4 anim-cycle: SEQ - flags: ANIMATED - movement: CW - } - - actor{ - name: GAT-NEGRE - bmp: gat.gif - bmp-rect: 0 0 24 28 - bmp-offset: -4 32 - pos: 8 8 0 - size: 8 8 8 - orient: XP anim-wait: 2 - flags: MOVING ANIMATED ORIENTABLE - movement: CW - } - - actor{ - name: CUADRO - bmp: altres.gif - bmp-rect: 66 75 18 32 - bmp-offset: 0 39 - pos: 14 23 6 - size: 1 1 9 - orient: YP - flags: ORIENTABLE - movement: CW - } - - actor{ - name: MESITA - bmp: caixes.gif - bmp-rect: 0 64 32 32 - bmp-offset: 0 32 - pos: 0 16 0 - size: 8 8 4 - movement: CW - } - - actor{ - name: LAMPARA - bmp: altres.gif - bmp-rect: 128 0 20 41 - bmp-offset: -6 45 - pos: 1 41 0 - size: 6 6 16 - movement: CW - } - - actor{ - name: ROOMBA - bmp: caixes.gif - bmp-rect: 160 0 32 32 - bmp-offset: 0 34 - pos: 32 32 0 - size: 8 8 2 - orient: XN - flags: REACTIVE MOVING DEADLY - react-mask: XP XN YP YN ZP ZN - movement: CCW - } - - actor{ - name: WC - bmp: altres.gif - bmp-rect: 105 0 21 33 - bmp-offset: -4 36 - pos: 8 8 0 - size: 8 8 8 - movement: CW - } - - actor{ - name: MANCUERNA - bmp: altres.gif - bmp-rect: 106 33 17 14 - bmp-offset: -6 20 - pos: 24 25 0 - size: 6 4 2 - movement: CW - } - - actor{ - name: CADIRA - bmp: caixes.gif - bmp-rect: 64 96 20 32 - bmp-offset: -8 40 - pos: 8 51 0 - size: 5 4 8 - orient: YP - movement: CW - } - -} - -category{ - name: coses - - actor{ - name: PILA - bmp: caixes.gif - bmp-rect: 160 96 32 32 - bmp-offset: 0 32 - pos: 24 8 0 - size: 8 8 8 - orient: YP - flags: ORIENTABLE + flags: SPECIAL movement: CW } diff --git a/source/m_editor_templates.cpp b/source/m_editor_templates.cpp index bd43be1..9a0b399 100644 --- a/source/m_editor_templates.cpp +++ b/source/m_editor_templates.cpp @@ -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; itemplate_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; } } diff --git a/source/m_game.cpp b/source/m_game.cpp index c115b48..97cd996 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -261,7 +261,7 @@ namespace modules if (console::isEnabled()) { console::toggle(); } else { - if (editor::isEditing()) room::editor::save(); + if (room::editor::isModified()) room::editor::save(); return GAME_MENU; } } diff --git a/source/room.cpp b/source/room.cpp index f5ee67d..7525c00 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -545,6 +545,11 @@ namespace room void modify() { modified = true; } + const bool isModified() + { + return modified; + } + void save() { char filename[] = "data/rooms/00.txt"; diff --git a/source/room.h b/source/room.h index d7bcd4e..db7be7e 100644 --- a/source/room.h +++ b/source/room.h @@ -62,6 +62,7 @@ namespace room int getCurrentRoom(); void modify(); + const bool isModified(); void save(); } }