From 543c6a81e345d592bd53d11e38d4a1ea26905f45 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 5 Oct 2023 18:55:51 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20l'animaci=C3=B3=20no=20funcionava?= =?UTF-8?q?=20be=20-=20Versi=C3=B3=20del=20Update=20dels=20actors=20per=20?= =?UTF-8?q?al=20Editor=20-=20[NEW]=20gui::TextBox=20-=20[NEW]=20input::get?= =?UTF-8?q?KeyPressed()=20-=20Acabant=20el=20editor...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/actor.cpp | 16 +++++++++++++++- source/actor.h | 3 ++- source/jinput.cpp | 6 ++++++ source/jinput.h | 2 ++ source/jui.cpp | 19 +++++++++++++++++++ source/jui.h | 1 + source/main.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 7 files changed, 80 insertions(+), 10 deletions(-) diff --git a/source/actor.cpp b/source/actor.cpp index f63be46..44696bc 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -545,7 +545,7 @@ namespace actor act->anim_frame=(act->anim_frame+1)%4; act->anim_wait_count=0; } else { - act->anim_wait++; + act->anim_wait_count++; } if (act->flags & FLAG_HERO) updateUserInput(act); @@ -560,6 +560,20 @@ namespace actor if (update_all && next) update(next); } + void updateEditor(actor_t *act, const bool update_all) + { + actor_t *next = act->next; + + if (act->anim_wait_count==act->anim_wait) { + act->anim_frame=(act->anim_frame+1)%4; + act->anim_wait_count=0; + } else { + act->anim_wait_count++; + } + + if (update_all && next) update(next); + } + void print(int x, int y, int num) { int digits=0; diff --git a/source/actor.h b/source/actor.h index f2d0fe3..38404bc 100644 --- a/source/actor.h +++ b/source/actor.h @@ -49,7 +49,7 @@ namespace actor uint8_t orient; uint8_t anim_cycle; uint8_t anim_frame; - uint8_t anim_wait; + int anim_wait; uint8_t anim_wait_count; uint16_t flags; @@ -81,6 +81,7 @@ namespace actor void reorder(); void update(actor_t *act, const bool update_all=true); + void updateEditor(actor_t *act, const bool update_all=true); void draw(actor_t *act, const bool draw_all=true); diff --git a/source/jinput.cpp b/source/jinput.cpp index 6ef6f47..63317a1 100644 --- a/source/jinput.cpp +++ b/source/jinput.cpp @@ -41,6 +41,12 @@ namespace input return keydown; } + // Torna el codi de la tecla que està sent polsada ara mateix + const uint8_t getKeyPressed() + { + return keypressed; + } + void updateKey(uint8_t key) { keydown = key; diff --git a/source/jinput.h b/source/jinput.h index 8776ab4..7ba55d2 100644 --- a/source/jinput.h +++ b/source/jinput.h @@ -25,6 +25,8 @@ namespace input /// @return Quina tecla està sent polsada const uint8_t whichKey(); + const uint8_t getKeyPressed(); + void updateKey(uint8_t key); void updateKeypressed(uint8_t key); void updateClk(uint8_t btn); diff --git a/source/jui.cpp b/source/jui.cpp index a861129..d1cca75 100644 --- a/source/jui.cpp +++ b/source/jui.cpp @@ -25,4 +25,23 @@ namespace ui } return 0; } + + const int textbox(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2) + { + const int mx = input::mouseX(); + const int my = input::mouseY(); + const bool inside = (mx>=x) && (mx=y) && (my= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19; + if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61; + return 32; +} + +void btn_txt(const char* label, const int x, const int y, char *var) { draw::print(label, x, y+3, 15, 0); int result = 0; - result = ui::button(var, x+22, y, 66, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE); + result = ui::textbox(var, x+22, y, 66, 11, WHITE, LIGHT+WHITE); if (result) { + const int len = strlen(var); + if (result == SDL_SCANCODE_BACKSPACE) { + if (len>0) var[len-1] = 0; + } else { + if (len<15) { + var[len] = scancode_to_char(result); + var[len+1] = 0; + } + } } } @@ -226,6 +243,8 @@ bool game::loop() // WHILE EDITING... editor_move_selected(); + actor::updateEditor(actor::getFirst()); + //actor::update(actor::getFirst()); actor::reorder(); @@ -244,7 +263,7 @@ bool game::loop() if (section==0) { draw::print("ROOM", 334, 13, YELLOW, LIGHT+BLACK); - if (ui::button("ACTORS", 365, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=1; + if (ui::button("ACTORS", 365, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=2; } else { if (ui::button("ROOM", 330, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=0; draw::print("ACTORS", 369, 13, YELLOW, BLACK); @@ -285,8 +304,8 @@ bool game::loop() btn_small(403, 70, act->bmp_rect.h, 0, 512); draw::print("OFFSET:", 330, 88, 15, 0); - btn_small(386, 85, act->bmp_offset.x, 0, 512); - btn_small(403, 85, act->bmp_offset.y, 0, 512); + 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); btn_small(369, 105, act->pos.x, 0, 512); @@ -309,6 +328,12 @@ bool game::loop() 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: @@ -325,8 +350,10 @@ bool game::loop() if (act==actor::getSelected()) { draw::color(TEAL); draw::fillrect(330, 40+line*9, 63, 9); - } else if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) { + } + if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) { actor::select(act); + section=1; } draw::print(act->name, 332, 42+line*9, WHITE, BLACK); line++;