Add custom formatter for regen text
[ryzomcore.git] / ryzom / client / src / interface_v3 / dbctrl_sheet.h
blobab44ce99fdef570958d9e73eb59afe17f363e296
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2011-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 // Copyright (C) 2012 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
7 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU Affero General Public License as
11 // published by the Free Software Foundation, either version 3 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Affero General Public License for more details.
19 // You should have received a copy of the GNU Affero General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef RZ_DBCTRL_SHEET_H
25 #define RZ_DBCTRL_SHEET_H
27 // nel
28 #include "nel/misc/types_nl.h"
29 #include "nel/misc/smart_ptr.h"
30 // client
31 #include "nel/gui/reflect.h"
32 #include "nel/gui/ctrl_draggable.h"
33 #include "nel/gui/interface_expr.h"
34 #include "nel/gui/action_handler.h"
35 #include "sphrase_manager.h"
36 // game share
37 #include "game_share/brick_types.h"
38 #include "game_share/trade_slot_type.h"
39 #include "game_share/skills.h"
40 #include "game_share/slot_types.h"
41 #include "game_share/rm_family.h"
42 #include "game_share/item_family.h"
44 #include "../time_client.h"
45 #include "item_info_waiter.h"
47 class CItemSheet;
48 class CPactSheet;
49 class CDBCtrlSheet;
50 class CMacroCmd;
51 class IListSheetBase;
52 class CSBrickSheet;
53 class CSPhraseSheet;
54 class COutpostBuildingSheet;
56 namespace NLGUI
58 class CViewRenderer;
59 class CViewText;
62 class CDBCtrlSheet;
64 // ***************************************************************************
65 // Item info request from server
66 class CControlSheetInfoWaiter : public IItemInfoWaiter
68 public:
69 CDBCtrlSheet* CtrlSheet;
70 string LuaMethodName;
71 bool Requesting;
72 CControlSheetInfoWaiter()
73 : IItemInfoWaiter(), Requesting(false)
74 { }
75 public:
76 std::string infoValidated() const;
77 void sendRequest();
78 virtual void infoReceived();
82 // ***************************************************************************
83 /** Common info for CDBCtrlSheet and CDBGroupListSheet
85 class CCtrlSheetInfo
87 public:
89 enum TSheetType
91 // Items. sheetId points to a CItemSheet via SheetMngr
92 SheetType_Item,
93 // A pact
94 SheetType_Pact,
95 // A skill
96 SheetType_Skill,
97 // Special : the type of the sheet is automatically deduced from its sheet, it drawn like an item
98 SheetType_Auto,
99 // A macro (ie:'open window inventory + dock bag1')
100 SheetType_Macro,
101 // Flag of a guild
102 SheetType_GuildFlag,
103 // A mission
104 SheetType_Mission,
105 // New Sabrina Brick
106 SheetType_SBrick,
107 // New Sabrina Phrase. Index in the PhraseBook
108 SheetType_SPhraseId,
109 // New Sabrina Phrase. Complete phrase used for bot chat sentence (sheet id represent a CSPhraseSheet)
110 SheetType_SPhrase,
111 // A teleport location (just the slot bitmap)
112 SheetType_Teleport_Location,
113 // A guild teleport type
114 SheetType_ElevatorDestination,
115 // An outpost building
116 SheetType_OutpostBuilding,
119 CCtrlSheetInfo();
121 enum TBrickSheetSize
123 BrickSheetWidth= 24,
124 BrickSheetHeight= 24,
127 public:
130 TSheetType _Type;
132 // If it is a brick or a spell, give all the brick type this slot accepts.
133 // Each bit is for the associated BRICK_TYPE::EBrickType enum (unnknown bit 0 etc...)
134 // Default is ALL (ie 0xFFFFFFFF)
135 uint32 _BrickTypeBitField;
137 // display.
138 sint32 _DispNoSheetBmpId; // Texture to display when no sheet (==0)
139 sint32 _SheetSelectionGroup; // group for sheet selection, or -1 if none
141 // Events
142 IActionHandler *_AHOnLeftClick;
143 CStringShared _AHLeftClickParams;
144 IActionHandler *_AHOnRightClick;
145 CStringShared _AHRightClickParams;
147 IActionHandler *_AHOnCanDrag;
148 CStringShared _AHCanDragParams;
149 IActionHandler *_AHOnDrag;
150 CStringShared _AHDragParams;
151 IActionHandler *_AHOnCanDrop;
152 CStringShared _AHCanDropParams;
153 IActionHandler *_AHOnDrop;
154 CStringShared _AHDropParams;
155 IActionHandler *_AHOnCannotDrop;
156 CStringShared _AHCannotDropParams;
158 CStringShared _ListMenuLeft;
159 CStringShared _ListMenuRight;
160 CStringShared _ListMenuRightEmptySlot;
163 bool _InterfaceColor : 1; // Color given by the interface ?
164 bool _UseQuantity : 1; // is the quantity read and displayed ?
165 bool _ReadQuantityFromSheet : 1; // Read quantity from sheet rather than from database
166 bool _UseQuality : 1; // is the quality read and displayed ?
167 bool _DisplayItemQuality : 1; // Do we have to display the quality for the item (false for Cosmetics and Teleport and if _UseQuality==fasle)?
168 bool _DuplicateOnDrag : 1; // when dragged, the item is shown twice : one version at the mouse position.
169 // and another in the source slot. Useful for items to buy that are in infinite quantity.
170 bool _AutoGrayed : 1; // if true then gray the ctrlSheeet if: 1/ Items: Is the Item Locked. 2/ Bricks: is the brick Latent.
171 bool _HasTradeSlotType : 1; // true is the SLOT_TYPE DB field should be taken in account
173 bool _BrickOverable : 1; // if Type is Brick, display like a button (because LeftClickable).
175 bool _DragCopy : 1; // true if support copy drag
177 bool _ForceItemBackGroundGeneric : 1;
179 // For an Item only, this tells what item type this slot accept. Undefined means ALL
180 SLOTTYPE::TSlotType _ItemSlot;
183 public:
184 bool parseCtrlInfo(xmlNodePtr cur, CInterfaceGroup * parentGroup);
186 // Context menu accessor/ One for each button
187 void setListMenuLeft (const std::string &cm) { _ListMenuLeft = cm; }
188 void setListMenuRight (const std::string &cm) { _ListMenuRight = cm; }
189 void setListMenuBoth (const std::string &cm) { _ListMenuLeft= _ListMenuRight= cm; }
190 const std::string &getListMenuLeft () { return _ListMenuLeft; }
191 const std::string &getListMenuRight () { return _ListMenuRight; }
192 const std::string &getListMenuRightEmptySlot () {return _ListMenuRightEmptySlot;}
195 // ***************************************************************************
197 * Class representing base for items that are described in Georges forms
198 * \author Matthieu 'TrapII' Besson
199 * \author Nevrax France
200 * \date 2002
202 class CDBCtrlSheet : public CCtrlDraggable, protected CCtrlSheetInfo
204 public:
205 DECLARE_UI_CLASS(CDBCtrlSheet)
207 // Release fucking statics
208 static void release ();
210 enum TSheetCategory { Item = 0, Pact, Skill, GuildFlag, Mission, Phrase, DontKnow };
211 public:
213 CDBCtrlSheet(const TCtorParam &param);
214 ~CDBCtrlSheet();
216 virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
218 virtual void updateCoords();
219 virtual void draw();
220 void drawSheet (sint32 scrX, sint32 scrY, bool draging, bool showSelectionBorder = true);
222 virtual bool handleEvent (const NLGUI::CEventDescriptor &event);
224 void setActionOnLeftClick (const std::string &ActionHandlerName) { _AHOnLeftClick = CAHManager::getInstance()->getAH(ActionHandlerName, _AHLeftClickParams); }
225 void setActionOnRightClick (const std::string &ActionHandlerName) { _AHOnRightClick = CAHManager::getInstance()->getAH(ActionHandlerName, _AHRightClickParams); }
226 void setActionOnDrop (const std::string &ActionHandlerName) { _AHOnDrop = CAHManager::getInstance()->getAH(ActionHandlerName, _AHDropParams); }
227 void setActionOnCanDrop (const std::string &ActionHandlerName) { _AHOnCanDrop = CAHManager::getInstance()->getAH(ActionHandlerName, _AHCanDropParams); }
228 void setParamsOnLeftClick (const std::string &ParamsHandlerName) { _AHLeftClickParams = ParamsHandlerName; }
229 void setParamsOnRightClick (const std::string &ParamsHandlerName) { _AHRightClickParams = ParamsHandlerName; }
230 void setParamsOnDrop (const std::string &ParamsHandlerName) { _AHDropParams = ParamsHandlerName; }
231 void setParamsOnCanDrop (const std::string &ParamsHandlerName) { _AHCanDropParams = ParamsHandlerName; }
233 const std::string &getActionOnLeftClick () const { return CAHManager::getInstance()->getAHName(_AHOnLeftClick); }
234 const std::string &getActionOnRightClick () const { return CAHManager::getInstance()->getAHName(_AHOnRightClick); }
235 const std::string &getActionOnDrop () const { return CAHManager::getInstance()->getAHName(_AHOnDrop); }
236 const std::string &getActionOnCanDrop () const { return CAHManager::getInstance()->getAHName(_AHOnCanDrop); }
237 const std::string &getParamsOnLeftClick () const { return _AHLeftClickParams; }
238 const std::string &getParamsOnRightClick () const { return _AHRightClickParams; }
239 const std::string &getParamsOnDrop () const { return _AHDropParams; }
240 const std::string &getParamsOnCanDrop () const { return _AHCanDropParams; }
242 void setListMenuLeft (const std::string &cm) { CCtrlSheetInfo::setListMenuLeft(cm); }
243 void setListMenuRight (const std::string &cm) { CCtrlSheetInfo::setListMenuRight(cm); }
244 void setListMenuBoth (const std::string &cm) { CCtrlSheetInfo::setListMenuBoth(cm); }
245 const std::string &getListMenuLeft () { return CCtrlSheetInfo::getListMenuLeft(); }
246 const std::string &getListMenuRight () { return CCtrlSheetInfo::getListMenuRight(); }
247 const std::string &getListMenuRightEmptySlot () {return CCtrlSheetInfo::getListMenuRightEmptySlot();}
249 void setCanDrop (bool cd) { _CanDrop = cd; }
250 bool getCanDrop () const { return _CanDrop; }
251 sint32 getDeltaDragX() {return _DeltaDragX;}
252 sint32 getDeltaDragY() {return _DeltaDragY;}
253 // For "oncandrag" action handlers only, which would want to avoid the drag
254 void setTempCanDrag(bool cd) {_TempCanDrag= cd;}
255 // called when a setCapturePointerLeft(NULL) is made for instance
257 CCtrlSheetInfo::TSheetType getType () const;
258 void setType (CCtrlSheetInfo::TSheetType type);
260 // Swap the content with another ctrl_sheet (debug): SheetId, Quantity and Quality
261 void swapSheet(CDBCtrlSheet *other);
262 void setSheetId(sint32 val) {_SheetId.setSInt32(val);}
263 void setQuality(sint32 val) {_Quality.setSInt32(val);}
264 void setQuantity(sint32 val) {_Quantity.setSInt32(val);}
265 void setItemNameId(uint32 val) {_NameId.setSInt32(val);}
266 void setEnchant(sint32 val) {_Enchant.setSInt32(val);}
268 // get sheet info.
269 sint32 getSheetId() const { return (sint32)_SheetId.getSInt32(); }
270 sint32 getQuality() const { return _UseQuality ? (sint32)_Quality.getSInt32() : 0; }
271 sint32 getEnchant() const { return _Enchant.getSInt32(); }
272 sint32 getQuantity() const { return (sint32)_Quantity.getSInt32(); }
273 uint32 getItemNameId() const { return (uint32)_NameId.getSInt32();}
274 // New Stack Size
275 sint32 getStackable() const { return (_Stackable>1) ? 999 : 1; }
277 // get non locked quantity (can be zero)
278 sint32 getNonLockedQuantity() const;
280 const CItemSheet *asItemSheet() const;
281 const CPactSheet *asPactSheet() const;
282 const CSBrickSheet *asSBrickSheet() const;
283 const CSPhraseSheet *asSPhraseSheet() const;
284 const COutpostBuildingSheet *asOutpostBuildingSheet() const;
286 // Operation on the link between the sheet and database. the string is the branch root of SHEET....
287 std::string getSheet() const;
288 void setSheet (const std::string &dbBranchId);
289 void setSheetFast( const std::string &dbParentBranchId, int sheetNum, int slotNum );
291 REFLECT_EXPORT_START(CDBCtrlSheet, CCtrlDraggable)
292 REFLECT_STRING("sheet", getSheet, setSheet);
293 REFLECT_RGBA("color", getSheetColor, setSheetColor);
294 REFLECT_RGBA("color1", getGuildColor1, setGuildColor1);
295 REFLECT_RGBA("color2", getGuildColor2, setGuildColor2);
296 REFLECT_SINT32("back", getGuildBack, setGuildBack);
297 REFLECT_SINT32("symbol", getGuildSymbol, setGuildSymbol);
298 REFLECT_BOOL("invert_symbol", getInvertGuildSymbol, setInvertGuildSymbol);
299 REFLECT_BOOL("can_drop", getCanDrop, setCanDrop);
300 REFLECT_STRING_REF ("left_click", getActionOnLeftClick, setActionOnLeftClick);
301 REFLECT_STRING_REF ("right_click", getActionOnRightClick, setActionOnRightClick);
302 REFLECT_STRING_REF ("left_click_params", getParamsOnLeftClick, setParamsOnLeftClick);
303 REFLECT_STRING_REF ("right_click_params", getParamsOnRightClick, setParamsOnRightClick);
304 REFLECT_STRING_REF ("on_drop", getActionOnDrop, setActionOnDrop);
305 REFLECT_STRING_REF ("on_drop_params", getParamsOnDrop, setParamsOnDrop);
306 REFLECT_STRING_REF ("on_can_drop", getActionOnCanDrop, setActionOnCanDrop);
307 REFLECT_STRING_REF ("on_can_drop_params", getParamsOnCanDrop, setParamsOnCanDrop);
308 REFLECT_LUA_METHOD("getDraggedSheet", luaGetDraggedSheet);
309 REFLECT_LUA_METHOD("getItemInfo", luaGetItemInfo);
310 REFLECT_LUA_METHOD("getName", luaGetName);
311 REFLECT_LUA_METHOD("getCreatorName", luaGetCreatorName);
312 REFLECT_LUA_METHOD("waitInfo", luaWaitInfo);
313 REFLECT_LUA_METHOD("buildCrystallizedSpellListBrick", luaBuildCrystallizedSpellListBrick);
314 REFLECT_EXPORT_END
316 int luaGetDraggedSheet(CLuaState &ls);
317 int luaGetItemInfo(CLuaState &ls);
318 int luaGetName(CLuaState &ls);
319 int luaGetCreatorName(CLuaState &ls);
320 int luaWaitInfo(CLuaState &ls);
321 int luaBuildCrystallizedSpellListBrick(CLuaState &ls);
323 // hardcode creation. User must setup other CtrlBase value (parent etc...)
324 void initSheet(const std::string &dbValue, const CCtrlSheetInfo &ctrlInfo);
325 void initSheetFast( const std::string &dbParentBranchId, int sheetNum, int slotNum,
326 const CCtrlSheetInfo &ctrlInfo );
328 // get the selection group for this ctrl sheet, or -1 if none
329 sint getSelectionGroup() const { return _SheetSelectionGroup; }
330 // get the selection group for this ctrl sheet as a string, or "" if none
331 const std::string &getSelectionGroupAsString() const;
333 // get the currently selected sheet (only one at a time)
334 static CDBCtrlSheet *getCurrSelection() { return _CurrSelection; }
336 // set the currently selected sheet.
337 static void setCurrSelection(CDBCtrlSheet *selected);
339 // get the root branch containing the properties for that sheet
340 NLMISC::CCDBNodeBranch *getRootBranch() const;
342 /** If the branch in setSheet(branch) is of the form ...:# (where # is a number), return this number.
343 * The value is hence modified by setSheet(). return 0 if not of this form.
345 uint32 getIndexInDB() const {return _IndexInDB;}
346 /** If the branch in setSheet(branch) is of the form ...:#:# (where # are numbers), return this number.
347 * The value is hence modified by setSheet(). return 0 if not of this form.
349 uint32 getSecondIndexInDB() const {return _SecondIndexInDB;}
351 // synonym for getSecondIndexInDB().
352 uint32 getInventoryIndex() const {return getSecondIndexInDB();}
354 // determine the inventory slot from the database branch id
355 static uint getInventorySlot( const std::string &dbBranchId );
357 // Get the last dropped sheet. The pointer is only valid during the call of the event handler
358 //static CDBCtrlSheet *getDraggedSheet() { return _LastDraggedSheet; }
360 /* Get the last selected sheet that have been draged or right clicked (should be use by menu to get their caller)
361 * It is used by the item actions like destroy, move etc..
363 static CDBCtrlSheet *getCurrSelSheet() { return _CurrMenuSheet; }
364 static void setCurrSelSheet(CDBCtrlSheet *sheet) { _CurrMenuSheet = sheet; }
367 /// \name SBrick / SPhrase
368 // @{
369 // true if the ctrl_sheet is a Sabrina brick
370 bool isSBrick() const {return getType() ==SheetType_SBrick;}
371 // true if magic sentence is a Sabrina phrase
372 bool isSPhraseId() const {return getType()==SheetType_SPhraseId;}
373 // true if magic sentence is a Sabrina phrase
374 bool isSPhrase() const {return getType()==SheetType_SPhrase;}
375 // true if brick or magic sentence
376 bool isSBrickOrSPhraseId() const
378 CCtrlSheetInfo::TSheetType type= getType();
379 return type==SheetType_SBrick || type==SheetType_SPhraseId;
381 bool isSPhraseIdMemory() const;
382 // special for macro and Memories
383 bool isMacroMemory() const;
384 // return the phrase slot from database.
385 sint32 getSPhraseId() const;
386 /// true if it is a shortcut
387 bool isShortCut() const {return _ShortCut;}
388 // @}
391 /// Setup the alpha of the sheet drawn
392 void setSheetColor(NLMISC::CRGBA color) {_SheetColor= color;}
393 NLMISC::CRGBA getSheetColor() const {return _SheetColor;}
395 /// Special ContextHelp for ctrl sheet.
396 virtual void getContextHelp(std::string &help) const;
398 virtual void getContextHelpToolTip(std::string &help) const;
401 /** true if an item of another ctrlSheet can be dropped on this slot.
402 * also return true if src is 0, or if _ItemSlot==UNDEFINED
404 bool canDropItem(CDBCtrlSheet *src) const;
406 /// Force the item/brick to be grayed. NB: no effect if "auto_grayed" is true
407 void setGrayed(bool state) { _Grayed= state;}
408 bool getGrayed() const
410 // If The Item sheet or phrase is 0, assume never grayed
411 if(_SheetId.getNodePtr() && getSheetId() == 0)
412 return false;
413 // NB: if a macro, getNodePtr()==NULL
414 else
415 return _Grayed;
417 // Additional gray for items. The item is finally grayed if one of this
418 void setItemWeared(bool state) {_ItemWeared= state;}
419 bool getItemWeared() const { return _ItemWeared;}
420 void setItemBeastGrayed(bool state) {_ItemBeastGrayed= state;}
421 bool getItemBeastGrayed() const { return _ItemBeastGrayed;}
423 void setUseQuality(bool use) { if(use!=_UseQuality) { _UseQuality= use; _NeedSetup= true;} }
424 void setUseQuantity(bool use) { if(use!=_UseQuantity) { _UseQuantity= use; _NeedSetup= true;} }
425 bool getUseQuality() const { return _UseQuality; }
426 bool getUseQuantity() const { return _UseQuantity; }
428 void setReadQuantityFromSheetFlag(bool on) { _ReadQuantityFromSheet = on; }
429 bool getReadQuantityFromSheetFlag() const { return _ReadQuantityFromSheet; }
431 // test if the sheet is a skill sheet
432 bool isSkill() const { return _HasTradeSlotType ? _TradeSlotType.getSInt32() == TRADE_SLOT_TYPE::Skill : false; }
434 // test if the sheet is a mission sheet
435 bool isMission() const;
437 // If the sheet is a skill, just get it
438 SKILLS::ESkills getSkill() const { return isSkill() ? (SKILLS::ESkills) getSheetId() : SKILLS::unknown; }
441 // set special behaviour
442 void setBehaviour(TRADE_SLOT_TYPE::TTradeSlotType type);
443 TRADE_SLOT_TYPE::TTradeSlotType getBehaviour() const { return _HasTradeSlotType ? (TRADE_SLOT_TYPE::TTradeSlotType) _TradeSlotType.getSInt32() : TRADE_SLOT_TYPE::StandardBehaviour; }
445 SLOTTYPE::TSlotType getItemSlot() { return _ItemSlot; }
446 void setItemSlot(SLOTTYPE::TSlotType slot) { _ItemSlot = slot; }
447 void setTextureNoItem(sint32 nTxID) { _DispNoSheetBmpId = nTxID; }
448 sint32 getTextureNoItem() { return _DispNoSheetBmpId; }
450 // copy the aspect of this sheet (not the handlers)
451 void copyAspect(CDBCtrlSheet *dest);
452 // true if same aspects.
453 bool sameAspect(CDBCtrlSheet *dest) const;
455 // get the sheet category
456 TSheetCategory getSheetCategory() const;
458 // get the ListSheet parent. NB: different code from CDBGroupListSheet and CDBGroupListSheetTrade. NULL if not found
459 IListSheetBase *getListSheetParent() const;
461 // get the index of this sheet in its parent list, or -1 if there's no such list
462 sint getIndexInParent() const;
464 // get the 'LOCKED' field in the db
465 NLMISC::CCDBNodeLeaf *getLockValuePtr() { return _GrayedLink; }
467 /// \name Macro
468 // @{
469 void readFromMacro(const CMacroCmd &mc); // Macro To ControlSheet
470 void writeToMacro(CMacroCmd &mc); // ControlSheet To Macro
471 void setMacroBack(uint8 nb);
472 void setMacroIcon(uint8 nb);
473 void setMacroOver(uint8 nb);
474 void setMacroText(const std::string &mcText);
475 sint32 getMacroId() const {return _MacroID;}
476 bool isMacro() const {return getType()==SheetType_Macro;}
477 // @}
479 /** According to ActualType, return true if the sheet is valid. eg: getSheetId()!=0 and brick exist
480 * for sheet type brucks. Always for Macros and skills.
482 bool isSheetValid() const;
484 /// \name Guild Flag
485 // @{
486 NLMISC::CRGBA getGuildColor1() const;
487 NLMISC::CRGBA getGuildColor2() const;
488 sint32 getGuildBack() const;
489 sint32 getGuildSymbol() const;
490 bool getInvertGuildSymbol() const;
492 void setGuildColor1(NLMISC::CRGBA col);
493 void setGuildColor2(NLMISC::CRGBA col);
494 void setGuildBack(sint32 n);
495 void setGuildSymbol(sint32 n);
496 void setInvertGuildSymbol(bool b);
497 // @}
499 /// \name For teleport location
500 // @{
501 void setSlot(const std::string &textureName);
502 void initSheetSize();
503 // @}
505 NLMISC::CCDBNodeLeaf *getSlotType() const { return _TradeSlotType.getNodePtr(); }
507 // get item weight
508 uint16 getItemWeight() const;
509 NLMISC::CCDBNodeLeaf *getItemWeightPtr() const;
510 // set item weight
511 void setItemWeight(uint16 weight);
513 // get item info version
514 uint8 getItemInfoVersion() const;
515 NLMISC::CCDBNodeLeaf *getItemInfoVersionPtr() const;
516 // set item info version
517 void setItemInfoVersion(uint8 infoVersion);
519 // get item Locked state
520 uint16 getItemLocked() const;
521 NLMISC::CCDBNodeLeaf *getItemLockedPtr() const;
522 // set item locked state
523 void setItemLocked(uint16 lock);
525 // get item PRICE. 0 if no DB
526 sint32 getItemPrice() const;
527 NLMISC::CCDBNodeLeaf *getItemPricePtr() const;
528 // set item PRICE
529 void setItemPrice(sint32 price);
531 // get item RESALE_FLAG. 0 if no DB
532 sint32 getItemResaleFlag() const;
533 NLMISC::CCDBNodeLeaf *getItemResaleFlagPtr() const;
534 // set item RESALE_FLAG
535 void setItemResaleFlag(sint32 rf);
537 //get item CREATE_TIME. 0 if no DB
538 sint32 getItemCreateTime() const;
539 NLMISC::CCDBNodeLeaf *getItemCreateTimePtr() const;
540 // set item CREATE_TIME
541 void setItemCreateTime(sint32 ct);
543 //get item SERIAL. 0 if no DB
544 sint32 getItemSerial() const;
545 NLMISC::CCDBNodeLeaf *getItemSerialPtr() const;
546 // set item CREATE_TIME
547 void setItemSerial(sint32 serial);
549 // get item locked by owner
550 bool getLockedByOwner() const;
552 // true if the inventory supports owner locking
553 bool canOwnerLock() const;
555 // get item SELLER_TYPE. 0 if no DB
556 sint32 getItemSellerType() const;
557 NLMISC::CCDBNodeLeaf *getItemSellerTypePtr() const;
558 // set item SELLER_TYPE
559 void setItemSellerType(sint32 rf);
561 // get item FABER_QUALITY. 0 if no DB
562 RM_CLASS_TYPE::TRMClassType getItemRMClassType() const;
563 NLMISC::CCDBNodeLeaf *getItemRMClassTypePtr() const {return _ItemRMClassType;}
564 // set item FABER_QUALITY
565 void setItemRMClassType(sint32 fq);
567 // get item FABER_STAT_TYPE. 0 if no DB
568 RM_FABER_STAT_TYPE::TRMStatType getItemRMFaberStatType() const;
569 NLMISC::CCDBNodeLeaf *getItemRMFaberStatTypePtr() const {return _ItemRMFaberStatType;}
570 // set item FABER_STAT_TYPE
571 void setItemRMFaberStatType(sint32 fss);
573 // get item PREREQUISIT_VALID. true of no DB
574 bool getItemPrerequisitValid() const;
575 NLMISC::CCDBNodeLeaf *getItemPrerequisitValidPtr() const;
576 // set item PREREQUISIT_VALID
577 void setItemPrerequisitValid(bool prv);
579 // get color index of item (return -1 if no color available)
580 sint32 getItemColor() const {if(_UserColor) return _UserColor->getValue32(); else return -1;}
581 // set item color (if possible)
582 void setItemColor(sint32 val) {if(_UserColor) _UserColor->setValue32(val);}
584 // Get the Actual item name. Localized version of SheetId, or given by server through NAMEID.
585 std::string getItemActualName() const;
587 /// true if support drag copy (with CTRL). action handler has to check control.
588 bool canDragCopy() const {return _DragCopy;}
590 // special for items, call it at initInGame()
591 static void initArmourColors();
593 // true if an item that respect Carac requirement. NB: still return true if not an item
594 bool checkItemRequirement();
596 virtual void serial(NLMISC::IStream &f);
598 // From CCtrlBase, for phrases, we use a special, enhanced tooltip window
599 virtual std::string getContextHelpWindowName() const;
601 // For auras, powers, etc. set the range of ticks during which regen occurs
602 void setRegenTickRange(const CTickRange &tickRange);
603 const CTickRange &getRegenTickRange() const { return _RegenTickRange; }
605 // Default regen text is displayed on bottom of icon.
606 void setRegenText(bool b) { _RegenTextEnabled = b; }
607 // Allow to override default formatter.
608 // First parameter will be replaced with current timer value (always >= 0)
609 // If its a lua function, then parameters are
610 // 1: current timer value; can be negative
611 // 2: DB path for ctrl root (ie UI:VARIABLES:BONUSES:0), or nil
613 // ie: "secondsToTimeStringShort" -> CInterfaceExpr::evalAsString("secondsToTimeStringShort(123)", ret)
614 // ie: "lua:secondsToTimeStringShort" -> CInterfaceExpr::evalAsString("lua:secondsToTimeStringShort(123, 'UI:VARIABLES:BONUSES:0')", ret)
615 void setRegenTextFct(const std::string &s);
616 void setRegenTextY(sint32 y) { _RegenTextY = y; }
617 void setRegenTextShadow(bool b) { _RegenTextShadow = b; }
618 void setRegenTextShadowColor(NLMISC::CRGBA c) { _RegenTextShadowColor = c; }
619 void setRegenTextOutline(bool b) { _RegenTextOutline = b; }
620 void setRegenTextOutlineColor(NLMISC::CRGBA c) { _RegenTextOutlineColor = c; }
621 void setRegenTextFontSize(uint32 s) { _RegenTextFontSize = s; }
622 void setRegenTextColor(NLMISC::CRGBA c) { _RegenTextColor = c; }
624 // start notify anim (at the end of regen usually)
625 void startNotifyAnim();
627 // callback from info waiter
628 void infoReceived();
630 // set enchant/buff marker visiblility
631 static void setShowIconBuffs(bool b) { _ShowIconBuffs = b; }
633 protected:
634 inline bool useItemInfoForFamily(ITEMFAMILY::EItemFamily family) const;
636 void setupItem();
637 void setupPact();
638 void setupMacro();
639 void setupGuildFlag();
640 void setupMission();
641 void setupSBrick();
642 void setupSPhrase();
643 void setupSPhraseId();
644 void setupOutpostBuilding();
645 // optSheet is for special faber
646 void setupDisplayAsSBrick(sint32 sheet, sint32 optSheet= 0);
647 // setup icon from phrases
648 void setupDisplayAsPhrase(const std::vector<NLMISC::CSheetId> &bricks, const std::string &phraseName);
650 // draw a number and returns the width of the drawn number
651 sint32 drawNumber(sint32 x, sint32 y, sint32 wSheet, sint32 hSheet, NLMISC::CRGBA color, sint32 value, bool rightAlign=true);
654 protected:
656 // Root branch of the DB
657 std::string _DbBranchName;
659 // items db entries
660 CInterfaceProperty _SheetId;
661 CInterfaceProperty _NameId;
662 CInterfaceProperty _Quantity;
663 CInterfaceProperty _Quality;
664 CInterfaceProperty _TradeSlotType;
665 CInterfaceProperty _Enchant;
666 CInterfaceProperty _PrerequisitValid;
667 CInterfaceProperty _Worned; // if true means that item is worned (red cross, no longer usable unless it's a tool)
669 // As node leaf for backward compatibilities
670 NLMISC::CCDBNodeLeaf *_ItemRMClassType;
671 NLMISC::CCDBNodeLeaf *_ItemRMFaberStatType;
673 mutable sint32 _LastSheetId;
674 bool _ItemInfoChanged;
676 /// Display
677 sint32 _DispSlotBmpId; // Display slot bitmap id
678 sint32 _DispSelSlotId;
680 sint32 _DispBackBmpId; // Back Icon
681 sint32 _DispSheetBmpId; // Main Icon
682 sint32 _DispOverBmpId; // Over Icon
683 sint32 _DispOver2BmpId; // Over Icon N0 2 for bricks / items. Useful for items when _DispOverBmpId is used to paint user color on the item.
685 std::string _HpBuffIcon;
686 std::string _SapBuffIcon;
687 std::string _StaBuffIcon;
688 std::string _FocusBuffIcon;
690 // texture ids to show
691 struct SBuffIcon
693 SBuffIcon(sint32 txid, NLMISC::CRGBA col=NLMISC::CRGBA::White)
694 :TextureId(txid), Color(col), IconW(0), IconH(0)
697 sint32 TextureId;
698 NLMISC::CRGBA Color;
699 sint32 IconW;
700 sint32 IconH;
702 std::vector<SBuffIcon> _BuffIcons;
703 std::vector<SBuffIcon> _EnchantIcons;
705 // Level Brick or Quality
706 union
708 sint32 _DispQuality;
709 sint32 _DispLevel;
711 // Quantity for items
712 sint32 _DispQuantity;
713 sint32 _Stackable;
715 sint32 _TextureIdOver;
717 uint32 _IndexInDB;
718 uint32 _SecondIndexInDB;
720 // For SBrick only. Display level?
721 bool _MustDisplayLevel : 1;
723 /// Events
725 bool _CanDrop : 1;
726 bool _Over : 1;
728 /// Is a TaskBar shortcut
729 bool _ShortCut : 1;
731 /// Draw the slot ?
732 bool _DrawSlot : 1;
734 /// Is the Item/Brick as to be grayed?
735 bool _ItemBeastGrayed : 1; // This is an item in a pack animal / beast, that is unavailable
736 bool _ItemWeared : 1; // Item weared (for bags item)
737 bool _Grayed : 1;
738 bool _Useable : 1; // if false, means more than grayed: "red-ed" we cannot get or use it. SBrick, SPhrase and SItem
740 /// Init after parse()
741 bool _SetupInit : 1;
743 /// true if need a full setup in setupItem() ...
744 mutable bool _NeedSetup : 1;
746 // Temp for oncandrag AH
747 bool _TempCanDrag : 1;
749 // For ArmourColorFromDB
750 bool _ArmourColorFromDB : 1;
752 // True if the Armour Color Bitmaps have been setuped
753 bool _ArmourColorBmpOk : 1;
755 // Bkup of Armour Color index. -1 or 0..7
756 sint8 _ArmourColorIndex;
758 CTickRange _RegenTickRange;
759 NLGUI::CViewText *_RegenText;
760 sint32 _RegenTextValue;
762 std::string _RegenTextFct;
763 bool _RegenTextFctLua;
764 bool _RegenTextEnabled;
765 bool _RegenTextShadow;
766 bool _RegenTextOutline;
767 sint32 _RegenTextY;
768 uint32 _RegenTextFontSize;
769 NLMISC::CRGBA _RegenTextShadowColor;
770 NLMISC::CRGBA _RegenTextOutlineColor;
771 NLMISC::CRGBA _RegenTextColor;
774 /// D'n'd
775 sint32 _DragX, _DragY;
776 sint32 _DeltaDragX, _DeltaDragY;
777 sint32 _IconW, _IconH;
779 // Global color of the control.
780 NLMISC::CRGBA _SheetColor;
782 // Special colors (item/bricks)
783 NLMISC::CRGBA _IconBackColor;
784 NLMISC::CRGBA _IconColor;
785 NLMISC::CRGBA _IconOverColor;
786 NLMISC::CRGBA _IconOver2Color;
787 // Item only: Special armour color. black(0) if is not an armour
788 uint32 _PackedArmourColor;
791 // For an Item only. Useful for LeftHand Filtering: must have a pointer to the right hand
792 CDBCtrlSheet *_OtherHandItemFilter;
794 // This String is optional and usage dependent for Item, Macro, or Sentence
795 std::string _OptString;
797 NLMISC::CCDBNodeLeaf *_GrayedLink;
799 // Macro or sentence String compiled as texture Ids and positions, from the _OptString.
800 struct CCharBitmap
802 sint32 X,Y;
803 sint32 Id;
805 std::vector<CCharBitmap> _CharBitmaps;
807 // Macro Id
808 sint32 _MacroID;
810 // Guild Flag
811 NL3D::UTextureFile *_GuildBack;
812 NL3D::UTextureFile *_GuildSymb;
813 static NL3D::UMaterial _GuildMat;
814 bool _UseGuildIcon;
815 NLMISC::CSheetId _GuildIcon;
817 // SPhrase version
818 sint32 _LastPhraseVersion;
820 // special for items : colour of armour
821 static NLMISC::CRGBA _ArmourColor[8];
823 // special for items. Carac Requirement
824 CHARACTERISTICS::TCharacteristics _ItemCaracReqType;
825 sint32 _ItemCaracReqValue;
827 // Special for Armour
828 NLMISC::CCDBNodeLeaf *_UserColor;
830 // keep pointer on item sheet
831 const CItemSheet *_ItemSheet;
833 // unique persistent phrase exposed to lua script
834 static NLMISC::CSmartPtr<CSPhraseComAdpater> _PhraseAdapter;
836 sint64 _NotifyAnimEndTime;
838 mutable CControlSheetInfoWaiter _ItemInfoWaiter;
839 private:
840 mutable TSheetType _ActualType;
842 static CDBCtrlSheet *_CurrSelection;
843 static CDBCtrlSheet *_CurrMenuSheet;
845 static bool _ShowIconBuffs;
846 private:
847 void updateActualType() const;
848 void updateIconSize();
849 void resetAllTexIDs();
850 void setupInit();
851 // remove enchant and buff markers from item icon
852 void clearIconBuffs();
854 void setupCharBitmaps(sint32 maxW, sint32 maxLine, sint32 maxWChar= 1000, bool topDown= false);
855 void resetCharBitmaps();
856 void displayCharBitmaps(sint32 rdrLayer, sint32 x, sint32 y, NLMISC::CRGBA color);
858 // special for items
859 void updateItemCharacRequirement(sint32 sheetId);
861 // Send ITEM_INFO:GET request to server to fetch Buffs, Enchant info
862 void setupItemInfoWaiter();
864 // update armour color, and cache
865 void updateArmourColor(sint8 col);
867 // setup sheet DB. _DbBranchName must be ok, and _SecondIndexInDb and _IndexInDb as well
868 void setupSheetDbLinks ();
871 // 'regen' rendering
872 // convert from uv coordinates in the [0, 1] x [0, 1] range to screen coords
873 inline void uvToScreen(float x, float y, NLMISC::CVector &screenPos, uint texSize) const;
874 // from an angle in the [0, 1] range, return both uv & screen coords for that angle
875 // (angle is projected on the side of rectangle of the 'regen' texture)
876 void buildPieCorner(float angle, NLMISC::CUV &uv, NLMISC::CVector &pos, uint texSize) const;
877 // from a start and end angle in the [0, 1] range, build the set of uv mapped triangles necessary
878 // to display that 'pie'
879 // NB : output are indeed quads, at the time ofthis writing, uv mappedtri randering not available ...
880 // so we turn them into quad for conveniency ...
881 uint buildPie(NLMISC::CQuadUV *quv, float startAngle, float endAngle, uint texSize);
883 // gelper to draw the notify animation
884 void drawRotatedQuad(CViewRenderer &vr, float angle, float scale, uint renderLayer, uint32 textureId, sint32 texWidth, sint32 texHeight);
886 // create and draw regen text over icon
887 void drawRegenText();
891 /** User type (used with expression system of the interface, see interface_expr.h, that contains a pointer to a CDBCtrlSheet
893 struct CDBCtrlSheetPtrUserType : public CInterfaceExprUserType
895 CDBCtrlSheet *Sheet; // pointer to a sheet
896 // ctor
897 CDBCtrlSheetPtrUserType(CDBCtrlSheet *sheet = NULL) : Sheet(sheet) {}
898 // from CInterfaceExprUserType
899 virtual CInterfaceExprUserType *clone() const { return new CDBCtrlSheetPtrUserType(*this); }
903 #endif // RZ_DBCTRL_SHEET_H
905 /* End of dbctrl_sheet.h */