/************************************************************************** ... **************************************************************************/ static int redraw_icon2(struct widget *pIcon) { int ret; SDL_Rect dest; Uint32 state; ret = (*baseclass_redraw)(pIcon); if (ret != 0) { return ret; } if(!pIcon) { return -3; } if(!pIcon->theme) { return -4; } state = get_wstate(pIcon); dest.x = pIcon->size.x; dest.y = pIcon->size.y; dest.w = pIcon->theme->w; dest.h = pIcon->theme->h; if (state == FC_WS_SELLECTED) { putframe(pIcon->dst->surface, dest.x + 1, dest.y + 1, dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); } if (state == FC_WS_PRESSED) { putframe(pIcon->dst->surface, dest.x + 1, dest.y + 1, dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); putframe(pIcon->dst->surface, dest.x, dest.y, dest.x + dest.w + adj_size(3), dest.y + dest.h + adj_size(3), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_PRESSED_FRAME)); } if (state == FC_WS_DISABLED) { putframe(pIcon->dst->surface, dest.x + 1, dest.y + 1, dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2), get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT)); } dest.x += adj_size(2); dest.y += adj_size(2); ret = alphablit(pIcon->theme, NULL, pIcon->dst->surface, &dest); if (ret) { return ret; } return 0; }
/************************************************************************** set new theme and callculate new size. **************************************************************************/ void set_new_icon2_theme(struct widget *pIcon_Widget, SDL_Surface *pNew_Theme, bool free_old_theme) { if ((pNew_Theme) && (pIcon_Widget)) { if(free_old_theme) { FREESURFACE(pIcon_Widget->theme); } pIcon_Widget->theme = pNew_Theme; pIcon_Widget->size.w = pNew_Theme->w + adj_size(4); pIcon_Widget->size.h = pNew_Theme->h + adj_size(4); } }
/************************************************************************** Create ( malloc ) Edit Widget structure. Edit Theme graphic is taken from pTheme->Edit surface; Text is taken from 'pString16'. 'length' parametr determinate width of Edit rect. This function determinate future size of Edit ( width, high ) and save this in: pWidget->size rectangle ( SDL_Rect ) function return pointer to allocated Edit Widget. **************************************************************************/ struct widget * create_edit(SDL_Surface *pBackground, struct gui_layer *pDest, SDL_String16 *pString16, Uint16 length, Uint32 flags) { SDL_Rect buf = {0, 0, 0, 0}; struct widget *pEdit = widget_new(); pEdit->theme = pTheme->Edit; pEdit->theme2 = pBackground; /* FIXME: make somewhere use of it */ pEdit->string16 = pString16; set_wflag(pEdit, (WF_FREE_STRING | WF_FREE_GFX | flags)); set_wstate(pEdit, FC_WS_DISABLED); set_wtype(pEdit, WT_EDIT); pEdit->mod = KMOD_NONE; baseclass_redraw = pEdit->redraw; pEdit->redraw = redraw_edit; if (pString16) { pEdit->string16->style |= SF_CENTER; buf = str16size(pString16); buf.h += adj_size(4); } length = MAX(length, buf.w + adj_size(10)); correct_size_bcgnd_surf(pTheme->Edit, &length, &buf.h); pEdit->size.w = length; pEdit->size.h = buf.h; if(pDest) { pEdit->dst = pDest; } else { pEdit->dst = add_gui_layer(pEdit->size.w, pEdit->size.h); } return pEdit; }
/**************************************************************************** Really resize the main window. ****************************************************************************/ static void real_resize_window_callback(void *data) { struct widget *widget; Uint32 flags = Main.screen->flags; if (gui_sdl_fullscreen) { flags |= SDL_FULLSCREEN; } else { flags &= ~SDL_FULLSCREEN; } set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, flags); if (C_S_RUNNING == client_state()) { /* Move units window to botton-right corner. */ set_new_unitinfo_window_pos(); /* Move minimap window to botton-left corner. */ set_new_minimap_window_pos(); /* Move cooling/warming icons to botton-right corner. */ widget = get_widget_pointer_form_main_list(ID_WARMING_ICON); widget_set_position(widget, (Main.screen->w - adj_size(10) - (widget->size.w * 2)), widget->size.y); widget = get_widget_pointer_form_main_list(ID_COOLING_ICON); widget_set_position(widget, (Main.screen->w - adj_size(10) - widget->size.w), widget->size.y); map_canvas_resized(Main.screen->w, Main.screen->h); update_info_label(); update_unit_info_label(get_units_in_focus()); center_on_something(); /* With redrawing full map. */ update_order_widgets(); } else { draw_intro_gfx(); dirty_all(); } flush_all(); }
/************************************************************************** Create ( malloc ) Icon2 Widget ( flat Button ) **************************************************************************/ struct widget * create_icon2(SDL_Surface *pIcon, struct gui_layer *pDest, Uint32 flags) { struct widget *pIcon_Widget = widget_new(); pIcon_Widget->theme = pIcon; set_wflag(pIcon_Widget, (WF_FREE_STRING | WF_FREE_GFX | flags)); set_wstate(pIcon_Widget, FC_WS_DISABLED); set_wtype(pIcon_Widget, WT_ICON2); pIcon_Widget->mod = KMOD_NONE; pIcon_Widget->dst = pDest; baseclass_redraw = pIcon_Widget->redraw; pIcon_Widget->redraw = redraw_icon2; if (pIcon) { pIcon_Widget->size.w = pIcon->w + adj_size(4); pIcon_Widget->size.h = pIcon->h + adj_size(4); } return pIcon_Widget; }
/************************************************************************** Ugly hack to create 4-state icon theme from static icon; **************************************************************************/ SDL_Surface *create_icon_theme_surf(SDL_Surface * pIcon) { SDL_Color bg_color = { 255, 255, 255, 128 }; SDL_Rect dest, src = get_smaller_surface_rect(pIcon); SDL_Surface *pTheme = create_surf_alpha((src.w + adj_size(4)) * 4, src.h + adj_size(4), SDL_SWSURFACE); dest.x = adj_size(2); dest.y = (pTheme->h - src.h) / 2; /* normal */ alphablit(pIcon, &src, pTheme, &dest); /* sellected */ dest.x += (src.w + adj_size(4)); alphablit(pIcon, &src, pTheme, &dest); /* draw sellect frame */ putframe(pTheme, dest.x - 1, dest.y - 1, dest.x + (src.w), dest.y + src.h, get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); /* pressed */ dest.x += (src.w + adj_size(4)); alphablit(pIcon, &src, pTheme, &dest); /* draw sellect frame */ putframe(pTheme, dest.x - 1, dest.y - 1, dest.x + src.w, dest.y + src.h, get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); /* draw press frame */ putframe(pTheme, dest.x - adj_size(2), dest.y - adj_size(2), dest.x + (src.w + 1), dest.y + (src.h + 1), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_PRESSED_FRAME)); /* disabled */ dest.x += (src.w + adj_size(4)); alphablit(pIcon, &src, pTheme, &dest); dest.w = src.w; dest.h = src.h; SDL_FillRectAlpha(pTheme, &dest, &bg_color); return pTheme; }
/************************************************************************** ... **************************************************************************/ void setup_auxiliary_tech_icons(void) { SDL_Color bg_color = {255, 255, 255, 136}; SDL_Surface *pSurf; SDL_String16 *pStr = create_str16_from_char(_("None"), adj_font(10)); pStr->style |= (TTF_STYLE_BOLD | SF_CENTER); /* create icons */ pSurf = create_surf_alpha(adj_size(50), adj_size(50), SDL_SWSURFACE); SDL_FillRect(pSurf, NULL, map_rgba(pSurf->format, bg_color)); putframe(pSurf, 0 , 0, pSurf->w - 1, pSurf->h - 1, map_rgba(pSurf->format, *get_game_colorRGB(COLOR_THEME_SCIENCEDLG_FRAME))); pNeutral_Tech_Icon = SDL_DisplayFormatAlpha(pSurf); pNone_Tech_Icon = SDL_DisplayFormatAlpha(pSurf); pFuture_Tech_Icon = SDL_DisplayFormatAlpha(pSurf); FREESURFACE(pSurf); /* None */ pSurf = create_text_surf_from_str16(pStr); blit_entire_src(pSurf, pNone_Tech_Icon , (adj_size(50) - pSurf->w) / 2 , (adj_size(50) - pSurf->h) / 2); FREESURFACE(pSurf); /* TRANS: Future Technology */ copy_chars_to_string16(pStr, _("FT")); pSurf = create_text_surf_from_str16(pStr); blit_entire_src(pSurf, pFuture_Tech_Icon, (adj_size(50) - pSurf->w) / 2 , (adj_size(50) - pSurf->h) / 2); FREESURFACE(pSurf); FREESTRING16(pStr); }
/************************************************************************** ... **************************************************************************/ static int spy_steal_popup(struct widget *pWidget) { struct city *pVcity = pWidget->data.city; int id = MAX_ID - pWidget->ID; struct player *pVictim = NULL; struct CONTAINER *pCont; struct widget *pBuf = NULL; struct widget *pWindow; SDL_String16 *pStr; SDL_Surface *pSurf; int max_col, max_row, col, i, count = 0; SDL_Rect area; popdown_diplomat_dialog(); if(pVcity) { pVictim = city_owner(pVcity); } if (pDiplomat_Dlg || !pVictim) { return 1; } count = 0; advance_index_iterate(A_FIRST, i) { if (player_invention_reachable(client.conn.playing, i, FALSE) && TECH_KNOWN == player_invention_state(pVictim, i) && (TECH_UNKNOWN == player_invention_state(client.conn.playing, i) || TECH_PREREQS_KNOWN == player_invention_state(client.conn.playing, i))) { count++; } } advance_index_iterate_end; if(!count) { /* if there is no known tech to steal then send steal order at Spy's Discretion */ int target_id = pVcity->id; request_diplomat_action(DIPLOMAT_STEAL, id, target_id, advance_count()); return -1; } pCont = fc_calloc(1, sizeof(struct CONTAINER)); pCont->id0 = pVcity->id; pCont->id1 = id;/* spy id */ pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = id; pDiplomat_Dlg->diplomat_target_id = pVcity->id; pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG)); pStr = create_str16_from_char(_("Select Advance to Steal"), adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = spy_steal_dlg_window_callback; set_wstate(pWindow , FC_WS_NORMAL); add_to_gui_list(ID_DIPLOMAT_DLG_WINDOW, pWindow); pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow; area = pWindow->area; area.w = MAX(area.w, adj_size(8)); /* ------------------ */ /* 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)); area.w += pBuf->size.w + adj_size(10); pBuf->action = exit_spy_steal_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, pBuf); /* ------------------------- */ count++; /* count + at Spy's Discretion */ /* max col - 104 is steal tech widget width */ max_col = (Main.screen->w - (pWindow->size.w - pWindow->area.w) - adj_size(2)) / adj_size(104); /* max row - 204 is steal tech widget height */ max_row = (Main.screen->h - (pWindow->size.h - pWindow->area.h)) / adj_size(204); /* make space on screen for scrollbar */ if (max_col * max_row < count) { max_col--; } if (count < max_col + 1) { col = count; } else { if (count < max_col + adj_size(3)) { col = max_col - adj_size(2); } else { if (count < max_col + adj_size(5)) { col = max_col - 1; } else { col = max_col; } } } pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= (TTF_STYLE_BOLD | SF_CENTER); count = 0; advance_index_iterate(A_FIRST, i) { if (player_invention_reachable(client.conn.playing, i, FALSE) && TECH_KNOWN == player_invention_state(pVictim, i) && (TECH_UNKNOWN == player_invention_state(client.conn.playing, i) || TECH_PREREQS_KNOWN == player_invention_state(client.conn.playing, i))) { count++; copy_chars_to_string16(pStr, advance_name_translation(advance_by_number(i))); pSurf = create_sellect_tech_icon(pStr, i, FULL_MODE); pBuf = create_icon2(pSurf, pWindow->dst, WF_FREE_THEME | WF_RESTORE_BACKGROUND); set_wstate(pBuf, FC_WS_NORMAL); pBuf->action = spy_steal_callback; pBuf->data.cont = pCont; add_to_gui_list(MAX_ID - i, pBuf); if (count > (col * max_row)) { set_wflag(pBuf, WF_HIDDEN); } } } advance_index_iterate_end; /* get spy tech */ i = advance_number(unit_type(game_unit_by_number(id))->require_advance); copy_chars_to_string16(pStr, _("At Spy's Discretion")); pSurf = create_sellect_tech_icon(pStr, i, FULL_MODE); pBuf = create_icon2(pSurf, pWindow->dst, (WF_FREE_THEME | WF_RESTORE_BACKGROUND| WF_FREE_DATA)); set_wstate(pBuf, FC_WS_NORMAL); pBuf->action = spy_steal_callback; pBuf->data.cont = pCont; add_to_gui_list(MAX_ID - advance_count(), pBuf); count++; /* --------------------------------------------------------- */ FREESTRING16(pStr); pDiplomat_Dlg->pdialog->pBeginWidgetList = pBuf; pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pDiplomat_Dlg->pdialog->pBeginWidgetList; pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pDiplomat_Dlg->pdialog->pEndWidgetList->prev->prev; /* -------------------------------------------------------------- */ i = 0; if (count > col) { count = (count + (col - 1)) / col; if (count > max_row) { pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList; count = max_row; i = create_vertical_scrollbar(pDiplomat_Dlg->pdialog, col, count, TRUE, TRUE); } } else { count = 1; } area.w = MAX(area.w, (col * pBuf->size.w + adj_size(2) + i)); area.h = count * pBuf->size.h + adj_size(2); /* alloca window theme and win background buffer */ pSurf = theme_get_background(theme, BACKGROUND_SPYSTEALDLG); if (resize_window(pWindow, pSurf, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h - pWindow->area.h) + area.h)) { FREESURFACE(pSurf); } area = pWindow->area; 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); setup_vertical_widgets_position(col, area.x + 1, area.y, 0, 0, pDiplomat_Dlg->pdialog->pBeginActiveWidgetList, pDiplomat_Dlg->pdialog->pEndActiveWidgetList); if(pDiplomat_Dlg->pdialog->pScroll) { setup_vertical_scrollbar_area(pDiplomat_Dlg->pdialog->pScroll, area.x + area.w, area.y, area.h, TRUE); } redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, FALSE); widget_mark_dirty(pWindow); return -1; }
/************************************************************************** Popup (or raise) the spaceship dialog for the given player. **************************************************************************/ void popup_spaceship_dialog(struct player *pPlayer) { struct SMALL_DLG *pSpaceShp; if(!(pSpaceShp = get_spaceship_dialog(pPlayer))) { struct widget *pBuf, *pWindow; SDL_String16 *pStr; char cBuf[128]; SDL_Rect area; pSpaceShp = fc_calloc(1, sizeof(struct SMALL_DLG)); fc_snprintf(cBuf, sizeof(cBuf), _("The %s Spaceship"), nation_adjective_for_player(pPlayer)); pStr = create_str16_from_char(cBuf, adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = space_dialog_window_callback; set_wstate(pWindow, FC_WS_NORMAL); pWindow->data.player = pPlayer; pWindow->private_data.small_dlg = pSpaceShp; add_to_gui_list(ID_WINDOW, pWindow); pSpaceShp->pEndWidgetList = pWindow; area = pWindow->area; /* ---------- */ /* create 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->data.player = pPlayer; pBuf->action = exit_space_dialog_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; area.w = MAX(area.w, (pBuf->size.w + adj_size(10))); add_to_gui_list(ID_BUTTON, pBuf); pBuf = create_themeicon_button_from_chars(pTheme->OK_Icon, pWindow->dst, _("Launch"), adj_font(12), 0); pBuf->action = launch_spaceship_callback; area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h + adj_size(20); add_to_gui_list(ID_BUTTON, pBuf); pStr = create_str16_from_char(get_spaceship_descr(NULL), adj_font(12)); pStr->bgcol = (SDL_Color) { 0, 0, 0, 0 }; pBuf = create_iconlabel(NULL, pWindow->dst, pStr, WF_RESTORE_BACKGROUND); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h + adj_size(20); add_to_gui_list(ID_LABEL, pBuf); pSpaceShp->pBeginWidgetList = pBuf; /* -------------------------------------------------------- */ area.w = MAX(area.w, adj_size(300) - (pWindow->size.w - pWindow->area.w)); resize_window(pWindow, NULL, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h - pWindow->area.h) + area.h); area = pWindow->area; widget_set_position(pWindow, (main_window_width() - pWindow->size.w) / 2, (main_window_height() - 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); /* launch button */ pBuf = pBuf->prev; pBuf->size.x = area.x + (area.w - pBuf->size.w) / 2; pBuf->size.y = area.y + area.h - pBuf->size.h - adj_size(7); /* info label */ pBuf = pBuf->prev; pBuf->size.x = area.x + (area.w - pBuf->size.w) / 2; pBuf->size.y = area.y + adj_size(7); dialog_list_prepend(dialog_list, pSpaceShp); refresh_spaceship_dialog(pPlayer); } else { if (sellect_window_group_dialog(pSpaceShp->pBeginWidgetList, pSpaceShp->pEndWidgetList)) { widget_flush(pSpaceShp->pEndWidgetList); } } }
/**************************************************************** Pops-up the Spy sabotage dialog, upon return of list of available improvements requested by the above function. *****************************************************************/ void popup_sabotage_dialog(struct city *pCity) { struct widget *pWindow = NULL, *pBuf = NULL , *pLast = NULL; struct CONTAINER *pCont; struct unit *pUnit = head_of_units_in_focus(); SDL_String16 *pStr; SDL_Rect area, area2; int n, w = 0, h, imp_h = 0; if (pDiplomat_Dlg || !pUnit || !unit_has_type_flag(pUnit, F_SPY)) { return; } is_unit_move_blocked = TRUE; pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = pUnit->id; pDiplomat_Dlg->diplomat_target_id = pCity->id; pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG)); pCont = fc_calloc(1, sizeof(struct CONTAINER)); pCont->id0 = pCity->id; pCont->id1 = pUnit->id;/* spy id */ pStr = create_str16_from_char(_("Select Improvement to Sabotage") , adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = diplomat_dlg_window_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_TERRAIN_ADV_DLG_WINDOW, pWindow); pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow; area = pWindow->area; area.h = MAX(area.h, adj_size(2)); /* ---------- */ /* 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)); area.w += pBuf->size.w + adj_size(10); pBuf->action = diplomat_close_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, pBuf); /* ---------- */ create_active_iconlabel(pBuf, pWindow->dst, pStr, _("City Production"), sabotage_impr_callback); pBuf->data.cont = pCont; set_wstate(pBuf, FC_WS_NORMAL); set_wflag(pBuf, WF_FREE_DATA); add_to_gui_list(MAX_ID - 1000, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; /* separator */ pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME); add_to_gui_list(ID_SEPARATOR, pBuf); area.h += pBuf->next->size.h; /* ------------------ */ n = 0; city_built_iterate(pCity, pImprove) { if (pImprove->sabotage > 0) { create_active_iconlabel(pBuf, pWindow->dst, pStr, (char *) city_improvement_name_translation(pCity, pImprove), sabotage_impr_callback); pBuf->data.cont = pCont; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - improvement_number(pImprove), pBuf); area.w = MAX(area.w , pBuf->size.w); imp_h += pBuf->size.h; if (!pDiplomat_Dlg->pdialog->pEndActiveWidgetList) { pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pBuf; } if (improvement_number(pImprove) > 9) { set_wflag(pBuf, WF_HIDDEN); } n++; /* ----------- */ } } city_built_iterate_end; pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pBuf; if (n > 0) { /* separator */ pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME); add_to_gui_list(ID_SEPARATOR, pBuf); area.h += pBuf->next->size.h; /* ------------------ */ } create_active_iconlabel(pBuf, pWindow->dst, pStr, _("At Spy's Discretion"), sabotage_impr_callback); pBuf->data.cont = pCont; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - B_LAST, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; /* ----------- */ pLast = pBuf; pDiplomat_Dlg->pdialog->pBeginWidgetList = pLast; pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList; /* ---------- */ if (n > 10) { imp_h = 10 * pBuf->size.h; n = create_vertical_scrollbar(pDiplomat_Dlg->pdialog, 1, 10, TRUE, TRUE); area.w += n; } /* ---------- */ area.h += imp_h; 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, pUnit->tile); w = area.w; if (pDiplomat_Dlg->pdialog->pScroll) { w -= n; imp_h = pBuf->size.w; } else { imp_h = 0; } /* 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); /* Production sabotage */ pBuf = pBuf->prev; pBuf->size.x = area.x; pBuf->size.y = area.y + 1; pBuf->size.w = w; h = pBuf->size.h; area2.x = adj_size(10); area2.h = adj_size(2); pBuf = pBuf->prev; while(pBuf) { if (pBuf == pDiplomat_Dlg->pdialog->pEndActiveWidgetList) { w -= imp_h; } pBuf->size.w = w; pBuf->size.x = pBuf->next->size.x; pBuf->size.y = pBuf->next->size.y + pBuf->next->size.h; if (pBuf->ID == ID_SEPARATOR) { FREESURFACE(pBuf->theme); pBuf->size.h = h; pBuf->theme = create_surf(w, h, SDL_SWSURFACE); area2.y = pBuf->size.h / 2 - 1; area2.w = pBuf->size.w - adj_size(20); SDL_FillRect(pBuf->theme , &area2, map_rgba(pBuf->theme->format, *get_game_colorRGB(COLOR_THEME_SABOTAGEDLG_SEPARATOR))); } if (pBuf == pLast) { break; } pBuf = pBuf->prev; } if (pDiplomat_Dlg->pdialog->pScroll) { setup_vertical_scrollbar_area(pDiplomat_Dlg->pdialog->pScroll, area.x + area.w, pDiplomat_Dlg->pdialog->pEndActiveWidgetList->size.y, area.y - pDiplomat_Dlg->pdialog->pEndActiveWidgetList->size.y + area.h, TRUE); } /* -------------------- */ /* redraw */ redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, 0); widget_flush(pWindow); }
/************************************************************************** Popup a dialog giving a diplomatic unit some options when moving into the target tile. **************************************************************************/ void popup_diplomat_dialog(struct unit *pUnit, struct tile *ptile) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_String16 *pStr; struct city *pCity; struct unit *pTunit; bool spy; SDL_Rect area; if (pDiplomat_Dlg) { return; } is_unit_move_blocked = TRUE; pCity = tile_city(ptile); spy = unit_has_type_flag(pUnit, F_SPY); pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = pUnit->id; pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG)); /* window */ if (pCity) { if(spy) { pStr = create_str16_from_char(_("Choose Your Spy's Strategy") , adj_font(12)); } else { pStr = create_str16_from_char(_("Choose Your Diplomat's Strategy"), adj_font(12)); } } else { pStr = create_str16_from_char(_("Subvert Enemy Unit"), adj_font(12)); } pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = diplomat_dlg_window_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_CARAVAN_DLG_WINDOW, pWindow); pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow; area = pWindow->area; area.w = MAX(area.w, adj_size(8)); area.h = MAX(area.h, adj_size(2)); /* ---------- */ if((pCity)) { /* Spy/Diplomat acting against a city */ pDiplomat_Dlg->diplomat_target_id = pCity->id; /* -------------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_EMBASSY, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Establish Embassy"), diplomat_embassy_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_INVESTIGATE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Investigate City"), diplomat_investigate_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (spy && diplomat_can_do_action(pUnit, SPY_POISON, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Poison City"), spy_poison_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_SABOTAGE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Sabotage City"), spy ? spy_sabotage_request : diplomat_sabotage_callback); pBuf->data.city = pCity; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_STEAL, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Steal Technology"), spy ? spy_steal_popup : diplomat_steal_callback); pBuf->data.city = pCity; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_INCITE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Incite a Revolt"), diplomat_incite_callback); pBuf->data.city = pCity; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_MOVE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Keep moving"), diplomat_keep_moving_callback); pBuf->data.city = pCity; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } } else { if((pTunit=unit_list_get(ptile->units, 0))){ /* Spy/Diplomat acting against a unit */ pDiplomat_Dlg->diplomat_target_id = pTunit->id; /* ---------- */ if (diplomat_can_do_action(pUnit, DIPLOMAT_BRIBE, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Bribe Enemy Unit"), diplomat_bribe_callback); pBuf->data.unit = pTunit; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } /* ---------- */ if (diplomat_can_do_action(pUnit, SPY_SABOTAGE_UNIT, ptile)) { create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Sabotage Enemy Unit"), spy_sabotage_unit_callback); pBuf->data.unit = pTunit; set_wstate(pBuf , FC_WS_NORMAL); add_to_gui_list(MAX_ID - pUnit->id , pBuf); area.w = MAX(area.w , pBuf->size.w); area.h += pBuf->size.h; } } } /* ---------- */ create_active_iconlabel(pBuf, pWindow->dst, pStr, _("Cancel"), diplomat_close_callback); set_wstate(pBuf , FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_LABEL , pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; /* ---------- */ pDiplomat_Dlg->pdialog->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, pUnit->tile); /* setup widget size and start position */ pBuf = pWindow->prev; setup_vertical_widgets_position(1, area.x, area.y + 1, area.w, 0, pDiplomat_Dlg->pdialog->pBeginWidgetList, pBuf); /* --------------------- */ /* redraw */ redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, 0); widget_flush(pWindow); }
enum Edit_Return_Codes edit_field(struct widget *pEdit_Widget) { struct EDIT pEdt; struct UniChar ___last; struct UniChar *pInputChain_TMP = NULL; enum Edit_Return_Codes ret; void *backup = pEdit_Widget->data.ptr; pEdt.pWidget = pEdit_Widget; pEdt.ChainLen = 0; pEdt.Truelength = 0; pEdt.Start_X = adj_size(5); pEdt.InputChain_X = 0; pEdit_Widget->data.ptr = (void *)&pEdt; SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); pEdt.pBg = create_bcgnd_surf(pEdit_Widget->theme, 2, pEdit_Widget->size.w, pEdit_Widget->size.h); /* Creating Chain */ pEdt.pBeginTextChain = text2chain(pEdit_Widget->string16->text); /* Creating Empty (Last) pice of Chain */ pEdt.pInputChain = &___last; pEdt.pEndTextChain = pEdt.pInputChain; pEdt.pEndTextChain->chr[0] = 32; /*spacebar */ pEdt.pEndTextChain->chr[1] = 0; /*spacebar */ pEdt.pEndTextChain->next = NULL; pEdt.pEndTextChain->prev = NULL; /* set font style (if any ) */ if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pEdit_Widget->string16->font, (pEdit_Widget->string16->style & 0x0F)); } pEdt.pEndTextChain->pTsurf = TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font, pEdt.pEndTextChain->chr, pEdit_Widget->string16->fgcol); /* create surface for each font in chain and find chain length */ if (pEdt.pBeginTextChain) { pInputChain_TMP = pEdt.pBeginTextChain; while (TRUE) { pEdt.ChainLen++; pInputChain_TMP->pTsurf = TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font, pInputChain_TMP->chr, pEdit_Widget->string16->fgcol); pEdt.Truelength += pInputChain_TMP->pTsurf->w; if (pInputChain_TMP->next == NULL) { break; } pInputChain_TMP = pInputChain_TMP->next; } /* set terminator of list */ pInputChain_TMP->next = pEdt.pInputChain; pEdt.pInputChain->prev = pInputChain_TMP; pInputChain_TMP = NULL; } else { pEdt.pBeginTextChain = pEdt.pInputChain; } redraw_edit_chain(&pEdt); set_wstate(pEdit_Widget, FC_WS_PRESSED); { /* local loop */ Uint16 rety = gui_event_loop((void *)&pEdt, NULL, edit_key_down, NULL, edit_mouse_button_down, NULL, NULL); if (pEdt.pBeginTextChain == pEdt.pEndTextChain) { pEdt.pBeginTextChain = NULL; } if (rety == MAX_ID) { ret = ED_FORCE_EXIT; } else { ret = (enum Edit_Return_Codes) rety; /* this is here becouse we have no knowladge that pEdit_Widget exist or nor in force exit mode from gui loop */ /* reset font settings */ if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pEdit_Widget->string16->font, TTF_STYLE_NORMAL); } if(ret != ED_ESC) { FC_FREE(pEdit_Widget->string16->text); pEdit_Widget->string16->text = chain2text(pEdt.pBeginTextChain, pEdt.ChainLen); pEdit_Widget->string16->n_alloc = (pEdt.ChainLen + 1) * sizeof(Uint16); } pEdit_Widget->data.ptr = backup; set_wstate(pEdit_Widget, FC_WS_NORMAL); } } FREESURFACE(pEdt.pEndTextChain->pTsurf); del_chain(pEdt.pBeginTextChain); FREESURFACE(pEdt.pBg); /* disable repeate key */ SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); /* disable Unicode */ SDL_EnableUNICODE(0); return ret; }
/************************************************************************** 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); }
/************************************************************************** Do any necessary pre-initialization of the UI, if necessary. **************************************************************************/ void ui_init(void) { char device[20]; /* struct widget *pInit_String = NULL;*/ SDL_Surface *pBgd; Uint32 iSDL_Flags; button_behavior.counting = FALSE; button_behavior.button_down_ticks = 0; button_behavior.hold_state = MB_HOLD_SHORT; button_behavior.event = fc_calloc(1, sizeof(SDL_MouseButtonEvent)); SDL_Client_Flags = 0; iSDL_Flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; /* auto center new windows in X enviroment */ putenv((char *)"SDL_VIDEO_CENTERED=yes"); init_sdl(iSDL_Flags); log_normal(_("Using Video Output: %s"), SDL_VideoDriverName(device, sizeof(device))); /* create splash screen */ #ifdef SMALL_SCREEN { SDL_Surface *pTmpSurf = load_surf(fileinfoname(get_data_dirs(), "misc/intro.png")); pBgd = zoomSurface(pTmpSurf, DEFAULT_ZOOM, DEFAULT_ZOOM, 0); FREESURFACE(pTmpSurf); } #else /* SMALL_SCREEN */ pBgd = load_surf(fileinfoname(get_data_dirs(), "misc/intro.png")); #endif /* SMALL_SCREEN */ if (pBgd && SDL_GetVideoInfo()->wm_available) { set_video_mode(pBgd->w, pBgd->h, SDL_SWSURFACE | SDL_ANYFORMAT); #if 0 /* * call this for other than X enviroments - currently not supported. */ center_main_window_on_screen(); #endif /* 0 */ alphablit(pBgd, NULL, Main.map, NULL); putframe(Main.map, 0, 0, Main.map->w - 1, Main.map->h - 1, &(SDL_Color) { 255, 255, 255, 255 }); FREESURFACE(pBgd); SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); } else { #ifndef SMALL_SCREEN set_video_mode(640, 480, SDL_SWSURFACE | SDL_ANYFORMAT); #else /* SMALL_SCREEN */ set_video_mode(320, 240, SDL_SWSURFACE | SDL_ANYFORMAT); #endif /* SMALL_SCREEN */ if(pBgd) { blit_entire_src(pBgd, Main.map, (Main.map->w - pBgd->w) / 2, (Main.map->h - pBgd->h) / 2); FREESURFACE(pBgd); } else { SDL_FillRect(Main.map, NULL, SDL_MapRGB(Main.map->format, 0, 0, 128)); SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); } } #if 0 /* create label beackground */ pBgd = create_surf_alpha(adj_size(350), adj_size(50), SDL_SWSURFACE); SDL_FillRect(pBgd, NULL, SDL_MapRGBA(pBgd->format, 255, 255, 255, 128)); putframe(pBgd, 0, 0, pBgd->w - 1, pBgd->h - 1, SDL_MapRGB(pBgd->format, 0, 0, 0)); pInit_String = create_iconlabel(pBgd, Main.gui, create_str16_from_char(_("Initializing Client"), adj_font(20)), WF_ICON_CENTER|WF_FREE_THEME); pInit_String->string16->style |= SF_CENTER; draw_label(pInit_String, (Main.screen->w - pInit_String->size.w) / 2, (Main.screen->h - pInit_String->size.h) / 2); flush_all(); copy_chars_to_string16(pInit_String->string16, _("Waiting for the beginning of the game")); #endif /* 0 */ flush_all(); }
/************************************************************************** This functions are pure madness :) Create Edit Field surface ( with Text) and blit them to Main.screen, on position 'pEdit_Widget->size.x , pEdit_Widget->size.y' Main role of this functions are been text input to GUI. This code allow you to add, del unichar from unistring. Graphic is taken from 'pEdit_Widget->theme' OldText is taken from 'pEdit_Widget->sting16' NewText is returned to 'pEdit_Widget->sting16' ( after free OldText ) if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit transparent ( Alpha = 128 ) NOTE: This functions can return NULL in 'pEdit_Widget->sting16->text' but never free 'pEdit_Widget->sting16' struct. **************************************************************************/ static Uint16 edit_key_down(SDL_keysym Key, void *pData) { struct EDIT *pEdt = (struct EDIT *)pData; struct UniChar *pInputChain_TMP; bool Redraw = FALSE; /* find which key is pressed */ switch (Key.sym) { case SDLK_ESCAPE: /* exit from loop without changes */ return ED_ESC; case SDLK_RETURN: case SDLK_KP_ENTER: /* exit from loop */ return ED_RETURN; case SDLK_KP6: if(Key.mod & KMOD_NUM) { goto INPUT; } case SDLK_RIGHT: { /* move cursor right */ if (pEdt->pInputChain->next) { if (pEdt->InputChain_X >= (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(10))) { pEdt->Start_X -= pEdt->pInputChain->pTsurf->w - (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(5) - pEdt->InputChain_X); } pEdt->pInputChain = pEdt->pInputChain->next; Redraw = TRUE; } } break; case SDLK_KP4: if(Key.mod & KMOD_NUM) { goto INPUT; } case SDLK_LEFT: { /* move cursor left */ if (pEdt->pInputChain->prev) { pEdt->pInputChain = pEdt->pInputChain->prev; if ((pEdt->InputChain_X <= (pEdt->pWidget->size.x + adj_size(9))) && (pEdt->Start_X != adj_size(5))) { if (pEdt->InputChain_X != (pEdt->pWidget->size.x + adj_size(5))) { pEdt->Start_X += (pEdt->pWidget->size.x - pEdt->InputChain_X + adj_size(5)); } pEdt->Start_X += (pEdt->pInputChain->pTsurf->w); } Redraw = TRUE; } } break; case SDLK_KP7: if(Key.mod & KMOD_NUM) { goto INPUT; } case SDLK_HOME: { /* move cursor to begin of chain (and edit field) */ pEdt->pInputChain = pEdt->pBeginTextChain; Redraw = TRUE; pEdt->Start_X = adj_size(5); } break; case SDLK_KP1: if(Key.mod & KMOD_NUM) { goto INPUT; } case SDLK_END: { /* move cursor to end of chain (and edit field) */ pEdt->pInputChain = pEdt->pEndTextChain; Redraw = TRUE; if (pEdt->pWidget->size.w - pEdt->Truelength < 0) { pEdt->Start_X = pEdt->pWidget->size.w - pEdt->Truelength - adj_size(5); } } break; case SDLK_BACKSPACE: { /* del element of chain (and move cursor left) */ if (pEdt->pInputChain->prev) { if ((pEdt->InputChain_X <= (pEdt->pWidget->size.x + adj_size(9))) && (pEdt->Start_X != adj_size(5))) { if (pEdt->InputChain_X != (pEdt->pWidget->size.x + adj_size(5))) { pEdt->Start_X += (pEdt->pWidget->size.x - pEdt->InputChain_X + adj_size(5)); } pEdt->Start_X += (pEdt->pInputChain->prev->pTsurf->w); } if (pEdt->pInputChain->prev->prev) { pEdt->pInputChain->prev->prev->next = pEdt->pInputChain; pInputChain_TMP = pEdt->pInputChain->prev->prev; pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w; FREESURFACE(pEdt->pInputChain->prev->pTsurf); FC_FREE(pEdt->pInputChain->prev); pEdt->pInputChain->prev = pInputChain_TMP; } else { pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w; FREESURFACE(pEdt->pInputChain->prev->pTsurf); FC_FREE(pEdt->pInputChain->prev); pEdt->pBeginTextChain = pEdt->pInputChain; } pEdt->ChainLen--; Redraw = TRUE; } } break; case SDLK_KP_PERIOD: if(Key.mod & KMOD_NUM) { goto INPUT; } case SDLK_DELETE: { /* del element of chain */ if (pEdt->pInputChain->next && pEdt->pInputChain->prev) { pEdt->pInputChain->prev->next = pEdt->pInputChain->next; pEdt->pInputChain->next->prev = pEdt->pInputChain->prev; pInputChain_TMP = pEdt->pInputChain->next; pEdt->Truelength -= pEdt->pInputChain->pTsurf->w; FREESURFACE(pEdt->pInputChain->pTsurf); FC_FREE(pEdt->pInputChain); pEdt->pInputChain = pInputChain_TMP; pEdt->ChainLen--; Redraw = TRUE; } if (pEdt->pInputChain->next && !pEdt->pInputChain->prev) { pEdt->pInputChain = pEdt->pInputChain->next; pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w; FREESURFACE(pEdt->pInputChain->prev->pTsurf); FC_FREE(pEdt->pInputChain->prev); pEdt->pBeginTextChain = pEdt->pInputChain; pEdt->ChainLen--; Redraw = TRUE; } } break; default: { INPUT:/* add new element of chain (and move cursor right) */ if (Key.unicode) { if (pEdt->pInputChain != pEdt->pBeginTextChain) { pInputChain_TMP = pEdt->pInputChain->prev; pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar)); pEdt->pInputChain->prev->next = pEdt->pInputChain; pEdt->pInputChain->prev->prev = pInputChain_TMP; pInputChain_TMP->next = pEdt->pInputChain->prev; } else { pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar)); pEdt->pInputChain->prev->next = pEdt->pInputChain; pEdt->pBeginTextChain = pEdt->pInputChain->prev; } pEdt->pInputChain->prev->chr[0] = Key.unicode; pEdt->pInputChain->prev->chr[1] = '\0'; if (pEdt->pInputChain->prev->chr) { if (get_wflags(pEdt->pWidget) & WF_PASSWD_EDIT) { Uint16 passwd_chr[2] = {'*', '\0'}; pEdt->pInputChain->prev->pTsurf = TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font, passwd_chr, pEdt->pWidget->string16->fgcol); } else { pEdt->pInputChain->prev->pTsurf = TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font, pEdt->pInputChain->prev->chr, pEdt->pWidget->string16->fgcol); } pEdt->Truelength += pEdt->pInputChain->prev->pTsurf->w; } if (pEdt->InputChain_X >= pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(10)) { if (pEdt->pInputChain == pEdt->pEndTextChain) { pEdt->Start_X = pEdt->pBg->w - adj_size(5) - pEdt->Truelength; } else { pEdt->Start_X -= pEdt->pInputChain->prev->pTsurf->w - (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(5) - pEdt->InputChain_X); } } pEdt->ChainLen++; Redraw = TRUE; } } break; } /* key pressed switch */ if (Redraw) { redraw_edit_chain(pEdt); } return ID_ERROR; }
/************************************************************************** Popup a dialog asking a diplomatic unit if it wishes to bribe the given enemy unit. **************************************************************************/ void popup_bribe_dialog(struct unit *pUnit, int cost) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_String16 *pStr; struct unit *pDiplomatUnit; char tBuf[255], cBuf[255]; bool exit = FALSE; SDL_Rect area; if (pBribe_Dlg) { return; } /* ugly hack */ pDiplomatUnit = head_of_units_in_focus(); if (!pDiplomatUnit || !is_diplomat_unit(pDiplomatUnit)) { return; } is_unit_move_blocked = TRUE; pBribe_Dlg = fc_calloc(1, sizeof(struct small_diplomat_dialog)); pBribe_Dlg->diplomat_id = pDiplomatUnit->id; pBribe_Dlg->diplomat_target_id = pUnit->id; pBribe_Dlg->pdialog = fc_calloc(1, sizeof(struct SMALL_DLG)); fc_snprintf(tBuf, ARRAY_SIZE(tBuf), PL_("Treasury contains %d gold.", "Treasury contains %d gold.", client_player()->economic.gold), client_player()->economic.gold); /* window */ pStr = create_str16_from_char(_("Bribe Enemy Unit"), adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = bribe_dlg_window_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_BRIBE_DLG_WINDOW, pWindow); pBribe_Dlg->pdialog->pEndWidgetList = pWindow; area = pWindow->area; area.w = MAX(area.w, adj_size(8)); area.h = MAX(area.h, adj_size(2)); if (cost <= client_player()->economic.gold) { fc_snprintf(cBuf, sizeof(cBuf), /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */ PL_("Bribe unit for %d gold?\n%s", "Bribe unit for %d gold?\n%s", cost), cost, tBuf); create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL); 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, _("Yes"), diplomat_bribe_yes_callback); pBuf->data.unit = pUnit; set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(MAX_ID - pDiplomatUnit->id, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; /* ------- */ create_active_iconlabel(pBuf, pWindow->dst, pStr, _("No") , exit_bribe_dlg_callback); set_wstate(pBuf , FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } else { /* 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)); area.w += pBuf->size.w + adj_size(10); pBuf->action = exit_bribe_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BRIBE_DLG_EXIT_BUTTON, pBuf); exit = TRUE; /* --------------- */ fc_snprintf(cBuf, sizeof(cBuf), /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */ PL_("Bribing the unit costs %d gold.\n%s", "Bribing the unit costs %d gold.\n%s", cost), cost, tBuf); create_active_iconlabel(pBuf, pWindow->dst, pStr, cBuf, NULL); 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, _("Traitors Demand Too Much!"), NULL); add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(area.w, pBuf->size.w); area.h += pBuf->size.h; } pBribe_Dlg->pdialog->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, pDiplomatUnit->tile); /* setup widget size and start position */ pBuf = pWindow; if (exit) {/* exit button */ pBuf = pBuf->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); } pBuf = pBuf->prev; setup_vertical_widgets_position(1, area.x, area.y + 1, area.w, 0, pBribe_Dlg->pdialog->pBeginWidgetList, pBuf); /* --------------------- */ /* redraw */ redraw_group(pBribe_Dlg->pdialog->pBeginWidgetList, pWindow, 0); widget_flush(pWindow); }
/************************************************************************** Create Edit Field surface ( with Text) and blit them to Main.screen, on position 'pEdit_Widget->size.x , pEdit_Widget->size.y' Graphic is taken from 'pEdit_Widget->theme' Text is taken from 'pEdit_Widget->sting16' if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit transparent ( Alpha = 128 ) function return Hight of created surfaces or (-1) if theme surface can't be created. **************************************************************************/ static int redraw_edit(struct widget *pEdit_Widget) { int ret; if (get_wstate(pEdit_Widget) == FC_WS_PRESSED) { return redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr); } else { int iRet = 0; SDL_Rect rDest = {pEdit_Widget->size.x, pEdit_Widget->size.y, 0, 0}; SDL_Surface *pEdit = NULL; SDL_Surface *pText; ret = (*baseclass_redraw)(pEdit_Widget); if (ret != 0) { return ret; } if (pEdit_Widget->string16->text && get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) { Uint16 *backup = pEdit_Widget->string16->text; size_t len = unistrlen(backup) + 1; char *cBuf = fc_calloc(1, len); memset(cBuf, '*', len - 1); cBuf[len - 1] = '\0'; pEdit_Widget->string16->text = convert_to_utf16(cBuf); pText = create_text_surf_from_str16(pEdit_Widget->string16); FC_FREE(pEdit_Widget->string16->text); FC_FREE(cBuf); pEdit_Widget->string16->text = backup; } else { pText = create_text_surf_from_str16(pEdit_Widget->string16); } pEdit = create_bcgnd_surf(pEdit_Widget->theme, get_wstate(pEdit_Widget), pEdit_Widget->size.w, pEdit_Widget->size.h); if (!pEdit) { return -1; } /* blit theme */ alphablit(pEdit, NULL, pEdit_Widget->dst->surface, &rDest); /* set position and blit text */ if (pText) { rDest.y += (pEdit->h - pText->h) / 2; /* blit centred text to botton */ if (pEdit_Widget->string16->style & SF_CENTER) { rDest.x += (pEdit->w - pText->w) / 2; } else { if (pEdit_Widget->string16->style & SF_CENTER_RIGHT) { rDest.x += pEdit->w - pText->w - adj_size(5); } else { rDest.x += adj_size(5); /* cennter left */ } } alphablit(pText, NULL, pEdit_Widget->dst->surface, &rDest); } /* pText */ iRet = pEdit->h; /* Free memory */ FREESURFACE(pText); FREESURFACE(pEdit); return iRet; } return 0; }
/************************************************************************** ... **************************************************************************/ static void show_main_page(void) { SDL_Color bg_color = {255, 255, 255, 96}; SDL_Color *line_color = &(SDL_Color) { 128, 128, 128, 255 }; int count = 0; struct widget *pWidget = NULL, *pWindow = NULL; SDL_Surface *pBackground; int h = 0; SDL_Rect area; char verbuf[200]; /* create dialog */ pStartMenu = fc_calloc(1, sizeof(struct SMALL_DLG)); pWindow = create_window_skeleton(NULL, NULL, 0); add_to_gui_list(ID_WINDOW, pWindow); pStartMenu->pEndWidgetList = pWindow; area = pWindow->area; /* Freeciv version */ /* TRANS: Freeciv 2.4.0, gui-sdl client */ fc_snprintf(verbuf, sizeof(verbuf), _("Freeciv %s, %s client"), VERSION_STRING, client_string); pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, verbuf, adj_font(12), (WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA)); pWidget->string16->style |= SF_CENTER | TTF_STYLE_BOLD; area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; add_to_gui_list(ID_LABEL, pWidget); /* Start New Game */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Start New Game"), adj_font(14), (WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA)); pWidget->action = start_new_game_callback; pWidget->string16->style |= SF_CENTER; set_wstate(pWidget, FC_WS_NORMAL); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; add_to_gui_list(ID_START_NEW_GAME, pWidget); /* Load Game */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Load Game"), adj_font(14), (WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND)); pWidget->action = load_game_callback; pWidget->string16->style |= SF_CENTER; set_wstate(pWidget, FC_WS_NORMAL); add_to_gui_list(ID_LOAD_GAME, pWidget); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; /* Join Game */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join Game"), adj_font(14), WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND); pWidget->action = join_game_callback; pWidget->string16->style |= SF_CENTER; set_wstate(pWidget, FC_WS_NORMAL); add_to_gui_list(ID_JOIN_GAME, pWidget); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; /* Join Pubserver */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join Pubserver"), adj_font(14), WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND); pWidget->action = servers_callback; pWidget->string16->style |= SF_CENTER; set_wstate(pWidget, FC_WS_NORMAL); add_to_gui_list(ID_JOIN_META_GAME, pWidget); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; /* Join LAN Server */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join LAN Server"), adj_font(14), WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND); pWidget->action = servers_callback; pWidget->string16->style |= SF_CENTER; set_wstate(pWidget, FC_WS_NORMAL); add_to_gui_list(ID_JOIN_GAME, pWidget); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; /* Options */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Options"), adj_font(14), WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND); pWidget->action = options_callback; pWidget->string16->style |= SF_CENTER; set_wstate(pWidget, FC_WS_NORMAL); add_to_gui_list(ID_CLIENT_OPTIONS_BUTTON, pWidget); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; /* Quit */ pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Quit"), adj_font(14), WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND); pWidget->action = quit_callback; pWidget->string16->style |= SF_CENTER; pWidget->key = SDLK_ESCAPE; set_wstate(pWidget, FC_WS_NORMAL); add_to_gui_list(ID_QUIT, pWidget); area.w = MAX(area.w, pWidget->size.w); h = MAX(h, pWidget->size.h); count++; pStartMenu->pBeginWidgetList = pWidget; /* ------*/ area.w += adj_size(30); h += adj_size(6); area.h = MAX(area.h, h * count); /* ------*/ pBackground = theme_get_background(theme, BACKGROUND_STARTMENU); if (resize_window(pWindow, pBackground, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h - pWindow->area.h) + area.h)) { FREESURFACE(pBackground); } area = pWindow->area; group_set_area(pWidget, pWindow->prev, area); setup_vertical_widgets_position(1, area.x, area.y, area.w, h, pWidget, pWindow->prev); area.h = h; SDL_FillRectAlpha(pWindow->theme, &area, &bg_color); widget_set_position(pWindow, (Main.screen->w - pWindow->size.w) - adj_size(20), (Main.screen->h - pWindow->size.h) - adj_size(20)); draw_intro_gfx(); redraw_group(pStartMenu->pBeginWidgetList, pStartMenu->pEndWidgetList, FALSE); putline(pWindow->dst->surface, area.x, area.y + (h - 1), area.x + area.w - 1, area.y + (h - 1), line_color); set_output_window_text(_("SDLClient welcomes you...")); chat_welcome_message(); meswin_dialog_popup(TRUE); flush_all(); }
/************************************************************************** Correct backgroud size ( set min size ). Used in create widget functions. **************************************************************************/ void correct_size_bcgnd_surf(SDL_Surface * pTheme, Uint16 * pWidth, Uint16 * pHigh) { *pWidth = MAX(*pWidth, 2 * (pTheme->w / adj_size(16))); *pHigh = MAX(*pHigh, 2 * (pTheme->h / adj_size(16))); }
/************************************************************************** ... **************************************************************************/ void redraw_widget_info_label(SDL_Rect *rect) { SDL_Surface *pText, *pBcgd; SDL_Rect srcrect, dstrect; SDL_Color color; struct widget *pWidget = pSellected_Widget; if (!pWidget || !pWidget->info_label) { return; } if (!pInfo_Label) { pInfo_Area = fc_calloc(1, sizeof(SDL_Rect)); color = pWidget->info_label->fgcol; pWidget->info_label->style |= TTF_STYLE_BOLD; pWidget->info_label->fgcol = *get_theme_color(COLOR_THEME_QUICK_INFO_TEXT); /* create string and bcgd theme */ pText = create_text_surf_from_str16(pWidget->info_label); pWidget->info_label->fgcol = color; pBcgd = create_filled_surface(pText->w + adj_size(10), pText->h + adj_size(6), SDL_SWSURFACE, get_theme_color(COLOR_THEME_QUICK_INFO_BG), TRUE); /* calculate start position */ if ((pWidget->dst->dest_rect.y + pWidget->size.y) - pBcgd->h - adj_size(6) < 0) { pInfo_Area->y = (pWidget->dst->dest_rect.y + pWidget->size.y) + pWidget->size.h + adj_size(3); } else { pInfo_Area->y = (pWidget->dst->dest_rect.y + pWidget->size.y) - pBcgd->h - adj_size(5); } if ((pWidget->dst->dest_rect.x + pWidget->size.x) + pBcgd->w + adj_size(5) > Main.screen->w) { pInfo_Area->x = (pWidget->dst->dest_rect.x + pWidget->size.x) - pBcgd->w - adj_size(5); } else { pInfo_Area->x = (pWidget->dst->dest_rect.x + pWidget->size.x) + adj_size(3); } pInfo_Area->w = pBcgd->w + adj_size(2); pInfo_Area->h = pBcgd->h + adj_size(3); pInfo_Label = SDL_DisplayFormatAlpha(pBcgd); FREESURFACE(pBcgd); /* draw text */ dstrect.x = adj_size(6); dstrect.y = adj_size(3); alphablit(pText, NULL, pInfo_Label, &dstrect); FREESURFACE(pText); /* draw frame */ putframe(pInfo_Label, 0, 0, pInfo_Label->w - 1, pInfo_Label->h - 1, get_theme_color(COLOR_THEME_QUICK_INFO_FRAME)); } if (rect) { dstrect.x = MAX(rect->x, pInfo_Area->x); dstrect.y = MAX(rect->y, pInfo_Area->y); srcrect.x = dstrect.x - pInfo_Area->x; srcrect.y = dstrect.y - pInfo_Area->y; srcrect.w = MIN((pInfo_Area->x + pInfo_Area->w), (rect->x + rect->w)) - dstrect.x; srcrect.h = MIN((pInfo_Area->y + pInfo_Area->h), (rect->y + rect->h)) - dstrect.y; alphablit(pInfo_Label, &srcrect, Main.screen, &dstrect); } else { alphablit(pInfo_Label, NULL, Main.screen, pInfo_Area); } if (correct_rect_region(pInfo_Area)) { SDL_UpdateRect(Main.screen, pInfo_Area->x, pInfo_Area->y, pInfo_Area->w, pInfo_Area->h); } return; }
/************************************************************************** Popup (or raise) the short player list dialog version. **************************************************************************/ void popup_players_nations_dialog(void) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_Surface *pLogo = NULL; SDL_String16 *pStr; char cBuf[128], *state; int n = 0, w = 0, units_h = 0; const struct player_diplstate *pDS; SDL_Rect area; if (pShort_Players_Dlg) { return; } pShort_Players_Dlg = fc_calloc(1, sizeof(struct ADVANCED_DLG)); /* TRANS: Nations report title */ pStr = create_str16_from_char(_("Nations") , adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = players_nations_window_dlg_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_WINDOW, pWindow); pShort_Players_Dlg->pEndWidgetList = pWindow; area = pWindow->area; /* ---------- */ /* 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)); area.w = MAX(area.w, pBuf->size.w + adj_size(10)); pBuf->action = exit_players_nations_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BUTTON, pBuf); /* ---------- */ players_iterate(pPlayer) { if (pPlayer != client.conn.playing) { if(!pPlayer->is_alive || is_barbarian(pPlayer)) { continue; } pDS = player_diplstate_get(client.conn.playing, pPlayer); if(pPlayer->ai_controlled) { state = _("AI"); } else { if (pPlayer->is_connected) { if (pPlayer->phase_done) { state = _("done"); } else { state = _("moving"); } } else { state = _("disconnected"); } } if(pDS->type == DS_CEASEFIRE) { fc_snprintf(cBuf, sizeof(cBuf), "%s(%s) - %d %s", nation_adjective_for_player(pPlayer), state, pDS->turns_left, PL_("turn", "turns", pDS->turns_left)); } else { fc_snprintf(cBuf, sizeof(cBuf), "%s(%s)", nation_adjective_for_player(pPlayer), state); } pStr = create_str16_from_char(cBuf, adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pLogo = get_nation_flag_surface(nation_of_player(pPlayer)); pBuf = create_iconlabel(pLogo, pWindow->dst, pStr, (/*WF_FREE_THEME|*/WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE)); /* now add some eye candy ... */ switch (pDS->type) { case DS_ARMISTICE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_WAR: if(can_meet_with_player(pPlayer) || can_intel_with_player(pPlayer)) { set_wstate(pBuf, FC_WS_NORMAL); pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR); } else { pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_PLRDLG_WAR_RESTRICTED)); } break; case DS_CEASEFIRE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_PEACE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_ALLIANCE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_NO_CONTACT: pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT)); break; default: set_wstate(pBuf, FC_WS_NORMAL); break; } pBuf->string16->bgcol = (SDL_Color) {0, 0, 0, 0}; pBuf->data.player = pPlayer; pBuf->action = player_nation_callback; add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(w, pBuf->size.w); area.h += pBuf->size.h; if (n > 19) { set_wflag(pBuf, WF_HIDDEN); } n++; } } players_iterate_end; pShort_Players_Dlg->pBeginWidgetList = pBuf; pShort_Players_Dlg->pBeginActiveWidgetList = pShort_Players_Dlg->pBeginWidgetList; pShort_Players_Dlg->pEndActiveWidgetList = pWindow->prev->prev; pShort_Players_Dlg->pActiveWidgetList = pShort_Players_Dlg->pEndActiveWidgetList; /* ---------- */ if (n > 20) { units_h = create_vertical_scrollbar(pShort_Players_Dlg, 1, 20, TRUE, TRUE); pShort_Players_Dlg->pScroll->count = n; n = units_h; area.w += n; units_h = 20 * pBuf->size.h; } else { units_h = area.h; } /* ---------- */ area.h = units_h; resize_window(pWindow, NULL, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h + pWindow->area.h) + area.h); area = pWindow->area; widget_set_position(pWindow, ((Main.event.motion.x + pWindow->size.w + adj_size(10) < Main.screen->w) ? (Main.event.motion.x + adj_size(10)) : (Main.screen->w - pWindow->size.w - adj_size(10))), ((Main.event.motion.y - adj_size(2) + pWindow->size.h < Main.screen->h) ? (Main.event.motion.y - adj_size(2)) : (Main.screen->h - pWindow->size.h - adj_size(10)))); w = area.w; if (pShort_Players_Dlg->pScroll) { w -= n; } /* 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); /* cities */ pBuf = pBuf->prev; setup_vertical_widgets_position(1, area.x, area.y, w, 0, pShort_Players_Dlg->pBeginActiveWidgetList, pBuf); if (pShort_Players_Dlg->pScroll) { setup_vertical_scrollbar_area(pShort_Players_Dlg->pScroll, area.x + area.w, area.y, area.h, TRUE); } /* -------------------- */ /* redraw */ redraw_group(pShort_Players_Dlg->pBeginWidgetList, pWindow, 0); widget_mark_dirty(pWindow); flush_dirty(); }
/************************************************************************** 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(); }
/************************************************************************** Create ( malloc ) Icon (theme)Button Widget structure. Icon graphic is taken from 'pIcon' surface (don't change with button changes ); Button Theme graphic is taken from pTheme->Button surface; Text is taken from 'pString16'. This function determinate future size of Button ( width, high ) and save this in: pWidget->size rectangle ( SDL_Rect ) function return pointer to allocated Button Widget. **************************************************************************/ struct widget * create_icon_button(SDL_Surface *pIcon, struct gui_layer *pDest, SDL_String16 *pStr, Uint32 flags) { SDL_Rect buf = {0, 0, 0, 0}; int w = 0, h = 0; struct widget *pButton; if (!pIcon && !pStr) { return NULL; } pButton = widget_new(); pButton->theme = pTheme->Button; pButton->theme2 = pIcon; pButton->string16 = pStr; set_wflag(pButton, (WF_FREE_STRING | flags)); set_wstate(pButton, FC_WS_DISABLED); set_wtype(pButton, WT_I_BUTTON); pButton->mod = KMOD_NONE; pButton->dst = pDest; baseclass_redraw = pButton->redraw; pButton->redraw = redraw_ibutton; if (pStr) { pButton->string16->style |= SF_CENTER; /* if BOLD == true then longest wight */ if (!(pStr->style & TTF_STYLE_BOLD)) { pStr->style |= TTF_STYLE_BOLD; buf = str16size(pStr); pStr->style &= ~TTF_STYLE_BOLD; } else { buf = str16size(pStr); } w = MAX(w, buf.w); h = MAX(h, buf.h); } if (pIcon) { if (pStr) { if ((flags & WF_ICON_UNDER_TEXT) || (flags & WF_ICON_ABOVE_TEXT)) { w = MAX(w, pIcon->w + adj_size(2)); h = MAX(h, buf.h + pIcon->h + adj_size(4)); } else { w = MAX(w, buf.w + pIcon->w + adj_size(20)); h = MAX(h, pIcon->h + adj_size(2)); } } else { w = MAX(w, pIcon->w + adj_size(2)); h = MAX(h, pIcon->h + adj_size(2)); } } else { w += adj_size(10); h += adj_size(2); } correct_size_bcgnd_surf(pTheme->Button, &w, &h); pButton->size.w = w; pButton->size.h = h; return pButton; }
/* ** make_mac_volume: "create" an HFS volume using the ISO data ** ** The HFS volume structures are set up (but no data is written yet). ** ** ISO volumes have a allocation size of 2048 bytes - regardless ** of the size of the volume. HFS allocation size is depends on volume ** size, so we may have to update the ISO structures to add in any ** padding. */ int FDECL2(make_mac_volume, struct directory *, dpnt, int, start_extent) { char vol_name[HFS_MAX_VLEN+1]; /* Mac volume name */ hfsvol *vol; /* Mac volume */ int vlen, vblen; /* vol length (bytes, blocks) */ int Csize, lastCsize; /* allocation sizes */ int ret = 0; /* return value */ int loop = 1; /* umount volume if we have had a previous attempt */ if (vol_save) if (hfs_umount(vol_save, 0) < 0) return (-1); /* set the default clump size to the ISO block size */ lastCsize = SECTOR_SIZE; if (verbose > 1) fprintf(stderr, "Creating HFS Volume info\n"); /* name or copy ISO volume name to Mac Volume name */ strncpy(vol_name, hfs_volume_id ? hfs_volume_id : volume_id, HFS_MAX_VLEN); vol_name[HFS_MAX_VLEN] = '\0'; /* get initial size of HFS volume (size of ISO volume) */ vblen = last_extent * BLK_CONV; /* add on size of extents/catalog file, but this may mean the allocation size will change, so loop round until the allocation size doesn't change */ while (loop) { hce->XTCsize = XClpSiz(vblen); vblen = get_vol_size(vblen); Csize = AlcSiz(vblen); if (Csize == lastCsize) { /* allocation size hasn't changed, so carry on */ loop = 0; } else { /* allocation size has changed, so update ISO volume size */ if ((vlen = get_adj_size(Csize)) < 0) { snprintf(hce->error, ERROR_SIZE, "too many files for HFS volume"); return (-1); } vlen += V_ROUND_UP(start_extent * SECTOR_SIZE, Csize); vblen = vlen / HFS_BLOCKSZ; lastCsize = Csize; } } /* set vlen to size in bytes */ /* vlen = hce->hfs_vol_size = vblen * HFS_BLOCKSZ; */ /* take off the label/map size */ vblen -= hce->hfs_map_size; vlen = hce->hfs_vol_size = vblen * HFS_BLOCKSZ; /* set the default allocation size for libhfs */ hce->Csize = Csize; /* format and mount the "volume" */ if (hfs_format(hce, 0, vol_name) < 0) { snprintf(hce->error, ERROR_SIZE, "can't HFS format %s",vol_name); return(-1); } /* update the ISO structures with new start extents and any padding required */ if (Csize != SECTOR_SIZE) { last_extent = adj_size(Csize, start_extent, hce->hfs_hdr_size + hce->hfs_map_size); adj_size_other(dpnt); } if ((vol = hfs_mount(hce, 0, 0)) == 0) { snprintf(hce->error, ERROR_SIZE, "can't HFS mount %s",vol_name); return(-1); } /* save the volume for possible later use */ vol_save = vol; /* Recursively "copy" the files to the volume - we need to know the first allocation block in the volume as starting blocks of files are relative to this. */ ret = copy_to_mac_vol(vol, dpnt); if (ret < 0) return(ret); /* make the Desktop files - I *think* this stops the Mac rebuilding the desktop when the CD is mounted on a Mac These will be ignored if they already exist */ if (create_dt) ret = make_desktop(vol, last_extent*BLK_CONV); if (ret < 0) return(ret); /* close the volume */ if (hfs_flush(vol) < 0) return(-1); /* unmount and set the start blocks for the catalog/extents files */ if (hfs_umount(vol, last_extent*BLK_CONV) < 0) return(-1); return(Csize); }