Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / item_special_effect.cpp
bloba4a0851da25c5e2af8d5b66e6c335f093ea172ea
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
18 #include "item_special_effect.h"
19 #include "nel/misc/algo.h"
20 #include "nel/misc/i18n.h"
21 #include "../sheet_manager.h"
23 using namespace std;
24 using namespace NLMISC;
26 CItemSpecialEffectHelper::CItemSpecialEffectHelper()
28 // Register special effects
29 registerItemSpecialEffect("ISE_FIGHT_ADD_CRITICAL");
30 registerItemSpecialEffect("ISE_FIGHT_VAMPIRISM");
31 registerItemSpecialEffect("ISE_MAGIC_DIVINE_INTERVENTION");
32 registerItemSpecialEffect("ISE_MAGIC_SHOOT_AGAIN");
33 registerItemSpecialEffect("ISE_CRAFT_ADD_STAT_BONUS");
34 registerItemSpecialEffect("ISE_CRAFT_ADD_LIMIT");
35 registerItemSpecialEffect("ISE_FORAGE_ADD_RM");
36 registerItemSpecialEffect("ISE_FORAGE_NO_RISK");
39 CItemSpecialEffectHelper* CItemSpecialEffectHelper::getInstance()
41 // Singleton
42 static CItemSpecialEffectHelper* instance = NULL;
43 if (instance == NULL)
44 instance = new CItemSpecialEffectHelper;
45 return instance;
48 void CItemSpecialEffectHelper::registerItemSpecialEffect(const string &name)
50 // store parameters to be replaced in UIstring
51 vector<string> params;
53 // get ui string
54 string ucs = CI18N::get("uiItemFX_" + name);
55 CSString p, s = ucs;
57 // locate and store parameters
58 // %p : percent
59 // %n : integer
60 // %r : real
61 // %s : string
62 p = s.splitTo('%', true);
63 while (!p.empty() && !s.empty())
65 if (s[0] == 'p' || s[0] == 'n' || s[0] == 'r' || s[0] == 's')
67 string tmp = "%";
68 tmp += s[0];
69 if (s.size() >=2 && (uint8)s[1] < (uint8)'\x80' && isdigit(s[1]))
70 tmp += s[1];
71 params.push_back(tmp);
73 p = s.splitTo('%', true);
76 effectMap.insert(make_pair(name, params));
79 void CItemSpecialEffectHelper::getItemSpecialEffectText(const CItemSheet *pIS, string &itemText)
81 // check if some effects are present on this item
82 bool firstEffect = false;
83 string effects;
84 effects += getEffect(pIS->getEffect1(), firstEffect);
85 effects += getEffect(pIS->getEffect2(), firstEffect);
86 effects += getEffect(pIS->getEffect3(), firstEffect);
87 effects += getEffect(pIS->getEffect4(), firstEffect);
89 if(!effects.empty()) effects += "\n";
91 // Display special effects info.
92 strFindReplace(itemText, "%special_effects", effects);
95 string CItemSpecialEffectHelper::getEffect(const std::string &effect, bool &first)
97 string result;
98 CSString eff = effect;
100 if (eff.empty())
101 return result;
103 // Get name id of effect
104 CSString name = toUpperAscii(eff.splitTo(':', true));
106 // Extract parameters from sheet
107 vector<CSString> params;
108 CSString param = eff.splitTo(':', true);
109 while (!param.empty())
111 params.push_back(param);
112 param = eff.splitTo(':', true);
115 // Check number of arguments
116 uint n = (uint)(effectMap[name]).size();
117 if (params.size() != n)
119 nlinfo("Bad arguments for : %s", effect.c_str());
120 return result;
123 // Get translated ui string
124 result = CI18N::get("uiItemFX_" + name);
126 // Add endline if it's not the first
127 if (!first)
128 first = true;
129 else
130 result = "\n" + result;
132 // Replace each parameters with value from sheet
133 //nlinfo("name = %s", name.c_str());
134 for (uint i=0 ; i<n ; i++)
136 string replace, p = effectMap[name][i];
137 //nlinfo("param = %s : %s", p.c_str(), params[i].c_str());
139 // %p : percent format
140 if (p[1] == 'p')
142 float f;
143 fromString(params[i], f);
144 replace = toString("%.1f", f*100);
146 // %n : integer format
147 else if (p[1] == 'n')
149 int a;
150 fromString(params[i], a);
151 replace = toString("%d", a);
153 // %r : real format
154 else if (p[1] == 'r')
156 float f;
157 fromString(params[i], f);
158 replace = toString("%.1f", f);
160 // %s : string format
161 else if (p[1] == 's')
163 replace = params[i];
165 else
167 continue;
170 strFindReplace(result, p.c_str(), replace);
173 return result;