/************************************************************************** ... **************************************************************************/ struct widget * create_textcheckbox(struct gui_layer *pDest, bool state, SDL_String16 *pStr, Uint32 flags) { struct widget *pCBox; struct CHECKBOX *pTmp; SDL_Surface *pSurf, *pIcon; struct widget *pTmpWidget; if (!pStr) { return create_checkbox(pDest, state, flags); } pTmp = fc_calloc(1, sizeof(struct CHECKBOX)); if (state) { pSurf = pTheme->CBOX_Sell_Icon; } else { pSurf = pTheme->CBOX_Unsell_Icon; } pIcon = create_icon_from_theme(pSurf, 0); pCBox = create_iconlabel(pIcon, pDest, pStr, (flags | WF_FREE_PRIVATE_DATA)); pStr->style &= ~SF_CENTER; pCBox->theme = pSurf; FREESURFACE(pIcon); set_wtype(pCBox, WT_TCHECKBOX); pTmp->state = state; pTmp->pTRUE_Theme = pTheme->CBOX_Sell_Icon; pTmp->pFALSE_Theme = pTheme->CBOX_Unsell_Icon; pCBox->private_data.cbox = pTmp; pTmpWidget = widget_new(); /* we can't use pCBox->redraw here, because it is of type iconlabel */ textcheckbox_baseclass_redraw = pTmpWidget->redraw; FREEWIDGET(pTmpWidget); pCBox->redraw = redraw_textcheckbox; return pCBox; }
/************************************************************************** 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); } } }
/************************************************************************** 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(); }
/************************************************************************** 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(); }
/**************************************************************** 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); }