Example #1
0
/**************************************************************************
  Update the information label which gives info on the current unit and the
  square under the current unit, for specified unit.  Note that in practice
  punit is almost always (or maybe strictly always?) the focus unit.
  Clears label if punit is NULL.
  Also updates the cursor for the map_canvas (this is related because the
  info label includes a "select destination" prompt etc).
  Also calls update_unit_pix_label() to update the icons for units on this
  square.
**************************************************************************/
void update_unit_info_label(struct unit_list *punitlist)
{
  char buffer[512];

  fc_snprintf(buffer, sizeof(buffer), "%s\n%s",
              get_unit_info_label_text1(punitlist),
              get_unit_info_label_text2(punitlist, 0));
  xaw_set_label(unit_info_label, buffer);

  if (punitlist && unit_list_size(punitlist) > 0) {
    switch (hover_state) {
    case HOVER_NONE:
      XUndefineCursor(display, XtWindow(map_canvas));
      break;
    case HOVER_PATROL:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_PATROL]);
      break;
    case HOVER_GOTO:
    case HOVER_CONNECT:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_GOTO]);
      break;
    case HOVER_NUKE:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_NUKE]);
      break;
    case HOVER_PARADROP:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_PARADROP]);
      break;
    }
  } else {
    xaw_set_label(unit_info_label, "");
    XUndefineCursor(display, XtWindow(map_canvas));
  }

  update_unit_pix_label(punitlist);
}
Example #2
0
/****************************************************************
... 
*****************************************************************/
void popup_rates_dialog(void)
{
  Position x, y;
  Dimension width, height;
  char buf[64];

  if (!can_client_issue_orders()) {
    return;
  }

  XtSetSensitive(main_form, FALSE);

  create_rates_dialog();
  
  XtVaGetValues(toplevel, XtNwidth, &width, XtNheight, &height, NULL);
  
  XtTranslateCoords(toplevel, (Position) width/10, (Position) height/10,
		    &x, &y);
  XtVaSetValues(rates_dialog_shell, XtNx, x, XtNy, y, NULL);

  my_snprintf(buf, sizeof(buf), _("%s max rate: %d%%"),
	      government_name_for_player(client.conn.playing),
	      get_player_bonus(client.conn.playing, EFT_MAX_RATES));
  xaw_set_label(rates_gov_label, buf);
  
  XtPopup(rates_dialog_shell, XtGrabNone);
}
Example #3
0
/**************************************************************************
...
**************************************************************************/
void update_info_label(void)
{
  int d = 0;

  xaw_set_label(info_command, get_info_label_text(TRUE));

  set_indicator_icons(client_research_sprite(),
		      client_warming_sprite(),
		      client_cooling_sprite(),
		      client_government_sprite());

  if (NULL == client.conn.playing) {
    return;
  }

  for (; d < (client.conn.playing->economic.luxury) / 10; d++) {
    xaw_set_bitmap(econ_label[d], get_tax_sprite(tileset, O_LUXURY)->pixmap);
  }
 
  for (; d < (client.conn.playing->economic.science + client.conn.playing->economic.luxury) / 10; d++) {
    xaw_set_bitmap(econ_label[d], get_tax_sprite(tileset, O_SCIENCE)->pixmap);
  }
 
  for(; d < 10; d++) {
    xaw_set_bitmap(econ_label[d], get_tax_sprite(tileset, O_GOLD)->pixmap);
  }
 
  update_timeout_label();
}
Example #4
0
/****************************************************************
...
*****************************************************************/
void city_dialog_update_polution(struct city_dialog *pdialog)
{
  char buf[512];
  struct city *pcity=pdialog->pcity;

  sprintf(buf, "Polution:    %3d", pcity->polution);

  xaw_set_label(pdialog->polution_label, buf);
}
Example #5
0
/****************************************************************
...
*****************************************************************/
void city_dialog_update_storage(struct city_dialog *pdialog)
{
  char buf[512];
  struct city *pcity=pdialog->pcity;
  
  sprintf(buf, "Granary: %3d/%-3d", pcity->food_stock,
	  10*pcity->size);

  xaw_set_label(pdialog->storage_label, buf);
}
Example #6
0
/****************************************************************
...
*****************************************************************/
void city_dialog_update_output(struct city_dialog *pdialog)
{
  char buf[512];
  struct city *pcity=pdialog->pcity;
  
  sprintf(buf, "Gold:    %2d (%+2d)\nLuxury:  %2d\nScience: %2d",
	  pcity->tax_total, calc_gold_remains(pcity),
	  pcity->luxury_total,
	  pcity->science_total);

  xaw_set_label(pdialog->output_label, buf);
}
Example #7
0
/****************************************************************
...
*****************************************************************/
void city_dialog_update_production(struct city_dialog *pdialog)
{
  char buf[512];
  struct city *pcity=pdialog->pcity;
  
  sprintf(buf, "Food:    %2d (%+2d)\nProd:    %2d (%+2d)\nTrade:   %2d (%+2d)",
	  pcity->food_prod, pcity->food_surplus,
	  pcity->shield_prod, pcity->shield_surplus,
	  pcity->trade_prod+pcity->corruption, pcity->trade_prod);

  xaw_set_label(pdialog->production_label, buf);
}
Example #8
0
void city_dialog_update_building(struct city_dialog *pdialog)
{
  char buf[512], buf2[512];
  struct city *pcity=pdialog->pcity;
  
  if(pcity->is_building_unit) {
    sprintf(buf, "%3d/%3d", pcity->shield_stock, 
	    get_unit_type(pcity->currently_building)->build_cost);
    sprintf(buf2, "%s", get_unit_type(pcity->currently_building)->name);
  }
  else {
    sprintf(buf, "%3d/%3d", pcity->shield_stock, 
	    get_improvement_type(pcity->currently_building)->build_cost);
    sprintf(buf2, "%s", 
	    get_improvement_name(pcity->currently_building));
  }
    
  XtSetSensitive(pdialog->buy_command, !pcity->did_buy);
  XtSetSensitive(pdialog->sell_command, !pcity->did_sell);

  xaw_set_label(pdialog->building_label, buf2);
  xaw_set_label(pdialog->progress_label, buf);
}
Example #9
0
/****************************************************************
 Callback for CMA the preset list. 
*****************************************************************/
static void select_preset(Widget w, XtPointer list,
                          XtPointer call_data)
{
  XawListReturnStruct *ret;
  const struct cm_parameter *param;
  struct cm_parameter parameter;
  struct cm_result *result;

  /* check gloabl variable current_city */
  fc_assert_ret(current_city != NULL);

  result = cm_result_new(current_city);
  ret = XawListShowCurrent(list);

  if (ret->list_index != XAW_LIST_NONE && cmafec_preset_num()) {
    param = cmafec_preset_get_parameter(ret->list_index);
    cmafec_set_fe_parameter(current_city, param);

    if (cma_is_city_under_agent(current_city, NULL)) {
      cma_release_city(current_city);
      cma_put_city_under_agent(current_city, param);
    }

    cmafec_get_fe_parameter(current_city, &parameter);
    cm_result_from_main_map(result, current_city);
    xaw_set_label(result_label,
        (char *) cmafec_get_result_descr(current_city, result, &parameter));

    output_type_iterate(i) {
      minimal_surplus[i] = param->minimal_surplus[i];
    } output_type_iterate_end;

    XtVaSetValues(celebrate_toggle, XtNlabel,
            param->require_happy ? _("Yes") : _("No"),
            XtNstate, parameter.require_happy, NULL);

    factors[O_LAST] = param->happy_factor;

    output_type_iterate(i) {
      factors[i] = param->factor[i];
    } output_type_iterate_end;
  }
Example #10
0
/**************************************************************************
 Show the Citizen Management Agent Dialog for the current city.
**************************************************************************/
void show_cma_dialog(struct city *pcity, Widget citydlg)
{
  Widget add_button, remove_button, help_button;
  Widget form, preset_viewport, close_button;
  Widget surplus_header, factor_header, prev;
  struct cm_parameter parameter;
  struct cm_result *result = cm_result_new(pcity);
  int i;

  current_city = pcity;
  stat_surplus_label = fc_malloc((O_LAST + 1) * sizeof(Widget));
  stat_factor_label = fc_malloc((O_LAST + 1) * sizeof(Widget));

  cma_dialog = 
    I_T(XtCreatePopupShell("cmapopup",
                           topLevelShellWidgetClass,
                           citydlg, NULL, 0));

  form = 
    XtVaCreateManagedWidget("cmaform",
                            formWidgetClass,
                            cma_dialog, NULL);

  preset_viewport = 
    XtVaCreateManagedWidget("cmapresetviewport",
                            viewportWidgetClass, form,
                            NULL);

  preset_list = 
    XtVaCreateManagedWidget("cmapresetlist",
                            listWidgetClass, preset_viewport,
                            XtNlist, (XtArgVal)initial_preset_list,
                            NULL);

  result_label = 
    I_L(XtVaCreateManagedWidget("cmaresultlabel",
                                labelWidgetClass, form,
                                XtNfromHoriz, preset_viewport,
                                NULL));

  surplus_header = 
    I_L(XtVaCreateManagedWidget("cmasurpluslabel",
                                labelWidgetClass, form,
                                XtNfromHoriz, preset_viewport,
                                XtNfromVert, result_label,
                                NULL));

  /* Create labels in the minimal surplus column. */
  prev = surplus_header;
  for (i = 0; i < (O_LAST + 1); i++) {
    I_L(stat_surplus_label[i] = 
        XtVaCreateManagedWidget("cmastatlabel",
                                labelWidgetClass, form,
                                XtNfromHoriz, preset_viewport,
                                XtNfromVert, prev,
                                XtNvertDistance, 1,
                                XtNlabel, (i == O_LAST) ? 
                                  _("Celebrate") : get_output_name(i),
                                NULL));
    prev = stat_surplus_label[i];
  }

  /* Create scrollbars in the minimal surplus column. */
  prev = surplus_header;
  output_type_iterate(i) {
    surplus_slider[i] = 
      XtVaCreateManagedWidget("cmapresetscroll",
                                  scrollbarWidgetClass, form,
                                  XtNfromHoriz, stat_surplus_label[i],
                                  XtNfromVert, prev,
                                  NULL);
    prev = stat_surplus_label[i];
  } output_type_iterate_end;

  celebrate_toggle = 
    I_L(XtVaCreateManagedWidget("cmapresettoggle",
                                toggleWidgetClass,form,
                                XtNfromHoriz, stat_surplus_label[0],
                                XtNfromVert, stat_surplus_label[O_LAST - 1],
                                NULL));

  /* Create header label in the factor column. */
  factor_header = 
    I_L(XtVaCreateManagedWidget("cmafactorlabel",
                                labelWidgetClass, form,
                                XtNfromHoriz, surplus_slider[0],
                                XtNfromVert, result_label,
                                NULL));

  /* Create stat labels in the factor column. */
  prev = factor_header;
  for (i = 0; i < (O_LAST + 1); i++) {
    I_L(stat_factor_label[i] =
        XtVaCreateManagedWidget("cmastatlabel",
                                labelWidgetClass, form,
                                XtNfromHoriz, surplus_slider[0],
                                XtNfromVert, prev,
                                XtNvertDistance, 1,
                                XtNlabel, (i == O_LAST) ?
                                  _("Celebrate") : get_output_name(i),
                                NULL));
    prev = stat_factor_label[i];
  }

  /* Create scrollbars in the factor column. */
  prev = factor_header;
  for (i = 0; i < (O_LAST + 1); i++) {
    factor_slider[i] =
      XtVaCreateManagedWidget("cmapresetscroll",
                                  scrollbarWidgetClass, form,
                                  XtNfromHoriz, stat_factor_label[i],
                                  XtNfromVert, prev,
                                  NULL);
    prev = stat_factor_label[i];
  }

  close_button = 
    I_L(XtVaCreateManagedWidget("cmaclosebutton",
                                commandWidgetClass, form,
                                XtNfromVert, preset_viewport,
                                NULL));

  control_button = 
    I_L(XtVaCreateManagedWidget("cmacontrolbutton",
                                commandWidgetClass, form,
                                XtNfromVert, preset_viewport,
                                XtNfromHoriz, close_button,
                                NULL));

  release_button = 
    I_L(XtVaCreateManagedWidget("cmareleasebutton",
                                commandWidgetClass, form,
                                XtNfromVert, preset_viewport,
                                XtNfromHoriz, control_button,
                                NULL));

  change_button =
    I_L(XtVaCreateManagedWidget("cmachangebutton",
                                commandWidgetClass, form,
                                XtNfromVert, preset_viewport,
                                XtNfromHoriz, release_button,
                                NULL));

  add_button = 
   I_L(XtVaCreateManagedWidget("cmaaddbutton",
                               commandWidgetClass, form,
                               XtNfromVert, preset_viewport,
                               XtNfromHoriz, change_button,
                               NULL));

  remove_button = 
     I_L(XtVaCreateManagedWidget("cmaremovebutton",
                                 commandWidgetClass, form, 
                                 XtNfromVert, preset_viewport,
                                 XtNfromHoriz, add_button,
                                 NULL));

  help_button = 
     I_L(XtVaCreateManagedWidget("cmahelpbutton",
                                 commandWidgetClass, form,
                                 XtNfromVert, preset_viewport,
                                 XtNfromHoriz, remove_button,
                                 NULL));

  XtAddCallback(control_button, XtNcallback, control_city,
                (XtPointer)preset_list);
  XtAddCallback(release_button, XtNcallback, release_city,
                (XtPointer)preset_list);
  XtAddCallback(change_button, XtNcallback, change_callback,
                (XtPointer)preset_list);
  XtAddCallback(add_button, XtNcallback, add_preset,
                (XtPointer)preset_list);
  XtAddCallback(remove_button, XtNcallback, remove_preset,
                (XtPointer)preset_list);
  XtAddCallback(preset_list, XtNcallback, select_preset,
                (XtPointer)preset_list);
  XtAddCallback(help_button, XtNcallback, cma_help,
                (XtPointer)preset_list);
  XtAddCallback(celebrate_toggle, XtNcallback,
                celebrate_callback, NULL);
  XtAddCallback(close_button, XtNcallback,
                close_callback, NULL);

  output_type_iterate(i) {
    XtAddCallback(surplus_slider[i], XtNscrollProc,
                  sliders_scroll_callback, NULL);
    XtAddCallback(surplus_slider[i], XtNjumpProc,
                  sliders_jump_callback, NULL);
  } output_type_iterate_end;

  for (i = 0; i < (O_LAST + 1); i++) {
    XtAddCallback(factor_slider[i], XtNscrollProc,
                  sliders_scroll_callback, NULL);
    XtAddCallback(factor_slider[i], XtNjumpProc,
                  sliders_jump_callback, NULL);
  }

  /* Update dialog with CMA parameters from city.  */
  cmafec_get_fe_parameter(current_city, &parameter);

  output_type_iterate(i) {
    minimal_surplus[i] = parameter.minimal_surplus[i];
  } output_type_iterate_end;

  XtVaSetValues(celebrate_toggle, 
         XtNlabel, parameter.require_happy ? _("Yes") : _("No"),
         XtNstate, parameter.require_happy, NULL);

  if (parameter.happy_factor > 0) {
    factors[O_LAST] = parameter.happy_factor;
  } else {
    factors[O_LAST] = 1;
  }

  output_type_iterate(i) {
    factors[i] = parameter.factor[i];
  } output_type_iterate_end;

  set_slider_values();
  update_cma_preset_list();

  XtVaSetValues(preset_list, XtNwidth, 200, NULL);
  XtVaSetValues(preset_list, XtNheight, 300, NULL);
  XtVaSetValues(celebrate_toggle, XtNwidth, 30, NULL);
  XtVaSetValues(result_label, XtNwidth, 360, NULL);
  XtVaSetValues(result_label, XtNheight, 110, NULL);

  output_type_iterate(i) {
    XtVaSetValues(stat_surplus_label[i], XtNwidth, 90, NULL);
    XtVaSetValues(stat_factor_label[i], XtNwidth, 90, NULL);
  } output_type_iterate_end;
  /* FIXME! Now we assume that output_type_iterate ends with O_LAST. */
  XtVaSetValues(stat_factor_label[O_LAST], XtNwidth, 90, NULL);

  XtRealizeWidget(cma_dialog);

  update_stat_labels(True);
  cm_result_from_main_map(result, pcity);
  xaw_set_label(result_label, 
       (char *) cmafec_get_result_descr(current_city, result, &parameter));

  XSetWMProtocols(display, XtWindow(cma_dialog),
                  &wm_delete_window, 1);
  XtVaSetValues(preset_viewport, XtNforceBars, True, NULL);
  xaw_set_relative_position(citydlg, cma_dialog, 5, 5);
  XtPopup(cma_dialog, XtGrabNone);

  cm_result_destroy(result);
}
Example #11
0
/**************************************************************************
...
**************************************************************************/
void rates_set_values(int tax, int no_tax_scroll, 
		      int lux, int no_lux_scroll,
		      int sci, int no_sci_scroll)
{
  char buf[64];
  Boolean tax_lock, lux_lock, sci_lock;
  int maxrate;
  
  if (!can_client_issue_orders()) {
    return;
  }

  XtVaGetValues(rates_tax_toggle, XtNstate, &tax_lock, NULL);
  XtVaGetValues(rates_lux_toggle, XtNstate, &lux_lock, NULL);
  XtVaGetValues(rates_sci_toggle, XtNstate, &sci_lock, NULL);
  
  maxrate = get_player_bonus(client.conn.playing, EFT_MAX_RATES);
  /* This's quite a simple-minded "double check".. */
  tax=MIN(tax, maxrate);
  lux=MIN(lux, maxrate);
  sci=MIN(sci, maxrate);
  
  if(tax+sci+lux!=100) {
    if(tax!=rates_tax_value) {
      if(!lux_lock)
	lux=MIN(MAX(100-tax-sci, 0), maxrate);
      if(!sci_lock)
	sci=MIN(MAX(100-tax-lux, 0), maxrate);
    }
    else if(lux!=rates_lux_value) {
      if(!tax_lock)
	tax=MIN(MAX(100-lux-sci, 0), maxrate);
      if(!sci_lock)
	sci=MIN(MAX(100-lux-tax, 0), maxrate);
    }
    else if(sci!=rates_sci_value) {
      if(!lux_lock)
	lux=MIN(MAX(100-tax-sci, 0), maxrate);
      if(!tax_lock)
	tax=MIN(MAX(100-lux-sci, 0), maxrate);
    }
    
    if(tax+sci+lux!=100) {
      lux=rates_lux_value;
      sci=rates_sci_value;
      tax=rates_tax_value;
      rates_tax_value=-1;
      rates_lux_value=-1;
      rates_sci_value=-1;
      no_tax_scroll=0;
      no_lux_scroll=0;
      no_sci_scroll=0;
    }

  }
  
  if(tax!=rates_tax_value) {
    my_snprintf(buf, sizeof(buf), _("Tax: %d%%"), tax);
    xaw_set_label(rates_tax_label, buf);
    if(!no_tax_scroll)
      XawScrollbarSetThumb(rates_tax_scroll, (tax/10)*1/11.0f, 1/11.0f);
    rates_tax_value=tax;
  }

  if(lux!=rates_lux_value) {
    my_snprintf(buf, sizeof(buf), _("Luxury: %d%%"), lux);
    xaw_set_label(rates_lux_label, buf);
    if(!no_lux_scroll)
      XawScrollbarSetThumb(rates_lux_scroll, (lux/10)*1/11.0f, 1/11.0f);
    rates_lux_value=lux;
  }

  if(sci!=rates_sci_value) {
    my_snprintf(buf, sizeof(buf), _("Science: %d%%"), sci);
    xaw_set_label(rates_sci_label, buf);
    if(!no_sci_scroll)
      XawScrollbarSetThumb(rates_sci_scroll, (sci/10)*1/11.0f, 1/11.0f);
    rates_sci_value=sci;
  }
  
}
Example #12
0
/**************************************************************************
...
**************************************************************************/
void rates_set_values(int tax, int no_tax_scroll, 
		      int lux, int no_lux_scroll,
		      int sci, int no_sci_scroll)
{
  char buf[16];
  Boolean tax_lock, lux_lock, sci_lock;
  
  XtVaGetValues(rates_tax_toggle, XtNstate, &tax_lock, NULL);
  XtVaGetValues(rates_lux_toggle, XtNstate, &lux_lock, NULL);
  XtVaGetValues(rates_sci_toggle, XtNstate, &sci_lock, NULL);
  
  if(tax+sci+lux!=100) {
    if(tax!=rates_tax_value) {
      if(!lux_lock)
	lux=MAX(100-tax-sci, 0);
      if(!sci_lock)
	sci=MAX(100-tax-lux, 0);
    }
    else if(lux!=rates_lux_value) {
      if(!tax_lock)
	tax=MAX(100-lux-sci, 0);
      if(!sci_lock)
	sci=MAX(100-lux-tax, 0);
    }
    else if(sci!=rates_sci_value) {
      if(!lux_lock)
	lux=MAX(100-tax-sci, 0);
      if(!tax_lock)
	tax=MAX(100-lux-sci, 0);
    }
    
    if(tax+sci+lux!=100) {
      lux=rates_lux_value;
      sci=rates_sci_value;
      tax=rates_tax_value;
      rates_tax_value=-1;
      rates_lux_value=-1;
      rates_sci_value=-1;
      no_tax_scroll=0;
      no_lux_scroll=0;
      no_sci_scroll=0;
    }

  }
  
  if(tax!=rates_tax_value) {
    sprintf(buf, "Tax: %d%%", tax);
    xaw_set_label(rates_tax_label, buf);
    if(!no_tax_scroll)
      my_XawScrollbarSetThumb(rates_tax_scroll, (tax/10)*1/11.0f, 1/11.0f);
    rates_tax_value=tax;
  }

  if(lux!=rates_lux_value) {
    sprintf(buf, "Luxury: %d%%", lux);
    xaw_set_label(rates_lux_label, buf);
    if(!no_lux_scroll)
      my_XawScrollbarSetThumb(rates_lux_scroll, (lux/10)*1/11.0f, 1/11.0f);
    rates_lux_value=lux;
  }

  if(sci!=rates_sci_value) {
    sprintf(buf, "Science: %d%%", sci);
    xaw_set_label(rates_sci_label, buf);
    if(!no_sci_scroll)
      my_XawScrollbarSetThumb(rates_sci_scroll, (sci/10)*1/11.0f, 1/11.0f);
    rates_sci_value=sci;
  }
  
}
Example #13
0
/**************************************************************************
...
**************************************************************************/
void update_timeout_label(void)
{
  xaw_set_label(timeout_label, get_timeout_label_text());
}