- [FIX] l'animació no funcionava be

- Versió del Update dels actors per al Editor
- [NEW] gui::TextBox
- [NEW] input::getKeyPressed()
- Acabant el editor...
This commit is contained in:
2023-10-05 18:55:51 +02:00
parent a141d11760
commit 543c6a81e3
7 changed files with 80 additions and 10 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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<x+w) && (my>=y) && (my<y+h);
const int txt_size = strlen(label)*4;
const int txt_x = x+(w-txt_size)/2;
draw::color(inside?c2:c1);
draw::fillrect(x, y, w, h);
draw::print(label, 1+txt_x, y+3, LIGHT+WHITE, PAPER);
if (inside)
{
return input::getKeyPressed();
}
return 0;
}
}

View File

@@ -3,4 +3,5 @@
namespace ui
{
const int button(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2, const int c3);
const int textbox(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2);
}

View File

@@ -155,7 +155,7 @@ void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vec
{
draw::print(label, x, y+3, 15, 0);
int result = 0;
int pos = 0;
std::size_t pos = 0;
while (pos<values.size())
{
if (values[pos]==var) break;
@@ -174,7 +174,7 @@ bool btn_opt2(const char* label, const int x, const int y, char *var, std::vecto
{
draw::print(label, x, y+3, 15, 0);
int result = 0;
int pos = 0;
std::size_t pos = 0;
std::string v = var;
while (pos < values.size() && v != values[pos])
{
@@ -192,13 +192,30 @@ bool btn_opt2(const char* label, const int x, const int y, char *var, std::vecto
return false;
}
void btn_txt(const char* label, const int x, const int y, const char *var)
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;
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++;