static void select_port_direction_cb(GtkCheckMenuItem * menu_item, gpointer user_data) { if (gtk_check_menu_item_get_active(menu_item)) { current_hex->facing = GPOINTER_TO_INT(user_data); guimap_draw_hex(gmap, current_hex); } }
static gint select_terrain_cb(G_GNUC_UNUSED GtkWidget * menu, gpointer user_data) { Terrain terrain = GPOINTER_TO_INT(user_data); Hex *adjacent; gint i; if (terrain == current_hex->terrain) return TRUE; current_hex->terrain = terrain; if (terrain_has_chit(terrain)) { if (current_hex->roll == 0) current_hex->roll = 2; } else current_hex->roll = 0; if (terrain != SEA_TERRAIN) current_hex->resource = NO_RESOURCE; if (terrain == SEA_TERRAIN || terrain == LAST_TERRAIN) { for (i = 0; i < 6; i++) { adjacent = hex_in_direction(current_hex, i); if (adjacent != NULL && adjacent->resource != NO_RESOURCE && adjacent->facing == (i + 3) % 6) { adjacent->resource = NO_RESOURCE; adjacent->facing = 0; guimap_draw_hex(gmap, adjacent); } } } guimap_draw_hex(gmap, current_hex); /* XXX Since some edges may have changed, we need to redisplay */ guimap_display(gmap); return TRUE; }
static gint key_press_map_cb(GtkWidget * area, GdkEventKey * event, gpointer user_data) { static gint last_x, last_y; static gchar *last_key; GuiMap *gmap = user_data; gint x, y; gboolean plus10; if (area->window == NULL || gmap->map == NULL) return FALSE; gtk_widget_get_pointer(area, &x, &y); current_hex = guimap_find_hex(gmap, x, y); if (current_hex == NULL || !terrain_has_chit(current_hex->terrain)) return TRUE; if (last_x == x && last_y == y && strcmp(last_key, "1") == 0) plus10 = TRUE; else plus10 = FALSE; if (!plus10 && strcmp(event->string, "2") == 0) current_hex->roll = 2; else if (strcmp(event->string, "3") == 0) current_hex->roll = 3; else if (strcmp(event->string, "4") == 0) current_hex->roll = 4; else if (strcmp(event->string, "5") == 0) current_hex->roll = 5; else if (strcmp(event->string, "6") == 0) current_hex->roll = 6; else if (strcmp(event->string, "8") == 0) current_hex->roll = 8; else if (strcmp(event->string, "9") == 0) current_hex->roll = 9; else if (plus10 && strcmp(event->string, "0") == 0) current_hex->roll = 10; else if (plus10 && strcmp(event->string, "1") == 0) current_hex->roll = 11; else if (plus10 && strcmp(event->string, "2") == 0) current_hex->roll = 12; guimap_draw_hex(gmap, current_hex); last_x = x; last_y = y; g_free(last_key); last_key = g_strdup(event->string); return TRUE; }
static gint select_port_resource_cb(G_GNUC_UNUSED GtkWidget * menu, gpointer user_data) { gint i; if (current_hex->resource == NO_RESOURCE) { for (i = 0; i < 6; i++) { const Hex *adjacent; adjacent = hex_in_direction(current_hex, i); if (adjacent != NULL && adjacent->terrain != LAST_TERRAIN && adjacent->terrain != SEA_TERRAIN) { current_hex->facing = i; break; } } } current_hex->resource = GPOINTER_TO_INT(user_data); guimap_draw_hex(gmap, current_hex); return TRUE; }
static gint button_press_map_cb(GtkWidget * area, GdkEventButton * event, gpointer user_data) { GuiMap *gmap = user_data; GtkWidget *menu; const Hex *adjacent; gboolean port_ok; gint num_ports; gint i; if (area->window == NULL || gmap->map == NULL) return FALSE; if (event->button != 1) return TRUE; current_hex = guimap_find_hex(gmap, event->x, event->y); if (current_hex == NULL) return TRUE; menu = NULL; if (event->button == 1) { MapElement element; Node *current_node; gint distance_node; gint distance_hex; current_node = guimap_find_node(gmap, event->x, event->y); element.node = current_node; distance_node = guimap_distance_cursor(gmap, &element, MAP_NODE, event->x, event->y); element.hex = current_hex; distance_hex = guimap_distance_cursor(gmap, &element, MAP_HEX, event->x, event->y); if (distance_node < distance_hex) { current_node->no_setup = !current_node->no_setup; for (i = 0; i < G_N_ELEMENTS(current_node->hexes); i++) { guimap_draw_hex(gmap, current_node->hexes[i]); } return TRUE; } else { menu = terrain_menu; } } else if (current_hex->roll > 0) { menu = roll_menu; for (i = 2; i <= 12; i++) { if (roll_numbers[i] != NULL) gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(roll_numbers[i]), current_hex->roll == i); } gtk_check_menu_item_set_active(shuffle_tile, current_hex->shuffle); } else if (current_hex->terrain == SEA_TERRAIN) { num_ports = 0; for (i = 0; i < 6; i++) { adjacent = hex_in_direction(current_hex, i); port_ok = FALSE; if (adjacent != NULL && adjacent->terrain != LAST_TERRAIN && adjacent->terrain != SEA_TERRAIN) { num_ports++; if (current_hex->resource != NO_RESOURCE) port_ok = TRUE; } gtk_widget_set_sensitive(port_directions[i], port_ok); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM (port_directions [i]), current_hex->facing == i && port_ok); } if (num_ports > 0) menu = port_menu; } if (menu != NULL) gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); return TRUE; }
void gui_draw_hex(const Hex * hex) { if (gmap->pixmap != NULL) guimap_draw_hex(gmap, hex); }