Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #898126 ยป 0033-sdl2-Rename-pUnit-to-adhere-coding-style-standards.patch

Marko Lindqvist, 2020-11-17 09:53 PM

View differences:

client/gui-sdl2/action_dialog.c
Popup a dialog asking a diplomatic unit if it wishes to bribe the
given enemy unit.
**************************************************************************/
void popup_bribe_dialog(struct unit *actor, struct unit *pUnit, int cost,
void popup_bribe_dialog(struct unit *actor, struct unit *punit, int cost,
const struct action *paction)
{
struct widget *pwindow = NULL, *pBuf = NULL;
......
pBribe_Dlg = fc_calloc(1, sizeof(struct small_diplomat_dialog));
pBribe_Dlg->act_id = paction->id;
pBribe_Dlg->actor_unit_id = actor->id;
pBribe_Dlg->target_id = pUnit->id;
pBribe_Dlg->target_id = punit->id;
pBribe_Dlg->pdialog = fc_calloc(1, sizeof(struct small_dialog));
fc_snprintf(tBuf, ARRAY_SIZE(tBuf), PL_("Treasury contains %d gold.",
......
/*------------*/
create_active_iconlabel(pBuf, pwindow->dst, pstr,
_("Yes"), diplomat_bribe_yes_callback);
pBuf->data.unit = pUnit;
pBuf->data.unit = punit;
set_wstate(pBuf, FC_WS_NORMAL);
add_to_gui_list(MAX_ID - actor->id, pBuf);
client/gui-sdl2/citydlg.c
static int activate_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
popdown_city_menu_dlg(TRUE);
if (pUnit) {
unit_focus_set(pUnit);
if (punit) {
unit_focus_set(punit);
}
}
return -1;
......
static int activate_and_exit_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
if (pUnit) {
if (punit) {
popdown_window_group_dialog(pcity_dlg->pBeginCityMenuWidgetList,
pcity_dlg->pEndCityMenuWidgetList);
pcity_dlg->pEndCityMenuWidgetList = NULL;
popdown_city_dialog(pcity_dlg->pCity);
center_tile_mapcanvas(unit_tile(pUnit));
unit_focus_set(pUnit);
center_tile_mapcanvas(unit_tile(punit));
unit_focus_set(punit);
}
}
return -1;
......
static int sentry_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
popdown_city_menu_dlg(TRUE);
if (pUnit) {
request_unit_sentry(pUnit);
if (punit) {
request_unit_sentry(punit);
}
}
return -1;
......
static int fortify_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
popdown_city_menu_dlg(TRUE);
if (pUnit) {
request_unit_fortify(pUnit);
if (punit) {
request_unit_fortify(punit);
}
}
return -1;
......
static int disband_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
popdown_city_menu_dlg(TRUE);
popup_unit_disband_dlg(pUnit, TRUE);
popup_unit_disband_dlg(punit, TRUE);
}
return -1;
}
......
static int homecity_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
popdown_city_menu_dlg(TRUE);
if (pUnit) {
request_unit_change_homecity(pUnit);
if (punit) {
request_unit_change_homecity(punit);
}
}
return -1;
......
static int upgrade_units_orders_city_dlg_callback(struct widget *pButton)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pButton->data.unit;
struct unit *punit = pButton->data.unit;
popdown_city_menu_dlg(TRUE);
popup_unit_upgrade_dlg(pUnit, TRUE);
popup_unit_upgrade_dlg(punit, TRUE);
}
return -1;
}
......
h = tileset_full_tile_height(tileset) + (adj_size(151) % (tileset_full_tile_height(tileset)+4)) / num_y;
}
unit_list_iterate(pList, pUnit) {
unit_list_iterate(pList, punit) {
const char *vetname;
putype = unit_type_get(pUnit);
vetname = utype_veteran_name_translation(putype, pUnit->veteran);
pHome_City = game_city_by_number(pUnit->homecity);
putype = unit_type_get(punit);
vetname = utype_veteran_name_translation(putype, punit->veteran);
pHome_City = game_city_by_number(punit->homecity);
fc_snprintf(cBuf, sizeof(cBuf), "%s (%d,%d,%s)%s%s\n%s\n(%d/%d)\n%s",
utype_name_translation(putype),
putype->attack_strength,
......
move_points_text(putype->move_rate, FALSE),
(vetname != NULL ? "\n" : ""),
(vetname != NULL ? vetname : ""),
unit_activity_text(pUnit),
pUnit->hp, putype->hp,
unit_activity_text(punit),
punit->hp, putype->hp,
pHome_City ? pHome_City->name : Q_("?homecity:None"));
if (pcity_dlg->page == SUPPORTED_UNITS_PAGE) {
int pcity_near_dist;
struct city *pnear_city = get_nearest_city(pUnit, &pcity_near_dist);
struct city *pnear_city = get_nearest_city(punit, &pcity_near_dist);
sz_strlcat(cBuf, "\n");
sz_strlcat(cBuf, get_nearest_city_text(pnear_city, pcity_near_dist));
surf = adj_surf(create_unit_surface(pUnit, TRUE, w, h));
surf = adj_surf(create_unit_surface(punit, TRUE, w, h));
} else {
surf = adj_surf(create_unit_surface(pUnit, FALSE, w, h));
surf = adj_surf(create_unit_surface(punit, FALSE, w, h));
}
pstr = create_utf8_from_char(cBuf, adj_font(10));
......
pBuf = create_icon2(surf, pwindow->dst, WF_FREE_THEME
| WF_RESTORE_BACKGROUND | WF_WIDGET_HAS_INFO_LABEL);
pBuf->info_label = pstr;
pBuf->data.unit = pUnit;
add_to_gui_list(MAX_ID - pUnit->id, pBuf);
pBuf->data.unit = punit;
add_to_gui_list(MAX_ID - punit->id, pBuf);
if (!pEnd) {
pEnd = pBuf;
......
typically means updating both the unit's home city (if any) and the
city in which it is present (if any).
**************************************************************************/
void refresh_unit_city_dialogs(struct unit *pUnit)
void refresh_unit_city_dialogs(struct unit *punit)
{
struct city *pcity_sup = game_city_by_number(pUnit->homecity);
struct city *pcity_pre = tile_city(unit_tile(pUnit));
struct city *pcity_sup = game_city_by_number(punit->homecity);
struct city *pcity_pre = tile_city(unit_tile(punit));
if (pcity_dlg && ((pcity_dlg->pCity == pcity_sup)
|| (pcity_dlg->pCity == pcity_pre))) {
client/gui-sdl2/cityrep.c
struct widget *pbuf = NULL;
struct widget *pwindow, *pLast;
utf8_str *pstr;
SDL_Surface *pText1, *pText2, *pText3, *pUnits_Icon, *pCMA_Icon, *pText4;
SDL_Surface *pText1, *pText2, *pText3, *units_icon, *pCMA_Icon, *pText4;
SDL_Surface *logo;
int togrow, w = 0 , count, ww = 0, hh = 0, name_w = 0, prod_w = 0, H;
char cbuf[128];
......
prod_w = pText4->w;
FREEUTF8STR(pstr);
pUnits_Icon = create_icon_from_theme(current_theme->UNITS_Icon, 0);
units_icon = create_icon_from_theme(current_theme->UNITS_Icon, 0);
pCMA_Icon = create_icon_from_theme(current_theme->CMA_Icon, 0);
/* --------------- */
......
set_wflag(pbuf, WF_HIDDEN);
}
hh = MAX(hh, pbuf->size.h);
pbuf->size.w = pUnits_Icon->w + adj_size(6);
pbuf->size.w = units_icon->w + adj_size(6);
add_to_gui_list(MAX_ID - pCity->id, pbuf);
/* ----------- */
......
/* setup window width */
area.w = name_w + adj_size(6) + pText1->w + adj_size(8) + pCMA_Icon->w
+ (pIcons->pBIG_Food->w + adj_size(6)) * 10 + pText2->w + adj_size(6)
+ pUnits_Icon->w + adj_size(6) + prod_w + adj_size(170);
+ units_icon->w + adj_size(6) + prod_w + adj_size(170);
if (count) {
pCityRep->end_active_widget_list = pLast->prev;
......
dst.y = area.y + 1;
dst.w = (pIcons->pBIG_Shield->w + adj_size(6)) + adj_size(10) +
(pIcons->pBIG_Shield_Corr->w + adj_size(6)) + adj_size(10) +
(pUnits_Icon->w + adj_size(6)) + adj_size(10) +
(units_icon->w + adj_size(6)) + adj_size(10) +
(pIcons->pBIG_Shield_Surplus->w + adj_size(6)) + adj_size(4);
dst.h = area.h - adj_size(2);
......
w += (pIcons->pBIG_Shield_Corr->w + adj_size(6)) + adj_size(10);
dst.x = w + adj_size(3);
dst.y = area.y + 1 + (hh - pUnits_Icon->h) / 2;
alphablit(pUnits_Icon, NULL, pwindow->theme, &dst, 255);
dst.y = area.y + 1 + (hh - units_icon->h) / 2;
alphablit(units_icon, NULL, pwindow->theme, &dst, 255);
w += (pUnits_Icon->w + adj_size(6)) + adj_size(10);
FREESURFACE(pUnits_Icon);
w += (units_icon->w + adj_size(6)) + adj_size(10);
FREESURFACE(units_icon);
dst.x = w + adj_size(3);
dst.y = area.y + 1 + (hh - pIcons->pBIG_Shield_Surplus->h) / 2;
alphablit(pIcons->pBIG_Shield_Surplus, NULL, pwindow->theme, &dst, 255);
client/gui-sdl2/dialogs.c
/* =======================================================================*/
/* ========================= UNIT UPGRADE DIALOG =========================*/
/* =======================================================================*/
static struct small_dialog *pUnit_Upgrade_Dlg = NULL;
static struct small_dialog *unit_upgrade_dlg = NULL;
/**********************************************************************//**
User interacted with upgrade unit widget.
......
static int upgrade_unit_window_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(pUnit_Upgrade_Dlg->begin_widget_list, pwindow);
move_window_group(unit_upgrade_dlg->begin_widget_list, pwindow);
}
return -1;
}
......
static int ok_upgrade_unit_window_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pwidget->data.unit;
struct unit *punit = pwidget->data.unit;
popdown_unit_upgrade_dlg();
/* enable city dlg */
enable_city_dlg_widgets();
free_city_units_lists();
request_unit_upgrade(pUnit);
request_unit_upgrade(punit);
flush_dirty();
}
return -1;
......
/**********************************************************************//**
Open unit upgrade dialog.
**************************************************************************/
void popup_unit_upgrade_dlg(struct unit *pUnit, bool city)
void popup_unit_upgrade_dlg(struct unit *punit, bool city)
{
char cBuf[128];
struct widget *pBuf = NULL, *pwindow;
......
enum unit_upgrade_result unit_upgrade_result;
SDL_Rect area;
if (pUnit_Upgrade_Dlg) {
if (unit_upgrade_dlg) {
/* just in case */
flush_dirty();
return;
}
pUnit_Upgrade_Dlg = fc_calloc(1, sizeof(struct small_dialog));
unit_upgrade_dlg = fc_calloc(1, sizeof(struct small_dialog));
unit_upgrade_result = unit_upgrade_info(pUnit, cBuf, sizeof(cBuf));
unit_upgrade_result = unit_upgrade_info(punit, cBuf, sizeof(cBuf));
pstr = create_utf8_from_char(_("Upgrade Obsolete Units"), adj_font(12));
pstr->style |= TTF_STYLE_BOLD;
......
pwindow->action = upgrade_unit_window_callback;
set_wstate(pwindow, FC_WS_NORMAL);
pUnit_Upgrade_Dlg->end_widget_list = pwindow;
unit_upgrade_dlg->end_widget_list = pwindow;
add_to_gui_list(ID_WINDOW, pwindow);
......
pBuf->action = ok_upgrade_unit_window_callback;
set_wstate(pBuf, FC_WS_NORMAL);
pBuf->data.unit = pUnit;
pBuf->data.unit = punit;
add_to_gui_list(ID_BUTTON, pBuf);
pBuf->size.w = MAX(pBuf->size.w, pBuf->next->size.w);
pBuf->next->size.w = pBuf->size.w;
......
}
/* ============================================ */
pUnit_Upgrade_Dlg->begin_widget_list = pBuf;
unit_upgrade_dlg->begin_widget_list = pBuf;
resize_window(pwindow, NULL, get_theme_color(COLOR_THEME_BACKGROUND),
(pwindow->size.w - pwindow->area.w) + area.w,
......
window_y = main_data.event.motion.y;
} else {
put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
unit_tile(pUnit));
unit_tile(punit));
}
widget_set_position(pwindow, window_x, window_y);
......
/* ================================================== */
/* redraw */
redraw_group(pUnit_Upgrade_Dlg->begin_widget_list, pwindow, 0);
redraw_group(unit_upgrade_dlg->begin_widget_list, pwindow, 0);
widget_mark_dirty(pwindow);
flush_dirty();
......
**************************************************************************/
static void popdown_unit_upgrade_dlg(void)
{
if (pUnit_Upgrade_Dlg) {
popdown_window_group_dialog(pUnit_Upgrade_Dlg->begin_widget_list,
pUnit_Upgrade_Dlg->end_widget_list);
FC_FREE(pUnit_Upgrade_Dlg);
if (unit_upgrade_dlg) {
popdown_window_group_dialog(unit_upgrade_dlg->begin_widget_list,
unit_upgrade_dlg->end_widget_list);
FC_FREE(unit_upgrade_dlg);
}
}
/* =======================================================================*/
/* ========================= UNIT DISBAND DIALOG =========================*/
/* =======================================================================*/
static struct small_dialog *pUnit_Disband_Dlg = NULL;
static struct small_dialog *unit_disband_dlg = NULL;
/**********************************************************************//**
User interacted with disband unit widget.
......
static int disband_unit_window_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(pUnit_Disband_Dlg->begin_widget_list, pwindow);
move_window_group(unit_disband_dlg->begin_widget_list, pwindow);
}
return -1;
......
static int ok_disband_unit_window_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pwidget->data.unit;
struct unit *punit = pwidget->data.unit;
popdown_unit_disband_dlg();
/* enable city dlg */
enable_city_dlg_widgets();
free_city_units_lists();
request_unit_disband(pUnit);
request_unit_disband(punit);
flush_dirty();
}
return -1;
......
/**********************************************************************//**
Open unit disband dialog.
**************************************************************************/
void popup_unit_disband_dlg(struct unit *pUnit, bool city)
void popup_unit_disband_dlg(struct unit *punit, bool city)
{
char cBuf[128];
struct widget *pBuf = NULL, *pwindow;
......
bool unit_disband_result;
SDL_Rect area;
if (pUnit_Disband_Dlg) {
if (unit_disband_dlg) {
/* just in case */
flush_dirty();
return;
}
pUnit_Disband_Dlg = fc_calloc(1, sizeof(struct small_dialog));
unit_disband_dlg = fc_calloc(1, sizeof(struct small_dialog));
{
struct unit_list *pUnits = unit_list_new();
struct unit_list *punits = unit_list_new();
unit_list_append(pUnits, pUnit);
unit_disband_result = get_units_disband_info(cBuf, sizeof(cBuf), pUnits);
unit_list_destroy(pUnits);
unit_list_append(punits, punit);
unit_disband_result = get_units_disband_info(cBuf, sizeof(cBuf), punits);
unit_list_destroy(punits);
}
pstr = create_utf8_from_char(_("Disband Units"), adj_font(12));
......
pwindow->action = disband_unit_window_callback;
set_wstate(pwindow, FC_WS_NORMAL);
pUnit_Disband_Dlg->end_widget_list = pwindow;
unit_disband_dlg->end_widget_list = pwindow;
add_to_gui_list(ID_WINDOW, pwindow);
......
pBuf->action = ok_disband_unit_window_callback;
set_wstate(pBuf, FC_WS_NORMAL);
pBuf->data.unit = pUnit;
pBuf->data.unit = punit;
add_to_gui_list(ID_BUTTON, pBuf);
pBuf->size.w = MAX(pBuf->size.w, pBuf->next->size.w);
pBuf->next->size.w = pBuf->size.w;
......
}
/* ============================================ */
pUnit_Disband_Dlg->begin_widget_list = pBuf;
unit_disband_dlg->begin_widget_list = pBuf;
resize_window(pwindow, NULL, get_theme_color(COLOR_THEME_BACKGROUND),
(pwindow->size.w - pwindow->area.w) + area.w,
......
window_y = main_data.event.motion.y;
} else {
put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
unit_tile(pUnit));
unit_tile(punit));
}
widget_set_position(pwindow, window_x, window_y);
......
/* ================================================== */
/* redraw */
redraw_group(pUnit_Disband_Dlg->begin_widget_list, pwindow, 0);
redraw_group(unit_disband_dlg->begin_widget_list, pwindow, 0);
widget_mark_dirty(pwindow);
flush_dirty();
......
**************************************************************************/
static void popdown_unit_disband_dlg(void)
{
if (pUnit_Disband_Dlg) {
popdown_window_group_dialog(pUnit_Disband_Dlg->begin_widget_list,
pUnit_Disband_Dlg->end_widget_list);
FC_FREE(pUnit_Disband_Dlg);
if (unit_disband_dlg) {
popdown_window_group_dialog(unit_disband_dlg->begin_widget_list,
unit_disband_dlg->end_widget_list);
FC_FREE(unit_disband_dlg);
}
}
/* =======================================================================*/
/* ======================== UNIT SELECTION DIALOG ========================*/
/* =======================================================================*/
static struct advanced_dialog *pUnit_Select_Dlg = NULL;
static struct advanced_dialog *unit_select_dlg = NULL;
/**********************************************************************//**
User interacted with unit selection window.
......
static int unit_select_window_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(pUnit_Select_Dlg->begin_widget_list, pwindow);
move_window_group(unit_select_dlg->begin_widget_list, pwindow);
}
return -1;
......
static int unit_select_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit =
struct unit *punit =
player_unit_by_number(client_player(), MAX_ID - pwidget->ID);
unit_select_dialog_popdown();
if (pUnit) {
request_new_unit_activity(pUnit, ACTIVITY_IDLE);
unit_focus_set(pUnit);
if (punit) {
request_new_unit_activity(punit, ACTIVITY_IDLE);
unit_focus_set(punit);
}
}
return -1;
......
**************************************************************************/
static void unit_select_dialog_popdown(void)
{
if (pUnit_Select_Dlg) {
if (unit_select_dlg) {
is_unit_move_blocked = FALSE;
popdown_window_group_dialog(pUnit_Select_Dlg->begin_widget_list,
pUnit_Select_Dlg->end_widget_list);
popdown_window_group_dialog(unit_select_dlg->begin_widget_list,
unit_select_dlg->end_widget_list);
FC_FREE(pUnit_Select_Dlg->pScroll);
FC_FREE(pUnit_Select_Dlg);
FC_FREE(unit_select_dlg->pScroll);
FC_FREE(unit_select_dlg);
flush_dirty();
}
}
......
{
struct widget *pBuf = NULL, *pwindow;
utf8_str *pstr;
struct unit *pUnit = NULL, *pFocus = head_of_units_in_focus();
struct unit *punit = NULL, *pFocus = head_of_units_in_focus();
const struct unit_type *punittype;
char cBuf[255];
int i, w = 0, n;
......
n = unit_list_size(ptile->units);
if (!n || pUnit_Select_Dlg) {
if (!n || unit_select_dlg) {
return;
}
is_unit_move_blocked = TRUE;
pUnit_Select_Dlg = fc_calloc(1, sizeof(struct advanced_dialog));
unit_select_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
fc_snprintf(cBuf , sizeof(cBuf), "%s (%d)", _("Unit selection") , n);
pstr = create_utf8_from_char(cBuf , adj_font(12));
......
set_wstate(pwindow, FC_WS_NORMAL);
add_to_gui_list(ID_UNIT_SELECT_DLG_WINDOW, pwindow);
pUnit_Select_Dlg->end_widget_list = pwindow;
unit_select_dlg->end_widget_list = pwindow;
area = pwindow->area;
......
for (i = 0; i < n; i++) {
const char *vetname;
pUnit = unit_list_get(ptile->units, i);
punittype = unit_type_get(pUnit);
vetname = utype_veteran_name_translation(punittype, pUnit->veteran);
punit = unit_list_get(ptile->units, i);
punittype = unit_type_get(punit);
vetname = utype_veteran_name_translation(punittype, punit->veteran);
if (unit_owner(pUnit) == client.conn.playing) {
if (unit_owner(punit) == client.conn.playing) {
fc_snprintf(cBuf , sizeof(cBuf), _("Contact %s (%d / %d) %s(%d,%d,%s) %s"),
(vetname != NULL ? vetname : ""),
pUnit->hp, punittype->hp,
punit->hp, punittype->hp,
utype_name_translation(punittype),
punittype->attack_strength,
punittype->defense_strength,
move_points_text(punittype->move_rate, FALSE),
unit_activity_text(pUnit));
unit_activity_text(punit));
} else {
int att_chance, def_chance;
fc_snprintf(cBuf , sizeof(cBuf), _("%s %s %s(A:%d D:%d M:%s FP:%d) HP:%d%%"),
nation_adjective_for_player(unit_owner(pUnit)),
nation_adjective_for_player(unit_owner(punit)),
(vetname != NULL ? vetname : ""),
utype_name_translation(punittype),
punittype->attack_strength,
punittype->defense_strength,
move_points_text(punittype->move_rate, FALSE),
punittype->firepower,
(pUnit->hp * 100 / punittype->hp + 9) / 10);
(punit->hp * 100 / punittype->hp + 9) / 10);
/* calculate chance to win */
if (sdl_get_chance_to_win(&att_chance, &def_chance, pUnit, pFocus)) {
if (sdl_get_chance_to_win(&att_chance, &def_chance, punit, pFocus)) {
/* TRANS: "CtW" = "Chance to Win"; preserve leading space */
cat_snprintf(cBuf, sizeof(cBuf), _(" CtW: Att:%d%% Def:%d%%"),
att_chance, def_chance);
......
create_active_iconlabel(pBuf, pwindow->dst, pstr, cBuf,
unit_select_callback);
add_to_gui_list(MAX_ID - pUnit->id , pBuf);
add_to_gui_list(MAX_ID - punit->id , pBuf);
area.w = MAX(area.w, pBuf->size.w);
area.h += pBuf->size.h;
if (unit_owner(pUnit) == client.conn.playing) {
if (unit_owner(punit) == client.conn.playing) {
set_wstate(pBuf, FC_WS_NORMAL);
}
......
}
}
pUnit_Select_Dlg->begin_widget_list = pBuf;
pUnit_Select_Dlg->begin_active_widget_list = pUnit_Select_Dlg->begin_widget_list;
pUnit_Select_Dlg->end_active_widget_list = pwindow->prev->prev;
pUnit_Select_Dlg->active_widget_list = pUnit_Select_Dlg->end_active_widget_list;
unit_select_dlg->begin_widget_list = pBuf;
unit_select_dlg->begin_active_widget_list = unit_select_dlg->begin_widget_list;
unit_select_dlg->end_active_widget_list = pwindow->prev->prev;
unit_select_dlg->active_widget_list = unit_select_dlg->end_active_widget_list;
area.w += adj_size(2);
if (n > NUM_SEEN) {
n = create_vertical_scrollbar(pUnit_Select_Dlg, 1, NUM_SEEN, TRUE, TRUE);
n = create_vertical_scrollbar(unit_select_dlg, 1, NUM_SEEN, TRUE, TRUE);
area.w += n;
/* ------- window ------- */
......
area = pwindow->area;
put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
unit_tile(pUnit));
unit_tile(punit));
w = area.w;
if (pUnit_Select_Dlg->pScroll) {
if (unit_select_dlg->pScroll) {
w -= n;
}
......
pBuf = pBuf->prev;
setup_vertical_widgets_position(1, area.x + 1, area.y, w, 0,
pUnit_Select_Dlg->begin_active_widget_list,
unit_select_dlg->begin_active_widget_list,
pBuf);
if (pUnit_Select_Dlg->pScroll) {
setup_vertical_scrollbar_area(pUnit_Select_Dlg->pScroll,
if (unit_select_dlg->pScroll) {
setup_vertical_scrollbar_area(unit_select_dlg->pScroll,
area.x + area.w, area.y,
area.h, TRUE);
}
/* ==================================================== */
/* redraw */
redraw_group(pUnit_Select_Dlg->begin_widget_list, pwindow, 0);
redraw_group(unit_select_dlg->begin_widget_list, pwindow, 0);
widget_flush(pwindow);
}
......
static int adv_unit_select_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pwidget->data.unit;
struct unit *punit = pwidget->data.unit;
popdown_advanced_terrain_dialog();
if (pUnit) {
request_new_unit_activity(pUnit, ACTIVITY_IDLE);
unit_focus_set(pUnit);
if (punit) {
request_new_unit_activity(punit, ACTIVITY_IDLE);
unit_focus_set(punit);
}
}
return -1;
......
static int adv_unit_select_all_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pwidget->data.unit;
struct unit *punit = pwidget->data.unit;
popdown_advanced_terrain_dialog();
if (pUnit) {
activate_all_units(unit_tile(pUnit));
if (punit) {
activate_all_units(unit_tile(punit));
}
}
return -1;
......
static int adv_unit_sentry_idle_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pwidget->data.unit;
struct unit *punit = pwidget->data.unit;
popdown_advanced_terrain_dialog();
if (pUnit) {
struct tile *ptile = unit_tile(pUnit);
if (punit) {
struct tile *ptile = unit_tile(punit);
unit_list_iterate(ptile->units, punit) {
if (unit_owner(punit) == client.conn.playing
&& ACTIVITY_IDLE == punit->activity
&& punit->ssa_controller == SSA_NONE
&& can_unit_do_activity(punit, ACTIVITY_SENTRY)) {
request_new_unit_activity(punit, ACTIVITY_SENTRY);
unit_list_iterate(ptile->units, other_unit) {
if (unit_owner(other_unit) == client.conn.playing
&& ACTIVITY_IDLE == other_unit->activity
&& other_unit->ssa_controller == SSA_NONE
&& can_unit_do_activity(other_unit, ACTIVITY_SENTRY)) {
request_new_unit_activity(other_unit, ACTIVITY_SENTRY);
}
} unit_list_iterate_end;
}
}
return -1;
}
......
#if 0
int x = pwidget->data.cont->id0;
int y = pwidget->data.cont->id1;
struct unit *pUnit = head_of_units_in_focus();
struct unit *punit = head_of_units_in_focus();
#endif
popdown_advanced_terrain_dialog();
#if 0
if (pUnit) {
enter_goto_state(pUnit);
if (punit) {
enter_goto_state(punit);
/* may not work */
do_unit_patrol_to(pUnit, map_pos_to_tile(x, y));
do_unit_patrol_to(punit, map_pos_to_tile(x, y));
exit_goto_state();
}
#endif /* 0 */
......
/* ---------- */
if (n) {
int i;
struct unit *pUnit;
struct unit *punit;
const struct unit_type *punittype = NULL;
units_h = 0;
......
pDefender = (pFocus_Unit ? get_defender(pFocus_Unit, ptile) : NULL);
pAttacker = (pFocus_Unit ? get_attacker(pFocus_Unit, ptile) : NULL);
for (i = 0; i < n; i++) {
pUnit = unit_list_get(ptile->units, i);
if (pUnit == pFocus_Unit) {
punit = unit_list_get(ptile->units, i);
if (punit == pFocus_Unit) {
continue;
}
punittype = unit_type_get(pUnit);
vetname = utype_veteran_name_translation(punittype, pUnit->veteran);
punittype = unit_type_get(punit);
vetname = utype_veteran_name_translation(punittype, punit->veteran);
if (unit_owner(pUnit) == client.conn.playing) {
if (unit_owner(punit) == client.conn.playing) {
fc_snprintf(cBuf, sizeof(cBuf),
_("Activate %s (%d / %d) %s (%d,%d,%s) %s"),
(vetname != NULL ? vetname : ""),
pUnit->hp, punittype->hp,
punit->hp, punittype->hp,
utype_name_translation(punittype),
punittype->attack_strength,
punittype->defense_strength,
move_points_text(punittype->move_rate, FALSE),
unit_activity_text(pUnit));
unit_activity_text(punit));
create_active_iconlabel(pBuf, pwindow->dst, pstr,
cBuf, adv_unit_select_callback);
pBuf->data.unit = pUnit;
pBuf->data.unit = punit;
set_wstate(pBuf, FC_WS_NORMAL);
add_to_gui_list(ID_LABEL, pBuf);
my_units++;
......
int att_chance, def_chance;
fc_snprintf(cBuf, sizeof(cBuf), _("%s %s %s (A:%d D:%d M:%s FP:%d) HP:%d%%"),
nation_adjective_for_player(unit_owner(pUnit)),
nation_adjective_for_player(unit_owner(punit)),
(vetname != NULL ? vetname : ""),
utype_name_translation(punittype),
punittype->attack_strength,
punittype->defense_strength,
move_points_text(punittype->move_rate, FALSE),
punittype->firepower,
((pUnit->hp * 100) / punittype->hp));
((punit->hp * 100) / punittype->hp));
/* calculate chance to win */
if (sdl_get_chance_to_win(&att_chance, &def_chance, pUnit, pFocus_Unit)) {
if (sdl_get_chance_to_win(&att_chance, &def_chance, punit, pFocus_Unit)) {
/* TRANS: "CtW" = "Chance to Win"; preserve leading space */
cat_snprintf(cBuf, sizeof(cBuf), _(" CtW: Att:%d%% Def:%d%%"),
att_chance, def_chance);
}
if (pAttacker && pAttacker == pUnit) {
if (pAttacker && pAttacker == punit) {
pstr->fgcol = *(get_game_color(COLOR_OVERVIEW_ENEMY_UNIT));
reset = TRUE;
} else {
if (pDefender && pDefender == pUnit) {
if (pDefender && pDefender == punit) {
pstr->fgcol = *(get_game_color(COLOR_OVERVIEW_MY_UNIT));
reset = TRUE;
}
......
#undef ADV_NUM_SEEN
} else { /* n == 1 */
/* one unit - give orders */
pUnit = unit_list_get(ptile->units, 0);
punittype = unit_type_get(pUnit);
if (pUnit != pFocus_Unit) {
punit = unit_list_get(ptile->units, 0);
punittype = unit_type_get(punit);
if (punit != pFocus_Unit) {
const char *vetname;
vetname = utype_veteran_name_translation(punittype, pUnit->veteran);
vetname = utype_veteran_name_translation(punittype, punit->veteran);
if ((pCity && city_owner(pCity) == client.conn.playing)
|| (unit_owner(pUnit) == client.conn.playing)) {
|| (unit_owner(punit) == client.conn.playing)) {
fc_snprintf(cBuf, sizeof(cBuf),
_("Activate %s (%d / %d) %s (%d,%d,%s) %s"),
(vetname != NULL ? vetname : ""),
pUnit->hp, punittype->hp,
punit->hp, punittype->hp,
utype_name_translation(punittype),
punittype->attack_strength,
punittype->defense_strength,
move_points_text(punittype->move_rate, FALSE),
unit_activity_text(pUnit));
unit_activity_text(punit));
create_active_iconlabel(pBuf, pwindow->dst, pstr,
cBuf, adv_unit_select_callback);
pBuf->data.unit = pUnit;
pBuf->data.unit = punit;
set_wstate(pBuf, FC_WS_NORMAL);
add_to_gui_list(ID_LABEL, pBuf);
......
int att_chance, def_chance;
fc_snprintf(cBuf, sizeof(cBuf), _("%s %s %s (A:%d D:%d M:%s FP:%d) HP:%d%%"),
nation_adjective_for_player(unit_owner(pUnit)),
nation_adjective_for_player(unit_owner(punit)),
(vetname != NULL ? vetname : ""),
utype_name_translation(punittype),
punittype->attack_strength,
punittype->defense_strength,
move_points_text(punittype->move_rate, FALSE),
punittype->firepower,
((pUnit->hp * 100) / punittype->hp));
((punit->hp * 100) / punittype->hp));
/* calculate chance to win */
if (sdl_get_chance_to_win(&att_chance, &def_chance, pUnit, pFocus_Unit)) {
if (sdl_get_chance_to_win(&att_chance, &def_chance, punit, pFocus_Unit)) {
/* TRANS: preserve leading space */
cat_snprintf(cBuf, sizeof(cBuf), _(" CtW: Att:%d%% Def:%d%%"),
att_chance, def_chance);
......
static int pillage_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = pwidget->data.unit;
struct unit *punit = pwidget->data.unit;
int what = MAX_ID - pwidget->ID;
popdown_pillage_dialog();
if (pUnit) {
if (punit) {
struct extra_type *target = extra_by_number(what);
request_new_unit_activity_targeted(pUnit, ACTIVITY_PILLAGE, target);
request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE, target);
}
}
return -1;
......
Popup a dialog asking the unit which improvement they would like to
pillage.
**************************************************************************/
void popup_pillage_dialog(struct unit *pUnit, bv_extras extras)
void popup_pillage_dialog(struct unit *punit, bv_extras extras)
{
struct widget *pwindow = NULL, *pBuf = NULL;
utf8_str *pstr;
......
create_active_iconlabel(pBuf, pwindow->dst, pstr,
(char *) name, pillage_callback);
pBuf->data.unit = pUnit;
pBuf->data.unit = punit;
set_wstate(pBuf, FC_WS_NORMAL);
add_to_gui_list(MAX_ID - what, pBuf);
......
area = pwindow->area;
put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
unit_tile(pUnit));
unit_tile(punit));
/* setup widget size and start position */
client/gui-sdl2/dialogs.h
void put_window_near_map_tile(struct widget *pwindow,
int window_width, int window_height,
struct tile *ptile);
void popup_unit_upgrade_dlg(struct unit *pUnit, bool city);
void popup_unit_disband_dlg(struct unit *pUnit, bool city);
void popup_unit_upgrade_dlg(struct unit *punit, bool city);
void popup_unit_disband_dlg(struct unit *punit, bool city);
void popup_government_dialog(void);
void popdown_notify_goto_dialog(void);
client/gui-sdl2/gotodlg.c
struct city *pdestcity = game_city_by_number(MAX_ID - pwidget->ID);
if (pdestcity) {
struct unit *pUnit = head_of_units_in_focus();
struct unit *punit = head_of_units_in_focus();
if (pUnit) {
if (punit) {
if (GOTO) {
send_goto_tile(pUnit, pdestcity->tile);
send_goto_tile(punit, pdestcity->tile);
} else {
request_unit_airlift(pUnit, pdestcity);
request_unit_airlift(punit, pdestcity);
}
}
}
client/gui-sdl2/gui_main.c
disable_focus_animation();
key_end_turn();
} else {
struct unit *pUnit;
struct unit *punit;
struct city *pCity;
if (NULL != (pUnit = head_of_units_in_focus())
&& (pCity = tile_city(unit_tile(pUnit))) != NULL
if (NULL != (punit = head_of_units_in_focus())
&& (pCity = tile_city(unit_tile(punit))) != NULL
&& city_owner(pCity) == client.conn.playing) {
popup_city_dialog(pCity);
}
client/gui-sdl2/helpdlg.c
struct units_buttons *store;
struct widget *pCloseButton = NULL;
struct widget *pListToggleButton = NULL;
struct widget *pUnitButton = NULL;
struct widget *pUnitNameLabel = NULL;
struct widget *pUnitInfoLabel = NULL;
struct widget *unit_button = NULL;
struct widget *unit_name_label = NULL;
struct widget *unit_info_label = NULL;
struct widget *pRequirementLabel = NULL;
struct widget *pRequirementLabel2 = NULL;
struct widget *pObsoleteByLabel = NULL;
......
alphablit(icon, NULL, background, &dst, 255);
FREESURFACE(icon);
pUnitButton = create_icon2(background, pwindow->dst,
unit_button = create_icon2(background, pwindow->dst,
WF_FREE_THEME | WF_RESTORE_BACKGROUND);
set_wstate(pUnitButton, FC_WS_NORMAL);
pUnitButton->action = change_unit_callback;
add_to_gui_list(MAX_ID - utype_number(ut), pUnitButton);
set_wstate(unit_button, FC_WS_NORMAL);
unit_button->action = change_unit_callback;
add_to_gui_list(MAX_ID - utype_number(ut), unit_button);
if (utype_count++ >= 10) {
set_wflag(pUnitButton, WF_HIDDEN);
set_wflag(unit_button, WF_HIDDEN);
}
} unit_type_iterate_end;
......
FREESURFACE(background_tmpl);
help_dlg->end_active_widget_list = dock->prev;
help_dlg->begin_widget_list = pUnitButton ? pUnitButton : pCloseButton;
help_dlg->begin_widget_list = unit_button ? unit_button : pCloseButton;
help_dlg->begin_active_widget_list = help_dlg->begin_widget_list;
if (utype_count > 10) {
......
}
punittype = utype_by_number(type_id);
pUnitNameLabel= create_iconlabel_from_chars(
unit_name_label= create_iconlabel_from_chars(
adj_surf(get_unittype_surface(punittype, direction8_invalid())),
pwindow->dst, utype_name_translation(punittype),
adj_font(24), WF_FREE_THEME);
pUnitNameLabel->ID = ID_LABEL;
widget_add_as_prev(pUnitNameLabel, dock);
dock = pUnitNameLabel;
unit_name_label->ID = ID_LABEL;
widget_add_as_prev(unit_name_label, dock);
dock = unit_name_label;
{
......
_("FirePower:"), punittype->firepower,
_("Hitpoints:"), punittype->hp);
pUnitInfoLabel = create_iconlabel_from_chars(NULL, pwindow->dst, buf,
unit_info_label = create_iconlabel_from_chars(NULL, pwindow->dst, buf,
adj_font(12), 0);
pUnitInfoLabel->ID = ID_LABEL;
widget_add_as_prev(pUnitInfoLabel, dock);
dock = pUnitInfoLabel;
unit_info_label->ID = ID_LABEL;
widget_add_as_prev(unit_info_label, dock);
dock = unit_info_label;
}
/* requirement */
......
}
}
pUnitNameLabel = store->dock->prev;
widget_set_position(pUnitNameLabel, start_x, area.y + adj_size(16));
unit_name_label = store->dock->prev;
widget_set_position(unit_name_label, start_x, area.y + adj_size(16));
start_y = pUnitNameLabel->size.y + pUnitNameLabel->size.h + adj_size(10);
start_y = unit_name_label->size.y + unit_name_label->size.h + adj_size(10);
pUnitInfoLabel = pUnitNameLabel->prev;
widget_set_position(pUnitInfoLabel, start_x, start_y);
unit_info_label = unit_name_label->prev;
widget_set_position(unit_info_label, start_x, start_y);
start_y += pUnitInfoLabel->size.h;
start_y += unit_info_label->size.h;
pRequirementLabel = store->pRequirementButton->next;
widget_set_position(pRequirementLabel, start_x, start_y);
client/gui-sdl2/mapctrl.c
#endif /* SCALE_UNITINFO */
static struct advanced_dialog *pMiniMap_Dlg = NULL;
static struct advanced_dialog *pUnitInfo_Dlg = NULL;
static struct advanced_dialog *unit_info_dlg = NULL;
int overview_w = 0;
int overview_h = 0;
......
bool draw_goto_patrol_lines = FALSE;
static struct widget *pNew_Turn_Button = NULL;
static struct widget *pUnits_Info_Window = NULL;
static struct widget *units_info_window = NULL;
static struct widget *pMiniMap_Window = NULL;
static struct widget *pFind_City_Button = NULL;
static struct widget *pRevolution_Button = NULL;
......
set_wstate(pIcon_Widget, FC_WS_NORMAL);
selected_widget = NULL;
if (pUnits_Info_Window->private_data.adv_dlg->end_active_widget_list) {
del_group(pUnits_Info_Window->private_data.adv_dlg->begin_active_widget_list,
pUnits_Info_Window->private_data.adv_dlg->end_active_widget_list);
if (units_info_window->private_data.adv_dlg->end_active_widget_list) {
del_group(units_info_window->private_data.adv_dlg->begin_active_widget_list,
units_info_window->private_data.adv_dlg->end_active_widget_list);
}
if (pUnits_Info_Window->private_data.adv_dlg->pScroll) {
hide_scrollbar(pUnits_Info_Window->private_data.adv_dlg->pScroll);
if (units_info_window->private_data.adv_dlg->pScroll) {
hide_scrollbar(units_info_window->private_data.adv_dlg->pScroll);
}
/* clear area under old unit info window */
widget_undraw(pUnits_Info_Window);
widget_mark_dirty(pUnits_Info_Window);
widget_undraw(units_info_window);
widget_mark_dirty(units_info_window);
/* new button direction */
alphablit(current_theme->L_ARROW_Icon, NULL, pIcon_Widget->theme, NULL, 255);
......
/* blit part of map window */
src.x = 0;
src.y = 0;
src.w = (pUnits_Info_Window->size.w - pUnits_Info_Window->area.w) + BLOCKU_W;
src.h = pUnits_Info_Window->theme->h;
src.w = (units_info_window->size.w - units_info_window->area.w) + BLOCKU_W;
src.h = units_info_window->theme->h;
window_area = pUnits_Info_Window->size;
alphablit(pUnits_Info_Window->theme, &src,
pUnits_Info_Window->dst->surface, &window_area, 255);
window_area = units_info_window->size;
alphablit(units_info_window->theme, &src,
units_info_window->dst->surface, &window_area, 255);
/* blit right vertical frame */
pBuf_Surf = ResizeSurface(current_theme->FR_Right, current_theme->FR_Right->w,
pUnits_Info_Window->area.h, 1);
units_info_window->area.h, 1);
window_area.y = pUnits_Info_Window->area.y;
window_area.x = pUnits_Info_Window->area.x + pUnits_Info_Window->area.w;
window_area.y = units_info_window->area.y;
window_area.x = units_info_window->area.x + units_info_window->area.w;
alphablit(pBuf_Surf, NULL,
pUnits_Info_Window->dst->surface, &window_area, 255);
units_info_window->dst->surface, &window_area, 255);
FREESURFACE(pBuf_Surf);
/* redraw widgets */
/* ID_ECONOMY */
pBuf = pUnits_Info_Window->prev;
pBuf = units_info_window->prev;
widget_redraw(pBuf);
/* ===== */
......
popdown_scale_unitinfo_dlg_callback(NULL);
#endif
} else {
if (main_window_width() - pUnits_Info_Window->size.w >=
if (main_window_width() - units_info_window->size.w >=
pMiniMap_Window->dst->dest_rect.x + pMiniMap_Window->size.w) {
set_wstate(pIcon_Widget, FC_WS_NORMAL);
......
set_new_unitinfo_window_pos();
widget_mark_dirty(pUnits_Info_Window);
widget_mark_dirty(units_info_window);
redraw_unit_info_label(get_units_in_focus());
} else {
......
#endif
} else {
if (((pMiniMap_Window->size.w - pMiniMap_Window->area.w) +
overview_w + BLOCKM_W) <= pUnits_Info_Window->dst->dest_rect.x) {
overview_w + BLOCKM_W) <= units_info_window->dst->dest_rect.x) {
set_wstate(pMap_Button, FC_WS_NORMAL);
selected_widget = NULL;
......
widget_mark_dirty(pwidget);
if ((((OVERVIEW_TILE_WIDTH + 1) * map.xsize) +
(pMiniMap_Window->size.w - pMiniMap_Window->area.w) + BLOCKM_W) <=
pUnits_Info_Window->dst->dest_rect.x) {
units_info_window->dst->dest_rect.x) {
char cBuf[4];
fc_snprintf(cBuf, sizeof(cBuf), "%d", OVERVIEW_TILE_WIDTH);
......
{
SDL_Color bg_color = {255, 255, 255, 128};
SDL_Surface *surf;
SDL_Rect area = {pUnits_Info_Window->area.x + BLOCKU_W,
pUnits_Info_Window->area.y, 0, 0};
struct widget *pwidget = pUnits_Info_Window;
SDL_Rect area = {units_info_window->area.x + BLOCKU_W,
units_info_window->area.y, 0, 0};
struct widget *pwidget = units_info_window;
if (w < DEFAULT_UNITS_W - BLOCKU_W) {
w = (pUnits_Info_Window->size.w - pUnits_Info_Window->area.w) + DEFAULT_UNITS_W;
w = (units_info_window->size.w - units_info_window->area.w) + DEFAULT_UNITS_W;
} else {
w += (pUnits_Info_Window->size.w - pUnits_Info_Window->area.w) + BLOCKU_W;
w += (units_info_window->size.w - units_info_window->area.w) + BLOCKU_W;
}
if (h < DEFAULT_UNITS_H) {
h = (pUnits_Info_Window->size.h - pUnits_Info_Window->area.h) + DEFAULT_UNITS_H;
h = (units_info_window->size.h - units_info_window->area.h) + DEFAULT_UNITS_H;
} else {
h += (pUnits_Info_Window->size.h - pUnits_Info_Window->area.h);
h += (units_info_window->size.h - units_info_window->area.h);
}
/* clear area under old map window */
......
draw_frame(pwidget->theme, 0, 0, pwidget->size.w, pwidget->size.h);
surf = ResizeSurface(current_theme->Block, BLOCKU_W,
pwidget->size.h - ((pUnits_Info_Window->size.h - pUnits_Info_Window->area.h)), 1);
pwidget->size.h - ((units_info_window->size.h - units_info_window->area.h)), 1);
blit_entire_src(surf, pwidget->theme, pUnits_Info_Window->area.x,
pUnits_Info_Window->area.y);
blit_entire_src(surf, pwidget->theme, units_info_window->area.x,
units_info_window->area.y);
FREESURFACE(surf);
area.w = w - BLOCKU_W - (pUnits_Info_Window->size.w - pUnits_Info_Window->area.w);
area.h = h - (pUnits_Info_Window->size.h - pUnits_Info_Window->area.h);
area.w = w - BLOCKU_W - (units_info_window->size.w - units_info_window->area.w);
area.h = h - (units_info_window->size.h - units_info_window->area.h);
SDL_FillRect(pwidget->theme, &area, map_rgba(pwidget->theme->format, bg_color));
/* economy button */
pwidget = pTax_Button;
FREESURFACE(pwidget->gfx);
pwidget->size.x = pwidget->dst->surface->w - w + pUnits_Info_Window->area.x
pwidget->size.x = pwidget->dst->surface->w - w + units_info_window->area.x
+ (BLOCKU_W - pwidget->size.w) / 2;
pwidget->size.y = pwidget->dst->surface->h - h + pwidget->area.y + 2;
/* research button */
pwidget = pwidget->prev;
FREESURFACE(pwidget->gfx);
pwidget->size.x = pwidget->dst->surface->w - w + pUnits_Info_Window->area.x
pwidget->size.x = pwidget->dst->surface->w - w + units_info_window->area.x
+ (BLOCKU_W - pwidget->size.w) / 2;
pwidget->size.y = pwidget->dst->surface->h - h + pUnits_Info_Window->area.y +
pwidget->size.y = pwidget->dst->surface->h - h + units_info_window->area.y +
pwidget->size.h + 2;
/* revolution button */
pwidget = pwidget->prev;
FREESURFACE(pwidget->gfx);
pwidget->size.x = pwidget->dst->surface->w - w + pUnits_Info_Window->area.x
pwidget->size.x = pwidget->dst->surface->w - w + units_info_window->area.x
+ (BLOCKU_W - pwidget->size.w) / 2;
pwidget->size.y = pwidget->dst->surface->h - h + pUnits_Info_Window->area.y +
pwidget->size.y = pwidget->dst->surface->h - h + units_info_window->area.y +
pwidget->size.h * 2 + 2;
/* show/hide unit's window button */
pwidget = pwidget->prev;
FREESURFACE(pwidget->gfx);
pwidget->size.x = pwidget->dst->surface->w - w + pUnits_Info_Window->area.x
pwidget->size.x = pwidget->dst->surface->w - w + units_info_window->area.x
+ (BLOCKU_W - pwidget->size.w) / 2;
pwidget->size.y = pUnits_Info_Window->area.y + pUnits_Info_Window->area.h -
pwidget->size.y = units_info_window->area.y + units_info_window->area.h -
pwidget->size.h - 2;
unitinfo_w = w;
......
struct widget *pInfo_Window = get_unit_info_window_widget();
int w = INFO_WIDTH * map.xsize;
int h = INFO_HEIGHT * map.ysize;
int current_w = pUnits_Info_Window->size.w - BLOCKU_W -
int current_w = units_info_window->size.w - BLOCKU_W -
(pInfo_Window->size.w - pInfo_Window->area.w);
int current_h = pUnits_Info_Window->size.h -
int current_h = units_info_window->size.h -
(pInfo_Window->size.h - pInfo_Window->area.h);
if ((((current_w > DEFAULT_UNITS_W - BLOCKU_W)
......
widget_redraw(pwidget);
widget_mark_dirty(pwidget);
if (main_data.screen->h - ((INFO_HEIGHT + 1) * map.ysize +
(pUnits_Info_Window->size.h - pUnits_Info_Window->area.h)) >= adj_size(40)) {
(units_info_window->size.h - units_info_window->area.h)) >= adj_size(40)) {
INFO_HEIGHT++;
resize_unit_info();
}
......
**************************************************************************/
void set_new_unitinfo_window_pos(void)
{
struct widget *pUnit_Window = pUnits_Info_Window;
struct widget *unit_window = units_info_window;
struct widget *pwidget;
SDL_Rect area;
if (SDL_Client_Flags & CF_UNITINFO_SHOWN) {
widget_set_position(pUnits_Info_Window,
main_window_width() - pUnits_Info_Window->size.w,
main_window_height() - pUnits_Info_Window->size.h);
widget_set_position(units_info_window,
main_window_width() - units_info_window->size.w,
main_window_height() - units_info_window->size.h);
} else {
widget_set_position(pUnit_Window,
widget_set_position(unit_window,
main_window_width() - BLOCKU_W - current_theme->FR_Right->w,
main_window_height() - pUnits_Info_Window->size.h);
main_window_height() - units_info_window->size.h);
}
area.x = pUnits_Info_Window->area.x;
area.y = pUnits_Info_Window->area.y;
area.x = units_info_window->area.x;
area.y = units_info_window->area.y;
area.w = BLOCKU_W;
area.h = DEFAULT_UNITS_H;
......
SDL_Surface *pIcon_theme = NULL;
char buf[256];
if (pUnitInfo_Dlg) {
if (unit_info_dlg) {
return;
}
pUnitInfo_Dlg = fc_calloc(1, sizeof(struct advanced_dialog));
unit_info_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
/* pUnits_Info_Window */
/* units_info_window */
pwindow = create_window_skeleton(NULL, NULL, 0);
resize_window(pwindow, NULL, NULL,
......
add_to_gui_list(ID_UNITS_WINDOW, pwindow);
pUnits_Info_Window = pwindow;
units_info_window = pwindow;
pUnitInfo_Dlg->end_widget_list = pUnits_Info_Window;
pUnits_Info_Window->private_data.adv_dlg = pUnitInfo_Dlg;
unit_info_dlg->end_widget_list = units_info_window;
units_info_window->private_data.adv_dlg = unit_info_dlg;
/* economy button */
pwidget = create_icon2(get_tax_surface(O_GOLD), pUnits_Info_Window->dst,
pwidget = create_icon2(get_tax_surface(O_GOLD), units_info_window->dst,
WF_FREE_GFX | WF_WIDGET_HAS_INFO_LABEL
| WF_RESTORE_BACKGROUND | WF_FREE_THEME);
......
/* research button */
pwidget = create_icon2(adj_surf(GET_SURF(client_research_sprite())),
pUnits_Info_Window->dst,
units_info_window->dst,
WF_FREE_GFX | WF_WIDGET_HAS_INFO_LABEL
| WF_RESTORE_BACKGROUND | WF_FREE_THEME);
/* TRANS: Research report action */
......
/* revolution button */
pwidget = create_icon2(adj_surf(GET_SURF(client_government_sprite())),
pUnits_Info_Window->dst,
units_info_window->dst,
WF_FREE_GFX | WF_WIDGET_HAS_INFO_LABEL
| WF_RESTORE_BACKGROUND | WF_FREE_THEME);
fc_snprintf(buf, sizeof(buf), "%s (%s)", _("Revolution"), "Ctrl+Shift+R");
......
alphablit(current_theme->MAP_Icon, NULL, pIcon_theme, NULL, 255);
alphablit(current_theme->R_ARROW_Icon, NULL, pIcon_theme, NULL, 255);
pwidget = create_themeicon(pIcon_theme, pUnits_Info_Window->dst,
pwidget = create_themeicon(pIcon_theme, units_info_window->dst,
WF_FREE_GFX | WF_FREE_THEME
| WF_RESTORE_BACKGROUND
| WF_WIDGET_HAS_INFO_LABEL);
......
add_to_gui_list(ID_TOGGLE_UNITS_WINDOW_BUTTON, pwidget);
pUnitInfo_Dlg->begin_widget_list = pwidget;
unit_info_dlg->begin_widget_list = pwidget;
SDL_Client_Flags |= CF_UNITINFO_SHOWN;
set_new_unitinfo_window_pos();
widget_redraw(pUnits_Info_Window);
widget_redraw(units_info_window);
}
/**********************************************************************//**
......
**************************************************************************/
void popdown_unitinfo_window(void)
{
if (pUnitInfo_Dlg) {
popdown_window_group_dialog(pUnitInfo_Dlg->begin_widget_list, pUnitInfo_Dlg->end_widget_list);
FC_FREE(pUnitInfo_Dlg);
if (unit_info_dlg) {
popdown_window_group_dialog(unit_info_dlg->begin_widget_list, unit_info_dlg->end_widget_list);
FC_FREE(unit_info_dlg);
SDL_Client_Flags &= ~CF_UNITINFO_SHOWN;
}
}
......
**************************************************************************/
static void disable_unitinfo_widgets(void)
{
struct widget *pBuf = pUnits_Info_Window->private_data.adv_dlg->begin_widget_list;
struct widget *pEnd = pUnits_Info_Window->private_data.adv_dlg->end_widget_list;
struct widget *pBuf = units_info_window->private_data.adv_dlg->begin_widget_list;
struct widget *pEnd = units_info_window->private_data.adv_dlg->end_widget_list;
set_group_state(pBuf, pEnd, FC_WS_DISABLED);
pEnd = pEnd->prev;
......
struct widget *pBuf, *pEnd;
if (can_client_issue_orders()) {
pBuf = pUnits_Info_Window->private_data.adv_dlg->begin_widget_list;
pEnd = pUnits_Info_Window->private_data.adv_dlg->end_widget_list;
pBuf = units_info_window->private_data.adv_dlg->begin_widget_list;
pEnd = units_info_window->private_data.adv_dlg->end_widget_list;
set_group_state(pBuf, pEnd, FC_WS_NORMAL);
pEnd = pEnd->prev;
......
**************************************************************************/
struct widget *get_unit_info_window_widget(void)
{
return pUnits_Info_Window;
return units_info_window;
}
/**********************************************************************//**
......
Popup a dialog to ask for the name of a new city. The given string
should be used as a suggestion.
**************************************************************************/
void popup_newcity_dialog(struct unit *pUnit, const char *pSuggestname)
void popup_newcity_dialog(struct unit *punit, const char *pSuggestname)
{
SDL_Surface *background;
utf8_str *pstr = NULL;
......
_("OK"), adj_font(10), 0);
pOK_Button->action = newcity_ok_callback;
pOK_Button->key = SDLK_RETURN;
pOK_Button->data.tile = unit_tile(pUnit);
pOK_Button->data.tile = unit_tile(punit);
area.h += pOK_Button->size.h;
......
pwindow->dst, _("Cancel"), adj_font(10), 0);
pCancel_Button->action = newcity_cancel_callback;
pCancel_Button->key = SDLK_ESCAPE;
pCancel_Button->data.tile = unit_tile(pUnit);
pCancel_Button->data.tile = unit_tile(punit);
/* correct sizes */
pCancel_Button->size.w += adj_size(5);
client/gui-sdl2/mapview.c
SDL_Surface *buf_surf;
utf8_str *pstr;
struct canvas *destcanvas;
struct unit *pUnit;
struct unit *punit;
if (punitlist != NULL && unit_list_size(punitlist) > 0) {
pUnit = unit_list_get(punitlist, 0);
punit = unit_list_get(punitlist, 0);
} else {
pUnit = NULL;
punit = NULL;
}
if (SDL_Client_Flags & CF_UNITINFO_SHOWN) {
......
/* blit theme surface */
widget_redraw(pInfo_Window);
if (pUnit) {
if (punit) {
SDL_Surface *pName, *pVet_Name = NULL, *pInfo, *pInfo_II = NULL;
int sy, y, width, height, n;
bool right;
char buffer[512];
struct tile *ptile = unit_tile(pUnit);
struct tile *ptile = unit_tile(punit);
const char *vetname;
/* get and draw unit name (with veteran status) */
pstr = create_utf8_from_char(unit_name_translation(pUnit), adj_font(12));
pstr = create_utf8_from_char(unit_name_translation(punit), adj_font(12));
pstr->style |= TTF_STYLE_BOLD;
pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
pName = create_text_surf_from_utf8(pstr);
......
}
change_ptsize_utf8(pstr, adj_font(10));
vetname = utype_veteran_name_translation(unit_type_get(pUnit),
pUnit->veteran);
vetname = utype_veteran_name_translation(unit_type_get(punit),
punit->veteran);
if (vetname != NULL) {
copy_chars_to_utf8_str(pstr, vetname);
pstr->fgcol = *get_theme_color(COLOR_THEME_MAPVIEW_UNITINFO_VETERAN_TEXT);
......
if (pInfo_Window->size.h >
4 * h + (DEFAULT_UNITS_H + (pInfo_Window->size.h - pInfo_Window->area.h)) || right) {
cat_snprintf(buffer, sizeof(buffer), _("\nFood/Prod/Trade: %s"),
get_tile_output_text(unit_tile(pUnit)));
get_tile_output_text(unit_tile(punit)));
}
copy_chars_to_utf8_str(pstr, buffer);
......
FREESURFACE(pName);
/* draw unit sprite */
buf_surf = ResizeSurfaceBox(get_unittype_surface(unit_type_get(pUnit),
pUnit->facing),
buf_surf = ResizeSurfaceBox(get_unittype_surface(unit_type_get(punit),
punit->facing),
adj_size(80), adj_size(80), 1, TRUE, TRUE);
src = (SDL_Rect){0, 0, buf_surf->w, buf_surf->h};
......
unit_list_iterate(ptile->units, aunit) {
SDL_Surface *tmp_surf;
if (aunit == pUnit) {
if (aunit == punit) {
continue;
}
......
hide_scrollbar(pInfo_Window->private_data.adv_dlg->pScroll);
}
}
} else { /* pUnit */
} else { /* punit */
if (pInfo_Window->private_data.adv_dlg->end_active_widget_list) {
del_group(pInfo_Window->private_data.adv_dlg->begin_active_widget_list,
client/gui-sdl2/menu.c
static int unit_order_callback(struct widget *pOrder_Widget)
{
if (PRESSED_EVENT(main_data.event)) {
struct unit *pUnit = head_of_units_in_focus();
struct unit *head_unit = head_of_units_in_focus();
set_wstate(pOrder_Widget, FC_WS_SELECTED);
selected_widget = pOrder_Widget;
if (!pUnit) {
if (!head_unit) {
return -1;
}
......
} unit_list_iterate_end;
break;
case ID_UNIT_ORDER_UPGRADE:
popup_unit_upgrade_dlg(pUnit, FALSE);
popup_unit_upgrade_dlg(head_unit, FALSE);
break;
case ID_UNIT_ORDER_CONVERT:
key_unit_convert();
break;
case ID_UNIT_ORDER_DISBAND:
popup_unit_disband_dlg(pUnit, FALSE);
popup_unit_disband_dlg(head_unit, FALSE);
break;
case ID_UNIT_ORDER_DIPLOMAT_DLG:
key_unit_action_select_tgt();
......
{
static Uint16 counter = 0;
struct unit_list *punits = NULL;
struct unit *pUnit = NULL;
struct unit *punit = NULL;
static char cBuf[128];
if ((C_S_RUNNING != client_state())
......
}
punits = get_units_in_focus();
pUnit = unit_list_get(punits, 0);
punit = unit_list_get(punits, 0);
if (pUnit && pUnit->ssa_controller == SSA_NONE) {
if (punit && punit->ssa_controller == SSA_NONE) {
struct city *pHomecity;
int time;
struct tile *ptile = unit_tile(pUnit);
struct tile *ptile = unit_tile(punit);
struct city *pCity = tile_city(ptile);
struct terrain *pterrain = tile_terrain(ptile);
struct base_type *pbase;
......
/* Enable the button for adding to a city in all cases, so we
* get an eventual error message from the server if we try. */
if (unit_can_add_or_build_city(pUnit)) {
if (unit_can_add_or_build_city(punit)) {
if (pCity) {
fc_snprintf(cBuf, sizeof(cBuf), "%s (%s)",
action_id_name_translation(ACTION_JOIN_CITY), "B");
......
set_wflag(pOrder_Build_AddTo_City_Button, WF_HIDDEN);
}
if (unit_can_help_build_wonder_here(pUnit)) {
if (unit_can_help_build_wonder_here(punit)) {
local_show(ID_UNIT_ORDER_BUILD_WONDER);
} else {
local_hide(ID_UNIT_ORDER_BUILD_WONDER);
}
pextra = next_extra_for_tile(ptile, EC_ROAD, unit_owner(pUnit), pUnit);
pextra = next_extra_for_tile(ptile, EC_ROAD, unit_owner(punit), punit);
if (pextra != NULL
&& can_unit_do_activity_targeted(pUnit, ACTIVITY_GEN_ROAD, pextra)) {
&& can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, pextra)) {
struct road_type *proad = extra_road_get(pextra);
enum road_compat compat = road_compat_special(proad);
time = turns_to_activity_done(ptile, ACTIVITY_GEN_ROAD, pextra, pUnit);
time = turns_to_activity_done(ptile, ACTIVITY_GEN_ROAD, pextra, punit);
/* TRANS: "Build Railroad (R) 3 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Build %s (%s) %d %s"),
......
set_wflag(pOrder_Road_Button, WF_HIDDEN);
}
/* unit_can_est_trade_route_here(pUnit) */
if (pCity && utype_can_do_action(unit_type_get(pUnit),
/* unit_can_est_trade_route_here(punit) */
if (pCity && utype_can_do_action(unit_type_get(punit),
ACTION_TRADE_ROUTE)
&& (pHomecity = game_city_by_number(pUnit->homecity))
&& (pHomecity = game_city_by_number(punit->homecity))
&& can_cities_trade(pHomecity, pCity)) {
int revenue = get_caravan_enter_city_trade_bonus(pHomecity, pCity,
pUnit->carrying,
punit->carrying,
TRUE);
if (can_establish_trade_route(pHomecity, pCity)) {
......
}
pextra = next_extra_for_tile(ptile, EC_IRRIGATION,
unit_owner(pUnit), pUnit);
unit_owner(punit), punit);
if (pextra != NULL &&
can_unit_do_activity_targeted(pUnit, ACTIVITY_IRRIGATE, pextra)) {
can_unit_do_activity_targeted(punit, ACTIVITY_IRRIGATE, pextra)) {
time = turns_to_activity_done(ptile, ACTIVITY_IRRIGATE,
pextra, pUnit);
pextra, punit);
/* TRANS: "Build Irrigation (I) 5 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Build %s (%s) %d %s"),
extra_name_translation(pextra), "I", time,
......
}
pextra = next_extra_for_tile(ptile, EC_MINE,
unit_owner(pUnit), pUnit);
unit_owner(punit), punit);
if (pextra != NULL
&& can_unit_do_activity_targeted(pUnit, ACTIVITY_MINE, pextra)) {
time = turns_to_activity_done(ptile, ACTIVITY_MINE, pextra, pUnit);
&& can_unit_do_activity_targeted(punit, ACTIVITY_MINE, pextra)) {
time = turns_to_activity_done(ptile, ACTIVITY_MINE, pextra, punit);
/* TRANS: "Build Mine (M) 5 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Build %s (%s) %d %s"),
extra_name_translation(pextra), "M", time,
......
set_wflag(pOrder_Mine_Button, WF_HIDDEN);
}
if (can_unit_do_activity(pUnit, ACTIVITY_CULTIVATE)) {
if (can_unit_do_activity(punit, ACTIVITY_CULTIVATE)) {
/* Activity always results in terrain change */
time = turns_to_activity_done(ptile, ACTIVITY_CULTIVATE, NULL, pUnit);
time = turns_to_activity_done(ptile, ACTIVITY_CULTIVATE, NULL, punit);
fc_snprintf(cBuf, sizeof(cBuf), "%s %s (%s) %d %s",
_("Cultivate to"),
terrain_name_translation(pterrain->cultivate_result),
......
set_wflag(pOrder_Cultivate_Button, WF_HIDDEN);
}
if (can_unit_do_activity(pUnit, ACTIVITY_PLANT)) {
if (can_unit_do_activity(punit, ACTIVITY_PLANT)) {
/* Activity always results in terrain change */
time = turns_to_activity_done(ptile, ACTIVITY_PLANT, NULL, pUnit);
time = turns_to_activity_done(ptile, ACTIVITY_PLANT, NULL, punit);
fc_snprintf(cBuf, sizeof(cBuf), "%s %s (%s) %d %s",
_("Plant to"),
terrain_name_translation(pterrain->plant_result),
......
set_wflag(pOrder_Plant_Button, WF_HIDDEN);
}
if (can_unit_do_activity(pUnit, ACTIVITY_TRANSFORM)) {
if (can_unit_do_activity(punit, ACTIVITY_TRANSFORM)) {
/* Activity always results in terrain change */
time = turns_to_activity_done(ptile, ACTIVITY_TRANSFORM, NULL, pUnit);
time = turns_to_activity_done(ptile, ACTIVITY_TRANSFORM, NULL, punit);
fc_snprintf(cBuf, sizeof(cBuf), "%s %s (%s) %d %s",
_("Transform to"),
terrain_name_translation(pterrain->transform_result),
......
set_wflag(pOrder_Transform_Button, WF_HIDDEN);
}
pbase = get_base_by_gui_type(BASE_GUI_FORTRESS, pUnit, ptile);
pbase = get_base_by_gui_type(BASE_GUI_FORTRESS, punit, ptile);
if (pbase != NULL) {
struct extra_type *base_extra = base_extra_get(pbase);
time = turns_to_activity_done(ptile, ACTIVITY_BASE, base_extra, pUnit);
time = turns_to_activity_done(ptile, ACTIVITY_BASE, base_extra, punit);
/* TRANS: "Build Fortress (Shift+F) 5 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Build %s (%s) %d %s"),
extra_name_translation(base_extra), "Shift+F", time,
......
set_wflag(pOrder_Fortress_Button, WF_HIDDEN);
}
if (can_unit_do_activity(pUnit, ACTIVITY_FORTIFYING)) {
if (can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) {
local_show(ID_UNIT_ORDER_FORTIFY);
} else {
local_hide(ID_UNIT_ORDER_FORTIFY);
}
pbase = get_base_by_gui_type(BASE_GUI_AIRBASE, pUnit, ptile);
pbase = get_base_by_gui_type(BASE_GUI_AIRBASE, punit, ptile);
if (pbase != NULL) {
struct extra_type *base_extra = base_extra_get(pbase);
time = turns_to_activity_done(ptile, ACTIVITY_BASE, base_extra, pUnit);
time = turns_to_activity_done(ptile, ACTIVITY_BASE, base_extra, punit);
/* TRANS: "Build Airbase (Shift+E) 5 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Build %s (%s) %d %s"),
extra_name_translation(base_extra), "Shift+E", time,
......
}
pextra = prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION,
unit_owner(pUnit), pUnit);
unit_owner(punit), punit);
if (pextra != NULL
&& can_unit_do_activity_targeted(pUnit, ACTIVITY_POLLUTION, pextra)) {
&& can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, pextra)) {
time = turns_to_activity_done(ptile, ACTIVITY_POLLUTION, pextra,
pUnit);
punit);
/* TRANS: "Clean Pollution (P) 3 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Clean %s (%s) %d %s"),
extra_name_translation(pextra), "P", time,
......
set_wflag(pOrder_Pollution_Button, WF_HIDDEN);
}
if (can_unit_paradrop(pUnit)) {
if (can_unit_paradrop(punit)) {
local_show(ID_UNIT_ORDER_PARADROP);
} else {
local_hide(ID_UNIT_ORDER_PARADROP);
}
pextra = prev_extra_in_tile(ptile, ERM_CLEANFALLOUT,
unit_owner(pUnit), pUnit);
unit_owner(punit), punit);
if (pextra != NULL
&& can_unit_do_activity_targeted(pUnit, ACTIVITY_FALLOUT, pextra)) {
&& can_unit_do_activity_targeted(punit, ACTIVITY_FALLOUT, pextra)) {
time = turns_to_activity_done(ptile, ACTIVITY_FALLOUT, pextra,
pUnit);
punit);
/* TRANS: "Clean Fallout (N) 3 turns" */
fc_snprintf(cBuf, sizeof(cBuf), _("Clean %s (%s) %d %s"),
extra_name_translation(pextra), "N", time,
......
set_wflag(pOrder_Fallout_Button, WF_HIDDEN);
}
if (can_unit_do_activity(pUnit, ACTIVITY_SENTRY)) {
if (can_unit_do_activity(punit, ACTIVITY_SENTRY)) {
local_show(ID_UNIT_ORDER_SENTRY);
} else {
local_hide(ID_UNIT_ORDER_SENTRY);
}
if (can_unit_do_activity(pUnit, ACTIVITY_PILLAGE)) {
if (can_unit_do_activity(punit, ACTIVITY_PILLAGE)) {
local_show(ID_UNIT_ORDER_PILLAGE);
} else {
local_hide(ID_UNIT_ORDER_PILLAGE);
}
if (pCity && can_unit_change_homecity(pUnit)
&& pCity->id != pUnit->homecity) {
if (pCity && can_unit_change_homecity(punit)
&& pCity->id != punit->homecity) {
local_show(ID_UNIT_ORDER_HOMECITY);
} else {
local_hide(ID_UNIT_ORDER_HOMECITY);
}
if (pUnit->client.occupied) {
if (punit->client.occupied) {
local_show(ID_UNIT_ORDER_UNLOAD_TRANSPORTER);
} else {
local_hide(ID_UNIT_ORDER_UNLOAD_TRANSPORTER);
......
local_hide(ID_UNIT_ORDER_UNLOAD);
}
if (is_unit_activity_on_tile(ACTIVITY_SENTRY, unit_tile(pUnit))) {
if (is_unit_activity_on_tile(ACTIVITY_SENTRY, unit_tile(punit))) {
local_show(ID_UNIT_ORDER_WAKEUP_OTHERS);
} else {
local_hide(ID_UNIT_ORDER_WAKEUP_OTHERS);
}
if (can_unit_do_autosettlers(pUnit)) {
if (can_unit_do_autosettlers(punit)) {
local_show(ID_UNIT_ORDER_AUTO_SETTLER);
} else {
local_hide(ID_UNIT_ORDER_AUTO_SETTLER);
}
if (can_unit_do_activity(pUnit, ACTIVITY_EXPLORE)) {
if (can_unit_do_activity(punit, ACTIVITY_EXPLORE)) {
local_show(ID_UNIT_ORDER_AUTO_EXPLORE);
} else {
local_hide(ID_UNIT_ORDER_AUTO_EXPLORE);
......
tgt = road_extra_get(proad);
road_conn_possible = can_unit_do_connect(pUnit, ACTIVITY_GEN_ROAD, tgt);
road_conn_possible = can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt);
} else {
road_conn_possible = FALSE;
}
......
tgt = road_extra_get(proad);
road_conn_possible = can_unit_do_connect(pUnit, ACTIVITY_GEN_ROAD, tgt);
road_conn_possible = can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt);
} else {
road_conn_possible = FALSE;
}
......
}
}
if (unit_can_do_action(pUnit, ACTION_ANY)) {
if (unit_can_do_action(punit, ACTION_ANY)) {
local_show(ID_UNIT_ORDER_DIPLOMAT_DLG);
} else {
local_hide(ID_UNIT_ORDER_DIPLOMAT_DLG);
}
if (unit_can_do_action(pUnit, ACTION_NUKE)) {
if (unit_can_do_action(punit, ACTION_NUKE)) {
local_show(ID_UNIT_ORDER_NUKE);
} else {
local_hide(ID_UNIT_ORDER_NUKE);
......
}
if (pCity && can_upgrade_unittype(client.conn.playing,
unit_type_get(pUnit))) {
unit_type_get(punit))) {
local_show(ID_UNIT_ORDER_UPGRADE);
} else {
local_hide(ID_UNIT_ORDER_UPGRADE);
}
if (unit_can_convert(pUnit)) {
if (unit_can_convert(punit)) {
local_show(ID_UNIT_ORDER_CONVERT);
} else {
local_hide(ID_UNIT_ORDER_CONVERT);
client/gui-sdl2/repodlgs.c
/* ===================================================================== */
/* ======================== Active Units Report ======================== */
/* ===================================================================== */
static struct advanced_dialog *pUnitsDlg = NULL;
static struct small_dialog *pUnits_Upg_Dlg = NULL;
static struct advanced_dialog *units_dlg = NULL;
static struct small_dialog *units_upg_dlg = NULL;
struct units_entry {
int active_count;
......
static int units_dialog_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(pUnitsDlg->begin_widget_list, pwindow);
move_window_group(units_dlg->begin_widget_list, pwindow);
}
return -1;
......
int ut1 = MAX_ID - pwidget->ID;
/* popdown upgrade dlg */
popdown_window_group_dialog(pUnits_Upg_Dlg->begin_widget_list,
pUnits_Upg_Dlg->end_widget_list);
FC_FREE(pUnits_Upg_Dlg);
popdown_window_group_dialog(units_upg_dlg->begin_widget_list,
units_upg_dlg->end_widget_list);
FC_FREE(units_upg_dlg);
dsend_packet_unit_type_upgrade(&client.conn, ut1);
}
......
static int upgrade_unit_window_callback(struct widget *pwindow)
{
if (PRESSED_EVENT(main_data.event)) {
move_window_group(pUnits_Upg_Dlg->begin_widget_list, pwindow);
move_window_group(units_upg_dlg->begin_widget_list, pwindow);
}
return -1;
......
static int cancel_upgrade_unit_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
if (pUnits_Upg_Dlg) {
popdown_window_group_dialog(pUnits_Upg_Dlg->begin_widget_list,
pUnits_Upg_Dlg->end_widget_list);
FC_FREE(pUnits_Upg_Dlg);
if (units_upg_dlg) {
popdown_window_group_dialog(units_upg_dlg->begin_widget_list,
units_upg_dlg->end_widget_list);
FC_FREE(units_upg_dlg);
flush_dirty();
}
}
......
ut1 = utype_by_number(MAX_ID - pwidget->ID);
if (pUnits_Upg_Dlg) {
if (units_upg_dlg) {
return 1;
}
......
widget_redraw(pwidget);
widget_mark_dirty(pwidget);
pUnits_Upg_Dlg = fc_calloc(1, sizeof(struct small_dialog));
units_upg_dlg = fc_calloc(1, sizeof(struct small_dialog));
ut2 = can_upgrade_unittype(client.conn.playing, ut1);
value = unit_upgrade_price(client.conn.playing, ut1, ut2);
......
add_to_gui_list(ID_WINDOW, pwindow);
pUnits_Upg_Dlg->end_widget_list = pwindow;
units_upg_dlg->end_widget_list = pwindow;
area = pwindow->area;
......
}
/* ============================================ */
pUnits_Upg_Dlg->begin_widget_list = pBuf;
units_upg_dlg->begin_widget_list = pBuf;
resize_window(pwindow, NULL, get_theme_color(COLOR_THEME_BACKGROUND),
(pwindow->size.w - pwindow->area.w) + area.w,
(pwindow->size.h - pwindow->area.h) + area.h);
widget_set_position(pwindow,
pUnitsDlg->end_widget_list->size.x +
(pUnitsDlg->end_widget_list->size.w - pwindow->size.w) / 2,
pUnitsDlg->end_widget_list->size.y +
(pUnitsDlg->end_widget_list->size.h - pwindow->size.h) / 2);
units_dlg->end_widget_list->size.x +
(units_dlg->end_widget_list->size.w - pwindow->size.w) / 2,
units_dlg->end_widget_list->size.y +
(units_dlg->end_widget_list->size.h - pwindow->size.h) / 2);
/* setup rest of widgets */
/* label */
......
/* ================================================== */
/* redraw */
redraw_group(pUnits_Upg_Dlg->begin_widget_list, pwindow, 0);
redraw_group(units_upg_dlg->begin_widget_list, pwindow, 0);
widget_mark_dirty(pwindow);
flush_dirty();
......
static int exit_units_dlg_callback(struct widget *pwidget)
{
if (PRESSED_EVENT(main_data.event)) {
if (pUnitsDlg) {
if (pUnits_Upg_Dlg) {
del_group_of_widgets_from_gui_list(pUnits_Upg_Dlg->begin_widget_list,
pUnits_Upg_Dlg->end_widget_list);
FC_FREE(pUnits_Upg_Dlg);
if (units_dlg) {
if (units_upg_dlg) {
del_group_of_widgets_from_gui_list(units_upg_dlg->begin_widget_list,
units_upg_dlg->end_widget_list);
FC_FREE(units_upg_dlg);
}
popdown_window_group_dialog(pUnitsDlg->begin_widget_list,
pUnitsDlg->end_widget_list);
FC_FREE(pUnitsDlg->pScroll);
FC_FREE(pUnitsDlg);
popdown_window_group_dialog(units_dlg->begin_widget_list,
units_dlg->end_widget_list);
FC_FREE(units_dlg->pScroll);
FC_FREE(units_dlg);
flush_dirty();
}
}
......
bool upgrade = FALSE;
SDL_Rect area;
if (pUnitsDlg) {
popdown_window_group_dialog(pUnitsDlg->begin_widget_list,
pUnitsDlg->end_widget_list);
if (units_dlg) {
popdown_window_group_dialog(units_dlg->begin_widget_list,
units_dlg->end_widget_list);
} else {
pUnitsDlg = fc_calloc(1, sizeof(struct advanced_dialog));
units_dlg = fc_calloc(1, sizeof(struct advanced_dialog));
}
fc_snprintf(cbuf, sizeof(cbuf), _("active"));
......
add_to_gui_list(ID_UNITS_DIALOG_WINDOW, pwindow);
pUnitsDlg->end_widget_list = pwindow;
units_dlg->end_widget_list = pwindow;
area = pwindow->area;
......
}
} unit_type_iterate_end;
pUnitsDlg->begin_widget_list = pBuf;
units_dlg->begin_widget_list = pBuf;
area.w = MAX(area.w, (tileset_full_tile_width(tileset) * 2 + name_w + adj_size(15))
+ (adj_size(4) * pText1->w + adj_size(46)) + (pText2->w + adj_size(16))
+ (pText5->w + adj_size(6)) + adj_size(2));
if (count > 0) {
pUnitsDlg->end_active_widget_list = pLast->prev;
pUnitsDlg->begin_active_widget_list = pUnitsDlg->begin_widget_list;
units_dlg->end_active_widget_list = pLast->prev;
units_dlg->begin_active_widget_list = units_dlg->begin_widget_list;
if (count > adj_size(80)) {
pUnitsDlg->active_widget_list = pUnitsDlg->end_active_widget_list;
if (pUnitsDlg->pScroll) {
pUnitsDlg->pScroll->count = count;
units_dlg->active_widget_list = units_dlg->end_active_widget_list;
if (units_dlg->pScroll) {
units_dlg->pScroll->count = count;
}
ww = create_vertical_scrollbar(pUnitsDlg, 8, 10, TRUE, TRUE);
ww = create_vertical_scrollbar(units_dlg, 8, 10, TRUE, TRUE);
area.w += ww;
area.h = (hh + 9 * (hh/2) + adj_size(10));
} else {
......
pBuf->size.y = start_y + (hh - pBuf->size.h) / 2;
start_y += (hh >> 1);
if (pBuf == pUnitsDlg->begin_active_widget_list) {
if (pBuf == units_dlg->begin_active_widget_list) {
break;
}
pBuf = pBuf->prev;
}
if (pUnitsDlg->pScroll) {
setup_vertical_scrollbar_area(pUnitsDlg->pScroll,
if (units_dlg->pScroll) {
setup_vertical_scrollbar_area(units_dlg->pScroll,
area.x + area.w, area.y,
area.h, TRUE);
}
}
/* ----------------------------------- */
redraw_group(pUnitsDlg->begin_widget_list, pwindow, 0);
redraw_group(units_dlg->begin_widget_list, pwindow, 0);
widget_mark_dirty(pwindow);
flush_dirty();
......
**************************************************************************/
void real_units_report_dialog_update(void *unused)
{
if (pUnitsDlg) {
if (units_dlg) {
struct units_entry units[U_LAST];
struct units_entry units_total;
struct widget *pwidget, *pbuf;
......
get_units_report_data(units, &units_total);
/* find if there are new units entry (if not then rebuild all) */
pwidget = pUnitsDlg->end_active_widget_list; /* icon of first list entry */
pwidget = units_dlg->end_active_widget_list; /* icon of first list entry */
unit_type_iterate(i) {
if ((units[utype_index(i)].active_count > 0)
|| (units[utype_index(i)].building_count > 0)) {
......
break;
}
if (pbuf->prev->prev->prev->prev->prev->prev->prev ==
pUnitsDlg->begin_active_widget_list) {
units_dlg->begin_active_widget_list) {
break;
}
......
} unit_type_iterate_end;
/* update list */
pwidget = pUnitsDlg->end_active_widget_list;
pwidget = units_dlg->end_active_widget_list;
unit_type_iterate(i) {
pbuf = pwidget; /* first widget (icon) of the first list entry */
......
/* search it */
pbuf = pwidget->next;
do {
del_widget_from_vertical_scroll_widget_list(pUnitsDlg, pbuf->prev);
del_widget_from_vertical_scroll_widget_list(units_dlg, pbuf->prev);
} while (((MAX_ID - pbuf->prev->ID) != utype_number(i))
&& (pbuf->prev != pUnitsDlg->begin_active_widget_list));
&& (pbuf->prev != units_dlg->begin_active_widget_list));
if (pbuf->prev == pUnitsDlg->begin_active_widget_list) {
if (pbuf->prev == units_dlg->begin_active_widget_list) {
/* list entry not found - can this really happen? */
del_widget_from_vertical_scroll_widget_list(pUnitsDlg, pbuf->prev);
pwidget = pbuf->prev; /* pUnitsDlg->begin_active_widget_list */
del_widget_from_vertical_scroll_widget_list(units_dlg, pbuf->prev);
pwidget = pbuf->prev; /* units_dlg->begin_active_widget_list */
search_finished = TRUE;
} else {
/* found it */
......
}
}
} else { /* player has no unit of this type */
if (pbuf && pbuf->next != pUnitsDlg->begin_active_widget_list) {
if (pbuf && pbuf->next != units_dlg->begin_active_widget_list) {
if (utype_number(i) < (MAX_ID - pbuf->ID)) {
continue;
} else {
pbuf = pbuf->next;
do {
del_widget_from_vertical_scroll_widget_list(pUnitsDlg,
del_widget_from_vertical_scroll_widget_list(units_dlg,
pbuf->prev);
} while (((MAX_ID - pbuf->prev->ID) == utype_number(i))
&& (pbuf->prev != pUnitsDlg->begin_active_widget_list));
if (pbuf->prev == pUnitsDlg->begin_active_widget_list) {
del_widget_from_vertical_scroll_widget_list(pUnitsDlg,
&& (pbuf->prev != units_dlg->begin_active_widget_list));
if (pbuf->prev == units_dlg->begin_active_widget_list) {
del_widget_from_vertical_scroll_widget_list(units_dlg,
pbuf->prev);
}
pwidget = pbuf->prev;
......
/* -------------------------------------- */
/* total active */
pbuf = pUnitsDlg->end_widget_list->prev->prev;
pbuf = units_dlg->end_widget_list->prev->prev;
fc_snprintf(cbuf, sizeof(cbuf), "%d", units_total.active_count);
copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
......
copy_chars_to_utf8_str(pbuf->string_utf8, cbuf);
/* -------------------------------------- */
redraw_group(pUnitsDlg->begin_widget_list, pUnitsDlg->end_widget_list, 0);
widget_mark_dirty(pUnitsDlg->end_widget_list);
redraw_group(units_dlg->begin_widget_list, units_dlg->end_widget_list, 0);
widget_mark_dirty(units_dlg->end_widget_list);
flush_dirty();
}
......
struct units_entry units[U_LAST];
struct units_entry units_total;
if (pUnitsDlg) {
if (units_dlg) {
return;
}
......
**************************************************************************/
void units_report_dialog_popdown(void)
{
if (pUnitsDlg) {
if (pUnits_Upg_Dlg) {
del_group_of_widgets_from_gui_list(pUnits_Upg_Dlg->begin_widget_list,
pUnits_Upg_Dlg->end_widget_list);
FC_FREE(pUnits_Upg_Dlg);
if (units_dlg) {
if (units_upg_dlg) {
del_group_of_widgets_from_gui_list(units_upg_dlg->begin_widget_list,
units_upg_dlg->end_widget_list);
FC_FREE(units_upg_dlg);
}
popdown_window_group_dialog(pUnitsDlg->begin_widget_list,
pUnitsDlg->end_widget_list);
FC_FREE(pUnitsDlg->pScroll);
FC_FREE(pUnitsDlg);
popdown_window_group_dialog(units_dlg->begin_widget_list,
units_dlg->end_widget_list);
FC_FREE(units_dlg->pScroll);
FC_FREE(units_dlg);
}
}
......
SDL_Surface *create_select_tech_icon(utf8_str *pstr, Tech_type_id tech_id,
enum tech_info_mode mode)
{
struct unit_type *pUnit = NULL;
struct unit_type *punit = NULL;
SDL_Surface *surf, *pText, *pTmp, *pTmp2;
SDL_Surface *Surf_Array[10], **pBuf_Array;
SDL_Rect dst;
......
/* -------------------------------------------------------- */
w = 0;
unit_type_iterate(un) {
pUnit = un;
if (advance_number(pUnit->require_advance) == tech_id) {
punit = un;
if (advance_number(punit->require_advance) == tech_id) {
Surf_Array[w++] = adj_surf(get_unittype_surface(un, direction8_invalid()));
}
} unit_type_iterate_end;
......
SDL_Surface *pColb_Surface = pIcons->pBIG_Colb;
int step, i, cost;
SDL_Rect dest;
struct unit_type *pUnit;
struct unit_type *punit;
struct widget *pChangeResearchButton;
struct widget *pChangeResearchGoalButton;
SDL_Rect area;
......
/* units */
unit_type_iterate(un) {
pUnit = un;
if (advance_number(pUnit->require_advance) == presearch->researching) {
punit = un;
if (advance_number(punit->require_advance) == presearch->researching) {
SDL_Surface *usurf = get_unittype_surface(un, direction8_invalid());
int w = usurf->w;
......
/* units */
unit_type_iterate(un) {
pUnit = un;
if (advance_number(pUnit->require_advance) == presearch->tech_goal) {
punit = un;
if (advance_number(punit->require_advance) == presearch->tech_goal) {
SDL_Surface *usurf = get_unittype_surface(un, direction8_invalid());
int w = usurf->w;
    (1-1/1)