Ejemplo n.º 1
0
/**************************************************************************
  Sets the "page" that the client should show.  See documentation in
  pages_g.h.
**************************************************************************/
void real_set_client_page(enum client_pages page)
{
    switch (old_page) {
    case PAGE_MAIN:
        popdown_start_menu();
        break;
    case PAGE_LOAD:
        popdown_load_game_dialog();
        break;
    case PAGE_NETWORK:
        close_connection_dialog();
        break;
    case PAGE_START:
        popdown_conn_list_dialog();
        break;
    case PAGE_GAME:
        close_game_page();
        break;
    default:
        break;
    }

    switch (page) {
    case PAGE_MAIN:
        show_main_page();
        break;
    case PAGE_LOAD:
        client_start_server();
        break;
    case PAGE_NETWORK:
        popup_join_game_dialog();
        break;
    case PAGE_START:
        conn_list_dialog_update();
        break;
    case PAGE_GAME:
        show_game_page();
        enable_main_widgets();
        update_info_label();
        unit_focus_update();
        update_unit_info_label(get_units_in_focus());
        update_turn_done_button_state();
        refresh_overview();
        menus_update();
        break;
    default:
        break;
    }

    old_page = page;
}
Ejemplo n.º 2
0
/**************************************************************************
...
**************************************************************************/
void handle_new_year(struct packet_new_year *ppacket)
{
  update_turn_done_button(1);
  enable_turn_done_button();
  
  game.year=ppacket->year;
  update_info_label();

  player_set_unit_focus_status(game.player_ptr);
  
  update_unit_focus();
    
  update_unit_info_label(get_unit_in_focus());

  seconds_to_turndone=game.timeout;

  update_report_dialogs();
}
Ejemplo n.º 3
0
/**************************************************************************
...
**************************************************************************/
void handle_game_state(struct packet_generic_integer *packet)
{
  if(client_state==CLIENT_SELECT_RACE_STATE && 
     packet->value==CLIENT_GAME_RUNNING_STATE) {
    popdown_races_dialog();
  }
  client_state=packet->value;

  if(client_state==CLIENT_GAME_RUNNING_STATE) {
    refresh_overview_canvas();
    refresh_overview_viewrect();
    player_set_unit_focus_status(game.player_ptr);

    update_unit_focus();
    update_unit_info_label(get_unit_in_focus());

    if(get_unit_in_focus())
      center_tile_mapcanvas(get_unit_in_focus()->x, get_unit_in_focus()->y);
    
  }
}
Ejemplo n.º 4
0
/****************************************************************************
  Really resize the main window.
****************************************************************************/
static void real_resize_window_callback(void *data)
{
    struct widget *widget;
    Uint32 flags = Main.screen->flags;

    if (gui_sdl_fullscreen) {
        flags |= SDL_FULLSCREEN;
    } else {
        flags &= ~SDL_FULLSCREEN;
    }
    set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, flags);

    if (C_S_RUNNING == client_state()) {
        /* Move units window to botton-right corner. */
        set_new_unitinfo_window_pos();
        /* Move minimap window to botton-left corner. */
        set_new_minimap_window_pos();

        /* Move cooling/warming icons to botton-right corner. */
        widget = get_widget_pointer_form_main_list(ID_WARMING_ICON);
        widget_set_position(widget, (Main.screen->w - adj_size(10)
                                     - (widget->size.w * 2)), widget->size.y);

        widget = get_widget_pointer_form_main_list(ID_COOLING_ICON);
        widget_set_position(widget, (Main.screen->w - adj_size(10)
                                     - widget->size.w), widget->size.y);

        map_canvas_resized(Main.screen->w, Main.screen->h);
        update_info_label();
        update_unit_info_label(get_units_in_focus());
        center_on_something();      /* With redrawing full map. */
        update_order_widgets();
    } else {
        draw_intro_gfx();
        dirty_all();
    }
    flush_all();
}
Ejemplo n.º 5
0
/**************************************************************************
  This function will reset the mouse cursor if it leaves the map.
**************************************************************************/
gboolean leave_mapcanvas(GtkWidget *widget, GdkEventCrossing *event)
{
  if (gtk_notebook_get_current_page(GTK_NOTEBOOK(top_notebook))
      != gtk_notebook_page_num(GTK_NOTEBOOK(top_notebook), map_widget)) {
    /* Map is not currently topmost tab. Do not use tile specific cursors. */
    update_mouse_cursor(CURSOR_DEFAULT);
    return TRUE;
  }

  /* Bizarrely, this function can be called even when we don't "leave"
   * the map canvas, for instance, it gets called any time the mouse is
   * clicked. */
  if (map_exists()
      && event->x >= 0 && event->y >= 0
      && event->x < mapview.width && event->y < mapview.height) {
    control_mouse_cursor(canvas_pos_to_tile(event->x, event->y));
  } else {
    update_mouse_cursor(CURSOR_DEFAULT);
  }

  update_unit_info_label(get_units_in_focus());
  return TRUE;
}
Ejemplo n.º 6
0
/**************************************************************************
...
**************************************************************************/
void handle_unit_info(struct packet_unit_info *packet)
{
  struct city *pcity;
  struct unit *punit;
  int repaint_unit;
  int repaint_city;
  
  repaint_unit=0;
  repaint_city=0;
  punit=unit_list_find(&game.players[packet->owner].units, packet->id);
  
  if(punit) {

    if(punit->activity!=packet->activity) { /* change activity */
      punit->activity=packet->activity;
  
      repaint_unit=1;
      
      /*      refresh_tile_mapcanvas(punit->x, punit->y, 1);
      update_unit_pix_label(punit);
      refresh_unit_city_dialogs(punit);
      update_unit_focus(); */
    }
    
    if(punit->homecity!=packet->homecity) { /* change homecity */
      struct city *pcity;
      if((pcity=game_find_city_by_id(punit->homecity))) {
	unit_list_unlink(&pcity->units_supported, punit);
	refresh_city_dialog(pcity);
      }
      
      punit->homecity=packet->homecity;
      if((pcity=game_find_city_by_id(punit->homecity))) {
	unit_list_insert(&pcity->units_supported, punit);
	refresh_city_dialog(pcity);
      }
    }

    if(punit->hp!=packet->hp) {                      /* hp changed */
      punit->hp=packet->hp;
      repaint_unit=1;
    }

    if(punit->attacks_left!=packet->attacksleft) {   /* #attacks changed */
      punit->attacks_left=packet->attacksleft;
      repaint_unit=1;
    }
    
    if(punit->x!=packet->x || punit->y!=packet->y) { /* change position */
      struct city *pcity;
      pcity=map_get_city(punit->x, punit->y);
      
      if(tile_is_known(packet->x, packet->y)) {
	do_move_unit(punit, packet);
	update_unit_focus();
      }
      else {
	unit_list_unlink(&game.players[packet->owner].units, punit);
	unit_list_unlink(&map_get_tile(punit->x, punit->y)->units, punit);
	refresh_tile_mapcanvas(punit->x, punit->y, 1);
	free(punit);
      }
      if(pcity)
	refresh_city_dialog(pcity);
      
      if((pcity=map_get_city(punit->x, punit->y)))
	refresh_city_dialog(pcity);
      
      repaint_unit=0;
    }
    if (punit->unhappiness!=packet->unhappiness) {
      punit->unhappiness=packet->unhappiness;
      repaint_city=1;
    }
    if (punit->upkeep!=packet->upkeep) {
      punit->upkeep=packet->upkeep;
      repaint_city=1;
    }
    if (repaint_city) {
      if((pcity=game_find_city_by_id(punit->homecity))) {
	refresh_city_dialog(pcity);
      }
    }

    punit->moves_left=packet->movesleft;
    punit->bribe_cost=packet->bribe_cost;
  }
  
  else {      /* create new unit */
    punit=(struct unit *)malloc(sizeof(struct unit));
    
    punit->id=packet->id;
    punit->owner=packet->owner;
    punit->x=packet->x;
    punit->y=packet->y;
    punit->veteran=packet->veteran;
    punit->homecity=packet->homecity;
    punit->type=packet->type;
    punit->attacks_left=packet->attacksleft;
    punit->moves_left=packet->movesleft;
    punit->hp=packet->hp;
    punit->unhappiness=0;
    punit->activity=packet->activity;
    punit->upkeep=0;
    punit->hp=packet->hp;
    punit->bribe_cost=packet->bribe_cost;
    
    unit_list_insert(&game.players[packet->owner].units, punit);
    unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit);
    
    if((pcity=game_find_city_by_id(punit->homecity)))
      unit_list_insert(&pcity->units_supported, punit);
    
    /* this is ugly - prevent unit from being drawn if it's moved into
     * screen by a transporter - only works for ground_units.. yak */
    if(!is_ground_unit(punit) || map_get_terrain(punit->x, punit->y)!=T_OCEAN)
      repaint_unit=1;
    else
      repaint_unit=0;
  }

  if(punit && punit==get_unit_in_focus())
    update_unit_info_label(punit);

  if(repaint_unit)
    refresh_tile_mapcanvas(punit->x, punit->y, 1);

  update_unit_focus(); 
}