Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / client_sheets / player_sheet.cpp
blob03bddd9dd870e596f361184446201c666d58bb68
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/>.
20 /////////////
21 // INCLUDE //
22 /////////////
23 #include "stdpch.h" // First include for pre-compiled headers.
24 // Georges
25 #include "nel/georges/u_form_elm.h"
26 // Client.
27 #include "player_sheet.h"
28 // Game share
29 #include "game_share/skills.h"
30 #include "game_share/skills_build.h"
33 ///////////
34 // USING //
35 ///////////
36 using namespace NLGEORGES;
37 using namespace std;
40 /////////////
41 // METHODS //
42 /////////////
43 //-----------------------------------------------
44 // CPlayerSheet :
45 // Constructor.
46 //-----------------------------------------------
47 CPlayerSheet::CPlayerSheet()
49 CharacterScalePos= 1;
50 Gender=0;
51 // Initialize the type.
52 Type = CEntitySheet::CHAR;
53 }// CPlayerSheet //
55 //-----------------------------------------------
56 // build :
57 // Build the sheet from an external script.
58 //-----------------------------------------------
59 void CPlayerSheet::build(const NLGEORGES::UFormElm &item)
61 // Initialize the scale.
62 Scale = 1.f;
64 // Player Gender.
65 if(!item.getValueByName(Gender, "Gender"))
66 debug("Key 'Gender' not found.");
68 // Get the skel.
69 if(!item.getValueByName(SkelFilename, "Skel"))
70 debug("Key 'Skel' not found.");
72 // Load the Animation Set Base Name.
73 if(!item.getValueByName(AnimSetBaseName, "AnimSetBaseName"))
74 debug("Key 'AnimSetBaseName' not found.");
75 // Force the CASE in UPPER to not be CASE SENSITIVE.
76 else
77 AnimSetBaseName = NLMISC::toLowerAscii(AnimSetBaseName);
79 // Load Lod character name
80 if(!item.getValueByName(LodCharacterName, "LodCharacterName"))
81 debug("Key 'LodCharacterName' not found.");
83 // Load Lod character apparition distance
84 if(!item.getValueByName(LodCharacterDistance, "LodCharacterDistance"))
85 debug("Key 'LodCharacterDistance' not found.");
87 // Get the people of the player.
88 string people;
89 if(!item.getValueByName(people, "Peuple"))
91 debug("Key 'Peuple' not found.");
92 People = EGSPD::CPeople::EndPeople;
94 else
95 People = EGSPD::CPeople::fromString(people);
97 // Get the Default Player Face filename.
98 if(!item.getValueByName(DefaultFace, "DefaultFace"))
99 debug("Key 'DefaultFace' not found.");
100 // Get the Default Player Chest filename.
101 if(!item.getValueByName(DefaultChest, "DefaultChest"))
102 debug("Key 'DefaultChest' not found.");
103 // Get the Default Player Legs filename.
104 if(!item.getValueByName(DefaultLegs, "DefaultLegs"))
105 debug("Key 'DefaultLegs' not found.");
106 // Get the Default Player Arms filename.
107 if(!item.getValueByName(DefaultArms, "DefaultArms"))
108 debug("Key 'DefaultArms' not found.");
109 // Get the Default Player Hands filename.
110 if(!item.getValueByName(DefaultHands, "DefaultHands"))
111 debug("Key 'DefaultHands' not found.");
112 // Get the Default Player Feet filename.
113 if(!item.getValueByName(DefaultFeet, "DefaultFeet"))
114 debug("Key 'DefaultFeet' not found.");
115 // Get the Default Player Hair filename.
116 if(!item.getValueByName(DefaultHair, "DefaultHair"))
117 debug("Key 'DefaultHair' not found.");
119 // get carac
120 if(!item.getValueByName(DefaultHair, "DefaultHair"))
121 debug("Key 'DefaultHair' not found.");
124 // NB: lod colors are given with panoply colors for players
127 // value to scale the "pos" channel of the animation of the player.
128 if(!item.getValueByName(CharacterScalePos, "CharacterScalePos"))
129 debug("Key 'CharacterScalePos' not found.");
131 #define PLAYER_SHEET_EQUIP "Basics.Equipment."
132 Body.build(PLAYER_SHEET_EQUIP "Body", item);
133 Legs.build(PLAYER_SHEET_EQUIP "Legs", item);
134 Arms.build(PLAYER_SHEET_EQUIP "Arms", item);
135 Hands.build(PLAYER_SHEET_EQUIP "Hands", item);
136 Feet.build(PLAYER_SHEET_EQUIP "Feet", item);
137 Head.build(PLAYER_SHEET_EQUIP "Head", item);
138 Face.build(PLAYER_SHEET_EQUIP "Face", item);
139 ObjectInRightHand.build(PLAYER_SHEET_EQUIP "ObjectInRightHand", item);
140 ObjectInLeftHand.build(PLAYER_SHEET_EQUIP "ObjectInLeftHand", item);
141 Headdress.build(PLAYER_SHEET_EQUIP "Headdress", item);
142 EarL.build(PLAYER_SHEET_EQUIP "EarL", item);
143 EarR.build(PLAYER_SHEET_EQUIP "EarR", item);
144 Neck.build(PLAYER_SHEET_EQUIP "Neck", item);
145 Shoulders.build(PLAYER_SHEET_EQUIP "Shoulders", item);
146 Back.build(PLAYER_SHEET_EQUIP "Back", item);
147 WristL.build(PLAYER_SHEET_EQUIP "WristL", item);
148 WristR.build(PLAYER_SHEET_EQUIP "WristR", item);
149 FingerL.build(PLAYER_SHEET_EQUIP "FingerL", item);
150 FingerR.build(PLAYER_SHEET_EQUIP "FingerR", item);
151 AnkleR.build(PLAYER_SHEET_EQUIP "AnkleR", item);
152 AnkleL.build(PLAYER_SHEET_EQUIP "AnkleL", item);
153 Ammo.build(PLAYER_SHEET_EQUIP "Ammo", item);
155 // build charac
156 buildCharac(item);
158 // load skills
159 loadSkillsSummaryFromSheet(item, "Basics.", Skills);
160 }// build //
163 //-----------------------------------------------
164 void CPlayerSheet::buildCharac(const NLGEORGES::UFormElm &item)
166 static const char characsBasePath[] = "Basics.Characteristics.";
167 for(uint k = 0; k < CHARACTERISTICS::NUM_CHARACTERISTICS; ++k)
169 const std::string &characName = CHARACTERISTICS::toString((CHARACTERISTICS::TCharacteristics)k);
170 std::string characPath = characsBasePath + characName;
171 if(!item.getValueByName(Characteristics[k], characPath.c_str()))
173 debug("Key " + characName + "not found.");
174 Characteristics[k] = 0;
180 //-----------------------------------------------
181 // serial :
182 // Serialize player sheet into binary data file.
183 //-----------------------------------------------
184 void CPlayerSheet::serial(NLMISC::IStream &f)
186 // Serialize class components.
187 f.serial(SkelFilename);
188 f.serial(AnimSetBaseName);
189 f.serial(Scale);
190 f.serial(LodCharacterName);
191 f.serial(LodCharacterDistance);
192 f.serial(CharacterScalePos);
193 f.serialEnum(People);
194 f.serial(DefaultFace);
195 f.serial(DefaultChest);
196 f.serial(DefaultLegs);
197 f.serial(DefaultArms);
198 f.serial(DefaultHands);
199 f.serial(DefaultFeet);
200 f.serial(DefaultHair);
201 f.serial(Gender);
202 // equipment
203 f.serial(Body);
204 f.serial(Legs);
205 f.serial(Arms);
206 f.serial(Hands);
207 f.serial(Feet);
208 f.serial(Head);
209 f.serial(Face);
210 f.serial(ObjectInRightHand);
211 f.serial(ObjectInLeftHand);
212 f.serial(Headdress);
213 f.serial(EarL);
214 f.serial(EarR);
215 f.serial(Neck);
216 f.serial(Shoulders);
217 f.serial(Back);
218 f.serial(WristL);
219 f.serial(WristR);
220 f.serial(FingerL);
221 f.serial(FingerR);
222 f.serial(AnkleL);
223 f.serial(AnkleR);
224 f.serial(Ammo);
226 for(uint k = 0; k < CHARACTERISTICS::NUM_CHARACTERISTICS; ++k)
228 f.serial(Characteristics[k]);
231 f.serialCont(Skills);
232 }// serial //
235 //=========================================================================================
236 void CPlayerSheet::CEquipment::build(const std::string &key,const NLGEORGES::UFormElm &item)
238 // Get the item (or shape) name.
239 string itemName;
240 if(!item.getValueByName(itemName, string(key + ".Item").c_str() ))
241 debug(NLMISC::toString("Key '%s.Item' not found.", key.c_str()));
242 else
243 Item = NLMISC::toLowerAscii(itemName);
245 // Get the color.
246 if(!item.getValueByName(Color, string(key + ".Color").c_str() ))
247 debug(NLMISC::toString("Key '%s.Color' not found.", key.c_str()));