00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038
00039 #include "stratagus.h"
00040
00041 #include <string>
00042 #include <vector>
00043 #include <map>
00044
00045 #include "video.h"
00046 #include "icons.h"
00047 #include "player.h"
00048 #include "ui.h"
00049 #include "menus.h"
00050
00051
00052
00053
00054
00055
00056 static std::vector<CIcon *> AllIcons;
00057 std::map<std::string, CIcon *> Icons;
00058
00059
00060
00061
00062
00063
00067 CIcon::CIcon(const std::string &ident) : G(NULL), Frame(0), Ident(ident)
00068 {
00069 }
00070
00074 CIcon::~CIcon()
00075 {
00076 CGraphic::Free(this->G);
00077 }
00078
00086 CIcon *CIcon::New(const std::string &ident)
00087 {
00088 CIcon *icon = Icons[ident];
00089 if (icon) {
00090 return icon;
00091 } else {
00092 icon = new CIcon(ident);
00093 Icons[ident] = icon;
00094 AllIcons.push_back(icon);
00095 return icon;
00096 }
00097 }
00098
00106 CIcon *CIcon::Get(const std::string &ident)
00107 {
00108 CIcon *icon = Icons[ident];
00109 if (!icon) {
00110 DebugPrint("icon not found: %s\n" _C_ ident.c_str());
00111 }
00112 return icon;
00113 }
00114
00120 void IconConfig::Load()
00121 {
00122 Assert(!Name.empty());
00123
00124 Icon = CIcon::Get(Name);
00125 if (!Icon) {
00126 fprintf(stderr, "Can't find icon %s\n", Name.c_str());
00127 ExitFatal(-1);
00128 }
00129 };
00130
00136 void InitIcons(void)
00137 {
00138 }
00139
00143 void LoadIcons(void)
00144 {
00145 for (size_t i = 0; i < AllIcons.size(); ++i) {
00146 CIcon *icon = AllIcons[i];
00147 icon->G->Load();
00148 ShowLoadProgress("Icons %s", icon->G->File.c_str());
00149 if (icon->Frame >= icon->G->NumFrames) {
00150 DebugPrint("Invalid icon frame: %s - %d\n" _C_
00151 icon->GetIdent().c_str() _C_ icon->Frame);
00152 icon->Frame = 0;
00153 }
00154 }
00155 }
00156
00160 void CleanIcons(void)
00161 {
00162 std::vector<CIcon *>::iterator i;
00163 for (i = AllIcons.begin(); i != AllIcons.end(); ++i) {
00164 delete *i;
00165 }
00166 AllIcons.clear();
00167 Icons.clear();
00168 }
00169
00177 void CIcon::DrawIcon(const CPlayer *player, int x, int y) const
00178 {
00179 CPlayerColorGraphic *g = dynamic_cast<CPlayerColorGraphic *>(this->G);
00180 if (g) {
00181 g->DrawPlayerColorFrameClip(player->Index, this->Frame, x, y);
00182 } else {
00183 this->G->DrawFrameClip(this->Frame, x, y);
00184 }
00185 }
00186
00197 void CIcon::DrawUnitIcon(const CPlayer *player, ButtonStyle *style,
00198 unsigned flags, int x, int y, const std::string &text) const
00199 {
00200 ButtonStyle s(*style);
00201
00202 s.Default.Sprite = s.Hover.Sprite = s.Clicked.Sprite = this->G;
00203 s.Default.Frame = s.Hover.Frame = s.Clicked.Frame = this->Frame;
00204 if (!(flags & IconSelected) && (flags & IconAutoCast)) {
00205 s.Default.BorderColorRGB = UI.ButtonPanel.AutoCastBorderColorRGB;
00206 s.Default.BorderColor = 0;
00207 }
00208
00209 DrawMenuButton(&s, flags, x, y, text);
00210 }
00211
00215 void IconCclRegister(void)
00216 {
00217 }
00218