Пример #1
0
/****************************************************************
...
*****************************************************************/
void create_races_dialog(struct player *pplayer)
{
  int per_row = 5;
  int i, j, len, maxracelen, index, nat_count;
  char maxracename[MAX_LEN_NAME];
  char namebuf[64];
  int space;
  XtWidgetGeometry geom;

  races_player = pplayer;
  maxracelen = 0;
  nations_iterate(pnation) {
    if (is_nation_playable(pnation)) {
      len = strlen(nation_adjective_translation(pnation));
      maxracelen = MAX(maxracelen, len);
    }
  } nations_iterate_end;
  maxracelen = MIN(maxracelen, MAX_LEN_NAME-1);
  fc_snprintf(maxracename, sizeof(maxracename), "%*s", maxracelen+2, "W");

  races_dialog_shell = I_T(XtCreatePopupShell("racespopup", 
					  transientShellWidgetClass,
					  toplevel, NULL, 0));

  races_form = XtVaCreateManagedWidget("racesform", 
				       formWidgetClass, 
				       races_dialog_shell, NULL);   

  races_label = I_L(XtVaCreateManagedWidget("raceslabel", 
				       labelWidgetClass, 
				       races_form, NULL));  

  races_toggles_viewport =
    XtVaCreateManagedWidget("racestogglesviewport",
			    viewportWidgetClass,
			    races_form,
			    XtNfromVert, races_label,
			    NULL);

  races_toggles_form =
    XtVaCreateManagedWidget("racestogglesform",
			    formWidgetClass,
			    races_toggles_viewport,
			    NULL);

  free(races_toggles);
  races_toggles = fc_calloc(nation_count(), sizeof(Widget));
  free(races_toggles_to_nations);
  races_toggles_to_nations = fc_calloc(nation_count(),
				       sizeof(struct nation_type *));

  i = 0;
  j = 0;
  index = 0;
  nations_iterate(pnation) {
    if (!is_nation_playable(pnation)) {
      continue;
    }

    if (j == 0) {
      index = i * per_row;
      fc_snprintf(namebuf, sizeof(namebuf), "racestoggle%d", index);
      if (i == 0) {
	races_toggles[index] =
	  XtVaCreateManagedWidget(namebuf,
				  toggleWidgetClass,
				  races_toggles_form,
				  XtNlabel, maxracename,
				  NULL);
      } else {
	races_toggles[index] =
	  XtVaCreateManagedWidget(namebuf,
				  toggleWidgetClass,
				  races_toggles_form,
				  XtNradioGroup,
				  races_toggles[index - 1],
				  XtNfromVert,
				  races_toggles[index - per_row],
				  XtNlabel, maxracename,
				  NULL);
      }
    } else {
      index = i * per_row + j;
      fc_snprintf(namebuf, sizeof(namebuf), "racestoggle%d", index);
      if (i == 0) {
	races_toggles[index] =
	  XtVaCreateManagedWidget(namebuf,
				  toggleWidgetClass,
				  races_toggles_form,
				  XtNradioGroup,
				  races_toggles[index - 1],
				  XtNfromHoriz,
				  races_toggles[index - 1],
				  XtNlabel, maxracename,
				  NULL);
      } else {
	races_toggles[index] =
	  XtVaCreateManagedWidget(namebuf,
				  toggleWidgetClass,
				  races_toggles_form,
				  XtNradioGroup,
				  races_toggles[index - 1],
				  XtNfromVert,
				  races_toggles[index - per_row],
				  XtNfromHoriz,
				  races_toggles[index - 1],
				  XtNlabel, maxracename,
				  NULL);
      }
    }

    races_toggles_to_nations[index] = pnation;

    j++;
    if (j >= per_row) {
      j = 0;
      i++;
    }
  } nations_iterate_end;
  nat_count = index + 1;

  races_leader_form =
    XtVaCreateManagedWidget("racesleaderform",
			    formWidgetClass,
			    races_form,
			    XtNfromVert, races_toggles_viewport,
/*			    XtNfromHoriz, races_toggles_viewport,*/
			    NULL);

  XtVaGetValues(races_leader_form, XtNdefaultDistance, &space, NULL);
  XtQueryGeometry(races_toggles[0], NULL, &geom);
  races_leader =
    XtVaCreateManagedWidget("racesleader",
			    asciiTextWidgetClass,
			    races_leader_form,
			    XtNeditType, XawtextEdit,
			    XtNwidth,
			      space + 2*(geom.width + geom.border_width),
			    XtNstring, "",
			    NULL);

  races_leader_pick_popupmenu = 0;

  races_leader_pick_menubutton =
    I_L(XtVaCreateManagedWidget("racesleaderpickmenubutton",
				menuButtonWidgetClass,
				races_leader_form,
/*				XtNfromVert, races_leader,*/
				XtNfromHoriz, races_leader,
				NULL));

  races_sex_label = I_L(XtVaCreateManagedWidget("racessexlabel",
				            labelWidgetClass,
				            races_form,
					    XtNfromVert, races_leader_form,
					    NULL));

  races_sex_form = XtVaCreateManagedWidget("racessexform",
					   formWidgetClass,
					   races_form,
					   XtNfromVert, races_sex_label,
					   NULL);

  races_sex_toggles[0] =
    I_L(XtVaCreateManagedWidget("racessextoggle0",
				toggleWidgetClass,
				races_sex_form,
				NULL));

  races_sex_toggles[1] =
    I_L(XtVaCreateManagedWidget("racessextoggle1",
				toggleWidgetClass,
				races_sex_form,
				XtNfromHoriz,
				(XtArgVal)races_sex_toggles[0],
				XtNradioGroup,
				races_sex_toggles[0],
				NULL));

  /* find out styles that can be used at the game beginning */
  /* Limit of 64 city_styles should be deleted. -ev */
  for (i = 0, b_s_num = 0; i < game.control.styles_count && i < 64; i++) {
    if (!city_style_has_requirements(&city_styles[i])) {
      city_style_idx[b_s_num] = i;
      city_style_ridx[i] = b_s_num;
      b_s_num++;
    }
  }

  races_style_label =
    I_L(XtVaCreateManagedWidget("racesstylelabel", 
				labelWidgetClass, 
				races_form,
				XtNfromVert, races_sex_form,
/*				XtNfromHoriz, races_toggles_viewport,*/
				NULL));  

  races_style_form =
    XtVaCreateManagedWidget("racesstyleform", 
			    formWidgetClass, 
			    races_form, 
			    XtNfromVert, races_style_label,
/*			    XtNfromHoriz, races_toggles_viewport,*/
			    NULL);   

  free(races_style_toggles);
  races_style_toggles = fc_calloc(b_s_num,sizeof(Widget));

  for( i = 0; i < ((b_s_num-1)/per_row)+1; i++) {
    index = i * per_row;
    fc_snprintf(namebuf, sizeof(namebuf), "racesstyle%d", index);
    if( i == 0 ) {
      races_style_toggles[index] =
	XtVaCreateManagedWidget(namebuf,
				toggleWidgetClass,
				races_style_form,
				XtNlabel, maxracename,
				NULL);
    } else {
      races_style_toggles[index] =
	XtVaCreateManagedWidget(namebuf,
				toggleWidgetClass,
				races_style_form,
				XtNradioGroup,
				races_style_toggles[index-1],
				XtNfromVert,
				races_style_toggles[index-per_row],
				XtNlabel, maxracename,
				NULL);
    }

    for( j = 1; j < per_row; j++) {
      index = i * per_row + j;
      if( index >= b_s_num ) break;
      fc_snprintf(namebuf, sizeof(namebuf), "racesstyle%d", index);
      if( i == 0 ) {
	races_style_toggles[index] =
	  XtVaCreateManagedWidget(namebuf,
				  toggleWidgetClass,
				  races_style_form,
				  XtNradioGroup,
				  races_style_toggles[index-1],
				  XtNfromHoriz,
				  races_style_toggles[index-1],
				  XtNlabel, maxracename,
				  NULL);
      } else {
	races_style_toggles[index] =
	  XtVaCreateManagedWidget(namebuf,
				  toggleWidgetClass,
				  races_style_form,
				  XtNradioGroup,
				  races_style_toggles[index-1],
				  XtNfromVert,
				  races_style_toggles[index-per_row],
				  XtNfromHoriz,
				  races_style_toggles[index-1],
				  XtNlabel, maxracename,
				  NULL);
      }
    }
  }

  races_action_form = XtVaCreateManagedWidget("racesactionform",
					      formWidgetClass,
					      races_form,
					      XtNfromVert, races_style_form,
					      NULL);

  races_ok_command =
    I_L(XtVaCreateManagedWidget("racesokcommand",
				commandWidgetClass,
				races_action_form,
				NULL));

  races_random_command =
    I_L(XtVaCreateManagedWidget("racesdisconnectcommand",
				commandWidgetClass,
				races_action_form,
				XtNfromHoriz, races_ok_command,
				NULL));

  races_quit_command =
    I_L(XtVaCreateManagedWidget("racesquitcommand",
				commandWidgetClass,
				races_action_form,
				XtNfromHoriz, races_random_command,
				NULL));

  XtAddCallback(races_random_command, XtNcallback,
		races_random_command_callback, NULL);
  XtAddCallback(races_quit_command, XtNcallback,
		races_quit_command_callback, NULL);


  for (i = 0; i < nation_count(); i++) {
    if (races_toggles[i]) {
      XtAddCallback(races_toggles[i], XtNcallback,
		    races_toggles_callback, INT_TO_XTPOINTER(i));
    }
  }


  XtAddCallback(races_ok_command, XtNcallback,
		races_ok_command_callback, NULL);


  XtSetKeyboardFocus(races_form, races_leader);

  XtRealizeWidget(races_dialog_shell);

/*  for(i=0; i<game.control.playable_nation_count; i++) {
    races_toggles_to_nations[i] = i;
  }
*/
  qsort(races_toggles_to_nations, nat_count,
	sizeof(struct nation_type *), races_indirect_compare);

  /* Build nation_to_race_toggle */
  free(nation_idx_to_race_toggle);
  nation_idx_to_race_toggle =
      fc_calloc(nation_count(), sizeof(int));
  for (i = 0; i < nation_count(); i++) {
    nation_idx_to_race_toggle[i] = -1;
  }
  for (i = 0; i < nation_count(); i++) {
    if (races_toggles_to_nations[i]) {
      nation_idx_to_race_toggle[nation_index(races_toggles_to_nations[i])] = i;
    }
  }

  for (i = 0; i < nation_count(); i++) {
    if (races_toggles[i]) {
      XtVaSetValues(races_toggles[i],
		    XtNlabel,
		      (XtArgVal)nation_adjective_translation(races_toggles_to_nations[i]),
		    NULL);
    }
  }

  for(i=0; i<b_s_num; i++) {
    XtVaSetValues(races_style_toggles[i], XtNlabel,
		  (XtArgVal)city_style_name_translation(city_style_idx[i]), NULL);
  }

  select_random_race();
}
Пример #2
0
/**************************************************************************
  Popup a dialog asking the unit which improvement they would like to
  pillage.
**************************************************************************/
void popup_pillage_dialog(struct unit *punit,
			  bv_special spe,
                          bv_bases bases,
                          bv_roads roads)
{
  Widget shell, form, dlabel, button, prev;
  struct act_tgt tgt;

  if (is_showing_pillage_dialog) {
    return;
  }
  is_showing_pillage_dialog = TRUE;
  unit_to_use_to_pillage = punit->id;

  XtSetSensitive (toplevel, FALSE);

  shell = I_T(XtCreatePopupShell("pillagedialog", transientShellWidgetClass,
				 toplevel, NULL, 0));
  form = XtVaCreateManagedWidget ("form", formWidgetClass, shell, NULL);
  dlabel = I_L(XtVaCreateManagedWidget("dlabel", labelWidgetClass, form, NULL));

  prev = dlabel;
  while (get_preferred_pillage(&tgt, spe, bases, roads)) {
    bv_special what_spe;
    bv_bases what_base;
    bv_roads what_road;
    int what = S_LAST;

    BV_CLR_ALL(what_spe);
    BV_CLR_ALL(what_base);
    BV_CLR_ALL(what_road);

    switch (tgt.type) {
      case ATT_SPECIAL:
        BV_SET(what_spe, tgt.obj.spe);
        what = tgt.obj.spe;
        clear_special(&spe, tgt.obj.spe);
        break;
      case ATT_BASE:
        BV_SET(what_base, tgt.obj.base);
        what = tgt.obj.base + S_LAST;
        BV_CLR(bases, tgt.obj.base);
        break;
      case ATT_ROAD:
        BV_SET(what_road, tgt.obj.road);
        what = tgt.obj.road + S_LAST + game.control.num_base_types;
        BV_CLR(roads, tgt.obj.road);
        break;
    }

    button =
      XtVaCreateManagedWidget ("button", commandWidgetClass, form,
                               XtNfromVert, prev,
                               XtNlabel,
                               (XtArgVal)(get_infrastructure_text(what_spe,
                                                                  what_base,
                                                                  what_road)),
                               NULL);
    XtAddCallback(button, XtNcallback, pillage_callback,
                  INT_TO_XTPOINTER(what));

    prev = button;
  }
  button =
    I_L(XtVaCreateManagedWidget("closebutton", commandWidgetClass, form,
				XtNfromVert, prev,
				NULL));
  XtAddCallback (button, XtNcallback, pillage_callback, NULL);

  xaw_set_relative_position (toplevel, shell, 10, 0);
  XtPopup (shell, XtGrabNone);
}
Пример #3
0
/****************************************************************
popup the dialog 10% inside the main-window 
*****************************************************************/
void unit_select_dialog_popup(struct tile *ptile)
{
  int i,n,r;
  char buffer[512];
  Arg args[4];
  int nargs;
  Widget unit_select_all_command, unit_select_close_command;
  Widget firstcolumn=0,column=0;
  Pixel bg;
  struct unit *unit_list[unit_list_size(ptile->units)];

  XtSetSensitive(main_form, FALSE);

  unit_select_dialog_shell =
    I_T(XtCreatePopupShell("unitselectdialogshell", 
			   transientShellWidgetClass,
			   toplevel, NULL, 0));

  unit_select_form = XtVaCreateManagedWidget("unitselectform", 
					     formWidgetClass, 
					     unit_select_dialog_shell, NULL);

  XtVaGetValues(unit_select_form, XtNbackground, &bg, NULL);
  XSetForeground(display, fill_bg_gc, bg);

  n = MIN(MAX_SELECT_UNITS, unit_list_size(ptile->units));
  r = number_of_rows(n);

  fill_tile_unit_list(ptile, unit_list);

  for(i=0; i<n; i++) {
    struct unit *punit = unit_list[i];
    struct unit_type *punittemp=unit_type(punit);
    struct city *pcity;
    struct canvas store;
    
    if(!(i%r))  {
      nargs=0;
      if(i)  { XtSetArg(args[nargs], XtNfromHoriz, column); nargs++;}
      column = XtCreateManagedWidget("column", formWidgetClass,
				     unit_select_form,
				     args, nargs);
      if(!i) firstcolumn=column;
    }

    unit_select_ids[i]=punit->id;

    pcity = player_city_by_number(client_player(), punit->homecity);
    
    fc_snprintf(buffer, sizeof(buffer), "%s(%s)\n%s", 
	    utype_name_translation(punittemp), 
	    pcity ? city_name(pcity) : "",
	    unit_activity_text(punit));

    unit_select_pixmaps[i]=XCreatePixmap(display, XtWindow(map_canvas), 
					 tileset_full_tile_width(tileset), tileset_full_tile_height(tileset),
					 display_depth);

    XFillRectangle(display, unit_select_pixmaps[i], fill_bg_gc,
		   0, 0, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset));
    store.pixmap = unit_select_pixmaps[i];
    put_unit(punit, &store, 0, 0);

    nargs=0;
    XtSetArg(args[nargs], XtNbitmap, (XtArgVal)unit_select_pixmaps[i]);nargs++;
    XtSetArg(args[nargs], XtNsensitive, 
             can_unit_do_activity(punit, ACTIVITY_IDLE));nargs++;
    if(i%r)  {
      XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++;
    }
    unit_select_commands[i]=XtCreateManagedWidget("unitselectcommands", 
						  commandWidgetClass,
						  column, args, nargs);

    nargs=0;
    XtSetArg(args[nargs], XtNlabel, (XtArgVal)buffer); nargs++;
    XtSetArg(args[nargs], XtNfromHoriz, unit_select_commands[i]); nargs++;
    if(i%r) {
      XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++;
    }
    unit_select_labels[i]=XtCreateManagedWidget("unitselectlabels", 
						labelWidgetClass, 
						column, args, nargs);

    XtAddCallback(unit_select_commands[i],
		  XtNdestroyCallback,free_bitmap_destroy_callback, NULL);
    XtAddCallback(unit_select_commands[i],
                  XtNcallback, unit_select_callback, NULL);
  }

  unit_select_no=i;

  unit_select_close_command =
    I_L(XtVaCreateManagedWidget("unitselectclosecommand", 
				commandWidgetClass,
				unit_select_form,
				XtNfromVert, firstcolumn,
				NULL));

  unit_select_all_command =
    I_L(XtVaCreateManagedWidget("unitselectallcommand", 
				commandWidgetClass,
				unit_select_form,
				XtNfromVert, firstcolumn,
				NULL));

  XtAddCallback(unit_select_close_command, XtNcallback, unit_select_callback, NULL);
  XtAddCallback(unit_select_all_command, XtNcallback, unit_select_all_callback, NULL);

  xaw_set_relative_position(toplevel, unit_select_dialog_shell, 15, 10);
  XtPopup(unit_select_dialog_shell, XtGrabNone);
}
Пример #4
0
/****************************************************************
...
*****************************************************************/
void create_rates_dialog(void)
{
  Widget rates_form;
  Widget rates_ok_command, rates_cancel_command;
  
  if (!can_client_issue_orders()) {
    return;
  }

  rates_dialog_shell =
    I_T(XtCreatePopupShell("ratespopup", transientShellWidgetClass,
			   toplevel, NULL, 0));

  rates_form = XtVaCreateManagedWidget("ratesform", 
				       formWidgetClass, 
				       rates_dialog_shell, NULL);   

  I_L(XtVaCreateManagedWidget("rateslabel", labelWidgetClass, 
			      rates_form, NULL));   

  rates_gov_label = XtVaCreateManagedWidget("ratesgovlabel",
					    labelWidgetClass,
					    rates_form, NULL);
  
  rates_tax_label = XtVaCreateManagedWidget("ratestaxlabel", 
					    labelWidgetClass, 
					    rates_form, NULL);

  rates_tax_scroll = XtVaCreateManagedWidget("ratestaxscroll", 
					     scrollbarWidgetClass, 
					     rates_form,
					     NULL);

  rates_tax_toggle = I_L(XtVaCreateManagedWidget("ratestaxtoggle", 
						 toggleWidgetClass, 
						 rates_form,
						 NULL));
    
  rates_lux_label = XtVaCreateManagedWidget("ratesluxlabel", 
					    labelWidgetClass, 
					    rates_form, NULL);

  rates_lux_scroll = XtVaCreateManagedWidget("ratesluxscroll", 
					     scrollbarWidgetClass, 
					     rates_form,
					     NULL);

  rates_lux_toggle = I_L(XtVaCreateManagedWidget("ratesluxtoggle", 
						 toggleWidgetClass, 
						 rates_form,
						 NULL));
  
  rates_sci_label = XtVaCreateManagedWidget("ratesscilabel", 
					    labelWidgetClass, 
					    rates_form, NULL);

  rates_sci_scroll = XtVaCreateManagedWidget("ratessciscroll", 
					     scrollbarWidgetClass, 
					     rates_form,
					     NULL);
  
  rates_sci_toggle = I_L(XtVaCreateManagedWidget("ratesscitoggle", 
						 toggleWidgetClass, 
						 rates_form,
						 NULL));
  
  rates_ok_command = I_L(XtVaCreateManagedWidget("ratesokcommand", 
						 commandWidgetClass,
						 rates_form,
						 NULL));

  rates_cancel_command = I_L(XtVaCreateManagedWidget("ratescancelcommand", 
						     commandWidgetClass,
						     rates_form,
						     NULL));

  XtAddCallback(rates_ok_command, XtNcallback, 
		rates_ok_command_callback, NULL);
  XtAddCallback(rates_cancel_command, XtNcallback, 
		rates_cancel_command_callback, NULL);

  XtAddCallback(rates_tax_scroll, XtNjumpProc, 
		rates_scroll_jump_callback, NULL);
  XtAddCallback(rates_tax_scroll, XtNscrollProc,
		rates_scroll_scroll_callback, NULL);

  
  XtAddCallback(rates_lux_scroll, XtNjumpProc, 
		rates_scroll_jump_callback, NULL);
  XtAddCallback(rates_lux_scroll, XtNscrollProc,
		rates_scroll_scroll_callback, NULL);

  
  XtAddCallback(rates_sci_scroll, XtNjumpProc, 
		rates_scroll_jump_callback, NULL);
  XtAddCallback(rates_sci_scroll, XtNscrollProc,
		rates_scroll_scroll_callback, NULL);

  XtRealizeWidget(rates_dialog_shell);

  
  rates_tax_value=-1;
  rates_lux_value=-1;
  rates_sci_value=-1;
  
  rates_set_values(client.conn.playing->economic.tax, 0,
		   client.conn.playing->economic.luxury, 0,
		   client.conn.playing->economic.science, 0);
}
Пример #5
0
/****************************************************************
popup the dialog 10% inside the main-window 
*****************************************************************/
void popup_goto_dialog(void)
{
  Position x, y;
  Dimension width, height;
  Boolean no_player_cities;

  if (!can_client_issue_orders() || get_num_units_in_focus() == 0) {
    return;
  }

  no_player_cities = !(city_list_size(client.conn.playing->cities));

  original_tile = get_center_tile_mapcanvas();
  
  XtSetSensitive(main_form, FALSE);
  
  goto_dialog_shell =
    I_T(XtCreatePopupShell("gotodialog", transientShellWidgetClass,
			   toplevel, NULL, 0));

  goto_form = XtVaCreateManagedWidget("gotoform", 
				      formWidgetClass, 
				      goto_dialog_shell, NULL);

  goto_label =
    I_L(XtVaCreateManagedWidget("gotolabel", labelWidgetClass, 
				goto_form, NULL));

  goto_viewport = XtVaCreateManagedWidget("gotoviewport", 
				      viewportWidgetClass, 
				      goto_form, 
				      NULL);

  goto_list = XtVaCreateManagedWidget("gotolist", 
				      listWidgetClass, 
				      goto_viewport, 
				      XtNlist, 
				      (XtArgVal)dummy_city_list,
				      NULL);

  goto_center_command =
    I_L(XtVaCreateManagedWidget("gotocentercommand", commandWidgetClass,
				goto_form, NULL));

  goto_airlift_command =
    I_L(XtVaCreateManagedWidget("gotoairliftcommand", commandWidgetClass,
				goto_form, NULL));

  goto_all_toggle =
    I_L(XtVaCreateManagedWidget("gotoalltoggle", toggleWidgetClass,
				goto_form,
				XtNstate, no_player_cities,
				XtNsensitive, !no_player_cities,
				NULL));

  goto_cancel_command =
    I_L(XtVaCreateManagedWidget("gotocancelcommand", commandWidgetClass,
				goto_form, NULL));

  XtAddCallback(goto_list, XtNcallback, goto_list_callback, NULL);
  XtAddCallback(goto_center_command, XtNcallback, 
		goto_goto_command_callback, NULL);
  XtAddCallback(goto_airlift_command, XtNcallback, 
		goto_airlift_command_callback, NULL);
  XtAddCallback(goto_all_toggle, XtNcallback,
		goto_all_toggle_callback, NULL);
  XtAddCallback(goto_cancel_command, XtNcallback, 
		goto_cancel_command_callback, NULL);

  XtRealizeWidget(goto_dialog_shell);

  update_goto_dialog(goto_list);

  XtVaGetValues(toplevel, XtNwidth, &width, XtNheight, &height, NULL);

  XtTranslateCoords(toplevel, (Position) width/10, (Position) height/10,
		    &x, &y);
  XtVaSetValues(goto_dialog_shell, XtNx, x, XtNy, y, NULL);

  XtPopup(goto_dialog_shell, XtGrabNone);

  /* force refresh of viewport so the scrollbar is added.
   * Buggy sun athena requires this */
  XtVaSetValues(goto_viewport, XtNforceBars, True, NULL);
}
Пример #6
0
/****************************************************************
...
*****************************************************************/
void create_players_dialog(bool raise)
{
  players_dialog_shell =
    I_IN(I_T(XtCreatePopupShell("playerspopup", 
				raise ? transientShellWidgetClass
				: topLevelShellWidgetClass,
				toplevel, NULL, 0)));

  players_form = XtVaCreateManagedWidget("playersform", 
				       formWidgetClass, 
				       players_dialog_shell, NULL);

  players_label = I_L(XtVaCreateManagedWidget("playerslabel", 
					labelWidgetClass, 
					players_form, NULL));   

   
  players_list = XtVaCreateManagedWidget("playerslist", 
					 listWidgetClass, 
					 players_form, 
					 NULL);

  players_close_command =
    I_L(XtVaCreateManagedWidget("playersclosecommand", commandWidgetClass,
				players_form, NULL));

  players_int_command =
    I_L(XtVaCreateManagedWidget("playersintcommand", commandWidgetClass,
				players_form,
				XtNsensitive, False,
				NULL));

  players_meet_command =
    I_L(XtVaCreateManagedWidget("playersmeetcommand", commandWidgetClass,
				players_form,
				XtNsensitive, False,
				NULL));

  players_war_command =
    I_L(XtVaCreateManagedWidget("playerswarcommand", commandWidgetClass,
				players_form,
				XtNsensitive, False,
				NULL));

  players_vision_command =
    I_L(XtVaCreateManagedWidget("playersvisioncommand", commandWidgetClass,
				players_form,
				XtNsensitive, False,
				NULL));

  players_sship_command =
    I_L(XtVaCreateManagedWidget("playerssshipcommand", commandWidgetClass,
				players_form,
				XtNsensitive, False,
				NULL));

  XtAddCallback(players_list, XtNcallback, players_list_callback, 
		NULL);
  
  XtAddCallback(players_close_command, XtNcallback, players_close_callback, 
		NULL);

  XtAddCallback(players_meet_command, XtNcallback, players_meet_callback, 
		NULL);
  
  XtAddCallback(players_int_command, XtNcallback, players_intel_callback, 
		NULL);

  XtAddCallback(players_war_command, XtNcallback, players_war_callback, 
		NULL);

  XtAddCallback(players_vision_command, XtNcallback, players_vision_callback, 
		NULL);

  XtAddCallback(players_sship_command, XtNcallback, players_sship_callback, 
		NULL);

  players_dialog_update();

  XtRealizeWidget(players_dialog_shell);
  
  XSetWMProtocols(display, XtWindow(players_dialog_shell), 
		  &wm_delete_window, 1);
  XtOverrideTranslations(players_dialog_shell,
    XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-players()"));
}
Пример #7
0
/**************************************************************************
...
**************************************************************************/
Widget create_messageopt_dialog(void)
{
  Widget shell, form, title, scrolled, explanation, ok, cancel, col;
  Widget colhead, space_head;
  Widget label[E_LAST];
  Widget longest_label = 0;
  Widget toggle = 0;
  int i, longest_len = 0;
  Dimension width;
  
  shell = I_T(XtCreatePopupShell("messageoptpopup", transientShellWidgetClass,
				 toplevel, NULL, 0));

  form = XtVaCreateManagedWidget("messageoptform", formWidgetClass, 
				 shell, NULL);   

  title = I_L(XtVaCreateManagedWidget("messageopttitle", labelWidgetClass,
				      form, NULL));

  explanation = I_L(XtVaCreateManagedWidget("messageoptexpl", labelWidgetClass,
					    form, NULL));

  scrolled = XtVaCreateManagedWidget("messageoptscroll", viewportWidgetClass, 
                                     form, NULL);

  col = XtVaCreateManagedWidget("messageoptcol", formWidgetClass, 
                                scrolled, NULL);

  /* space_head labels are "empty" labels in column heading which are
   * used so that we can arrange the constraints without loops.
   * They essentially act as vertical filler.
   */
  space_head = XtVaCreateManagedWidget("messageoptspacehead", labelWidgetClass,
                                       col, NULL);
  
  colhead = I_L(XtVaCreateManagedWidget("messageoptcolhead", labelWidgetClass,
                                        col, NULL));

  for(i = 0; i < E_LAST; i++)  {
    const char *text = get_event_message_text(sorted_events[i]);
    int len = strlen(text);

    label[i] = XtVaCreateManagedWidget("label", labelWidgetClass, col,
				       XtNlabel, text, XtNfromVert,
				       (i == 0) ? space_head : label[i - 1],
				       NULL);

    if (len > longest_len) {
      longest_len = len;
      longest_label = label[i];
    }

    /* 
     * The addition of a scrollbar screws things up. There must be a
     * better way to do this.
     */
    XtVaGetValues(label[i], XtNwidth, &width, NULL);
    XtVaSetValues(label[i], XtNwidth, width + 15, NULL);
  }

  XtVaGetValues(longest_label, XtNwidth, &width, NULL);
  XtVaSetValues(space_head, XtNwidth, width + 15, NULL);
  XtVaSetValues(colhead, XtNfromHoriz, space_head, NULL);

  for (i = 0; i < E_LAST; i++) {
    int j;

    for (j = 0; j < NUM_MW; j++) {
      toggle = XtVaCreateManagedWidget("toggle", toggleWidgetClass, col,
				       XtNfromHoriz,
				       (j == 0 ? space_head : toggle),
				       XtNfromVert,
				       (i == 0) ? space_head : label[i - 1],
				       NULL);
      XtAddCallback(toggle, XtNcallback, toggle_callback, NULL);
      messageopt_toggles[sorted_events[i]][j] = toggle;
    }
  }

  ok = I_L(XtVaCreateManagedWidget("messageoptokcommand",
				   commandWidgetClass,
				   form, NULL));
  
  cancel = I_L(XtVaCreateManagedWidget("messageoptcancelcommand",
				       commandWidgetClass,
				       form, NULL));
	       
  XtAddCallback(ok, XtNcallback, messageopt_ok_command_callback, 
                (XtPointer)shell);
  XtAddCallback(cancel, XtNcallback, messageopt_cancel_command_callback, 
                (XtPointer)shell);
  
  XtRealizeWidget(shell);

  xaw_horiz_center(title);
  xaw_horiz_center(explanation);

  return shell;
}
Пример #8
0
/****************************************************************
...
*****************************************************************/
static int create_improvements_list(struct player *pplayer,
				    struct city *pcity, bool make_modal)
{  
  Widget spy_sabotage_form;
  Widget close_command;
  Dimension width1, width2; 
  int j;

  static const char *improvements_can_sabotage[B_LAST+1]; 
  
  spy_sabotage_shell =
    I_T(XtVaCreatePopupShell("spysabotageimprovementspopup", 
			     (make_modal ? transientShellWidgetClass :
			      topLevelShellWidgetClass),
			     toplevel, NULL));  
  
  spy_sabotage_form = XtVaCreateManagedWidget("spysabotageimprovementsform", 
					     formWidgetClass,
					     spy_sabotage_shell,
					     NULL);   

  spy_improvements_list_label =
    I_L(XtVaCreateManagedWidget("spysabotageimprovementslistlabel", 
				labelWidgetClass, 
				spy_sabotage_form,
				NULL));

  spy_improvements_list = XtVaCreateManagedWidget("spysabotageimprovementslist", 
					      listWidgetClass,
					      spy_sabotage_form,
					      NULL);

  close_command =
    I_L(XtVaCreateManagedWidget("spysabotageimprovementsclosecommand", 
				commandWidgetClass,
				spy_sabotage_form,
				NULL));
  
  spy_sabotage_command =
    I_L(XtVaCreateManagedWidget("spysabotageimprovementscommand", 
				commandWidgetClass,
				spy_sabotage_form,
				XtNsensitive, False,
				NULL));
  

  XtAddCallback(spy_improvements_list, XtNcallback, spy_select_improvement_callback, NULL);
  XtAddCallback(close_command, XtNcallback, spy_close_sabotage_callback, NULL);
  XtAddCallback(spy_sabotage_command, XtNcallback, spy_sabotage_callback, NULL);
  XtRealizeWidget(spy_sabotage_shell);

  /* Now populate the list */
  
  j = 0;
  improvements_can_sabotage[j] = _("City Production");
  improvement_type[j++] = -1;

  city_built_iterate(pcity, pimprove) {
    if (pimprove->sabotage > 0) {
      improvements_can_sabotage[j] = city_improvement_name_translation(pcity, pimprove);
      improvement_type[j++] = improvement_number(pimprove);
    }  
  } city_built_iterate_end;

  if(j > 1) {
    improvements_can_sabotage[j] = _("At Spy's Discretion");
    improvement_type[j++] = B_LAST;
  } else {
    improvement_type[0] = B_LAST; /* fake "discretion", since must be production */
  }

  improvements_can_sabotage[j] = NULL;
  
  XtSetSensitive(spy_sabotage_command, FALSE);
  
  XawListChange(spy_improvements_list, (String *) improvements_can_sabotage,
		0, 0, 1);
  XtVaGetValues(spy_improvements_list, XtNwidth, &width1, NULL);
  XtVaGetValues(spy_improvements_list_label, XtNwidth, &width2, NULL);
  XtVaSetValues(spy_improvements_list, XtNwidth, MAX(width1,width2), NULL); 
  XtVaSetValues(spy_improvements_list_label, XtNwidth, MAX(width1,width2), NULL); 

  return j;
}
Пример #9
0
/****************************************************************
...
*****************************************************************/
static int create_advances_list(struct player *pplayer,
				struct player *pvictim, bool make_modal)
{  
  Widget spy_tech_form;
  Widget close_command;
  Dimension width1, width2; 
  int j;

  static const char *advances_can_steal[A_LAST+1]; 

  spy_tech_shell =
    I_T(XtVaCreatePopupShell("spystealtechpopup", 
			     (make_modal ? transientShellWidgetClass :
			      topLevelShellWidgetClass),
			     toplevel, NULL));  
  
  spy_tech_form = XtVaCreateManagedWidget("spystealtechform", 
					     formWidgetClass,
					     spy_tech_shell,
					     NULL);   

  spy_advances_list_label =
    I_L(XtVaCreateManagedWidget("spystealtechlistlabel", labelWidgetClass, 
				spy_tech_form, NULL));

  spy_advances_list = XtVaCreateManagedWidget("spystealtechlist", 
					      listWidgetClass,
					      spy_tech_form,
					      NULL);

  close_command =
    I_L(XtVaCreateManagedWidget("spystealtechclosecommand", commandWidgetClass,
				spy_tech_form, NULL));
  
  spy_steal_command =
    I_L(XtVaCreateManagedWidget("spystealtechcommand", commandWidgetClass,
				spy_tech_form,
				XtNsensitive, False,
				NULL));
  

  XtAddCallback(spy_advances_list, XtNcallback, spy_select_tech_callback, NULL);
  XtAddCallback(close_command, XtNcallback, spy_close_tech_callback, NULL);
  XtAddCallback(spy_steal_command, XtNcallback, spy_steal_callback, NULL);
  XtRealizeWidget(spy_tech_shell);

  /* Now populate the list */
  
  j = 0;
  advances_can_steal[j] = _("NONE");
  advance_type[j] = -1;

  if (pvictim) { /* you don't want to know what lag can do -- Syela */
    advance_index_iterate(A_FIRST, i) {
      if(player_invention_state(pvictim, i)==TECH_KNOWN && 
         (player_invention_state(pplayer, i)==TECH_UNKNOWN || 
          player_invention_state(pplayer, i)==TECH_PREREQS_KNOWN)) {
      
        advances_can_steal[j] = advance_name_translation(advance_by_number(i));
        advance_type[j++] = i;
      }
    }
    advances_can_steal[j] = _("At Spy's Discretion");
    advance_type[j++] = A_UNSET;
  } advance_index_iterate_end;

  if(j == 0) j++;
  advances_can_steal[j] = NULL; 
  
  XtSetSensitive(spy_steal_command, FALSE);
  
  XawListChange(spy_advances_list, (char **)advances_can_steal, 0, 0, 1);
  XtVaGetValues(spy_advances_list, XtNwidth, &width1, NULL);
  XtVaGetValues(spy_advances_list_label, XtNwidth, &width2, NULL);
  XtVaSetValues(spy_advances_list, XtNwidth, MAX(width1,width2), NULL); 
  XtVaSetValues(spy_advances_list_label, XtNwidth, MAX(width1,width2), NULL); 

  return j;
}
Пример #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;
  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, TRUE);
  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);
}