- [NEW] Botó per a activar/desactivar l'edició

- [NEW] Seleccionar actors amb CTRL+Up/Down
This commit is contained in:
2024-06-13 13:29:13 +02:00
parent 50c768edb3
commit 46d46b93cf
2 changed files with 83 additions and 12 deletions

View File

@@ -110,7 +110,7 @@ int sx=1, sy=0;
if (sign) draw::draw(x,y,5,7,50,120);
}
const bool btn(const char* label, const int x, const int y, int &var, int min, int max)
/*const bool btn(const char* label, const int x, const int y, int &var, int min, int max)
{
char buffer[100];
int result=0;
@@ -122,7 +122,7 @@ const bool btn(const char* label, const int x, const int y, int &var, int min, i
return true;
}
return false;
}
}*/
const bool btn_small(const int x, const int y, int &var, int min, int max)
{
@@ -267,20 +267,74 @@ const bool btn_txt(const char* label, const int x, const int y, char *var)
int section = SECTION_ROOM;
void editor_select_by_keyboard()
{
if ( !(input::keyDown(SDL_SCANCODE_LCTRL) || input::keyDown(SDL_SCANCODE_RCTRL)) ) return;
actor::actor_t *selected = actor::getSelected();
if ( input::keyPressed(SDL_SCANCODE_UP) )
{
if (!selected) {
actor::actor_t *first = actor::getFirst();
while (first && (first->flags&FLAG_IGNORE)) first=first->next;
actor::select(first);
} else {
if (selected->prev) {
actor::actor_t *prev = selected->prev;
while (prev && (prev->flags&FLAG_IGNORE)) prev=prev->prev;
actor::select(prev);
} else {
actor::actor_t *last = actor::getLast();
while (last && (last->flags&FLAG_IGNORE)) last=last->prev;
actor::select(last);
}
}
section=SECTION_ACTOR;
}
if ( input::keyPressed(SDL_SCANCODE_DOWN) )
{
if (!selected) {
actor::actor_t *last = actor::getLast();
while (last && (last->flags&FLAG_IGNORE)) last=last->prev;
actor::select(last);
} else {
if (selected->next) {
actor::actor_t *next = selected->next;
while (next && (next->flags&FLAG_IGNORE)) next=next->next;
if (next) {
actor::select(next);
} else {
actor::actor_t *first = actor::getFirst();
while (first && (first->flags&FLAG_IGNORE)) first=first->next;
actor::select(first);
}
} else {
actor::actor_t *first = actor::getFirst();
while (first && (first->flags&FLAG_IGNORE)) first=first->next;
actor::select(first);
}
}
section=SECTION_ACTOR;
}
}
void editor_move_selected()
{
actor::actor_t *selected = actor::getSelected();
if (!selected) return;
if ( input::keyDown(SDL_SCANCODE_LCTRL) || input::keyDown(SDL_SCANCODE_RCTRL) ) return;
vec3_t min = room::getMin();
vec3_t max = room::getMax();
if ( input::keyDown(SDL_SCANCODE_LEFT) && selected->pos.x>min.x ) { selected->pos.x--; actor::setDirty(selected); }
if ( input::keyDown(SDL_SCANCODE_RIGHT) && selected->pos.x<max.x ) { selected->pos.x++; actor::setDirty(selected); }
if ( input::keyDown(SDL_SCANCODE_UP) && selected->pos.y>min.y ) { selected->pos.y--; actor::setDirty(selected); }
if ( input::keyDown(SDL_SCANCODE_DOWN) && selected->pos.y<max.y ) { selected->pos.y++; actor::setDirty(selected); }
if ( input::keyDown(SDL_SCANCODE_PAGEDOWN) && selected->pos.z>min.z ) { selected->pos.z--; actor::setDirty(selected); }
if ( input::keyDown(SDL_SCANCODE_PAGEUP) /*&& selected->pos.z<max.z*/ ) { selected->pos.z++; actor::setDirty(selected); }
if ( input::keyDown(SDL_SCANCODE_LEFT) && selected->pos.x>min.x ) { selected->pos.x--; actor::setDirty(selected); room::editor::modify(); }
if ( input::keyDown(SDL_SCANCODE_RIGHT) && selected->pos.x<max.x ) { selected->pos.x++; actor::setDirty(selected); room::editor::modify(); }
if ( input::keyDown(SDL_SCANCODE_UP) && selected->pos.y>min.y ) { selected->pos.y--; actor::setDirty(selected); room::editor::modify(); }
if ( input::keyDown(SDL_SCANCODE_DOWN) && selected->pos.y<max.y ) { selected->pos.y++; actor::setDirty(selected); room::editor::modify(); }
if ( input::keyDown(SDL_SCANCODE_PAGEDOWN) && selected->pos.z>min.z ) { selected->pos.z--; actor::setDirty(selected); room::editor::modify(); }
if ( input::keyDown(SDL_SCANCODE_PAGEUP) /*&& selected->pos.z<max.z*/ ) { selected->pos.z++; actor::setDirty(selected); room::editor::modify(); }
}
bool game::loop()
@@ -300,6 +354,7 @@ bool game::loop()
}
actor::reorder();
editor_select_by_keyboard();
draw::resetViewport();
draw::cls(2);
@@ -407,14 +462,22 @@ bool game::loop()
draw::setViewport(420, 0, 100, 240);
draw::color(WHITE);
draw::fillrect(0, 0, 100, 240);
if (ui::button("EDITING", 2, 2, 96, 11, editor::isEditing()))
{
room::load(room::editor::getCurrentRoom());
editor::setEditing(!editor::isEditing());
}
draw::color(LIGHT+WHITE);
draw::fillrect(2, 2, 96, 236);
draw::fillrect(2, 22, 96, 216);
draw::color(PAPER);
draw::rect(2, 2, 96, 236);
draw::setViewport(420, 2, 100, 238);
draw::rect(2, 22, 96, 216);
draw::setViewport(420, 22, 100, 218);
bool changed = false;
switch (section)
{
case SECTION_GENERAL:

View File

@@ -3,6 +3,7 @@
#include "jfile.h"
#include "jutil.h"
#include "actor.h"
#include "editor.h"
namespace room
{
@@ -95,9 +96,14 @@ namespace room
//void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn, uint8_t col, uint8_t floor, uint8_t walls, uint8_t door, uint8_t walldoor)
void load(const int room)
{
if (modified) editor::save();
if (modified && ::editor::isEditing()) editor::save();
if (room > 64) { perror("ERROR: Nombre d'habitació massa gran! Eixint..."); exit(1); }
actor::actor_t *sel = actor::getSelected();
char selected_actor_name[16]; selected_actor_name[0] = 0;
if (sel) strcpy(selected_actor_name, sel->name);
init();
// Primer carreguem els valors per defecte
@@ -181,6 +187,8 @@ namespace room
}
current_room = room;
refresh();
actor::select(actor::find(selected_actor_name));
}
void update()