/**************************************************************** ... *****************************************************************/ 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); }
/**************************************************************** Fills the buf with proper text which should be displayed on the helpbuild wonder button. *****************************************************************/ static void get_help_build_wonder_button_label(char* buf, int bufsize, bool* help_build_possible) { struct city* destcity = game_find_city_by_number(caravan_city_id); struct unit* caravan = game_find_unit_by_number(caravan_unit_id); if (destcity && caravan && unit_can_help_build_wonder(caravan, destcity)) { my_snprintf(buf, bufsize, _("Help build _Wonder (%d remaining)"), impr_build_shield_cost(destcity->production.value.building) - destcity->shield_stock); *help_build_possible = TRUE; } else { my_snprintf(buf, bufsize, _("Help build _Wonder")); *help_build_possible = 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); }