/**************************************************************** ... *****************************************************************/ 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); }
PyObject* py_get_caravan_options(struct unit *punit, struct city *phomecity, struct city *pdestcity) { bool can_establish, can_trade, can_wonder; can_trade = can_cities_trade(phomecity, pdestcity); can_establish = can_trade && can_establish_trade_route(phomecity, pdestcity); return Py_BuildValue("iii", can_establish, can_trade, can_wonder); }
/**************************************************************** ... *****************************************************************/ 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); } }
/************************************************************************** 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); }