/**************************************************************** ... *****************************************************************/ void popup_caravan_dialog(struct unit *punit, struct city *phomecity, struct city *pdestcity) { char buf[128]; fc_snprintf(buf, sizeof(buf), _("Your %s from %s reaches the city of %s.\nWhat now?"), unit_name_translation(punit), city_name(phomecity), city_name(pdestcity)); caravan_city_id=pdestcity->id; /* callbacks need these */ caravan_unit_id=punit->id; caravan_dialog=popup_message_dialog(toplevel, "caravandialog", buf, caravan_establish_trade_callback, 0, 0, caravan_help_build_wonder_callback, 0, 0, caravan_keep_moving_callback, 0, 0, NULL); if (!can_cities_trade(phomecity, pdestcity)) XtSetSensitive(XtNameToWidget(caravan_dialog, "*button0"), FALSE); if(!unit_can_help_build_wonder(punit, pdestcity)) XtSetSensitive(XtNameToWidget(caravan_dialog, "*button1"), FALSE); }
/**************************************************************** ... *****************************************************************/ void popup_caravan_dialog(struct unit *punit, struct city *phomecity, struct city *pdestcity) { char title_buf[128], buf[128], wonder[128]; bool can_establish, can_trade, can_wonder; fc_snprintf(title_buf, sizeof(title_buf), /* TRANS: %s is a unit type */ _("Your %s Has Arrived"), unit_name_translation(punit)); fc_snprintf(buf, sizeof(buf), _("Your %s from %s reaches the city of %s.\nWhat now?"), unit_name_translation(punit), city_name(phomecity), city_name(pdestcity)); caravan_city_id=pdestcity->id; /* callbacks need these */ caravan_unit_id=punit->id; get_help_build_wonder_button_label(wonder, sizeof(wonder), &can_wonder); can_trade = can_cities_trade(phomecity, pdestcity); can_establish = can_trade && can_establish_trade_route(phomecity, pdestcity); caravan_dialog = popup_choice_dialog(GTK_WINDOW(toplevel), title_buf, buf, (can_establish ? _("Establish _Trade route") : _("Enter Marketplace")),caravan_establish_trade_callback, NULL, wonder,caravan_help_build_wonder_callback, NULL, _("_Keep moving"), NULL, NULL, NULL); g_signal_connect(caravan_dialog, "destroy", G_CALLBACK(caravan_destroy_callback), NULL); if (!can_trade) { choice_dialog_button_set_sensitive(caravan_dialog, 0, FALSE); } if (!can_wonder) { choice_dialog_button_set_sensitive(caravan_dialog, 1, FALSE); } }
/**************************************************************** Popups the diplomat dialog *****************************************************************/ void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile) { struct city *pcity; struct unit *ptunit; struct astring text = ASTRING_INIT; diplomat_id=punit->id; if((pcity=tile_city(dest_tile))){ /* Spy/Diplomat acting against a city */ diplomat_target_id=pcity->id; astr_set(&text, _("Your %s has arrived at %s.\nWhat is your command?"), unit_name_translation(punit), city_name(pcity)); if (!unit_has_type_flag(punit, UTYF_SPY)) { diplomat_dialog = popup_message_dialog(toplevel, "diplomatdialog", astr_str(&text), diplomat_embassy_callback, 0, 1, diplomat_investigate_callback, 0, 1, spy_poison_callback, 0, 1, diplomat_sabotage_callback, 0, 1, diplomat_steal_callback, 0, 1, diplomat_incite_callback, 0, 1, diplomat_keep_moving_callback_city, 0, 1, diplomat_cancel_callback, 0, 0, NULL); } else { diplomat_dialog = popup_message_dialog(toplevel, "spydialog", astr_str(&text), diplomat_embassy_callback, 0, 1, diplomat_investigate_callback, 0, 1, spy_poison_callback, 0, 1, spy_request_sabotage_list, 0, 1, spy_steal_popup, 0, 1, diplomat_incite_callback, 0, 1, diplomat_keep_moving_callback_city, 0, 1, diplomat_cancel_callback, 0, 0, NULL); } if(!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button0"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button1"), FALSE); } if(!diplomat_can_do_action(punit, SPY_POISON, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button2"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button3"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button4"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button5"), FALSE); } if(!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) { XtSetSensitive(XtNameToWidget(diplomat_dialog, "*button6"), FALSE); } } else { if ((ptunit = unit_list_get(dest_tile->units, 0))) { /* Spy/Diplomat acting against a unit */ Widget shl; astr_set(&text, _("Your %s is waiting for your command."), unit_name_translation(punit)); diplomat_target_id=ptunit->id; shl=popup_message_dialog(toplevel, "spybribedialog", astr_str(&text), diplomat_bribe_callback, 0, 0, spy_sabotage_unit_callback, 0, 0, diplomat_keep_moving_callback_unit, 0, 1, diplomat_cancel_callback, 0, 0, NULL); if(!diplomat_can_do_action(punit, DIPLOMAT_BRIBE, dest_tile)) XtSetSensitive(XtNameToWidget(shl, "*button0"), FALSE); if(!diplomat_can_do_action(punit, SPY_SABOTAGE_UNIT, dest_tile)) XtSetSensitive(XtNameToWidget(shl, "*button1"), FALSE); if(!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) XtSetSensitive(XtNameToWidget(shl, "*button2"), FALSE); } } astr_free(&text); }
/**************************************************************** ... *****************************************************************/ 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) { static struct astring str = ASTRING_INIT; /* TRANS: %s is a unit name, e.g., Spy */ astr_set(&str, _("At %s's Discretion"), unit_name_translation(game_unit_by_number(diplomat_id))); improvements_can_sabotage[j] = astr_str(&str); 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; }
/**************************************************************** ... *****************************************************************/ 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; } } { static struct astring str = ASTRING_INIT; /* TRANS: %s is a unit name, e.g., Spy */ astr_set(&str, _("At %s's Discretion"), unit_name_translation(game_unit_by_number(diplomat_id))); advances_can_steal[j] = astr_str(&str); 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; }
/************************************************************************** Popup a dialog giving a player choices when their caravan arrives at a city (other than its home city). Example: - Establish trade route. - Help build wonder. - Keep moving. **************************************************************************/ void popup_caravan_dialog(struct unit *pUnit, struct city *pHomecity, struct city *pDestcity) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_String16 *pStr; struct CONTAINER *pCont; char cBuf[128]; SDL_Rect area; if (pCaravan_Dlg) { return; } caravan_unit_id=pUnit->id; caravan_city_id=pDestcity->id; pCont = fc_calloc(1, sizeof(struct CONTAINER)); pCont->id0 = pUnit->id; pCont->id1 = pDestcity->id; pCaravan_Dlg = fc_calloc(1, sizeof(struct SMALL_DLG)); is_unit_move_blocked = TRUE; fc_snprintf(cBuf, sizeof(cBuf), _("Your %s has arrived at %s"), unit_name_translation(pUnit), city_name(pDestcity)); /* window */ pStr = create_str16_from_char(cBuf, adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = caravan_dlg_window_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_CARAVAN_DLG_WINDOW, pWindow); pCaravan_Dlg->pEndWidgetList = pWindow; area = pWindow->area; area.h = MAX(area.h, adj_size(2)); /* ---------- */ if (can_cities_trade(pHomecity, pDestcity)) { int revenue = get_caravan_enter_city_trade_bonus(pHomecity, pDestcity); if (can_establish_trade_route(pHomecity, pDestcity)) { fc_snprintf(cBuf, sizeof(cBuf), _("Establish Trade route with %s ( %d R&G + %d trade )"), city_name(pHomecity), revenue, trade_between_cities(pHomecity, pDestcity)); } else { revenue = (revenue + 2) / 3; fc_snprintf(cBuf, sizeof(cBuf), _("Enter Marketplace ( %d R&G bonus )"), revenue); } create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, caravan_establish_trade_callback); pBuf->data.cont = pCont; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (unit_can_help_build_wonder(pUnit, pDestcity)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Help build Wonder"), caravan_help_build_wonder_callback); pBuf->data.cont = pCont; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Keep moving"), exit_caravan_dlg_callback); pBuf->data.cont = pCont; set_wstate(pBuf, FC_WS_NORMAL); set_wflag(pBuf, WF_FREE_DATA); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; /* ---------- */ pCaravan_Dlg->pBeginWidgetList = pBuf; /* setup window size and start position */ resize_window(pWindow, NULL, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h - pWindow->area.h) + area.h); area = pWindow->area; auto_center_on_focus_unit(); put_window_near_map_tile(pWindow, pWindow->size.w, pWindow->size.h, unit_tile(pUnit)); /* setup widget size and start position */ pBuf = pWindow->prev; setup_vertical_widgets_position(1, area.x, area.y + 1, area.w, 0, pCaravan_Dlg->pBeginWidgetList, pBuf); /* --------------------- */ /* redraw */ redraw_group(pCaravan_Dlg->pBeginWidgetList, pWindow, 0); widget_flush(pWindow); }
/**************************************************************** Popup new diplomat dialog. *****************************************************************/ void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile) { struct city *pcity; struct unit *ptunit; GtkWidget *shl; struct astring title = ASTRING_INIT, text = ASTRING_INIT; diplomat_id = punit->id; if ((pcity = tile_city(dest_tile))) { /* Spy/Diplomat acting against a city */ diplomat_target_id = pcity->id; astr_set(&title, /* TRANS: %s is a unit name, e.g., Spy */ _("Choose Your %s's Strategy"), unit_name_translation(punit)); astr_set(&text, _("Your %s has arrived at %s.\nWhat is your command?"), unit_name_translation(punit), city_name(pcity)); if (!unit_has_type_flag(punit, UTYF_SPY)) { shl = popup_choice_dialog(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text), _("Establish _Embassy"), diplomat_embassy_callback, NULL, _("_Investigate City"), diplomat_investigate_callback, NULL, _("_Sabotage City"), diplomat_sabotage_callback, NULL, _("Steal _Technology"), diplomat_steal_callback, NULL, _("Incite a _Revolt"), diplomat_incite_callback, NULL, _("_Keep moving"), diplomat_keep_moving_callback, NULL, GTK_STOCK_CANCEL, diplomat_cancel_callback, NULL, NULL); if (!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile)) choice_dialog_button_set_sensitive(shl, 0, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile)) choice_dialog_button_set_sensitive(shl, 1, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile)) choice_dialog_button_set_sensitive(shl, 2, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile)) choice_dialog_button_set_sensitive(shl, 3, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile)) choice_dialog_button_set_sensitive(shl, 4, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) choice_dialog_button_set_sensitive(shl, 5, FALSE); } else { shl = popup_choice_dialog(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text), _("Establish _Embassy"), diplomat_embassy_callback, NULL, _("_Investigate City"), diplomat_investigate_callback, NULL, _("_Poison City"), spy_poison_callback, NULL, _("Industrial _Sabotage"), spy_request_sabotage_list, NULL, _("Steal _Technology"), spy_steal_popup, NULL, _("Incite a _Revolt"), diplomat_incite_callback, NULL, _("_Keep moving"), diplomat_keep_moving_callback, NULL, GTK_STOCK_CANCEL, diplomat_cancel_callback, NULL, NULL); if (!diplomat_can_do_action(punit, DIPLOMAT_EMBASSY, dest_tile)) choice_dialog_button_set_sensitive(shl, 0, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INVESTIGATE, dest_tile)) choice_dialog_button_set_sensitive(shl, 1, FALSE); if (!diplomat_can_do_action(punit, SPY_POISON, dest_tile)) choice_dialog_button_set_sensitive(shl, 2, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_SABOTAGE, dest_tile)) choice_dialog_button_set_sensitive(shl, 3, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_STEAL, dest_tile)) choice_dialog_button_set_sensitive(shl, 4, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_INCITE, dest_tile)) choice_dialog_button_set_sensitive(shl, 5, FALSE); if (!diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) choice_dialog_button_set_sensitive(shl, 6, FALSE); } diplomat_dialog = shl; choice_dialog_set_hide(shl, TRUE); g_signal_connect(shl, "destroy", G_CALLBACK(diplomat_destroy_callback), NULL); g_signal_connect(shl, "delete_event", G_CALLBACK(diplomat_cancel_callback), NULL); } else { if ((ptunit = unit_list_get(dest_tile->units, 0))){ /* Spy/Diplomat acting against a unit */ diplomat_target_id = ptunit->id; astr_set(&text, /* TRANS: %s is a unit name, e.g., Diplomat, Spy */ _("Your %s is waiting for your command."), unit_name_translation(punit)); shl = popup_choice_dialog(GTK_WINDOW(toplevel), _("Subvert Enemy Unit"), astr_str(&text), _("_Bribe Enemy Unit"), diplomat_bribe_callback, NULL, _("_Sabotage Enemy Unit"), spy_sabotage_unit_callback, NULL, GTK_STOCK_CANCEL, diplomat_cancel_callback, NULL, NULL); if (!diplomat_can_do_action(punit, DIPLOMAT_BRIBE, dest_tile)) { choice_dialog_button_set_sensitive(shl, 0, FALSE); } if (!diplomat_can_do_action(punit, SPY_SABOTAGE_UNIT, dest_tile)) { choice_dialog_button_set_sensitive(shl, 1, FALSE); } diplomat_dialog = shl; choice_dialog_set_hide(shl, TRUE); g_signal_connect(shl, "destroy", G_CALLBACK(diplomat_destroy_callback), NULL); g_signal_connect(shl, "delete_event", G_CALLBACK(diplomat_cancel_callback), NULL); } } astr_free(&title); astr_free(&text); }
/**************************************************************** Creates spy's building sabotaging dialog *****************************************************************/ static void create_improvements_list(struct player *pplayer, struct city *pcity) { GtkWidget *sw, *label, *vbox, *view; GtkListStore *store; GtkCellRenderer *rend; GtkTreeViewColumn *col; GtkTreeIter it; spy_sabotage_shell = gtk_dialog_new_with_buttons(_("Sabotage Improvements"), NULL, 0, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Sabotage"), GTK_RESPONSE_ACCEPT, NULL); setup_dialog(spy_sabotage_shell, toplevel); gtk_window_set_position(GTK_WINDOW(spy_sabotage_shell), GTK_WIN_POS_MOUSE); gtk_dialog_set_default_response(GTK_DIALOG(spy_sabotage_shell), GTK_RESPONSE_ACCEPT); label = gtk_frame_new(_("Select Improvement to Sabotage")); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(spy_sabotage_shell))), label); vbox = gtk_vbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(label), vbox); store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); rend = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE, "mnemonic-widget", view, "label", _("_Improvements:"), "xalign", 0.0, "yalign", 0.5, NULL); gtk_container_add(GTK_CONTAINER(vbox), label); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(sw), view); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_widget_set_size_request(sw, -1, 200); gtk_container_add(GTK_CONTAINER(vbox), sw); /* Now populate the list */ gtk_list_store_append(store, &it); gtk_list_store_set(store, &it, 0, _("City Production"), 1, -1, -1); city_built_iterate(pcity, pimprove) { if (pimprove->sabotage > 0) { gtk_list_store_append(store, &it); gtk_list_store_set(store, &it, 0, city_improvement_name_translation(pcity, pimprove), 1, improvement_number(pimprove), -1); } } city_built_iterate_end; gtk_list_store_append(store, &it); { struct astring str = ASTRING_INIT; /* TRANS: %s is a unit name, e.g., Spy */ astr_set(&str, _("At %s's Discretion"), unit_name_translation(game_unit_by_number(diplomat_id))); gtk_list_store_set(store, &it, 0, astr_str(&str), 1, B_LAST, -1); astr_free(&str); } gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_sabotage_shell), GTK_RESPONSE_ACCEPT, FALSE); gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(spy_sabotage_shell))); g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), "changed", G_CALLBACK(spy_improvements_callback), NULL); g_signal_connect(spy_sabotage_shell, "response", G_CALLBACK(spy_improvements_response), NULL); sabotage_improvement = -2; gtk_tree_view_focus(GTK_TREE_VIEW(view)); }
/**************************************************************** Create spy's tech stealing dialog *****************************************************************/ static void create_advances_list(struct player *pplayer, struct player *pvictim) { GtkWidget *sw, *label, *vbox, *view; GtkListStore *store; GtkCellRenderer *rend; GtkTreeViewColumn *col; spy_tech_shell = gtk_dialog_new_with_buttons(_("Steal Technology"), NULL, 0, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Steal"), GTK_RESPONSE_ACCEPT, NULL); setup_dialog(spy_tech_shell, toplevel); gtk_window_set_position(GTK_WINDOW(spy_tech_shell), GTK_WIN_POS_MOUSE); gtk_dialog_set_default_response(GTK_DIALOG(spy_tech_shell), GTK_RESPONSE_ACCEPT); label = gtk_frame_new(_("Select Advance to Steal")); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(spy_tech_shell))), label); vbox = gtk_vbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(label), vbox); store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); rend = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new_with_attributes(NULL, rend, "text", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE, "mnemonic-widget", view, "label", _("_Advances:"), "xalign", 0.0, "yalign", 0.5, NULL); gtk_container_add(GTK_CONTAINER(vbox), label); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(sw), view); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_widget_set_size_request(sw, -1, 200); gtk_container_add(GTK_CONTAINER(vbox), sw); /* Now populate the list */ if (pvictim) { /* you don't want to know what lag can do -- Syela */ GtkTreeIter it; GValue value = { 0, }; 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)) { gtk_list_store_append(store, &it); g_value_init(&value, G_TYPE_STRING); g_value_set_static_string(&value, advance_name_for_player(client.conn.playing, i)); gtk_list_store_set_value(store, &it, 0, &value); g_value_unset(&value); gtk_list_store_set(store, &it, 1, i, -1); } } advance_index_iterate_end; gtk_list_store_append(store, &it); g_value_init(&value, G_TYPE_STRING); { struct astring str = ASTRING_INIT; /* TRANS: %s is a unit name, e.g., Spy */ astr_set(&str, _("At %s's Discretion"), unit_name_translation(game_unit_by_number(diplomat_id))); g_value_set_string(&value, astr_str(&str)); astr_free(&str); } gtk_list_store_set_value(store, &it, 0, &value); g_value_unset(&value); gtk_list_store_set(store, &it, 1, A_UNSET, -1); } gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_tech_shell), GTK_RESPONSE_ACCEPT, FALSE); gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(spy_tech_shell))); g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), "changed", G_CALLBACK(spy_advances_callback), NULL); g_signal_connect(spy_tech_shell, "response", G_CALLBACK(spy_advances_response), NULL); steal_advance = 0; gtk_tree_view_focus(GTK_TREE_VIEW(view)); }
/**************************************************************** Popup new diplomat dialog. *****************************************************************/ void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile) { struct city *pcity; struct unit *ptunit; GtkWidget *shl; struct astring title = ASTRING_INIT, text = ASTRING_INIT; diplomat_target_id[ATK_CITY] = -1; diplomat_target_id[ATK_UNIT] = -1; diplomat_id = punit->id; astr_set(&title, /* TRANS: %s is a unit name, e.g., Spy */ _("Choose Your %s's Strategy"), unit_name_translation(punit)); astr_set(&text, /* TRANS: %s is a unit name, e.g., Diplomat, Spy */ _("Your %s is waiting for your command."), unit_name_translation(punit)); shl = choice_dialog_start(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text)); if ((pcity = tile_city(dest_tile))) { /* Spy/Diplomat acting against a city */ diplomat_target_id[ATK_CITY] = pcity->id; action_entry(shl, action_enabled_unit_on_city_local( ACTION_ESTABLISH_EMBASSY, punit, pcity), _("Establish _Embassy"), (GCallback)diplomat_embassy_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_INVESTIGATE_CITY, punit, pcity), _("_Investigate City"), (GCallback)diplomat_investigate_callback); action_entry(shl, action_enabled_unit_on_city_local(ACTION_SPY_POISON, punit, pcity), _("_Poison City"), (GCallback)spy_poison_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_SABOTAGE_CITY, punit, pcity), _("_Sabotage City"), (GCallback)diplomat_sabotage_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_TARGETED_SABOTAGE_CITY, punit, pcity), _("Industrial _Sabotage"), (GCallback)spy_request_sabotage_list); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_STEAL_TECH, punit, pcity), _("Steal _Technology"), (GCallback)diplomat_steal_callback); action_entry(shl, action_enabled_unit_on_city_local( ACTION_SPY_TARGETED_STEAL_TECH, punit, pcity), _("Industrial espionage"), (GCallback)spy_steal_popup); action_entry(shl, action_enabled_unit_on_city_local(ACTION_SPY_INCITE_CITY, punit, pcity), _("Incite a _Revolt"), (GCallback)diplomat_incite_callback); } if ((ptunit = unit_list_get(dest_tile->units, 0))) { /* Spy/Diplomat acting against a unit */ diplomat_target_id[ATK_UNIT] = ptunit->id; action_entry(shl, action_enabled_unit_on_unit_local( ACTION_SPY_BRIBE_UNIT, punit, ptunit), _("_Bribe Enemy Unit"), (GCallback)diplomat_bribe_callback); action_entry(shl, action_enabled_unit_on_unit_local( ACTION_SPY_SABOTAGE_UNIT, punit, ptunit), _("_Sabotage Enemy Unit"), (GCallback)spy_sabotage_unit_callback); } if (diplomat_can_do_action(punit, DIPLOMAT_MOVE, dest_tile)) { if (pcity) { choice_dialog_add(shl, _("_Keep moving"), (GCallback)diplomat_keep_moving_city_callback, NULL, FALSE); } else { choice_dialog_add(shl, _("_Keep moving"), (GCallback)diplomat_keep_moving_unit_callback, NULL, FALSE); } } choice_dialog_add(shl, GTK_STOCK_CANCEL, (GCallback)diplomat_cancel_callback, NULL, FALSE); choice_dialog_end(shl); diplomat_dialog = shl; choice_dialog_set_hide(shl, TRUE); g_signal_connect(shl, "destroy", G_CALLBACK(diplomat_destroy_callback), NULL); g_signal_connect(shl, "delete_event", G_CALLBACK(diplomat_cancel_callback), NULL); astr_free(&title); astr_free(&text); }