static int players_window_dlg_callback(struct widget *pWindow) { if (Main.event.button.button == SDL_BUTTON_LEFT) { if (move_window_group_dialog(pPlayers_Dlg->pBeginWidgetList, pWindow)) { sellect_window_group_dialog(pPlayers_Dlg->pBeginWidgetList, pWindow); players_dialog_update(); } else { if(sellect_window_group_dialog(pPlayers_Dlg->pBeginWidgetList, pWindow)) { widget_flush(pWindow); } } } return -1; }
static int toggle_draw_alliance_status_callback(struct widget *pWidget) { if (Main.event.button.button == SDL_BUTTON_LEFT) { /* exit button -> neutral -> war -> casefire -> peace -> alliance */ struct widget *pPlayer = pPlayers_Dlg->pEndWidgetList->prev->prev->prev->prev->prev->prev; SDL_Client_Flags ^= CF_DRAW_PLAYERS_ALLIANCE_STATUS; do{ pPlayer = pPlayer->prev; FREESURFACE(pPlayer->gfx); } while(pPlayer != pPlayers_Dlg->pBeginWidgetList); players_dialog_update(); } return -1; }
/**************************************************************** ... *****************************************************************/ void create_players_dialog(bool raise) { players_dialog_shell = I_IN(I_T(XtCreatePopupShell("playerspopup", raise ? transientShellWidgetClass : topLevelShellWidgetClass, toplevel, NULL, 0))); players_form = XtVaCreateManagedWidget("playersform", formWidgetClass, players_dialog_shell, NULL); players_label = I_L(XtVaCreateManagedWidget("playerslabel", labelWidgetClass, players_form, NULL)); players_list = XtVaCreateManagedWidget("playerslist", listWidgetClass, players_form, NULL); players_close_command = I_L(XtVaCreateManagedWidget("playersclosecommand", commandWidgetClass, players_form, NULL)); players_int_command = I_L(XtVaCreateManagedWidget("playersintcommand", commandWidgetClass, players_form, XtNsensitive, False, NULL)); players_meet_command = I_L(XtVaCreateManagedWidget("playersmeetcommand", commandWidgetClass, players_form, XtNsensitive, False, NULL)); players_war_command = I_L(XtVaCreateManagedWidget("playerswarcommand", commandWidgetClass, players_form, XtNsensitive, False, NULL)); players_vision_command = I_L(XtVaCreateManagedWidget("playersvisioncommand", commandWidgetClass, players_form, XtNsensitive, False, NULL)); players_sship_command = I_L(XtVaCreateManagedWidget("playerssshipcommand", commandWidgetClass, players_form, XtNsensitive, False, NULL)); XtAddCallback(players_list, XtNcallback, players_list_callback, NULL); XtAddCallback(players_close_command, XtNcallback, players_close_callback, NULL); XtAddCallback(players_meet_command, XtNcallback, players_meet_callback, NULL); XtAddCallback(players_int_command, XtNcallback, players_intel_callback, NULL); XtAddCallback(players_war_command, XtNcallback, players_war_callback, NULL); XtAddCallback(players_vision_command, XtNcallback, players_vision_callback, NULL); XtAddCallback(players_sship_command, XtNcallback, players_sship_callback, NULL); players_dialog_update(); XtRealizeWidget(players_dialog_shell); XSetWMProtocols(display, XtWindow(players_dialog_shell), &wm_delete_window, 1); XtOverrideTranslations(players_dialog_shell, XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-players()")); }
/************************************************************************** Popup (or raise) the player list dialog. **************************************************************************/ void popup_players_dialog(bool raise) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_Surface *pLogo = NULL, *pZoomed = NULL; SDL_String16 *pStr; SDL_Rect dst; int i, n, h; double a, b, r; SDL_Rect area; if (pPlayers_Dlg) { return; } n = 0; players_iterate(pPlayer) { if(is_barbarian(pPlayer)) { continue; } n++; } players_iterate_end; if(n < 2) { return; } pPlayers_Dlg = fc_calloc(1, sizeof(struct SMALL_DLG)); pStr = create_str16_from_char(_("Players"), adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = players_window_dlg_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_WINDOW, pWindow); pPlayers_Dlg->pEndWidgetList = pWindow; /* ---------- */ /* exit button */ pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"), adj_font(12)); pBuf->action = exit_players_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BUTTON, pBuf); /* ---------- */ for(i = 0; i<DS_LAST; i++) { switch (i) { case DS_ARMISTICE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_NEUTRAL_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_neutral_status_callback; pBuf->key = SDLK_n; break; case DS_WAR: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_WAR_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_war_status_callback; pBuf->key = SDLK_w; break; case DS_CEASEFIRE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_CEASEFIRE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_ceasefire_status_callback; pBuf->key = SDLK_c; break; case DS_PEACE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_PEACE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_pease_status_callback; pBuf->key = SDLK_p; break; case DS_ALLIANCE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_alliance_status_callback; pBuf->key = SDLK_a; break; default: /* no contact */ continue; break; } set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(ID_CHECKBOX, pBuf); } /* ---------- */ players_iterate(pPlayer) { if(is_barbarian(pPlayer)) { continue; } pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= (TTF_STYLE_BOLD|SF_CENTER); pLogo = get_nation_flag_surface(nation_of_player(pPlayer)); { /* Aim for a flag height of 60 pixels, but draw smaller flags if there * are more players */ double zoom = DEFAULT_ZOOM * (60.0 - n) / pLogo->h; pZoomed = zoomSurface(pLogo, zoom, zoom, 1); } pBuf = create_icon2(pZoomed, pWindow->dst, WF_RESTORE_BACKGROUND | WF_WIDGET_HAS_INFO_LABEL | WF_FREE_THEME); pBuf->info_label = pStr; if(!pPlayer->is_alive) { pStr = create_str16_from_char(_("R.I.P.") , adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_TEXT); pLogo = create_text_surf_from_str16(pStr); FREESTRING16(pStr); dst.x = (pZoomed->w - pLogo->w) / 2; dst.y = (pZoomed->h - pLogo->h) / 2; alphablit(pLogo, NULL, pZoomed, &dst); FREESURFACE(pLogo); } if(pPlayer->is_alive) { set_wstate(pBuf, FC_WS_NORMAL); } pBuf->data.player = pPlayer; pBuf->action = player_callback; add_to_gui_list(ID_LABEL, pBuf); } players_iterate_end; pPlayers_Dlg->pBeginWidgetList = pBuf; resize_window(pWindow, NULL, NULL, adj_size(500), adj_size(400)); area = pWindow->area; r = MIN(area.w, area.h); r -= ((MAX(pBuf->size.w, pBuf->size.h) * 2)); r /= 2; a = (2.0 * M_PI) / n; widget_set_position(pWindow, (Main.screen->w - pWindow->size.w) / 2, (Main.screen->h - pWindow->size.h) / 2); /* exit button */ pBuf = pWindow->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); n = area.y; pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pStr->bgcol = (SDL_Color) {0, 0, 0, 0}; for(i = 0; i<DS_LAST; i++) { switch (i) { case DS_ARMISTICE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE); break; case DS_WAR: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR); break; case DS_CEASEFIRE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE); break; case DS_PEACE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE); break; case DS_ALLIANCE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE); break; default: /* no contact */ continue; break; } copy_chars_to_string16(pStr, diplstate_type_translated_name(i)); pLogo = create_text_surf_from_str16(pStr); pBuf = pBuf->prev; h = MAX(pBuf->size.h, pLogo->h); pBuf->size.x = area.x + adj_size(5); pBuf->size.y = n + (h - pBuf->size.h) / 2; dst.x = adj_size(5) + pBuf->size.w + adj_size(6); dst.y = n + (h - pLogo->h) / 2; alphablit(pLogo, NULL, pWindow->theme, &dst); n += h; FREESURFACE(pLogo); } FREESTRING16(pStr); /* first player shield */ pBuf = pBuf->prev; pBuf->size.x = area.x + area.w / 2 - pBuf->size.w / 2; pBuf->size.y = area.y + area.h / 2 - r - pBuf->size.h / 2; n = 1; if(pBuf != pPlayers_Dlg->pBeginWidgetList) { do{ pBuf = pBuf->prev; b = M_PI_2 + n * a; pBuf->size.x = area.x + area.w / 2 - r * cos(b) - pBuf->size.w / 2; pBuf->size.y = area.y + area.h / 2 - r * sin(b) - pBuf->size.h / 2; n++; } while(pBuf != pPlayers_Dlg->pBeginWidgetList); } players_dialog_update(); }