/* * Create the wid_game_map_client */ void wid_game_map_client_wid_create (void) { if (sdl_is_exiting()) { return; } if (wid_game_map_client_window) { return; } wid_notify_flush(); LOG("Client: Create map"); { fpoint tl = {0.0f, 0.0f}; fpoint br = {1.0f, 1.0f}; wid_game_map_client_window = wid_new_square_window("wid_game_map_client"); wid_set_movable(wid_game_map_client_window, false); wid_set_do_not_raise(wid_game_map_client_window, true); wid_set_no_shape(wid_game_map_client_window); wid_set_mode(wid_game_map_client_window, WID_MODE_NORMAL); wid_set_text_advance(wid_game_map_client_window, 0.9f); wid_set_text_scaling(wid_game_map_client_window, 2.0f); wid_set_text_pos(wid_game_map_client_window, true, 0.5f, 0.10f); wid_set_text_bot(wid_game_map_client_window, true); wid_set_text_lhs(wid_game_map_client_window, true); wid_set_tl_br_pct(wid_game_map_client_window, tl, br); fsize sz = {0.0f, 0.0f}; wid_set_tex_tl(wid_game_map_client_window, sz); fsize sz2 = {1.0f, 1.0f}; wid_set_tex_br(wid_game_map_client_window, sz2); wid_set_on_key_down(wid_game_map_client_window, wid_game_map_key_event); wid_set_on_joy_down(wid_game_map_client_window, wid_game_map_joy_event); } { fpoint tl = {0.00f, 0.00f}; fpoint br = {1.00f, 1.00f}; wid_game_map_client_grid_container = wid_new_container(wid_game_map_client_window, "wid game client grid container"); wid_set_no_shape(wid_game_map_client_grid_container); wid_set_color(wid_game_map_client_grid_container, WID_COLOR_TL, BLACK); wid_set_color(wid_game_map_client_grid_container, WID_COLOR_BG, BLACK); wid_set_color(wid_game_map_client_grid_container, WID_COLOR_BR, BLACK); wid_set_on_mouse_motion(wid_game_map_client_grid_container, wid_game_map_client_receive_mouse_motion); wid_set_tl_br_pct(wid_game_map_client_grid_container, tl, br); wid_set_tex(wid_game_map_client_grid_container, 0, 0); wid_set_on_key_down(wid_game_map_client_grid_container, wid_game_map_key_event); wid_set_on_joy_down(wid_game_map_client_grid_container, wid_game_map_joy_event); LOG("Client: Created map container window"); } { double base_tile_width = ((1.0f / ((double)TILES_SCREEN_WIDTH)) * (double)global_config.video_gl_width); double base_tile_height = ((1.0f / ((double)TILES_SCREEN_HEIGHT)) * (double)global_config.video_gl_height); fpoint tl = { 0, 0 }; fpoint br = { 0, 0 }; br.x += base_tile_width; br.y += base_tile_height; client_tile_width = br.x - tl.x; client_tile_height = br.y - tl.y; client_tile_width = br.x - tl.x; client_tile_height = br.y - tl.y; if (!client_tile_width) { client_tile_width = TILE_WIDTH; } if (!client_tile_height) { client_tile_height = TILE_HEIGHT; } wid_new_grid(wid_game_map_client_grid_container, MAP_WIDTH, MAP_HEIGHT, client_tile_width, client_tile_height); LOG("Client: Created map container window grid"); } /* * Mark that we want to learn the starting stats so we can use those * when starting again with this player type. */ global_config.starting_stats_inited = false; level_pos_t level_pos = global_config.stats.level_pos; if (!level_pos.x && !level_pos.y) { level_pos.x = (myrand() % LEVEL_INITIAL_RANDOM) + 1; level_pos.y = 1; } client_level = level_new(wid_game_map_client_grid_container, level_pos, false /* is_editor */, false /* is_map_editor */, false /* on_server */); LOG("Client: Created level %d.%d", level_pos.y, level_pos.x); if (!client_level) { WARN("failed to load level %u.%u", level_pos.y, level_pos.x); } wid_game_map_client_vert_scroll = wid_new_vert_scroll_bar(wid_game_map_client_window, wid_game_map_client_grid_container); wid_game_map_client_horiz_scroll = wid_new_horiz_scroll_bar(wid_game_map_client_window, wid_game_map_client_grid_container); wid_visible(wid_get_parent(wid_game_map_client_vert_scroll), 0); wid_visible(wid_get_parent(wid_game_map_client_horiz_scroll), 0); wid_visible(wid_game_map_client_vert_scroll, 0); wid_visible(wid_game_map_client_horiz_scroll, 0); wid_update(wid_game_map_client_vert_scroll); wid_update(wid_game_map_client_horiz_scroll); wid_game_map_client_score_update(client_level, true /* redo */); wid_hide(wid_game_map_client_window, 0); if (global_config.server_current_players > 1) { wid_visible(wid_chat_window, 0); } }
/* * Key down etc... */ static uint8_t wid_text_input_receive_input (widp w, const SDL_KEYSYM *key) { widp button; switch (key->sym) { case SDLK_RETURN: button = wid_find(wid_get_top_parent(w), "ok"); if (button) { wid_text_input_button_selected(button); return (true); } button = wid_find(wid_get_top_parent(w), "yes"); if (button) { wid_text_input_button_selected(button); return (true); } if (wid_text_input_button_selected(w)) { return (true); } break; case SDLK_ESCAPE: { button = wid_find(wid_get_top_parent(w), "cancel"); if (button) { wid_text_input_button_selected(button); return (true); } button = wid_find(wid_get_top_parent(w), "no"); if (button) { wid_text_input_button_selected(button); return (true); } button = wid_find(wid_get_top_parent(w), "close"); if (button) { wid_text_input_button_selected(button); return (true); } if (wid_text_input_button_selected(w)) { return (true); } break; } default: break; } /* * Feed to the general input handler */ int32_t ret = wid_receive_input(w, key); /* * Update the text_input to show only matching files. */ widp container = wid_find(wid_get_top_parent(w), wid_text_input_filelist_container_str); if (!container) { return (ret); } tree_root *r = wid_get_children(container); if (!r) { return (ret); } tree_node *n = tree_root_first(r); while (n) { fpoint container_tl; fpoint container_br; fpoint trough_tl; fpoint trough_br; double child_height; widp child; fpoint tl; fpoint br; child = (typeof(child)) n; /* * If a partial match, highlight the widget. */ if (strncmp(wid_get_text(child), wid_get_text(w), strlen(wid_get_text(w)))) { n = tree_get_next(r, r->node, n); continue; } wid_set_mode(child, WID_MODE_ACTIVE); /* * Find where the child is with respect to the parent. */ wid_get_tl_br(child, &tl, &br); wid_get_tl_br(container, &container_tl, &container_br); /* * Compare within the overall height of all children. */ wid_get_children_size(container, 0, &child_height); /* * What percentage of the way down. */ double pct = (double)(tl.y - container_tl.y) / (double)child_height; /* * Now adjust the scrollbar. */ widp scrollbar = wid_get_scrollbar_vert(container); /* * But we need the trough height. */ wid_get_tl_br(wid_get_parent(scrollbar), &trough_tl, &trough_br); double trough_height = wid_get_height(wid_get_parent(scrollbar)); /* * Now apply the same percentage as a wid move. */ wid_move_to_abs_in(scrollbar, trough_tl.x, trough_tl.y + pct * trough_height, 100); return (ret); } return (ret); }