static gboolean init_scenario_buttons (ScenariosState *state) { /* Show button */ state->show_button = go_gtk_builder_get_widget (state->base.gui, "show_button"); if (state->show_button == NULL) return TRUE; g_signal_connect (G_OBJECT (state->show_button), "clicked", G_CALLBACK (scenarios_show_clicked_cb), state); /* Delete button */ state->delete_button = go_gtk_builder_get_widget (state->base.gui, "delete_button"); if (state->delete_button == NULL) return TRUE; g_signal_connect (G_OBJECT (state->delete_button), "clicked", G_CALLBACK (scenarios_delete_clicked_cb), state); /* Summary button */ state->summary_button = go_gtk_builder_get_widget (state->base.gui, "summary_button"); if (state->summary_button == NULL) return TRUE; g_signal_connect (G_OBJECT (state->summary_button), "clicked", G_CALLBACK (scenarios_summary_clicked_cb), state); set_selection_state (state, FALSE); return FALSE; }
static void scenarios_delete_clicked_cb (G_GNUC_UNUSED GtkWidget *button, ScenariosState *state) { data_analysis_output_t dao; GtkTreeSelection *selection; GtkTreeIter iter; GtkTreeModel *model; gchar *value; gboolean all_deleted; GnmScenario *sc; GList *l; restore_old_values (state); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (state->scenarios_treeview)); dao_init_new_sheet (&dao); dao.sheet = state->base.sheet; if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) return; model = gtk_tree_view_get_model (GTK_TREE_VIEW (state->scenarios_treeview)); gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 0, &value, -1); gtk_list_store_remove (GTK_LIST_STORE (model), &iter); sc = gnm_sheet_scenario_find (state->base.sheet, value); if (sc) g_object_set_data (G_OBJECT (sc), "marked_deleted", GUINT_TO_POINTER (TRUE)); set_selection_state (state, FALSE); all_deleted = TRUE; for (l = state->base.sheet->scenarios; l && all_deleted; l = l->next) { GnmScenario *sc = l->data; if (!g_object_get_data (G_OBJECT (sc), "marked_deleted")) all_deleted = FALSE; } gtk_widget_set_sensitive (state->summary_button, !all_deleted); }
void main_game::run(float dt) { game_base::run(dt); // world position for interactions world_mouse_pos = camera.viewport_to_world(mouse->position, screen_rect); nebular_background->run(camera); current_level->run(dt); if (state == game_state::game_base) { bullet_particle_system.upload(dt, screen_rect); sparks_particle_system.upload(dt, screen_rect); ship_sys.run(dt, screen_rect); ship_sys.calc_screen_pos(camera, screen_rect); background_dust->run(camera, screen_rect); waypoint_visualizer->run(); trails_renderer->run(camera); if (ship_sys.size() > 0) { auto button_container = (ui::ui_container*)ui.named_elements["ship_button_container"]; uint32_t current_button_count = 0; for (auto button_it = button_container->begin(); button_it != button_container->end(); ++button_it) { current_button_count++; } if (current_button_count < ship_sys.size()) { for (uint32_t i = 0; i < ship_sys.size() - current_button_count; ++i) { auto new_selection_button = new ship_selection_button(button_container); } } auto current_button = (ship_selection_button*)*button_container->begin(); for (auto ship_it = ship_sys.begin(); ship_it != ship_sys.end(); ++ship_it) { auto screen_pos = (*ship_it)->screen_position; current_button->set_margin_left(floor(screen_pos.x - 8.f)); current_button->set_margin_top(floor(screen_pos.y - 8.f)); if ((*ship_it)->team == 0) { if (exists_in(teams[0].selected_ships, *ship_it)) { current_button->set_selection_state(ship_selection_button_state::selected); } else { current_button->set_selection_state(ship_selection_button_state::player); } } else { current_button->set_selection_state(ship_selection_button_state::enemy); } current_button->assc_ship = *ship_it; current_button->mouse_button_released(ui::get_ui_handler(&main_game::ship_selection_button_mouse_released, this)); current_button = (ship_selection_button*)current_button->get_next_leaf(); } while (current_button) { current_button->set_visibility(false); current_button = (ship_selection_button*)current_button->get_next_leaf(); } button_container->arrange_layout(viewport); } // camera movements if (mouse->wheel_y > 0) { camera.zoom_in(dt); } if (mouse->wheel_y < 0) { camera.zoom_out(dt); } if (mouse->is_down(mouse_buttons::middle)) { camera.move(mouse->delta.reflect_y()); } if (mouse->was_pressed(mouse_buttons::left)) { // enabled selection rect if (!ui.render_context.is_drawn_pixel(world_mouse_pos)) { selection_anchor = world_mouse_pos; is_selection_active = true; selection_renderer->show(); } } if (is_selection_active) { if (!ui.render_context.is_drawn_pixel(world_mouse_pos)) { teams[0].previous_selected_ships.clear(); teams[0].selected_ships.swap(teams[0].previous_selected_ships); // create selection rect selection_rect.position.x = min(selection_anchor.x, world_mouse_pos.x); selection_rect.position.y = min(selection_anchor.y, world_mouse_pos.y); selection_rect.size.width = abs(selection_anchor.x - world_mouse_pos.x); selection_rect.size.height = abs(selection_anchor.y - world_mouse_pos.y); selection_renderer->set_rect(selection_rect); // find ships inside selection rect rect ship_rect; for (auto& current_ship : teams[0].ships) { ship_rect.position.x = current_ship->transform.position.x - current_ship->dimension.size.width * 0.5f; ship_rect.position.y = current_ship->transform.position.y - current_ship->dimension.size.height * 0.5f; ship_rect.size.width = current_ship->dimension.size.width; ship_rect.size.height = current_ship->dimension.size.height; if (selection_rect.intersects(ship_rect)) { teams[0].selected_ships.push_back(current_ship); } } // check if some ship was selected for (auto selected_ship : teams[0].selected_ships) { if (!exists_in(teams[0].previous_selected_ships, selected_ship)) { selected_ship->select(); } } // check if some ship was unselected for (auto prev_selected_ship : teams[0].previous_selected_ships) { if (!exists_in(teams[0].selected_ships, prev_selected_ship)) { prev_selected_ship->unselect(); } } } } if (mouse->was_released(mouse_buttons::left)) { // disabled selection rect is_selection_active = false; selection_renderer->hide(); } if (mouse->was_pressed(mouse_buttons::right)) { if (ui.is_drawn_pixel(mouse->position)) { } else { // order selected ships to fly to mouse position waypoint new_waypoint; new_waypoint.type = waypoint_type::fly_to_position; new_waypoint.position_target = world_mouse_pos; add_waypoint_to_selection(new_waypoint); } } // damp screen shake amplitude screen_shake.set_amplitude(screen_shake.get_amplitude() * exp(-4.0f * dt)); } if (state == game_state::loading) { if (!loader.is_finished()) { ((ui_label*)ui.named_elements["loading_label"])->set_text(std::to_string((int)(loader.get_progress() * 100.f))); loader.load(hub, 10.f); loading_squares->run(loader.get_progress()); } else { change_game_state(game_state::game_base); } } }
static void cb_selection_changed (G_GNUC_UNUSED GtkTreeSelection *selection, ScenariosState *state) { set_selection_state (state, TRUE); }