/********************************************************************** Set city icons sprite value; should only happen after tileset_load_tiles(tileset). ***********************************************************************/ void tilespec_setup_city_icons(void) { struct sprite *pSpr = NULL; pIcons = ( struct City_Icon *)fc_calloc(1, sizeof( struct City_Icon )); load_city_icon_surface(pSpr, pBIG_Food_Corr, "city.food_waste"); load_city_icon_surface(pSpr, pBIG_Shield_Corr, "city.shield_waste"); load_city_icon_surface(pSpr, pBIG_Trade_Corr, "city.trade_waste"); load_city_icon_surface(pSpr, pBIG_Food, "city.food"); pIcons->pBIG_Food_Surplus = crop_rect_from_surface(pIcons->pBIG_Food, NULL); SDL_SetAlpha(pIcons->pBIG_Food_Surplus, SDL_SRCALPHA, 128); load_city_icon_surface(pSpr, pBIG_Shield, "city.shield"); pIcons->pBIG_Shield_Surplus = crop_rect_from_surface(pIcons->pBIG_Shield, NULL); SDL_SetAlpha(pIcons->pBIG_Shield_Surplus, SDL_SRCALPHA, 128); load_city_icon_surface(pSpr, pBIG_Trade, "city.trade"); load_city_icon_surface(pSpr, pBIG_Luxury, "city.lux"); load_city_icon_surface(pSpr, pBIG_Coin, "city.coin"); load_city_icon_surface(pSpr, pBIG_Colb, "city.colb"); load_city_icon_surface(pSpr, pBIG_Face, "city.red_face"); load_city_icon_surface(pSpr, pBIG_Coin_Corr, "city.dark_coin"); load_city_icon_surface(pSpr, pBIG_Coin_UpKeep, "city.unkeep_coin"); /* small icon */ load_city_icon_surface(pSpr, pFood, "city.small_food"); load_city_icon_surface(pSpr, pShield, "city.small_shield"); load_city_icon_surface(pSpr, pTrade, "city.small_trade"); load_city_icon_surface(pSpr, pFace, "city.small_red_face"); load_city_icon_surface(pSpr, pLuxury, "city.small_lux"); load_city_icon_surface(pSpr, pCoin, "city.small_coin"); load_city_icon_surface(pSpr, pColb, "city.small_colb"); load_city_icon_surface(pSpr, pPollution, "city.pollution"); /* ================================================================= */ load_city_icon_surface(pSpr, pPolice, "city.police"); /* ================================================================= */ pIcons->pWorklist = create_surf_alpha(9,9, SDL_SWSURFACE); SDL_FillRect(pIcons->pWorklist, NULL, SDL_MapRGB(pIcons->pWorklist->format, 255, 255,255)); putframe(pIcons->pWorklist, 0,0, pIcons->pWorklist->w - 1, pIcons->pWorklist->h - 1, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); putline(pIcons->pWorklist, 3, 2, 5, 2, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); putline(pIcons->pWorklist, 3, 4, 7, 4, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); putline(pIcons->pWorklist, 3, 6, 6, 6, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); /* ================================================================= */ /* force reload citizens icons */ pIcons->style = 999; }
/************************************************************************** Create string16 struct with ptsize font. Font will be loaded or aliased with existing font of that size. pInTextString must be allocated in memory (MALLOC/fc_calloc) **************************************************************************/ SDL_String16 * create_string16(Uint16 *pInTextString, size_t n_alloc, Uint16 ptsize) { SDL_String16 *str = fc_calloc(1, sizeof(SDL_String16)); if (!ptsize) { str->ptsize = theme_default_font_size(theme); } else { str->ptsize = ptsize; } if ((str->font = load_font(str->ptsize)) == NULL) { log_error("create_string16: load_font failed"); FC_FREE(str); return str; } str->style = TTF_STYLE_NORMAL; str->bgcol = (SDL_Color) {0, 0, 0, 0}; str->fgcol = *get_game_colorRGB(COLOR_THEME_TEXT); str->render = 2; /* pInTextString must be allocated in memory (MALLOC/fc_calloc) */ str->text = pInTextString; str->n_alloc = n_alloc; return str; }
/************************************************************************** ... **************************************************************************/ SDL_Color * get_tech_color(Tech_type_id tech_id) { if (player_invention_reachable(client.conn.playing, tech_id)) { switch (player_invention_state(client.conn.playing, tech_id)) { case TECH_UNKNOWN: return get_game_colorRGB(COLOR_REQTREE_UNKNOWN); case TECH_KNOWN: return get_game_colorRGB(COLOR_REQTREE_KNOWN); case TECH_PREREQS_KNOWN: return get_game_colorRGB(COLOR_REQTREE_PREREQS_KNOWN); default: return get_game_colorRGB(COLOR_REQTREE_BACKGROUND); } } return get_game_colorRGB(COLOR_REQTREE_UNREACHABLE); }
/************************************************************************** ... **************************************************************************/ 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 redraw_edit_chain(struct EDIT *pEdt) { struct UniChar *pInputChain_TMP; SDL_Rect Dest, Dest_Copy = {0, 0, 0, 0}; int iStart_Mod_X; int ret; Dest_Copy.x = pEdt->pWidget->size.x; Dest_Copy.y = pEdt->pWidget->size.y; ret = (*baseclass_redraw)(pEdt->pWidget); if (ret != 0) { return ret; } /* blit theme */ Dest = Dest_Copy; alphablit(pEdt->pBg, NULL, pEdt->pWidget->dst->surface, &Dest); /* set start parametrs */ pInputChain_TMP = pEdt->pBeginTextChain; iStart_Mod_X = 0; Dest_Copy.y += (pEdt->pBg->h - pInputChain_TMP->pTsurf->h) / 2; Dest_Copy.x += pEdt->Start_X; /* draw loop */ while (pInputChain_TMP) { Dest_Copy.x += iStart_Mod_X; /* chech if we draw inside of edit rect */ if (Dest_Copy.x > pEdt->pWidget->size.x + pEdt->pBg->w - 4) { break; } if (Dest_Copy.x > pEdt->pWidget->size.x) { Dest = Dest_Copy; alphablit(pInputChain_TMP->pTsurf, NULL, pEdt->pWidget->dst->surface, &Dest); } iStart_Mod_X = pInputChain_TMP->pTsurf->w; /* draw cursor */ if (pInputChain_TMP == pEdt->pInputChain) { Dest = Dest_Copy; putline(pEdt->pWidget->dst->surface, Dest.x - 1, Dest.y + (pEdt->pBg->h / 8), Dest.x - 1, Dest.y + pEdt->pBg->h - (pEdt->pBg->h / 4), get_game_colorRGB(COLOR_THEME_EDITFIELD_CARET)); /* save active element position */ pEdt->InputChain_X = Dest_Copy.x; } pInputChain_TMP = pInputChain_TMP->next; } /* while - draw loop */ widget_flush(pEdt->pWidget); return 0; }
/**************************************************************** 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); }