- Seguim treballant eternament en l'editor... pero ja comença a estar apanyadet

This commit is contained in:
2023-10-06 18:56:24 +02:00
parent 601b93478a
commit ef2a89b620

View File

@@ -52,7 +52,7 @@ void restart()
void game::init() void game::init()
{ {
draw::init("The Pool", 420, 240, 3); draw::init("The Pool", 520, 240, 3);
//room::init(); //room::init();
surf = draw::loadSurface("test.gif"); surf = draw::loadSurface("test.gif");
@@ -82,6 +82,12 @@ void game::init()
box->mov_push = PUSH_XN; box->mov_push = PUSH_XN;
actor::setDirty(box, true); actor::setDirty(box, true);
box = actor::create("BOX2", {32,32,0}, {8,8,8}, "test.gif", {32,0,32,32}, {0,32});
box->flags = FLAG_PUSHABLE | FLAG_GRAVITY;
box->movement = MOV_CW;
box->mov_push = PUSH_XN;
actor::setDirty(box, true);
restart(); restart();
actor::select(actor::find("BOX")); actor::select(actor::find("BOX"));
@@ -125,10 +131,10 @@ void btn_small(const int x, const int y, int &var, int min, int max, bool restrt
{ {
char buffer[100]; char buffer[100];
int result=0; int result=0;
result=ui::button(SDL_itoa(var, buffer, 10), x, y, 15, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE); result=ui::spin(SDL_itoa(var, buffer, 10), x, y, 17, 11);
if (result) if (result)
{ {
var=SDL_max(min, SDL_min(max, var-(result-2))); var=SDL_max(min, SDL_min(max, var+result));
if (restrt) restart(); if (restrt) restart();
} }
} }
@@ -137,9 +143,9 @@ void btn_check(const int x, const int y, const char* label, uint16_t &flags, con
{ {
int result=0; int result=0;
if (flags & value) { if (flags & value) {
result=ui::button(label, x, y, 20, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE); result=ui::check(label, x, y, 24, 11, true);
} else { } else {
result=ui::button(label, x, y, 20, 11, BLACK, WHITE, LIGHT+PURPLE); result=ui::check(label, x, y, 24, 11, false);
} }
if (result) if (result)
{ {
@@ -153,7 +159,8 @@ void btn_check(const int x, const int y, const char* label, uint16_t &flags, con
void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vector<uint8_t> values, std::vector<std::string> labels) void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vector<uint8_t> values, std::vector<std::string> labels)
{ {
draw::print(label, x, y+3, 15, 0); //draw::print(label, x, y+3, 15, 0);
ui::label(label, x, y, 32, 11);
int result = 0; int result = 0;
std::size_t pos = 0; std::size_t pos = 0;
while (pos<values.size()) while (pos<values.size())
@@ -162,7 +169,7 @@ void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vec
pos++; pos++;
} }
result = ui::combo(labels[pos].c_str(), x+32, y, 56, 11); result = ui::combo(labels[pos].c_str(), x+31, y, 65, 11);
if (result) if (result)
{ {
pos++; if (pos==values.size()) pos=0; pos++; if (pos==values.size()) pos=0;
@@ -172,7 +179,8 @@ void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vec
bool btn_opt2(const char* label, const int x, const int y, char *var, std::vector<std::string> values) bool btn_opt2(const char* label, const int x, const int y, char *var, std::vector<std::string> values)
{ {
draw::print(label, x, y+3, 15, 0); //draw::print(label, x, y+3, PAPER, 0);
ui::label(label, x, y, 32, 11);
int result = 0; int result = 0;
std::size_t pos = 0; std::size_t pos = 0;
std::string v = var; std::string v = var;
@@ -182,7 +190,7 @@ bool btn_opt2(const char* label, const int x, const int y, char *var, std::vecto
} }
if (pos==values.size()) pos = 0; if (pos==values.size()) pos = 0;
result = ui::combo(var, x+32, y, 56, 11); result = ui::combo(var, x+31, y, 65, 11);
if (result) if (result)
{ {
pos++; if (pos==values.size()) pos=0; pos++; if (pos==values.size()) pos=0;
@@ -202,9 +210,10 @@ const uint8_t scancode_to_char(const uint8_t scancode)
void btn_txt(const char* label, const int x, const int y, char *var) void btn_txt(const char* label, const int x, const int y, char *var)
{ {
draw::print(label, x, y+3, PAPER, 0); //draw::print(label, x, y+3, PAPER, 0);
ui::label(label, x, y, 32, 11);
int result = 0; int result = 0;
result = ui::textbox(var, x+22, y, 66, 11, LIGHT+WHITE, LIGHT+YELLOW); result = ui::textbox(var, x+31, y, 65, 11);
if (result) if (result)
{ {
const int len = strlen(var); const int len = strlen(var);
@@ -229,12 +238,12 @@ void editor_move_selected()
vec3_t min = room::getMin(); vec3_t min = room::getMin();
vec3_t max = room::getMax(); vec3_t max = room::getMax();
if ( input::keyDown(SDL_SCANCODE_LEFT) && selected->pos.x>min.x ) selected->pos.x--; 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++; 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--; 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++; 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--; 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++; if ( input::keyDown(SDL_SCANCODE_PAGEUP) /*&& selected->pos.z<max.z*/ ) { selected->pos.z++; actor::setDirty(selected); }
} }
bool game::loop() bool game::loop()
@@ -249,101 +258,76 @@ bool game::loop()
actor::reorder(); actor::reorder();
draw::resetViewport();
draw::cls(2); draw::cls(2);
draw::setViewport(100,0,320,240);
room::draw(); room::draw();
actor::draw(actor::getFirst()); actor::draw(actor::getFirst());
room::draw2(); room::draw2();
//draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0); //draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0);
draw::color(WHITE); /*
draw::fillrect(320, 0, 100, 240);
print(0,0,input::mouseX()); print(0,0,input::mouseX());
print(0,20,input::mouseY()); print(0,20,input::mouseY());
print(0,30,input::mouseBtn(1)?1:0); print(0,30,input::mouseBtn(1)?1:0);
print(0,40,input::mouseBtn(2)?1:0); print(0,40,input::mouseBtn(2)?1:0);
print(0,50,input::mouseBtn(3)?1:0); print(0,50,input::mouseBtn(3)?1:0);
*/
/*
if (section==0) { if (section==0) {
draw::print("ROOM", 334, 13, YELLOW, LIGHT+BLACK); draw::print("ROOM", 334, 13, YELLOW, LIGHT+BLACK);
if (ui::button("ACTORS", 365, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=2; if (ui::button("ACTORS", 365, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=1;
} else { } else {
if (ui::button("ROOM", 330, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=0; if (ui::button("ROOM", 330, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=0;
draw::print("ACTORS", 369, 13, YELLOW, BLACK); draw::print("ACTORS", 369, 13, YELLOW, BLACK);
} }
*/
actor::actor_t *act = nullptr; actor::actor_t *act = nullptr;
/*
switch (section) { switch (section) {
case 0: case 0:
btn("ROOM WIDTH:", 330, 40, room_w, 0, 3); */
btn("ROOM HEIGHT:", 330, 55, room_h, 0, 3); draw::setViewport(0,0,100,240);
draw::print("DOORS:", 330, 80, 15, 0); draw::color(WHITE);
btn_small(352, 80, room_xn, -1, 5, true); draw::fillrect(0, 0, 100, 240);
btn_small(369, 80, room_yp, -1, 5, true);
btn_small(386, 80, room_xp, -1, 5, true);
btn_small(403, 80, room_yn, -1, 5, true);
btn("COLOR:", 330, 140, room_color, 5, 11); btn("ROOM WIDTH:", 10, 40, room_w, 0, 3);
btn("FLOOR:", 330, 155, room_floor, 0, 5); btn("ROOM HEIGHT:", 10, 55, room_h, 0, 3);
btn("WALLS:", 330, 170, room_walls, 0, 5);
btn("DOORS:", 330, 185, room_doors, 0, 4); draw::print("DOORS:", 10, 80, 15, 0);
btn("WDOORS:", 330, 200, room_walldoors, 0, 5); btn_small(32, 80, room_xn, -1, 5, true);
btn_small(49, 80, room_yp, -1, 5, true);
btn_small(66, 80, room_xp, -1, 5, true);
btn_small(83, 80, room_yn, -1, 5, true);
btn("COLOR:", 10, 140, room_color, 5, 11);
btn("FLOOR:", 10, 155, room_floor, 0, 5);
btn("WALLS:", 10, 170, room_walls, 0, 5);
btn("DOORS:", 10, 185, room_doors, 0, 4);
btn("WDOORS:", 10, 200, room_walldoors, 0, 5);
/*
break; break;
case 1: case 1:
act = actor::getSelected(); */
if (act) draw::setViewport(420, 0, 100, 240);
{ draw::color(WHITE);
btn_txt("NAME:", 330, 40, act->name); draw::fillrect(0, 0, 100, 240);
if (btn_opt2("BMP:", 330, 51, act->bmp, gifs)) {
draw::freeSurface(act->surface);
act->surface = draw::loadSurface(act->bmp);
}
draw::print("RECT:", 330, 73, 15, 0);
btn_small(352, 70, act->bmp_rect.x, 0, 512);
btn_small(369, 70, act->bmp_rect.y, 0, 512);
btn_small(386, 70, act->bmp_rect.w, 0, 512);
btn_small(403, 70, act->bmp_rect.h, 0, 512);
draw::print("OFFSET:", 330, 88, 15, 0); draw::setViewport(420, 2, 100, 240);
btn_small(386, 85, act->bmp_offset.x, -32, 64);
btn_small(403, 85, act->bmp_offset.y, -32, 64);
draw::print("POS:", 330, 108, 15, 0); draw::color(LIGHT+WHITE);
btn_small(369, 105, act->pos.x, 0, 512); draw::fillrect(2, 0, 96, 100);
btn_small(386, 105, act->pos.y, 0, 512); draw::color(PAPER);
btn_small(403, 105, act->pos.z, 0, 512); draw::rect(2, 0, 96, 100);
draw::print("SIZE:", 330, 123, 15, 0); const int mx = draw::getLocalX(input::mouseX());
btn_small(369, 120, act->size.x, 0, 512); const int my = draw::getLocalY(input::mouseY());
btn_small(386, 120, act->size.y, 0, 512);
btn_small(403, 120, act->size.z, 0, 512);
btn_opt("ORIENT:", 330, 135, act->orient, {PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN}, {"NONE", "XP", "XN", "YP", "YN"});
btn_check(330, 150, "HERO", act->flags, FLAG_HERO);
btn_check(352, 150, "PUSH", act->flags, FLAG_PUSHABLE);
btn_check(374, 150, "REAC", act->flags, FLAG_REACTIVE);
btn_check(396, 150, "MOVI", act->flags, FLAG_MOVING);
btn_check(330, 165, "ANIM", act->flags, FLAG_ANIMATED);
btn_check(352, 165, "ORIE", act->flags, FLAG_ORIENTABLE);
btn_check(374, 165, "DEAD", act->flags, FLAG_DEADLY);
btn_check(396, 165, "GRAV", act->flags, FLAG_GRAVITY);
btn_opt("MOVEMNT:", 330, 180, act->movement, {MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_HUNT}, {"NONE", "X", "Y", "Z", "CW", "CCW", "RAND", "HUNT"});
btn_opt("ANIMCYC:", 330, 195, act->anim_cycle, {0, 1}, {"0 1 0 2", "0 1 2 3"});
draw::print("ANIM SPEED:", 330, 213, 15, 0);
btn_small(403, 210, act->anim_wait, 0, 10);
break;
}
case 2:
draw::color(TEAL);
draw::rect(328, 38, 67, 94);
const int mx = input::mouseX();
const int my = input::mouseY();
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3); const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
int line = 0; int line = 0;
@@ -351,19 +335,101 @@ bool game::loop()
while (act) { while (act) {
if ((act->flags&FLAG_NOEDITOR)!=FLAG_NOEDITOR) { if ((act->flags&FLAG_NOEDITOR)!=FLAG_NOEDITOR) {
if (act==actor::getSelected()) { if (act==actor::getSelected()) {
draw::color(TEAL); draw::color(LIGHT+BLUE);
draw::fillrect(330, 40+line*9, 63, 9); draw::fillrect(4, 2+line*9, 92, 9);
} }
if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) { if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnDown) {
actor::select(act); actor::select(act);
section=1; //section=1;
} }
draw::print(act->name, 332, 42+line*9, WHITE, BLACK); draw::print(act->name, 6, 4+line*9, LIGHT+WHITE, BLACK);
line++;
}
act = act->next;
}
act = actor::getSelected();
if (act)
{
draw::setViewport(420, 110, 100, 240);
btn_txt("NAME:", 2, 0, act->name);
if (btn_opt2("BMP:", 2, 10, act->bmp, gifs)) {
draw::freeSurface(act->surface);
act->surface = draw::loadSurface(act->bmp);
}
//draw::print("RECT:", 2, 64, PAPER, 0);
ui::label("RECT", 2, 20, 32, 11);
btn_small(33, 20, act->bmp_rect.x, 0, 512);
btn_small(49, 20, act->bmp_rect.y, 0, 512);
btn_small(65, 20, act->bmp_rect.w, 0, 512);
btn_small(81, 20, act->bmp_rect.h, 0, 512);
ui::label("OFFSET", 2, 30, 32, 11);
btn_small(65, 30, act->bmp_offset.x, -32, 64);
btn_small(81, 30, act->bmp_offset.y, -32, 64);
ui::label("POS", 2, 42, 32, 11);
btn_small(49, 42, act->pos.x, 0, 512);
btn_small(65, 42, act->pos.y, 0, 512);
btn_small(81, 42, act->pos.z, 0, 512);
ui::label("SIZE", 2, 52, 32, 11);
btn_small(49, 52, act->size.x, 0, 512);
btn_small(65, 52, act->size.y, 0, 512);
btn_small(81, 52, act->size.z, 0, 512);
btn_check(2, 64, "HERO", act->flags, FLAG_HERO);
btn_check(26, 64, "PUSH", act->flags, FLAG_PUSHABLE);
btn_check(50, 64, "REAC", act->flags, FLAG_REACTIVE);
btn_check(74, 64, "MOVI", act->flags, FLAG_MOVING);
btn_check(2, 74, "ANIM", act->flags, FLAG_ANIMATED);
btn_check(26, 74, "ORIE", act->flags, FLAG_ORIENTABLE);
btn_check(50, 74, "DEAD", act->flags, FLAG_DEADLY);
btn_check(74, 74, "GRAV", act->flags, FLAG_GRAVITY);
btn_opt("ORIENT", 2, 86, act->orient, {PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN}, {"NONE", "XP", "XN", "YP", "YN"});
btn_opt("MOVEMNT", 2, 96, act->movement, {MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_HUNT}, {"NONE", "X", "Y", "Z", "CW", "CCW", "RAND", "HUNT"});
btn_opt("ANIMCYC", 2, 106, act->anim_cycle, {0, 1}, {"0 1 0 2", "0 1 2 3"});
//draw::print("ANIM SPEED:", 2, 156, 15, 0);
ui::label("ANMSPED", 2, 116, 32, 11);
btn_small(81, 116, act->anim_wait, 0, 10);
/*
break;
}
*/
/* case 2:
draw::setViewport(320, 38, 100, 100);
draw::color(LIGHT+WHITE);
draw::fillrect(2, 0, 96, 100);
draw::color(PAPER);
draw::rect(2, 0, 96, 100);
const int mx = draw::getLocalX(input::mouseX());
const int my = draw::getLocalY(input::mouseY());
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
int line = 0;
act = actor::getFirst();
while (act) {
if ((act->flags&FLAG_NOEDITOR)!=FLAG_NOEDITOR) {
if (act==actor::getSelected()) {
draw::color(LIGHT+BLUE);
draw::fillrect(4, 2+line*9, 92, 9);
}
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnDown) {
actor::select(act);
//section=1;
}
draw::print(act->name, 6, 4+line*9, LIGHT+WHITE, BLACK);
line++; line++;
} }
act = act->next; act = act->next;
} }
break; break;
*/
} }
draw::render(); draw::render();