updated ui input function

pull/1/head
Sara 2023-04-11 08:11:56 +02:00
parent 8d644c6d4c
commit 6fc06012b6
1 changed files with 12 additions and 13 deletions

View File

@ -131,16 +131,15 @@ void load_game() {
add_mouse_button_listener(SDL_BUTTON_RMASK, &on_erase); add_mouse_button_listener(SDL_BUTTON_RMASK, &on_erase);
add_mouse_button_listener(SDL_BUTTON_MMASK, &on_middle_mouse); add_mouse_button_listener(SDL_BUTTON_MMASK, &on_middle_mouse);
add_mouse_listener(0, &on_drag_world); add_mouse_listener(0, &on_drag_world);
} }
void start_game() { void start_game() {
g_active_view.width = 21; g_active_view.width = 21;
on_clear_key(1);
} }
void update_game() { void update_game() {
if(drawing == 1) drawing = 2; if(drawing == 1) drawing = 2;
update_input();
mouse_world_position(&cursor.x, &cursor.y); mouse_world_position(&cursor.x, &cursor.y);
cursor.x += 0.1f; cursor.y += 0.1f; cursor.x += 0.1f; cursor.y += 0.1f;
@ -175,26 +174,27 @@ void update_game() {
} }
void update_ui() { void update_ui() {
rectshape_t shape = (rectshape_t){ update_input();
0.0f, 0.0f, 1.f, 0.015f, 0, RLAYER_UI,
{100,100,100,255}, {0,0,0,0} const int offset_selected = cursor_tile - 1;
};
int w = world_sheet.w / world_sheet.tile_width,
h = world_sheet.h / world_sheet.tile_height,
offset_selected = cursor_tile - 1;
rectshape_t selected_tile_rect = (rectshape_t) { rectshape_t selected_tile_rect = (rectshape_t) {
offset_selected * 0.015f, 0.f, 0.015f, 0.015f, 0.001f, RLAYER_UI-10, offset_selected * 0.015f, 0.f, 0.015f, 0.015f, 0.001f, RLAYER_UI-10,
{0,0,0,0}, {255, 255, 255, 255} {0,0,0,0}, {255, 255, 255, 255}
}; };
draw_rect(&selected_tile_rect); draw_rect(&selected_tile_rect);
rectshape_t shape = (rectshape_t) {
0.0f, 0.0f, 1.f, 0.015f, 0, RLAYER_UI,
{100,100,100,255}, {0,0,0,0}
};
draw_rect(&shape); draw_rect(&shape);
int i = 0;
float mx, my; float mx, my;
mouse_screen_position(&mx, &my); mouse_screen_position(&mx, &my);
for(auto& original: g_tilemap.tileset.set) { for(int i=0;i<g_tilemap.tileset.set.size();++i) {
// make a copy of the reference sprite and adjust it to fit the ui // make a copy of the reference sprite and adjust it to fit the ui
sprite_t sprite = original; sprite_t sprite = g_tilemap.tileset.set.at(i);
sprite.depth = RLAYER_UI-5; sprite.depth = RLAYER_UI-5;
sprite.x = i * 0.015f; sprite.y = 0; sprite.x = i * 0.015f; sprite.y = 0;
sprite.sx = 0.015f; sprite.sy = 0.015f; sprite.sx = 0.015f; sprite.sy = 0.015f;
@ -210,6 +210,5 @@ void update_ui() {
} }
} }
++i;
} }
} }