/************************************************************************** Popup dialog where the user choose the name of the new city punit = (settler) unit which builds the city suggestname = suggetion of the new city's name **************************************************************************/ void popup_newcity_dialog(struct unit *punit, char *suggestname) { input_dialog_create(toplevel, "shellnewcityname", _("What should we call our new city?"), suggestname, name_new_city_callback, INT_TO_XTPOINTER(punit->id), name_new_city_callback, INT_TO_XTPOINTER(0)); }
/**************************************************************** Create a new preset, first asking for the presets name. *****************************************************************/ static void add_preset(Widget w, XtPointer client_data, XtPointer call_data) { input_dialog_create(cma_dialog, "cmapresetname", _("What should we name the new preset?"), _("new preset"), new_preset_callback, INT_TO_XTPOINTER(TRUE), new_preset_callback, INT_TO_XTPOINTER(FALSE)); }
/************************************************************************** ... **************************************************************************/ void races_toggles_callback(Widget w, XtPointer client_data, XtPointer call_data) { int index = XTPOINTER_TO_INT(client_data); struct nation_type *race = races_toggles_to_nations[index]; int j; Widget entry; if(races_leader_pick_popupmenu) XtDestroyWidget(races_leader_pick_popupmenu); races_leader_pick_popupmenu = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, races_leader_pick_menubutton, NULL); local_nation_count = nation_count(); j = 0; nation_leader_list_iterate(nation_leaders(race), pleader) { entry = XtVaCreateManagedWidget(nation_leader_name(pleader), smeBSBObjectClass, races_leader_pick_popupmenu, NULL); XtAddCallback(entry, XtNcallback, races_leader_pick_callback, INT_TO_XTPOINTER(local_nation_count * j + nation_index(race))); j++; } nation_leader_list_iterate_end;
/************************************************************************** Called to fill econ_label pixmaps (showing tax/lux/sci rates). It may be called again if the tileset changes. **************************************************************************/ void fill_econ_label_pixmaps(void) { int i; int econ_label_count = 10; for(i = 0; i < econ_label_count; i++) { struct sprite *s = i < 5 ? get_tax_sprite(tileset, O_SCIENCE) : get_tax_sprite(tileset, O_GOLD); XtVaSetValues(econ_label[i], XtNbitmap, s->pixmap, NULL); XtAddCallback(econ_label[i], XtNcallback, taxrates_callback, INT_TO_XTPOINTER(i)); } }
/**************************************************************** Confirm that the user wants to remove the selected preset. *****************************************************************/ static void remove_preset(Widget w, XtPointer list, XtPointer call_data) { XawListReturnStruct *ret = XawListShowCurrent(preset_list); char buf[256]; if (ret->list_index != XAW_LIST_NONE && cmafec_preset_num()) { fc_snprintf(buf, sizeof(buf), _("Do you really want to remove %s?"), cmafec_preset_get_descr(ret->list_index)); popup_message_dialog(cma_dialog, "cmaremovepreset", buf, remove_preset_yes, INT_TO_XTPOINTER(ret->list_index), 0, remove_preset_no, 0, 0, NULL); } }
/**************************************************************** ... *****************************************************************/ 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(); }
/************************************************************************** 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); }