context state control and wall selection
This commit is contained in:
parent
f768cff6d2
commit
10d243055d
6 changed files with 152 additions and 32 deletions
|
|
@ -31,7 +31,12 @@ bool kubo_window_should_close(struct kubo_context *context) {
|
|||
|
||||
void kubo_window_tick(struct kubo_context *context) {
|
||||
window_render(context);
|
||||
window_mouse_input(context);
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
window_left_mouse(context);
|
||||
}
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
||||
window_right_mouse(context);
|
||||
}
|
||||
window_key_input(context);
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +48,7 @@ static void window_render(struct kubo_context *context) {
|
|||
struct kubo_wall *wall = kubo_wall_arr_get(&context->walls, i);
|
||||
assert(wall != NULL);
|
||||
|
||||
kubo_wall_render(wall);
|
||||
kubo_wall_render(wall, context->state == KUBO_CONTEXT_WALL_SELECT);
|
||||
}
|
||||
|
||||
kubo_bar_render(context);
|
||||
|
|
@ -51,19 +56,23 @@ static void window_render(struct kubo_context *context) {
|
|||
EndDrawing();
|
||||
}
|
||||
|
||||
static void window_mouse_input(struct kubo_context *context) {
|
||||
int bar_limit = GetScreenHeight() - KUBO_BAR_HEIGHT;
|
||||
static void window_left_mouse(struct kubo_context *context) {
|
||||
switch (context->state) {
|
||||
case KUBO_CONTEXT_WALL_NEW:
|
||||
new_wall_click(context);
|
||||
break;
|
||||
case KUBO_CONTEXT_WALL_SELECT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
Vector2 new_pos = GetMousePosition();
|
||||
if (new_pos.y < bar_limit) {
|
||||
kubo_wall_add_vertex(current_wall, new_pos);
|
||||
current_wall->state = KUBO_WALL_DRAWING;
|
||||
}
|
||||
} else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
||||
current_wall->state = KUBO_WALL_DONE;
|
||||
static void window_right_mouse(struct kubo_context *context) {
|
||||
switch (context->state) {
|
||||
case KUBO_CONTEXT_WALL_NEW:
|
||||
new_wall_end(context);
|
||||
break;
|
||||
case KUBO_CONTEXT_WALL_SELECT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,14 +89,53 @@ static void window_key_input(struct kubo_context *context) {
|
|||
break;
|
||||
|
||||
case KEY_W:
|
||||
context->state = KUBO_CONTEXT_STATE_WALL_NEW;
|
||||
kubo_context_set_state(context, KUBO_CONTEXT_WALL_NEW);
|
||||
break;
|
||||
|
||||
case KEY_S:
|
||||
context->state = KUBO_CONTEXT_STATE_WALL_SELECT;
|
||||
kubo_context_set_state(context, KUBO_CONTEXT_WALL_SELECT);
|
||||
break;
|
||||
|
||||
case KEY_RIGHT:
|
||||
case KEY_UP:
|
||||
case KEY_L:
|
||||
case KEY_K:
|
||||
kubo_context_select_next_wall(context);
|
||||
break;
|
||||
|
||||
case KEY_LEFT:
|
||||
case KEY_DOWN:
|
||||
case KEY_J:
|
||||
case KEY_H:
|
||||
kubo_context_select_prev_wall(context);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void new_wall_click(struct kubo_context *context) {
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
if (!current_wall) {
|
||||
return;
|
||||
}
|
||||
|
||||
int bar_limit = GetScreenHeight() - KUBO_BAR_HEIGHT;
|
||||
Vector2 new_pos = GetMousePosition();
|
||||
if (new_pos.y < bar_limit) {
|
||||
kubo_wall_add_vertex(current_wall, new_pos);
|
||||
current_wall->state = KUBO_WALL_DRAWING;
|
||||
}
|
||||
}
|
||||
|
||||
static void new_wall_end(struct kubo_context *context) {
|
||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||
|
||||
if (!current_wall) {
|
||||
return;
|
||||
}
|
||||
|
||||
current_wall->state = KUBO_WALL_DONE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue