Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / action_handler_game.cpp
blob0486c2efd1d6d1265002762ce88def2c8a54f6c1
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2020 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "stdpch.h"
26 #include <sstream>
27 #include <locale>
29 // Interface includes
30 #include "interface_manager.h"
31 #include "nel/gui/action_handler.h"
32 #include "action_handler_base.h"
33 #include "action_handler_misc.h"
34 #include "bot_chat_manager.h"
35 #include "bot_chat_page_all.h"
36 #include "bot_chat_page_news.h"
37 #include "bot_chat_page_create_guild.h"
38 #include "bot_chat_page_mission.h"
39 #include "bot_chat_page_mission_end.h"
40 #include "bot_chat_page_trade.h"
41 #include "bot_chat_page_player_gift.h"
42 #include "bot_chat_page_dynamic_mission.h"
43 #include "bot_chat_page_ring_sessions.h"
44 #include "dbctrl_sheet.h"
45 #include "nel/gui/ctrl_sheet_selection.h"
46 #include "nel/gui/interface_expr.h"
47 #include "nel/gui/group_menu.h"
48 #include "nel/gui/group_container.h"
49 #include "nel/gui/group_editbox.h"
50 #include "inventory_manager.h"
51 #include "guild_manager.h"
52 #include "../net_manager.h"
53 #include "interface_ddx.h"
54 #include "nel/gui/group_tree.h"
55 #include "group_map.h"
56 #include "nel/gui/view_bitmap.h"
57 #include "action_handler_tools.h"
58 #include "../connection.h"
59 #include "../client_chat_manager.h"
60 #include "group_compas.h"
62 // Game specific includes
63 #include "../motion/user_controls.h"
64 #include "../entities.h"
65 #include "../misc.h"
66 #include "../sheet_manager.h"
67 #include "../actions_client.h"
68 #include "people_interraction.h"
69 #include "../game_context_menu.h"
70 #include "../sound_manager.h"
71 #include "../far_tp.h"
72 #include "nel/gui/interface_link.h"
73 #include "../npc_icon.h"
74 #include "user_agent.h"
76 // Game Share
77 #include "game_share/character_summary.h"
78 #include "game_share/brick_types.h"
79 #include "game_share/seeds.h"
80 #include "game_share/entity_types.h"
81 #include "game_share/inventories.h"
82 //#include "game_share/sheath.h"
83 //#include "game_share/jobs.h"
84 #include "game_share/animals_orders.h"
85 #include "game_share/animal_status.h"
86 #include "game_share/animal_type.h"
87 #include "game_share/interface_flags.h"
88 #include "game_share/slot_equipment.h"
89 #include "game_share/bot_chat_types.h"
90 #include "game_share/constants.h"
91 #include "game_share/scores.h"
93 // Game Config
94 #include "nel/gui/dbgroup_combo_box.h"
95 #include "nel/gui/ctrl_button.h"
96 #include "../global.h"
98 using namespace std;
99 using namespace NL3D;
100 using namespace NLMISC;
101 using namespace BRICK_TYPE;
103 extern NL3D::UDriver *Driver;
104 extern NLMISC::CLog g_log;
105 extern bool ShowInterface;
106 extern bool ShowHelp;
107 extern uint8 PlayerSelectedSlot;
108 extern bool IsInRingSession;
110 // Context help
111 extern void contextHelp (const std::string &help);
113 extern CClientChatManager ChatMngr;
115 void beastOrder (const std::string &orderStr, const std::string &beastIndexStr, bool confirmFree = true);
118 string convertLanguageIntToLanguageCode(sint val)
120 switch(val)
122 default:
123 case 0: return "en"; break;
124 case 1: return "fr"; break;
125 case 2: return "de"; break;
126 case 3: return "ru"; break;
127 case 4: return "es"; break;
131 /**********************************************************************************************************
133 * GAME CONTEXT MENU handlers *
135 ***********************************************************************************************************/
138 // Does the player know this skill?
139 static bool playerKnowSkill( SKILLS::ESkills e)
141 CInterfaceManager *pIM = CInterfaceManager::getInstance();
142 string sPath = "SERVER:CHARACTER_INFO:SKILLS:" + toStringEnum( e ) + ":SKILL";
143 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sPath,false);
144 if ((pNL != NULL) && (pNL->getValue64() > 0))
145 return true;
146 else
147 return false;
151 // ***************************************************************************
152 // GCM Activation : called when activate the game context menu
153 // ***************************************************************************
155 class CHandlerActiveGameContextMenu : public IActionHandler
157 public:
158 void execute (CCtrlBase *pCaller, const std::string &/* sParams */)
160 // Invalidate all lines
161 CGroupMenu *pGM = dynamic_cast<CGroupMenu*>(pCaller);
162 if (pGM == NULL) return;
164 // Id names of the lines in the game_context_menu.xml ...
165 static const char *sIdNames[] = { "talk", "use", "lift", "look", "attack", "invit", "exchange",
166 "mount", "train" };
167 const uint32 numOptions = sizeof(sIdNames) / sizeof(sIdNames[0]);
169 uint32 i;
170 CViewTextMenu *pVTM;
171 const string sMenuPath = "ui:interface:game_context_menu";
173 for (i = 0; i < numOptions; ++i)
175 pVTM = dynamic_cast<CViewTextMenu*>(pGM->getElement(sMenuPath+":"+sIdNames[i]));
176 if (pVTM != NULL) pVTM->setGrayed(true);
180 REGISTER_ACTION_HANDLER( CHandlerActiveGameContextMenu, "active_game_context_menu");
182 // ***************************************************************************
183 // GCM Talk
184 // ***************************************************************************
186 class CHandlerContextTalk : public IActionHandler
188 public:
189 void execute (CCtrlBase *pCaller, const std::string &/* sParams */)
191 CInterfaceManager *im = CInterfaceManager::getInstance();
192 CEntityCL *selection = EntitiesMngr.entity(UserEntity->selection());
193 if (selection && selection->Type == CEntityCL::Player)
195 string name = CEntityCL::removeTitleAndShardFromName(selection->getEntityName());
196 if (name.empty()) return;
197 CAHManager::getInstance()->runActionHandler("enter_tell", pCaller, "player=" + name);
200 protected:
202 REGISTER_ACTION_HANDLER( CHandlerContextTalk, "context_talk");
207 // ***************************************************************************
208 // sendBotChatStart
209 // helper increment session id and send session id to the server with specified message
210 // ***************************************************************************
211 static void sendBotChatStart(const string &msgName)
213 CBotChatManager::getInstance()->incrementSessionID();
214 CBitMemStream out;
215 string msg = "BOTCHAT:" + msgName;;
216 if(GenericMsgHeaderMngr.pushNameToStream(msg, out))
218 uint16 session = CBotChatManager::getInstance()->getSessionID();
219 out.serial(session);
220 NetMngr.push(out);
222 else
224 nlwarning("msg %s does not exist.", msg.c_str());
229 // ***************************************************************************
230 // GCM Ring Sessions
231 // ***************************************************************************
232 class CHandlerContextRingSessions : public IActionHandler
234 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
236 // do not send start message to server here (not really a bot chage page, but should dissapear
237 // when player go away)
239 CInterfaceManager *pIM = CInterfaceManager::getInstance();
240 CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId("ui:interface:ring_sessions");
242 // check if selection is a Ring terminal
243 CEntityCL * selection = EntitiesMngr.entity(UserEntity->selection());
244 if (selection && selection->sheetId()==NLMISC::CSheetId("object_karavan_device_neutrl_sel.creature"))
246 CVectorD vect1 = selection->pos();
247 CVectorD vect2 = UserEntity->pos();
249 double distanceSquare = pow(vect1.x-vect2.x,2) + pow(vect1.y-vect2.y,2);
251 if(distanceSquare > MaxTalkingDistSquare)
253 UserEntity->moveTo(UserEntity->selection(), 3.0, CUserEntity::WebPage);
254 if (pIE->getActive())
256 CBotChatManager::getInstance()->setCurrPage(NULL);
259 else
261 if (!pIE->getActive())
263 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->RingSessions);
267 else
269 if (pIE != NULL) pIE->setActive(false);
273 REGISTER_ACTION_HANDLER( CHandlerContextRingSessions, "context_ring_sessions");
276 // ***************************************************************************
277 // GCM Trade Item (with bot)
278 // ***************************************************************************
279 class CHandlerContextTradeItem : public IActionHandler
281 public:
282 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
284 sendBotChatStart("START_TRADE_ITEM");
285 BotChatPageAll->Trade->setBuyOnly(false);
286 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::Money);
287 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatTrade"));
288 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
290 // Context help
291 contextHelp ("inventory");
294 REGISTER_ACTION_HANDLER( CHandlerContextTradeItem, "context_trade_item");
296 // ***************************************************************************
297 // GCM Trade Teleport (with bot)
298 // ***************************************************************************
299 class CHandlerContextTradeTeleport : public IActionHandler
301 public:
302 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
304 sendBotChatStart("START_TRADE_TELEPORT");
305 BotChatPageAll->Trade->setBuyOnly(true);
306 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::Money);
307 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatTeleport"));
308 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
309 // Context help
310 contextHelp ("inventory");
313 REGISTER_ACTION_HANDLER( CHandlerContextTradeTeleport, "context_trade_teleport");
315 // ***************************************************************************
316 // GCM Trade Faction items/bricks/named items/bonuses (with bot)
317 // ***************************************************************************
318 class CHandlerContextTradeFaction : public IActionHandler
320 public:
321 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
323 sendBotChatStart("START_TRADE_FACTION");
324 BotChatPageAll->Trade->setBuyOnly(true);
325 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::MoneyFactionPoints);
326 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatFaction"));
327 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
328 // Context help
329 contextHelp ("inventory");
332 REGISTER_ACTION_HANDLER( CHandlerContextTradeFaction, "context_trade_faction");
334 // ***************************************************************************
335 // GCM Trade Cosmetic (with bot)
336 // ***************************************************************************
337 class CHandlerContextTradeCosmetic : public IActionHandler
339 public:
340 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
342 sendBotChatStart("START_TRADE_ITEM");
343 BotChatPageAll->Trade->setBuyOnly(true);
344 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::Money);
345 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatCosmetic"));
346 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
347 // Context help
348 contextHelp ("inventory");
351 REGISTER_ACTION_HANDLER( CHandlerContextTradeCosmetic, "context_trade_cosmetic");
353 // ***************************************************************************
354 // GCM Trade Guild Options (with bot) (le concierge)
355 // ***************************************************************************
356 class CHandlerContextTradeGuildOptions : public IActionHandler
358 public:
359 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
361 sendBotChatStart("START_TRADE_GUILD_OPTIONS");
362 BotChatPageAll->Trade->setBuyOnly(true);
363 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::MoneyGuildXP);
364 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatGuildOptions"));
365 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
366 // Context help
367 contextHelp ("inventory");
370 REGISTER_ACTION_HANDLER( CHandlerContextTradeGuildOptions, "context_trade_guild_options");
372 // ***************************************************************************
373 // GCM Trade Outpost Building (with bot) (the building itself)
374 // ***************************************************************************
375 class CHandlerContextTradeOutpostBuilding : public IActionHandler
377 public:
378 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
380 sendBotChatStart("START_TRADE_GUILD_OPTIONS");
381 BotChatPageAll->Trade->setBuyOnly(true);
382 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::GuildMoney);
383 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatGuildOptions"));
384 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
385 // Context help
386 contextHelp ("inventory");
389 REGISTER_ACTION_HANDLER( CHandlerContextTradeOutpostBuilding, "context_trade_outpost_building");
391 // ***************************************************************************
392 // GCM Trade phrase from the guild role master
393 // ***************************************************************************
394 class CHandlerContextTradeGuildRoleMaster : public IActionHandler
396 public:
397 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
399 sendBotChatStart("START_GUILD_RESEARCH");
400 BotChatPageAll->Trade->setBuyOnly(true);
401 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::GuildXP);
402 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiBotChatGuildRoleMaster"));
403 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
404 // Context help
405 contextHelp ("inventory");
408 REGISTER_ACTION_HANDLER( CHandlerContextTradeGuildRoleMaster, "context_trade_guild_role_master");
410 // ***************************************************************************
411 // GCM Trade Skill (with bot)
412 // ***************************************************************************
413 class CHandlerContextTradeSkill : public IActionHandler
415 public:
416 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
418 sendBotChatStart("START_TRADE_SKILL");
419 BotChatPageAll->Trade->setBuyOnly(true);
420 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::SkillPoints);
421 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiLearn"));
422 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
425 REGISTER_ACTION_HANDLER(CHandlerContextTradeSkill, "context_trade_skill");
427 // ***************************************************************************
428 // GCM Trade Pacts (with bot)
429 // ***************************************************************************
430 class CHandlerContextTradePact : public IActionHandler
432 public:
433 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
435 sendBotChatStart("START_TRADE_PACT");
436 BotChatPageAll->Trade->setBuyOnly(true);
437 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::SkillPoints);
438 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiLearn"));
439 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
442 REGISTER_ACTION_HANDLER(CHandlerContextTradePact, "context_trade_pact");
444 // ***************************************************************************
445 // GCM Trade Phrases (with bot)
446 // ***************************************************************************
447 class CHandlerContextTradePhrase : public IActionHandler
449 public:
450 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
452 sendBotChatStart("START_TRADE_ACTION");
453 BotChatPageAll->Trade->setBuyOnly(true);
454 BotChatPageAll->Trade->setBuyMean(CBotChatPageTrade::SkillPoints);
455 BotChatPageAll->Trade->setTitle(NLMISC::CI18N::get("uiLearn"));
456 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->Trade);
459 REGISTER_ACTION_HANDLER(CHandlerContextTradePhrase, "context_trade_phrase");
461 // ***************************************************************************
462 // GCM Choose mission
463 // ***************************************************************************
464 class CHandlerContextChooseMission : public IActionHandler
466 public:
467 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
469 sendBotChatStart("START_CHOOSE_MISSION");
470 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::Mission);
471 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
474 REGISTER_ACTION_HANDLER(CHandlerContextChooseMission, "context_choose_mission");
476 // ***************************************************************************
477 // GCM Create guild
478 // ***************************************************************************
479 class CHandlerContextCreateGuild : public IActionHandler
481 public:
482 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
484 CBotChatManager::getInstance()->incrementSessionID();
486 sendMsgToServer("BOTCHAT:START_CREATE_GUILD");
488 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->CreateGuild);
490 // Context help
491 contextHelp ("guild");
494 REGISTER_ACTION_HANDLER(CHandlerContextCreateGuild, "context_create_guild");
497 // ***************************************************************************
498 // GCM Mission option
499 // ***************************************************************************
500 class CHandlerContextMissionOption : public IActionHandler
502 public:
503 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
505 std::string id = getParam(sParams, "id");
506 sint intId;
507 if (!fromString(id, intId)) return;
508 //nlinfo("intId = %d", intId);
509 CBotChatManager::getInstance()->incrementSessionID();
511 CInterfaceManager *im = CInterfaceManager::getInstance();
512 // get flags
513 std::string playerGiftNeededDbPath = toString("LOCAL:TARGET:CONTEXT_MENU:MISSIONS_OPTIONS:%d:PLAYER_GIFT_NEEDED", intId);
514 CCDBNodeLeaf *playerGiftNeeded = NLGUI::CDBManager::getInstance()->getDbProp(playerGiftNeededDbPath, false);
515 if (!playerGiftNeeded) return;
517 //CBotChatManager::getInstance()->setChosenMissionFlags((uint) missionFlags->getValue8());
518 // a gift from player is required
519 sendMsgToServer("BOTCHAT:CONTINUE_MISSION", (uint8)intId);
521 if (playerGiftNeeded->getValue8())
523 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->PlayerGift);
527 REGISTER_ACTION_HANDLER(CHandlerContextMissionOption, "mission_option");
530 // ***************************************************************************
531 // GCM Missions
532 // ***************************************************************************
534 class CHandlerContextMissions : public IActionHandler
536 public:
537 void execute (CCtrlBase *pCaller, const std::string &sParams)
539 CInterfaceManager *im = CInterfaceManager::getInstance();
540 // if there is only a single page available for missions, go to that page directly
541 CCDBNodeLeaf *progs = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:TARGET:PROGRAMMES", false);
542 if (!progs)
544 nlwarning("<CHandlerContextMissions::execute> can't retrieve programs.");
545 return;
547 bool missionsToDo = (progs->getValue32() & (1 << BOTCHATTYPE::AvailableMissionFamily)) != 0;
548 bool missionsToContinue = (progs->getValue32() & (1 << BOTCHATTYPE::CompletedMissionFamily)) != 0;
549 bool missionsTofinish = (progs->getValue32() & (1 << BOTCHATTYPE::ContinuedMissionFamily)) != 0;
550 if (missionsToDo && !missionsToContinue && !missionsTofinish)
552 startBotChatAtPage(BOTCHATTYPE::AvailableMissions);
554 else if (!missionsToDo && missionsToContinue && !missionsTofinish)
556 startBotChatAtPage(BOTCHATTYPE::MissionProgress);
558 else if (!missionsToDo && !missionsToContinue && missionsTofinish)
560 startBotChatAtPage(BOTCHATTYPE::CompletedMissions);
562 else
564 startBotChatAtPage(BOTCHATTYPE::MissionStartPage);
568 REGISTER_ACTION_HANDLER(CHandlerContextMissions, "context_missions");
571 // ***************************************************************************
572 // GCM Available missions
573 // ***************************************************************************
575 class CHandlerContextAvailableMissions : public IActionHandler
577 public:
578 void execute (CCtrlBase *pCaller, const std::string &sParams)
580 startBotChatAtPage(BOTCHATTYPE::AvailableMissions); // missions list page. If only one option, go to this page ?
583 REGISTER_ACTION_HANDLER(CHandlerContextAvailableMissions, "context_available_missions");
585 // ***************************************************************************
586 // GCM Constinue missions
587 // ***************************************************************************
588 class CHandlerContextContinueMissions : public IActionHandler
590 public:
591 void execute (CCtrlBase *pCaller, const std::string &sParams)
593 startBotChatAtPage(BOTCHATTYPE::MissionProgress); // missions list page. If only one option, go to this page ?
596 REGISTER_ACTION_HANDLER(CHandlerContextContinueMissions, "context_continue_missions");
598 // ***************************************************************************
599 // GCM Finish missions
600 // ***************************************************************************
601 class CHandlerContextFinishMissions : public IActionHandler
603 public:
604 void execute (CCtrlBase *pCaller, const std::string &sParams)
606 startBotChatAtPage(BOTCHATTYPE::CompletedMissions); // missions list page. If only one option, go to this page ?
609 REGISTER_ACTION_HANDLER(CHandlerContextFinishMissions, "context_finish_missions");
613 // ***************************************************************************
614 // GCM Attack
615 // ***************************************************************************
617 class CHandlerContextAttack : public IActionHandler
619 public:
620 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
623 if( !UserEntity->canEngageCombat() )
624 return;
626 // Move to the current selection and attack.
627 UserEntity->moveToAttack();
629 protected:
631 REGISTER_ACTION_HANDLER( CHandlerContextAttack, "context_attack");
633 // ***************************************************************************
634 // GCM Duel
635 // ***************************************************************************
637 class CHandlerContextDuel : public IActionHandler
639 public:
640 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
642 sendMsgToServer("DUEL:ASK");
645 REGISTER_ACTION_HANDLER( CHandlerContextDuel, "context_duel");
647 // ***************************************************************************
648 // GCM UnDuel
649 // ***************************************************************************
651 class CHandlerContextUnDuel : public IActionHandler
653 public:
654 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
656 sendMsgToServer("DUEL:ABANDON");
659 REGISTER_ACTION_HANDLER( CHandlerContextUnDuel, "context_unduel");
661 // ***************************************************************************
662 // GCM PVP Challenge
663 // ***************************************************************************
665 class CHandlerContextPVPChallenge : public IActionHandler
667 public:
668 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
670 sendMsgToServer("PVP_CHALLENGE:ASK");
673 REGISTER_ACTION_HANDLER( CHandlerContextPVPChallenge, "context_pvp_challenge");
675 // ***************************************************************************
676 // GCM Un_PVP_Challenge
677 // ***************************************************************************
679 class CHandlerContextUnPVPChallenge : public IActionHandler
681 public:
682 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
684 sendMsgToServer("PVP_CHALLENGE:ABANDON");
687 REGISTER_ACTION_HANDLER( CHandlerContextUnPVPChallenge, "context_unpvp_challenge");
689 // ***************************************************************************
690 // GCM Invit
691 // ***************************************************************************
693 class CHandlerContextInvit : public IActionHandler
695 public:
696 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
698 // Game Specific Code
699 sendMsgToServer("TEAM:JOIN_PROPOSAL");
701 protected:
703 REGISTER_ACTION_HANDLER( CHandlerContextInvit, "context_invit");
705 // ***************************************************************************
706 // GCM Guild Invit
707 // ***************************************************************************
709 class CHandlerContextGuildInvit : public IActionHandler
711 public:
712 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
714 // Game Specific Code
715 sendMsgToServer("GUILD:INVITATION");
717 protected:
719 REGISTER_ACTION_HANDLER( CHandlerContextGuildInvit, "context_guild_invit");
721 // ***************************************************************************
722 // GCM Add to friend list
723 // ***************************************************************************
724 class CHandlerContextAddToFriendList : public IActionHandler
726 public:
727 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
729 CLFECOMMON::TCLEntityId trader = UserEntity->selection();
730 if (trader != CLFECOMMON::INVALID_SLOT)
732 CEntityCL *entity = EntitiesMngr.entity(trader);
733 if (entity)
735 string playerName = entity->getEntityName();
736 if (!playerName.empty())
738 PeopleInterraction.askAddContact(playerName, &PeopleInterraction.FriendList);
744 REGISTER_ACTION_HANDLER( CHandlerContextAddToFriendList, "context_add_to_friend_list");
747 // ***************************************************************************
748 // chooseSheath
749 // ***************************************************************************
751 static void chooseSheath (ITEMFAMILY::EItemFamily eIF, string sAllSkills)
753 // Choose right sheath
754 CInterfaceManager *pIM = CInterfaceManager::getInstance();
755 CCDBNodeLeaf *pNLwrite = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("ui_set_active"));
756 CCDBNodeLeaf *pNLread = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("set_nb"));
757 sint32 nNbSheath = (sint32)pNLread->getValue64();
758 if (nNbSheath == 0) return;
759 pNLread = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("set_active"));
760 sint32 nActiveSheath = (sint32)pNLread->getValue64();
761 bool bFound = false;
762 for (sint32 i = 0; i < ((nNbSheath/2)+1); ++i)
764 for (sint32 j = 0; j < 2; ++j)
766 sint32 nSheathToTest;
767 if (j == 0)
768 nSheathToTest = nActiveSheath + i;
769 else
770 nSheathToTest = nActiveSheath - i;
771 while (nSheathToTest < INVENTORIES::sheath) nSheathToTest += nNbSheath;
772 while (nSheathToTest >= (INVENTORIES::sheath+nNbSheath)) nSheathToTest -= nNbSheath;
774 string sPath;
775 sPath = CWidgetManager::getInstance()->getParser()->getDefine("set_base") + ":" + NLMISC::toString(nSheathToTest) + ":" + CWidgetManager::getInstance()->getParser()->getDefine("set_r") + ":SHEET";
776 pNLread = NLGUI::CDBManager::getInstance()->getDbProp(sPath);
777 sint32 sheetid = (sint32)pNLread->getValue64();
778 CItemSheet *pIS = dynamic_cast<CItemSheet *>(SheetMngr.get(CSheetId(sheetid)));
779 if (pIS != NULL)
781 if (pIS->Family == eIF)
783 // YOYO: Fast search. important because skill_list is too big for "training" buton case
784 string skillList= IActionHandler::getParam (sAllSkills, "skill_list");
785 if( !skillList.empty() )
787 std::vector<string> strList;
788 NLMISC::splitString(skillList, ",", strList);
789 for(uint k=0;k<strList.size();k++)
791 static string sSkillToTrain;
792 sSkillToTrain= strList[k];
793 // remove \n,\t and spaces
794 while( !sSkillToTrain.empty() &&
795 (sSkillToTrain[0]==' ' || sSkillToTrain[0]=='\n' || sSkillToTrain[0]=='\t') )
796 sSkillToTrain.erase(0, 1);
797 // If the tool skill match the skill filter, and if the player know this skill => OK!
798 if (pIS->Tool.Skill == SKILLS::toSkill(sSkillToTrain) && playerKnowSkill(pIS->Tool.Skill) )
800 bFound = true;
801 pNLwrite->setValue64(nSheathToTest);
802 break;
806 if (bFound) break;
810 if (bFound) break;
816 // ***************************************************************************
817 // GCM Exchange
818 // ***************************************************************************
820 class CHandlerContextExchange : public IActionHandler
822 public:
823 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
825 // Game Specific Code
826 sendMsgToServer("EXCHANGE:PROPOSAL");
828 protected:
830 REGISTER_ACTION_HANDLER( CHandlerContextExchange, "context_exchange");
832 // ***************************************************************************
833 // GCM Free look
834 // ***************************************************************************
835 class CHandlerContextFreeLook : public IActionHandler
837 public:
838 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
840 // Free Look Mode Activated.
841 UserControls.startFreeLook();
843 protected:
845 REGISTER_ACTION_HANDLER( CHandlerContextFreeLook, "context_free_look");
847 // ***************************************************************************
848 // GCM Move
849 // ***************************************************************************
850 class CHandlerMove : public IActionHandler
852 public:
853 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
855 // Autowalk Mode Activated.
856 UserControls.autowalkState(true);
858 protected:
860 REGISTER_ACTION_HANDLER( CHandlerMove, "context_move");
862 // ***************************************************************************
863 // GCM Stop
864 // ***************************************************************************
865 class CHandlerStop : public IActionHandler
867 public:
868 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
870 // Autowalk Mode Activated.
871 UserControls.autowalkState(false);
873 protected:
875 REGISTER_ACTION_HANDLER( CHandlerStop, "context_stop");
877 // ***************************************************************************
878 class CHandlerExitFreeLook : public IActionHandler
880 public:
881 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
883 // Deactivate free look mode
884 UserControls.stopFreeLook();
886 protected:
888 REGISTER_ACTION_HANDLER( CHandlerExitFreeLook, "exit_free_look");
890 // ***************************************************************************
891 // GCM Loot Action
892 // ***************************************************************************
893 class CHandlerContextLootAction : public IActionHandler
895 public:
896 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
898 NetMngr.pushPickup(UserEntity->selection(), LHSTATE::LOOTABLE);
900 // For loot open directly temporary inventory
901 CTempInvManager::getInstance()->open(TEMP_INV_MODE::Loot);
903 protected:
905 REGISTER_ACTION_HANDLER( CHandlerContextLootAction, "context_loot");
907 // ***************************************************************************
908 // GCM Quartering Action
909 // ***************************************************************************
910 class CHandlerContextHarvestAction : public IActionHandler
912 public:
913 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
915 NetMngr.pushPickup(UserEntity->selection(), LHSTATE::HARVESTABLE);
916 // For quartering and forage open directly temporary inventory
917 CTempInvManager::getInstance()->open(TEMP_INV_MODE::Quarter);
919 protected:
921 REGISTER_ACTION_HANDLER( CHandlerContextHarvestAction, "context_quartering");
923 // ***************************************************************************
924 // GCM Forage Action
925 // ***************************************************************************
926 class CHandlerContextForageExtract : public IActionHandler
928 public:
929 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
931 if (UserEntity->selection())
933 CEntityCL *pSel = EntitiesMngr.entity(UserEntity->selection());
934 if (pSel != NULL)
935 if (pSel->isForageSource())
936 UserEntity->moveToExtractionPhrase(UserEntity->selection(), 2.0f, std::numeric_limits<uint>::max(), std::numeric_limits<uint>::max(), true);
940 REGISTER_ACTION_HANDLER( CHandlerContextForageExtract, "context_extract_rm");
943 // ***************************************************************************
944 // GCM Quit Team
945 // ***************************************************************************
947 class CHandlerContextQuitTeam : public IActionHandler
949 public:
950 void execute (CCtrlBase *pCaller, const std::string &sParams)
952 // directly launch the quit_team AH.
953 CInterfaceManager *pIM= CInterfaceManager::getInstance();
954 CAHManager::getInstance()->runActionHandler("quit_team",pCaller, sParams);
956 protected:
958 REGISTER_ACTION_HANDLER( CHandlerContextQuitTeam, "context_quit_team");
961 // ***************************************************************************
962 // GCM Quit Guild
963 // ***************************************************************************
965 class CHandlerContextQuitGuild : public IActionHandler
967 public:
968 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
970 CInterfaceManager *pIM= CInterfaceManager::getInstance();
972 // Ask if ok before.
973 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQQuitGuild"), "do_quit_guild");
975 protected:
977 REGISTER_ACTION_HANDLER( CHandlerContextQuitGuild, "context_quit_guild");
980 // If Ok.
981 class CHandlerDoQuitGuild : public IActionHandler
983 public:
984 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
986 // Create the message for the server to execute a phrase.
987 sendMsgToServer("GUILD:QUIT");
988 CGuildManager::getInstance()->closeAllInterfaces();
990 if (PeopleInterraction.TheUserChat.Filter.getTargetGroup() == CChatGroup::guild)
991 ChatMngr.updateChatModeAndButton(CChatGroup::say);
994 REGISTER_ACTION_HANDLER( CHandlerDoQuitGuild, "do_quit_guild");
997 // ***************************************************************************
998 // GCM Disengage
999 // ***************************************************************************
1001 class CHandlerContextDisengage : public IActionHandler
1003 public:
1004 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1006 // Disengage
1007 UserEntity->disengage();
1009 protected:
1012 REGISTER_ACTION_HANDLER( CHandlerContextDisengage, "context_disengage");
1014 // ***************************************************************************
1015 // GCM Mount
1016 // ***************************************************************************
1018 class CHandlerContextMount : public IActionHandler
1020 public:
1021 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1023 CEntityCL *sel = EntitiesMngr.entity(UserEntity->selection());
1024 if (sel == NULL) return;
1026 // Game Specific Code
1027 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1029 // Look through Database the index of the mount selected
1030 for (uint32 i = 0; i < MAX_INVENTORY_ANIMAL; i++)
1032 CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", i), false);
1033 CCDBNodeLeaf *typeProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:TYPE", i), false);
1034 if ((uidProp != NULL) && (uidProp->getValue32() == (sint32)sel->dataSetId()) &&
1035 (typeProp != NULL) && (typeProp->getValue32() == ANIMAL_TYPE::Mount))
1037 beastOrder("mount", toString(i+1)); // why +1 ? : dixit sendAnimalCommand in EGS : index 0 = all animals, 1 = animal 0 etc
1038 CAHManager::getInstance()->runActionHandler("animal_target", NULL, toString(i+1));
1039 UserEntity->moveTo(UserEntity->selection(),2.0,CUserEntity::None);
1044 REGISTER_ACTION_HANDLER( CHandlerContextMount, "context_mount");
1046 // ***************************************************************************
1047 // GCM Unseat
1048 // ***************************************************************************
1050 class CHandlerContextUnseat : public IActionHandler
1052 public:
1053 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1055 // Game Specific Code
1056 beastOrder("unmount", "0");
1058 // Set the database in local.
1059 if(ClientCfg.Local)
1061 // Prepare the database to unseat
1062 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->slot()) + ":P" + toString(CLFECOMMON::PROPERTY_MODE), MBEHAV::NORMAL);
1063 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->slot()) + ":P" + toString(CLFECOMMON::PROPERTY_ENTITY_MOUNTED_ID), CLFECOMMON::INVALID_SLOT);
1064 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->mount()) + ":P" + toString(CLFECOMMON::PROPERTY_MODE), MBEHAV::NORMAL);
1065 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->mount()) + ":P" + toString(CLFECOMMON::PROPERTY_RIDER_ENTITY_ID), CLFECOMMON::INVALID_SLOT);
1066 // Read the database to unseat.
1067 CEntityCL *mount = EntitiesMngr.entity(UserEntity->mount());
1068 if(mount)
1070 mount->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_MODE);
1071 mount->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_RIDER_ENTITY_ID);
1073 UserEntity->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_MODE);
1074 UserEntity->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_ENTITY_MOUNTED_ID);
1077 protected:
1080 REGISTER_ACTION_HANDLER( CHandlerContextUnseat, "context_unseat");
1083 // ***************************************************************************
1084 class CHandlerContextWebPage : public IActionHandler
1086 public:
1087 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1089 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1091 // start the npc web page
1092 CLuaManager::getInstance().executeLuaScript("game:startNpcWebPage()", true);
1095 REGISTER_ACTION_HANDLER( CHandlerContextWebPage, "context_web_page");
1100 // ***************************************************************************
1101 // GCM Mission option
1102 // ***************************************************************************
1103 class CHandlerContextMissionRing : public IActionHandler
1105 public:
1106 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
1108 std::string id = getParam(sParams, "id");
1109 sint idInDb;
1110 if (!fromString(id, idInDb)) return;
1112 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1114 // get ID
1115 CCDBNodeLeaf *dbMissionId = NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSION_RING:%d:ID", idInDb), false);
1116 if (!dbMissionId)
1117 return;
1118 uint32 missionId= dbMissionId->getValue32();
1120 // send msg
1121 sendMsgToServer("RING_MISSION:MISSION_RING_SELECT", (uint32)missionId);
1124 REGISTER_ACTION_HANDLER(CHandlerContextMissionRing, "mission_ring");
1127 /**********************************************************************************************************
1129 * game handlers *
1131 ***********************************************************************************************************/
1134 // ***************************************************************************
1135 //quit the game
1136 class CAHQuitGame : public IActionHandler
1138 public:
1139 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1141 /* todo game_exit
1142 game_exit = true;
1143 nlinfo("User Request to Quit the game"); */
1146 REGISTER_ACTION_HANDLER( CAHQuitGame, "quit_game");
1149 // ***************************************************************************
1150 //quit the game
1151 class CAHQuitRyzom : public IActionHandler
1153 public:
1154 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1156 // If we are not connected, quit now
1157 if((!ConnectionReadySent) && (!FarTP.isLeavingEGS()))
1159 game_exit = true;
1160 ryzom_exit = true;
1161 nlinfo("User Request to Quit ryzom");
1163 else
1165 // Don't quit but wait for server Quit
1166 game_exit_request = true;
1167 ryzom_exit_request = true;
1169 const char *msgName = "CONNECTION:CLIENT_QUIT_REQUEST";
1170 CBitMemStream out;
1171 nlverify(GenericMsgHeaderMngr.pushNameToStream(msgName, out));
1172 bool bypassDisconnectionTimer = FarTP.isFastDisconnectGranted() && (!IsInRingSession); // no need on a ring shard, as it's very short
1173 out.serial(bypassDisconnectionTimer);
1174 FarTP.writeSecurityCodeForDisconnection(out); // must always be written because of msg.xml (or could have a special handler in the FS)
1175 NetMngr.push(out);
1176 //nlinfo("impulseCallBack : %s sent", msgName.c_str());
1180 REGISTER_ACTION_HANDLER( CAHQuitRyzom, "quit_ryzom");
1182 // ***************************************************************************
1183 //paying account for Free Trial
1184 class CAHPayingAccount : public IActionHandler
1186 public:
1187 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1189 paying_account_request = FreeTrial;
1190 if(!FreeTrial)
1192 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1193 CAHManager::getInstance()->runActionHandler("quit_ryzom", NULL);
1197 REGISTER_ACTION_HANDLER( CAHPayingAccount, "paying_account");
1199 // ***************************************************************************
1200 //force quit the game
1201 class CAHQuitRyzomNow : public IActionHandler
1203 public:
1204 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1206 if(!paying_account_already_request && FreeTrial)
1208 paying_account_request = true;
1209 game_exit_after_paying_account_request = true;
1211 else
1213 game_exit = true;
1214 ryzom_exit = true;
1216 paying_account_already_request = false;
1218 //game_exit = true;
1219 //ryzom_exit = true;
1221 nlinfo("User Force to Quit ryzom");
1224 REGISTER_ACTION_HANDLER( CAHQuitRyzomNow, "quit_ryzom_now");
1227 // ***************************************************************************
1228 //Abort quit the game
1229 class CAHQuitRyzomAbort : public IActionHandler
1231 public:
1232 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1234 if(ClientCfg.Local)
1236 game_exit_request = false;
1237 ryzom_exit_request = false;
1238 nlinfo("User Abort to Quit ryzom");
1240 else
1242 // send a message to server, thru cancel cast
1243 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1244 CAHManager::getInstance()->runActionHandler("phrase_cancel_cast", NULL);
1246 paying_account_request = false;
1247 paying_account_already_request = false;
1250 REGISTER_ACTION_HANDLER( CAHQuitRyzomAbort, "quit_ryzom_abort");
1252 // ***************************************************************************
1253 //Abort quit the game
1254 class CAHCloseFreeTrialQuitting : public IActionHandler
1256 public:
1257 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1259 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1261 paying_account_request = false;
1263 if(game_exit_after_paying_account_request)
1265 game_exit = true;
1266 ryzom_exit = true;
1267 game_exit_after_paying_account_request = false;
1269 else
1271 paying_account_already_request = true;
1272 CAHManager::getInstance()->runActionHandler("quit_ryzom", NULL);
1275 CAHManager::getInstance()->runActionHandler("leave_modal", NULL);
1278 REGISTER_ACTION_HANDLER( CAHCloseFreeTrialQuitting, "close_free_trial_game_quitting");
1281 // ***************************************************************************
1282 // quit the ring session and return to mainland Ryzom
1283 class CAHReturnToMainland : public IActionHandler
1285 public:
1286 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1288 FarTP.requestReturnToPreviousSession();
1291 REGISTER_ACTION_HANDLER( CAHReturnToMainland, "return_to_mainland");
1293 // ***************************************************************************
1294 // quit the ring session and return to character selection
1295 class CAHReselectCharacter : public IActionHandler
1297 public:
1298 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1300 nlinfo("User request to reselect character");
1301 FarTP.requestReconnection();
1304 REGISTER_ACTION_HANDLER( CAHReselectCharacter, "reselect_character");
1306 // ***************************************************************************
1307 /** Select an item in a selection group
1309 class CSelectItemSheet : public IActionHandler
1311 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
1313 CDBCtrlSheet *ctrlSheet = dynamic_cast<CDBCtrlSheet *>(pCaller);
1314 if (!ctrlSheet) return;
1315 sint selectionGroup = ctrlSheet->getSelectionGroup();
1316 CInterfaceManager *im = CInterfaceManager::getInstance();
1317 const CCtrlSheetSelection &css = CWidgetManager::getInstance()->getParser()->getCtrlSheetSelection();
1318 const CSheetSelectionGroup *csg = css.getGroup(selectionGroup);
1319 if (csg && csg->isActive())
1321 if (ctrlSheet->getSheetId() != 0)
1323 // set the slot as the current selection
1324 CDBCtrlSheet::setCurrSelection(ctrlSheet);
1326 else
1328 CDBCtrlSheet::setCurrSelection(NULL);
1331 bool canUse = true;
1332 bool canBuild = true;
1333 bool canUseBuiltItem = true;
1334 // check if user has the level to use the item (applies to item & plans)
1335 if (ctrlSheet->getSheetCategory() == CDBCtrlSheet::Item)
1337 if (csg && csg->getName() == "buy_selection")
1339 const CItemSheet *is = ctrlSheet->asItemSheet();
1340 if (is)
1342 // get the needed skill to use the item
1343 SKILLS::ESkills rs = is->getRequiredSkill();
1344 if (rs < SKILLS::unknown)
1346 #define SKILL_PATH "SERVER:CHARACTER_INFO:SKILLS:"
1347 string path = toString(SKILL_PATH "%d:SKILL", (int) rs);
1348 CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(path,false);
1349 if (nl)
1351 if (nl->getValue32() == 0)
1353 canUse = false;
1358 // display msg in the system infos
1359 if (!canUse)
1361 string msg = CI18N::get("msgCantUseItem");
1362 string cat = getStringCategory(msg, msg);
1363 im->displaySystemInfo(msg, cat);
1365 if (!canBuild)
1367 string msg = CI18N::get("msgCantBuild");
1368 string cat = getStringCategory(msg, msg);
1369 im->displaySystemInfo(msg, cat);
1371 if (!canUseBuiltItem)
1373 string msg = CI18N::get("msgCantUseBuiltItem");
1374 string cat = getStringCategory(msg, msg);
1375 im->displaySystemInfo(msg, cat);
1380 showItemFlags(im, canUse, canBuild, canUseBuiltItem);
1385 /** On the trade windows, display or not : can use item, can build item, can use built item
1387 void showItemFlags(CInterfaceManager *im, bool canUse, bool canBuild, bool canUseBuiltItem);
1389 REGISTER_ACTION_HANDLER (CSelectItemSheet, "select_item");
1391 void CSelectItemSheet::showItemFlags(CInterfaceManager *im,bool canUse,bool canBuild,bool canUseBuiltItem)
1393 if (!im) return;
1394 CInterfaceGroup *gr;
1395 #define BOT_CHAT_TRADE_PATH "ui:interface:bot_chat_trade:header_opened:trade_content:"
1396 gr = dynamic_cast<CInterfaceGroup *>( CWidgetManager::getInstance()->getElementFromId(BOT_CHAT_TRADE_PATH "cant_use_item"));
1397 if (gr) gr->setActive(!canUse);
1398 gr = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(BOT_CHAT_TRADE_PATH "cant_use_built_item"));
1399 if (gr) gr->setActive(!canUseBuiltItem);
1400 gr = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(BOT_CHAT_TRADE_PATH "cant_build_item"));
1401 if (gr) gr->setActive(!canBuild);
1405 // ***************************************************************************
1406 /** Set a price in the given DB entries
1409 class CSetPriceInDB : public IActionHandler
1411 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1413 std::string ls = getParam(Params, "ls");
1414 std::string ms = getParam(Params, "ms");
1415 std::string bs = getParam(Params, "bs");
1416 std::string vbs = getParam(Params, "vbs");
1417 std::string value = getParam(Params, "value");
1418 if (ls.empty() || ms.empty() || bs.empty() || vbs.empty() || value.empty())
1420 nlwarning("<CSetItemPriceInDB::execute> can't get db address for all kind of seeds, or can't get value");
1421 return;
1423 CInterfaceExprValue price;
1424 if (!CInterfaceExpr::eval(value, price) || !price.toInteger())
1426 nlwarning("<CSetPriceInDB::execute> : Can't evaluate price");
1427 return;
1429 CInterfaceManager *im = CInterfaceManager::getInstance();
1430 if (price.getInteger() >= 0)
1432 CSeeds money;
1433 money.setTotal(price.getInteger());
1434 NLGUI::CDBManager::getInstance()->getDbProp(ls)->setValue64(money.getLS());
1435 NLGUI::CDBManager::getInstance()->getDbProp(ms)->setValue64(money.getMS());
1436 NLGUI::CDBManager::getInstance()->getDbProp(bs)->setValue64(money.getBS());
1437 NLGUI::CDBManager::getInstance()->getDbProp(vbs)->setValue64(money.getVBS());
1439 else
1441 // undefined price
1442 NLGUI::CDBManager::getInstance()->getDbProp(ls)->setValue64(-1);
1443 NLGUI::CDBManager::getInstance()->getDbProp(ms)->setValue64(-1);
1444 NLGUI::CDBManager::getInstance()->getDbProp(bs)->setValue64(-1);
1445 NLGUI::CDBManager::getInstance()->getDbProp(vbs)->setValue64(-1);
1449 REGISTER_ACTION_HANDLER (CSetPriceInDB, "set_price_in_db");
1452 // ***************************************************************************
1453 /** Pack animal orders
1455 //give an order to the beast
1456 void beastOrder (const std::string &orderStr, const std::string &beastIndexStr, bool confirmFree)
1458 uint8 order = (uint8) ANIMALS_ORDERS::stringToBeastOrder(orderStr);
1459 if (order == ANIMALS_ORDERS::UNKNOWN_BEAST_ORDER)
1461 nlwarning("<beastOrder> : invalid beast order : %s", orderStr.c_str());
1462 return;
1464 sint64 beastIndex;
1465 if (!CInterfaceExpr::evalAsInt(beastIndexStr, beastIndex))
1467 nlwarning("<beastOrder> : can't read beast index");
1468 return;
1470 // 0 is for all beasts => MAX_INVENTORY_ANIMAL is a valid selection
1471 if (beastIndex > MAX_INVENTORY_ANIMAL)
1473 nlwarning("<beastOrder> : invalid animal index %d, maximum is %d", beastIndex, (int) MAX_INVENTORY_ANIMAL);
1474 return;
1477 // if the order is a free, and if confirm, open a message first
1478 if(order == ANIMALS_ORDERS::FREE && confirmFree)
1480 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1481 if(beastIndex==0)
1482 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQConfirmFreeAllAnimal"),
1483 "do_beast_free", toString(beastIndex) );
1484 else
1485 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQConfirmFreeAnimal"),
1486 "do_beast_free", toString(beastIndex) );
1488 // else launch the command
1489 else
1491 // execute the order.
1492 const char *msgName = "ANIMALS:BEAST";
1493 CBitMemStream out;
1494 if(GenericMsgHeaderMngr.pushNameToStream(msgName, out))
1496 uint8 u8BeastIndex = (uint8) beastIndex;
1497 out.serial(u8BeastIndex); // to activate on server side
1498 // 0 -> all beasts, otherwise, the index of the beast
1499 out.serial(order);
1500 NetMngr.push(out);
1502 else
1503 nlwarning("<beastOrder> : unknown message name : '%s'.", msgName);
1507 // ***************************************************************************
1508 class CHandlerBeastOrder : public IActionHandler
1510 public:
1511 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1513 string orderStr = getParam(Params,"order");
1514 if( orderStr == "mount" )
1516 // target the beast
1517 CInterfaceManager * pIM= CInterfaceManager::getInstance();
1518 string beastIndex;
1519 if( CInterfaceExpr::evalAsString(getParam(Params,"beast_index"), beastIndex) )
1521 CAHManager::getInstance()->runActionHandler("animal_target", NULL, beastIndex);
1523 // move to the beast
1524 UserEntity->moveTo(UserEntity->selection(),3.0,CUserEntity::Mount);
1526 else
1527 beastOrder (getParam(Params,"order"), getParam(Params,"beast_index"), true);
1530 REGISTER_ACTION_HANDLER( CHandlerBeastOrder, "beast_order")
1533 // ***************************************************************************
1534 class CHandlerDoBeastFree : public IActionHandler
1536 public:
1537 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1539 // free with no confirm
1540 if (!UserEntity->isBusy())
1541 beastOrder ("free", Params, false);
1544 REGISTER_ACTION_HANDLER( CHandlerDoBeastFree, "do_beast_free")
1547 // ***************************************************************************
1548 // Change Possible Orders
1549 class CHandlerAnimalMenuOption : public IActionHandler
1551 public:
1552 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
1554 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1555 CInterfaceGroup *pMenu= dynamic_cast<CInterfaceGroup*>(pCaller);
1556 if(!pMenu) return;
1558 CViewTextMenu *pFollow = dynamic_cast<CViewTextMenu*>(pMenu->getView("follow"));
1559 CViewTextMenu *pStop = dynamic_cast<CViewTextMenu*>(pMenu->getView("stop"));
1560 CViewTextMenu *pFree = dynamic_cast<CViewTextMenu*>(pMenu->getView("free"));
1561 CViewTextMenu *pEnterStable = dynamic_cast<CViewTextMenu*>(pMenu->getView("enter_stable"));
1562 CViewTextMenu *pLeaveStable = dynamic_cast<CViewTextMenu*>(pMenu->getView("leave_stable"));
1563 CViewTextMenu *pEnterBag = dynamic_cast<CViewTextMenu*>(pMenu->getView("enter_bag"));
1564 CViewTextMenu *pLeaveBag = dynamic_cast<CViewTextMenu*>(pMenu->getView("leave_bag"));
1565 CViewTextMenu *pMount = dynamic_cast<CViewTextMenu*>(pMenu->getView("mount"));
1566 CViewTextMenu *pUnseat = dynamic_cast<CViewTextMenu*>(pMenu->getView("unseat"));
1568 // Get the animal Selected. 0 for Alls, 1,2,3,4,5 for each pack animal
1569 CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:BEAST_SELECTED", false);
1570 if(!node) return;
1571 sint selected= node->getValue32();
1573 // Enable menu entries according to each beast
1574 // All Mode
1575 if(selected==0)
1577 // Test all menu option ('OR': display even if *all* animals don't comply with the commands)
1578 for(uint i=0;i<MAX_INVENTORY_ANIMAL;i++)
1580 // Get the entity if it is in vision
1581 CEntityCL* selectedAnimalInVision = NULL;
1582 CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", i), false);
1583 if ( uidProp )
1585 CLFECOMMON::TClientDataSetIndex datasetIndex = uidProp->getValue32();
1586 selectedAnimalInVision = EntitiesMngr.getEntityByCompressedIndex( datasetIndex );
1589 // Enable menu items
1590 testMenuOptionForPackAnimal(selectedAnimalInVision, i, (i==0),
1591 pFollow, pStop, pFree, pEnterStable, pLeaveStable, pMount, pUnseat, pEnterBag, pLeaveBag);
1594 else if(selected>=1 && selected<=MAX_INVENTORY_ANIMAL)
1596 // Get the entity if it is in vision
1597 CEntityCL* selectedAnimalInVision = NULL;
1598 CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", selected-1), false);
1599 if ( uidProp )
1601 CLFECOMMON::TClientDataSetIndex datasetIndex = uidProp->getValue32();
1602 selectedAnimalInVision = EntitiesMngr.getEntityByCompressedIndex( datasetIndex );
1605 // Enable menu items
1606 testMenuOptionForPackAnimal(selectedAnimalInVision, selected-1, true,
1607 pFollow, pStop, pFree, pEnterStable, pLeaveStable, pMount, pUnseat, pEnterBag, pLeaveBag);
1611 REGISTER_ACTION_HANDLER( CHandlerAnimalMenuOption, "animal_menu_option")
1614 // ***************************************************************************
1615 // Target an animal
1616 class CHandlerAnimalTarget : public IActionHandler
1618 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
1620 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1622 // retrieve the index of the animal
1623 sint animalIndex = 0;
1624 bool ok = false;
1625 // If comes from the button, get direct index
1626 if( !sParams.empty() )
1628 fromString(sParams, animalIndex);
1629 ok = true;
1632 // If success to get the animal id
1633 if(ok)
1635 // Get the animal id.
1636 CLFECOMMON::TClientDataSetIndex entityUid= CLFECOMMON::INVALID_CLIENT_DATASET_INDEX;
1638 if(animalIndex>=1 && animalIndex<=MAX_INVENTORY_ANIMAL)
1640 CCDBNodeLeaf *prop = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", animalIndex-1), false);
1641 if(prop) entityUid= prop->getValue32();
1644 if(entityUid != CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
1646 // get the entity by its received UID
1647 CEntityCL *entity= EntitiesMngr.getEntityByCompressedIndex(entityUid);
1648 if(entity)
1649 // Select this entity.
1650 UserEntity->selection(entity->slot());
1651 else
1653 // the entity is not in vision, can't select it
1654 pIM->displaySystemInfo(CI18N::get("uiAnimalSelectNotInVision"), "CHK");
1660 REGISTER_ACTION_HANDLER( CHandlerAnimalTarget, "animal_target" );
1663 // ***************************************************************************
1664 // Open an animal inventory
1665 class CHandlerAnimalOpenInventory : public IActionHandler
1667 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
1669 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1671 // retrieve the index of the animal
1672 sint animalIndex= 0;
1673 bool ok= false;
1674 // If comes from the button, get direct index
1675 if( !sParams.empty() )
1677 fromString(sParams, animalIndex);
1678 ok= true;
1681 // If success to get the animal id
1682 if(ok)
1684 if(animalIndex>=1 && animalIndex<=MAX_INVENTORY_ANIMAL)
1686 // show/hide the inventory
1687 CInterfaceElement *group= CWidgetManager::getInstance()->getElementFromId(toString("ui:interface:inv_pa%d", animalIndex-1) );
1689 if(group) group->setActive(!group->getActive());
1694 REGISTER_ACTION_HANDLER( CHandlerAnimalOpenInventory, "animal_open_inventory" );
1697 // ***************************************************************************
1698 // closeGroup Helper
1699 // ***************************************************************************
1700 static void closeGroup(const string &groupName)
1702 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1703 CInterfaceGroup *pIG = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(groupName));
1704 if (pIG == NULL) return;
1705 pIG->setActive(false);
1708 // ***************************************************************************
1709 // ACCEPT TEAM INVITE
1710 // ***************************************************************************
1712 class CHandlerAcceptTeamInvitation : public IActionHandler
1714 public:
1715 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1717 closeGroup("ui:interface:join_team_proposal");
1718 sendMsgToServer("TEAM:JOIN");
1720 protected:
1723 REGISTER_ACTION_HANDLER( CHandlerAcceptTeamInvitation, "accept_team_invitation");
1725 // ***************************************************************************
1726 // REFUSE TEAM INVITE
1727 // ***************************************************************************
1729 class CHandlerRefuseTeamInvitation : public IActionHandler
1731 public:
1732 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1734 closeGroup("ui:interface:join_team_proposal");
1735 sendMsgToServer("TEAM:JOIN_PROPOSAL_DECLINE");
1737 protected:
1740 REGISTER_ACTION_HANDLER( CHandlerRefuseTeamInvitation, "refuse_team_invitation");
1742 // ***************************************************************************
1743 // ACCEPT GUILD INVITE
1744 // ***************************************************************************
1746 class CHandlerAcceptGuildInvitation : public IActionHandler
1748 public:
1749 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1751 sendMsgToServer("GUILD:ACCEPT_INVITATION");
1752 CGuildManager::getInstance()->quitJoinProposal();
1756 REGISTER_ACTION_HANDLER( CHandlerAcceptGuildInvitation, "accept_guild_invitation");
1758 // ***************************************************************************
1759 // REFUSE GUILD INVITE
1760 // ***************************************************************************
1762 class CHandlerRefuseGuildInvitation : public IActionHandler
1764 public:
1765 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1767 sendMsgToServer("GUILD:REFUSE_INVITATION");
1768 CGuildManager::getInstance()->quitJoinProposal();
1771 REGISTER_ACTION_HANDLER( CHandlerRefuseGuildInvitation, "refuse_guild_invitation");
1773 // ***************************************************************************
1774 // ACCEPT DUEL INVITE
1775 // ***************************************************************************
1777 class CHandlerAcceptDuelInvitation : public IActionHandler
1779 public:
1780 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1782 closeGroup("ui:interface:join_duel_proposal");
1783 sendMsgToServer("DUEL:ACCEPT");
1787 REGISTER_ACTION_HANDLER( CHandlerAcceptDuelInvitation, "accept_duel_invitation");
1789 // ***************************************************************************
1790 // REFUSE DUEL INVITE
1791 // ***************************************************************************
1793 class CHandlerRefuseDuelInvitation : public IActionHandler
1795 public:
1796 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1798 closeGroup("ui:interface:join_duel_proposal");
1799 sendMsgToServer("DUEL:REFUSE");
1802 REGISTER_ACTION_HANDLER( CHandlerRefuseDuelInvitation, "refuse_duel_invitation");
1804 // ***************************************************************************
1805 // ACCEPT PVP CHALLENGE INVITE
1806 // ***************************************************************************
1808 class CHandlerAcceptPVPChallengeInvitation : public IActionHandler
1810 public:
1811 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1813 closeGroup("ui:interface:join_pvp_challenge_proposal");
1814 sendMsgToServer("PVP_CHALLENGE:ACCEPT");
1818 REGISTER_ACTION_HANDLER( CHandlerAcceptPVPChallengeInvitation, "accept_pvp_challenge_invitation");
1820 // ***************************************************************************
1821 // REFUSE PVP CHALLENGE INVITE
1822 // ***************************************************************************
1824 class CHandlerRefusePVPChallengeInvitation : public IActionHandler
1826 public:
1827 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1829 closeGroup("ui:interface:join_pvp_challenge_proposal");
1830 sendMsgToServer("PVP_CHALLENGE:REFUSE");
1833 REGISTER_ACTION_HANDLER( CHandlerRefusePVPChallengeInvitation, "refuse_pvp_challenge_invitation");
1835 // ***************************************************************************
1836 // CHOOSE PVP CLAN
1837 // ***************************************************************************
1839 class CHandlerChoosePVPClan : public IActionHandler
1841 public:
1842 virtual void execute (CCtrlBase *pCaller, const string &Params)
1844 closeGroup("ui:interface:join_pvp_clan_proposal");
1846 uint8 clan = 0;
1847 if( Params == "neutral" )
1848 clan = 0;
1849 else if( Params == "clan1" )
1850 clan = 1;
1851 else if( Params == "clan2" )
1852 clan = 2;
1854 sendMsgToServer("PVP_VERSUS:CLAN", clan);
1857 REGISTER_ACTION_HANDLER( CHandlerChoosePVPClan, "pvp_clan_join");
1860 // ***************************************************************************
1861 // Launch Bug Reporting Tool
1862 // ***************************************************************************
1864 class CAHLaunchBugReport : public IActionHandler
1866 public:
1867 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1869 if (ClientCfg.Light)
1871 vector<string> v;
1872 CWidgetManager::getInstance()->runProcedure ("proc_reset_interface", NULL, v);
1874 //CInterfaceManager::getInstance()->launchContextMenuInGame("ui:interface:game_context_menu");
1876 ICommand::execute("bugReport 80", g_log);
1879 REGISTER_ACTION_HANDLER( CAHLaunchBugReport, "launch_bug_report");
1881 // ***************************************************************************
1882 // Launch Help Tool
1883 // ***************************************************************************
1885 class CAHLaunchHelp : public IActionHandler
1887 public:
1889 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1891 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1893 string url = getParam (Params, "url");
1894 string helpContainer = getParam (Params, "help_container");
1895 if (helpContainer.empty ())
1896 helpContainer = "ui:interface:help_browser";
1898 // open the help browser
1899 CInterfaceElement *pIG= CWidgetManager::getInstance()->getElementFromId(helpContainer);
1900 if(pIG)
1901 pIG->setActive(true);
1903 // browse the url
1904 CAHManager::getInstance()->runActionHandler("browse", NULL, "name="+helpContainer+":content:html|url="+url);
1907 REGISTER_ACTION_HANDLER( CAHLaunchHelp, "launch_help");
1909 // ***************************************************************************
1910 static bool findInterfacePath(string &sPath, CCtrlBase *pCaller)
1912 if (sPath.rfind(':') == string::npos)
1914 if (pCaller == NULL) return false;
1915 sPath = pCaller->getId() + ":" + sPath;
1917 else
1919 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1920 string elt = sPath.substr(0,sPath.rfind(':'));
1921 CInterfaceElement *pIE;
1922 if (pCaller != NULL)
1923 pIE = CWidgetManager::getInstance()->getElementFromId(pCaller->getId(), elt);
1924 else
1925 pIE = CWidgetManager::getInstance()->getElementFromId(elt);
1926 if (pIE == NULL) return false;
1927 sPath = pIE->getId() + ":" + sPath.substr(sPath.rfind(':')+1,sPath.size());
1929 return true;
1932 // ***************************************************************************
1933 // TARGET NAME AND TITLE MANAGEMENT
1934 // ***************************************************************************
1936 // Callbacks that check that while we are waiting for the string to display the
1937 // user has not changed its target
1939 // *** check for user selection and remove title
1940 class CSPPRemoveTitleAndCheckSelection : public CStringPostProcessRemoveTitle
1942 public:
1944 sint32 Slot;
1946 bool cbIDStringReceived(string &inout)
1948 if (UserEntity != NULL)
1950 if (UserEntity->selection() == Slot)
1952 string copyInout = inout;
1953 CStringPostProcessRemoveTitle::cbIDStringReceived(inout);
1954 if (inout.empty())
1956 CEntityCL *entity = EntitiesMngr.entity(Slot);
1957 CCharacterCL *pChar = dynamic_cast<CCharacterCL*>(entity);
1958 bool womanTitle = false;
1959 if (pChar != NULL)
1960 womanTitle = pChar->getGender() == GSGENDER::female;
1962 copyInout = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(CEntityCL::getTitleFromName(copyInout), womanTitle);
1964 // Sometimes translation contains another title
1965 string::size_type pos = copyInout.find('$');
1966 if (pos != string::npos)
1968 copyInout = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(CEntityCL::getTitleFromName(copyInout), womanTitle);
1971 CStringPostProcessRemoveTitle::cbIDStringReceived(copyInout);
1972 inout = copyInout;
1975 return true;
1979 return false;
1983 // *** check for user selection and remove name (keep title)
1984 class CSPPRemoveNameAndCheckSelection : public CStringPostProcessRemoveName
1986 public:
1988 sint32 Slot;
1990 bool cbIDStringReceived(string &inout)
1992 if (UserEntity != NULL)
1994 if (UserEntity->selection() == Slot)
1996 CEntityCL *entity = EntitiesMngr.entity(Slot);
1997 CCharacterCL *pChar = dynamic_cast<CCharacterCL*>(entity);
1998 if (pChar != NULL)
2000 const CCharacterSheet *pSheet = pChar->getSheet();
2001 if (pSheet != NULL)
2003 string sFame = pSheet->getFame();
2004 if (strnicmp(sFame.c_str(),"tribe_",6)==0)
2006 inout = STRING_MANAGER::CStringManagerClient::getFactionLocalizedName(sFame);
2007 return true; // return tribe name
2010 Woman = pChar->getGender() == GSGENDER::female;
2013 CStringPostProcessRemoveName::cbIDStringReceived(inout);
2015 return true; // return title
2018 return false;
2022 // *** called when target change or target name change
2023 class CActionHandlerSetTargetName : public IActionHandler
2025 virtual void execute (CCtrlBase *pCaller, const string &Params)
2027 string sSlot = getParam(Params,"slot");
2028 string sNameTarget = getParam(Params,"target");
2029 string sTitleTarget = getParam(Params,"title");
2031 if (sSlot.empty()) return;
2033 if (!findInterfacePath(sNameTarget, pCaller)) return;
2034 findInterfacePath(sTitleTarget, pCaller);
2036 CInterfaceExprValue evValue;
2037 if (CInterfaceExpr::eval(sSlot, evValue, NULL))
2039 sint32 nSlot = (sint32)evValue.getInteger();
2041 string TargetName;
2042 string TargetTitle;
2044 // Get from nSlot
2045 if (nSlot > -1)
2047 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2048 // uint32 nDBid = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString(nSlot)+":P6")->getValue32();
2049 uint32 nDBid = 0;
2050 if (nSlot < sint32(EntitiesMngr.entities().size()) && EntitiesMngr.entities()[nSlot] != NULL)
2052 nDBid = EntitiesMngr.entities()[nSlot]->getNameId();
2055 if (nDBid != 0)
2057 CSPPRemoveTitleAndCheckSelection *pSPPRT = new CSPPRemoveTitleAndCheckSelection;
2058 pSPPRT->Slot = nSlot;
2059 CSPPRemoveNameAndCheckSelection *pSPPRN = new CSPPRemoveNameAndCheckSelection;
2060 pSPPRN->Slot = nSlot;
2061 pIM->addServerID(sNameTarget, nDBid, pSPPRT);
2062 pIM->addServerID(sTitleTarget, nDBid, pSPPRN);
2064 else
2066 CEntityCL *pE = EntitiesMngr.entity(nSlot);
2067 if (pE != NULL)
2069 TargetName = pE->getDisplayName();
2070 TargetTitle = pE->getTitle();
2074 // Set to target
2075 CInterfaceExprValue evUCStr;
2076 TargetName = STRING_MANAGER::CStringManagerClient::getLocalizedName(TargetName);
2077 evUCStr.setString(TargetName);
2078 CInterfaceLink::setTargetProperty(sNameTarget, evUCStr);
2079 evUCStr.setString(TargetTitle);
2080 CInterfaceLink::setTargetProperty(sTitleTarget, evUCStr);
2084 REGISTER_ACTION_HANDLER (CActionHandlerSetTargetName, "set_target_name");
2086 // ***************************************************************************
2087 class CActionHandlerSetTargetForceRegionLevel: public IActionHandler
2089 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2091 string sSlot = getParam(Params,"slot");
2092 string sTargetRegion = getParam(Params,"targetRegion");
2093 string sTargetLevel = getParam(Params,"targetLevel");
2095 // Access UI elements
2096 if (sSlot.empty()) return;
2097 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2098 CViewBitmap *pVBR = dynamic_cast<CViewBitmap*>(CWidgetManager::getInstance()->getElementFromId(sTargetRegion));
2099 if (pVBR == NULL)
2100 return;
2101 CViewBitmap *pVBL = dynamic_cast<CViewBitmap*>(CWidgetManager::getInstance()->getElementFromId(sTargetLevel));
2102 if (pVBL == NULL)
2103 return;
2104 CInterfaceExprValue evValue;
2105 if (!CInterfaceExpr::eval(sSlot, evValue, NULL))
2106 return;
2107 sint32 nSlot = (sint32)evValue.getInteger();
2108 CCtrlBase *pTooltip = dynamic_cast<CCtrlBase*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:header_opened:force"));
2110 // Access target entity
2111 CEntityCL *pE = NULL;
2112 if ( (nSlot == -1) || ((pE = EntitiesMngr.entity(nSlot)) == NULL) )
2114 // If untargetted, clear
2115 pVBL->setTexture(string());
2116 pVBR->setColor(CRGBA(0,0,0,0));
2118 if (pTooltip)
2119 pTooltip->setDefaultContextHelp(std::string());
2121 return;
2124 sint nLevelForce;
2125 sint nForceRegion;
2126 if ( pE->isPlayer() )
2128 // Player => deduce RegionForce & ForceLevel from the database
2129 CCDBNodeLeaf *pDbTargetUid = NLGUI::CDBManager::getInstance()->getDbProp( CWidgetManager::getInstance()->getParser()->getDefine("target_uid") );
2130 if ( ! pDbTargetUid )
2131 return;
2132 // Hide the target level if the USER is not in PVP FACTION
2133 // Hide the target level if the TARGET is not in PVP FACTION
2134 // Also, hide it If the database is not in sync with the local target slot
2135 if (!UserEntity || !(UserEntity->getPvpMode()&PVP_MODE::PvpZoneFaction) ||
2136 !(pE->getPvpMode()&PVP_MODE::PvpZoneFaction) ||
2137 pE->dataSetId() != (CLFECOMMON::TClientDataSetIndex)pDbTargetUid->getValue32() )
2139 pVBL->setTexture(string());
2140 pVBR->setColor(CRGBA(0,0,0,0));
2142 if (pTooltip)
2143 pTooltip->setDefaultContextHelp(CI18N::get("uittTargetUnknown"));
2145 return;
2147 CCDBNodeLeaf *pDbPlayerLevel = NLGUI::CDBManager::getInstance()->getDbProp( CWidgetManager::getInstance()->getParser()->getDefine("target_player_level") );
2148 if ( ! pDbPlayerLevel )
2149 return;
2150 sint nLevel = pDbPlayerLevel->getValue32();
2151 if ( nLevel < 250 )
2153 nLevelForce = ((nLevel % 50) * 5 / 50) + 1;
2154 nForceRegion = (nLevel < 20) ? 1 : (nLevel / 50) + 2;
2156 else
2158 nLevelForce = 6; // same as named creatures
2159 nForceRegion = 8;
2162 else
2164 // Creature => RegionForce & ForceLevel are in its sheet
2165 CCharacterSheet *pCS = dynamic_cast<CCharacterSheet*>(SheetMngr.get(pE->sheetId()));
2166 if (pCS == NULL || pCS->RegionForce==-1)
2168 pVBL->setTexture(string());
2169 pVBR->setColor(CRGBA(0,0,0,0));
2171 if (pTooltip)
2172 pTooltip->setDefaultContextHelp(std::string());
2174 return;
2177 nForceRegion = pCS->RegionForce;
2178 nLevelForce = pCS->ForceLevel;
2181 // Set color
2182 if (nForceRegion > 6) nForceRegion = 6;
2183 if (nForceRegion < 1) nForceRegion = 1;
2184 CRGBA col = CInterfaceElement::convertColor(CWidgetManager::getInstance()->getParser()->getDefine("region_force_"+toString(nForceRegion)).c_str());
2185 pVBR->setColor(col);
2187 // Set texture
2188 if (nLevelForce > 8) nLevelForce = 8;
2189 if (nLevelForce < 1) nLevelForce = 1;
2190 string sTexture = CWidgetManager::getInstance()->getParser()->getDefine("force_level_"+toString(nLevelForce));
2191 pVBL->setTexture(sTexture);
2193 // Set tooltip
2194 CCtrlBase *tooltip = dynamic_cast<CCtrlBase*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:header_opened:force"));
2195 if (tooltip)
2197 string str;
2199 if (nForceRegion == 1)
2200 nForceRegion = 2;
2202 // Normal
2203 if (nLevelForce < 6)
2205 sint min = (nForceRegion-2) * 50 + (nLevelForce-1) * 10 + 1;
2206 sint max = (nForceRegion-2) * 50 + nLevelForce * 10;
2208 str= CI18N::get("uittTargetLevel");
2209 strFindReplace(str, "%min", toString(min));
2210 strFindReplace(str, "%max", toString(max));
2212 // Boss
2213 else if (nLevelForce == 8)
2215 sint n = (nForceRegion-1) * 50;
2216 if (pE->isNPC())
2217 str= CI18N::get("uittTargetGuardBoss");
2218 else
2219 str= CI18N::get("uittTargetBoss");
2220 strFindReplace(str, "%n", toString("%d", n) );
2222 // Named
2223 else
2225 sint n = (nForceRegion-1) * 50;
2226 str= CI18N::get("uittTargetNamed");
2227 strFindReplace(str, "%n", toString("%d", n) );
2230 tooltip->setDefaultContextHelp(str);
2234 REGISTER_ACTION_HANDLER (CActionHandlerSetTargetForceRegionLevel, "set_force_region_level");
2236 // ***************************************************************************
2237 class CAHUpdateCurrentMode : public IActionHandler
2239 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2241 string sValue = getParam(Params,"value");
2242 string sDBLink = getParam(Params,"dblink");
2243 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2244 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sDBLink, false);
2245 if (pNL == NULL) return;
2247 CInterfaceExprValue eVal;
2248 if (!CInterfaceExpr::eval(sValue, eVal, NULL)) return;
2250 sint32 nNewMode = (sint32)eVal.getInteger();
2252 sint32 nModeMinInf, nModeMaxInf, nModeMinLab, nModeMaxLab, nModeMinKey, nModeMaxKey;
2253 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_min_info"), nModeMinInf);
2254 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_max_info"), nModeMaxInf);
2255 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_min_lab"), nModeMinLab);
2256 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_max_lab"), nModeMaxLab);
2257 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_min_keys"), nModeMinKey);
2258 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_max_keys"), nModeMaxKey);
2260 sint32 nMode = 0;
2261 if ((nNewMode >= nModeMinInf) && (nNewMode <= nModeMaxInf))
2262 nMode = 1;
2263 if ((nNewMode >= nModeMinLab) && (nNewMode <= nModeMaxLab))
2264 nMode = 2;
2265 if ((nNewMode >= nModeMinKey) && (nNewMode <= nModeMaxKey))
2266 nMode = 3;
2269 if (nNewMode != 0)
2270 if (nNewMode == pNL->getValue32())
2272 // We have pushed 2 times the same button
2273 nNewMode ++;
2274 if (nMode == 1)
2276 if (nNewMode > nModeMaxInf) nNewMode = nModeMinInf;
2278 else if (nMode == 2)
2280 if (nNewMode > nModeMaxLab) nNewMode = nModeMinLab;
2282 else if (nMode == 3)
2284 if (nNewMode > nModeMaxKey) nNewMode = nModeMinKey;
2288 // Found the first active entry in db
2289 if (nMode == 2)
2291 bool bFound = false;
2292 while (!bFound)
2294 CCDBNodeLeaf *pIntFlags = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INTERFACES:FLAGS", false);
2295 if (pIntFlags == NULL) return;
2296 sint64 nIntFlags = pIntFlags->getValue64();
2298 sint32 tmpMode;
2300 // Is NewMode entry active ?
2301 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_magic"), tmpMode);
2302 if (nNewMode == tmpMode)
2303 if ((nIntFlags & (1<<INTERFACE_FLAGS::Magic)) != 0)
2304 bFound = true;
2306 if (!bFound)
2308 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_combat"), tmpMode);
2309 if (nNewMode == tmpMode)
2310 if ((nIntFlags & (1<<INTERFACE_FLAGS::Combat)) != 0)
2311 bFound = true;
2314 if (!bFound)
2316 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_faber_create"), tmpMode);
2317 if (nNewMode == tmpMode)
2318 if ((nIntFlags & (1<<INTERFACE_FLAGS::FaberCreate)) != 0)
2319 bFound = true;
2322 if (!bFound)
2324 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_faber_repair"), tmpMode);
2325 if (nNewMode == tmpMode)
2326 if ((nIntFlags & (1<<INTERFACE_FLAGS::FaberRepair)) != 0)
2327 bFound = true;
2330 if (!bFound)
2332 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_faber_refine"), tmpMode);
2333 if (nNewMode == tmpMode)
2334 if ((nIntFlags & (1<<INTERFACE_FLAGS::FaberRefine)) != 0)
2335 bFound = true;
2338 if (!bFound)
2340 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_commerce"), tmpMode);
2341 if (nNewMode == tmpMode)
2342 if ((nIntFlags & (1<<INTERFACE_FLAGS::Commerce)) != 0)
2343 bFound = true;
2346 if (!bFound)
2348 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_macros"), tmpMode);
2349 if (nNewMode == tmpMode)
2350 bFound = true; // Not in DB !!!
2353 if (!bFound)
2355 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_special_labo"), tmpMode);
2356 if (nNewMode == tmpMode)
2357 if ((nIntFlags & (1<<INTERFACE_FLAGS::Special)) != 0)
2358 bFound = true;
2361 if (!bFound)
2363 nNewMode++;
2364 if (nNewMode > nModeMaxLab) nNewMode = nModeMinLab;
2365 if (nNewMode == pNL->getValue32()) return;
2370 pNL->setValue32(nNewMode);
2373 REGISTER_ACTION_HANDLER (CAHUpdateCurrentMode, "update_current_mode");
2375 // ***************************************************************************
2376 class CAHToggleChat : public IActionHandler
2378 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2380 ShowInterface = !ShowInterface;
2383 REGISTER_ACTION_HANDLER (CAHToggleChat, "toggle_chat");
2385 // ***************************************************************************
2386 class CAHToggleHelp : public IActionHandler
2388 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2390 #if FINAL_VERSION
2391 if( ClientCfg.Local || hasPrivilegeDEV() || hasPrivilegeSGM() || hasPrivilegeGM() )
2392 #endif
2394 ShowHelp = !ShowHelp;
2398 REGISTER_ACTION_HANDLER (CAHToggleHelp, "toggle_help");
2400 // ***************************************************************************
2401 class CAHSelfTarget : public IActionHandler
2403 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2405 // Select the entity
2406 UserEntity->selection(0);
2409 REGISTER_ACTION_HANDLER (CAHSelfTarget, "self_target");
2411 // ***************************************************************************
2412 class CAHNoTarget : public IActionHandler
2414 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2416 // Select the entity
2417 UserEntity->selection(CLFECOMMON::INVALID_SLOT);
2420 REGISTER_ACTION_HANDLER (CAHNoTarget, "no_target");
2422 // ***************************************************************************
2423 class CAHTarget : public IActionHandler
2425 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2427 string entityName = getParam(Params, "entity");
2428 if (entityName.empty()) return;
2430 string completeMatch = getParam(Params, "prefer_complete_match");
2431 bool quiet = (getParam (Params, "quiet") == "true");
2433 vector<string> keywords;
2434 NLMISC::splitString(entityName, " ", keywords);
2435 if (!keywords.empty() && keywords[0].size() > 0 && keywords[0][0] == '"')
2437 // entity name is in quotes, do old style match with 'starts with' filter
2438 // search for optional second parameter from old command for prefer_complete_match param
2439 keywords.clear();
2441 string::size_type lastOf = entityName.rfind("\"");
2442 if (lastOf == 0)
2443 lastOf = string::npos;
2445 // override the value only when there is no 'prefer_complete_match' parameter set
2446 if (completeMatch.empty() && lastOf < entityName.size())
2447 completeMatch = trim(entityName.substr(lastOf+1));
2449 entityName = entityName.substr(1, lastOf-1);
2452 // late check because only possible if doing 'starts-with' search
2453 bool preferCompleteMatch = (completeMatch != "0");
2455 CEntityCL *entity = NULL;
2456 if (preferCompleteMatch)
2458 // Try to get the entity with complete match first
2459 entity = EntitiesMngr.getEntityByName (entityName, false, true);
2462 if (entity == NULL && !keywords.empty())
2464 entity = EntitiesMngr.getEntityByKeywords(keywords, true);
2467 if (entity == NULL)
2469 // Get the entity with a partial match using 'starts with' search
2470 entity = EntitiesMngr.getEntityByName(entityName, false, false);
2473 if (entity == NULL)
2475 //Get the entity with a sheetName
2476 entity = EntitiesMngr.getEntityBySheetName(entityName);
2479 if (entity && entity->properties().selectable() && !entity->getDisplayName().empty())
2481 UserEntity->selection(entity->slot());
2482 if (ClientCfg.TargetChangeCompass)
2484 CGroupCompas *gc = dynamic_cast<CGroupCompas *>(CWidgetManager::getInstance()->getElementFromId("ui:interface:compass"));
2485 if (gc)
2487 CCompassTarget ct;
2488 ct.setType(CCompassTarget::Selection);
2490 gc->setActive(true);
2491 gc->setTarget(ct);
2492 gc->blink();
2493 CWidgetManager::getInstance()->setTopWindow(gc);
2497 else if (!quiet)
2499 CInterfaceManager::getInstance()->displaySystemInfo(CI18N::get("uiTargetErrorCmd"));
2503 REGISTER_ACTION_HANDLER (CAHTarget, "target");
2505 // ***************************************************************************
2506 class CAHTargetLandmark : public IActionHandler
2508 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2510 string search = getParam(Params, "search");
2511 if (search.empty()) return;
2513 bool startsWith = false;
2514 if (search.size() > 0 && (search[0] == '\'' || search[0] == '"') && search[0] == search[search.size()-1])
2516 startsWith = true;
2517 search = trimQuotes(search);
2520 const std::string mapid = "ui:interface:map:content:map_content:actual_map";
2521 CGroupMap* cgMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId(mapid));
2522 if (cgMap)
2524 if (!cgMap->targetLandmarkByName(search, startsWith))
2526 CInterfaceManager::getInstance()->displaySystemInfo(CI18N::get("uiTargetErrorCmd"));
2531 REGISTER_ACTION_HANDLER (CAHTargetLandmark, "target_landmark");
2534 class CAHAddShape : public IActionHandler
2536 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2538 string sShape = getParam(Params, "shape");
2540 if (sShape.empty())
2542 nlwarning("Command 'add_shape': need at least the parameter shape.");
2543 return;
2546 if (!Scene)
2548 nlwarning("No scene available");
2549 return;
2552 if (!UserEntity)
2554 nlwarning("UserEntity not yet defined, possibly called runAH from Lua");
2555 return;
2558 double x = UserEntity->pos().x;
2559 double y = UserEntity->pos().y;
2560 double z = UserEntity->pos().z;
2561 CVector userDir = UserEntity->dir();
2562 float s = 1.0f;
2563 string skeleton = getParam(Params, "skeleton");
2564 string c = getParam(Params, "text");
2565 string u = getParam(Params, "url");
2566 string texture_name = getParam(Params, "texture");
2567 string highlight = getParam(Params, "highlight");
2568 string transparency = getParam(Params, "transparency");
2570 if (!getParam(Params, "x").empty())
2571 fromString(getParam(Params, "x"), x);
2572 if (!getParam(Params, "y").empty())
2573 fromString(getParam(Params, "y"), y);
2574 if (!getParam(Params, "z").empty())
2575 fromString(getParam(Params, "z"), z);
2576 if (!getParam(Params, "scale").empty())
2577 fromString(getParam(Params, "scale"), s);
2578 if (!getParam(Params, "angle").empty())
2580 float a;
2581 fromString(getParam(Params, "angle"), a);
2582 userDir = CVector(sin(a), cos(a), 0.f);
2585 bool have_shapes = true;
2586 while(have_shapes)
2588 string shape;
2589 string::size_type index = sShape.find(string(" "));
2590 // multiple shapes/fx
2591 if (index != string::npos)
2593 shape = sShape.substr(0, index);
2594 sShape = sShape.substr(index+1);
2596 else
2598 shape = sShape;
2599 have_shapes = false;
2602 sint32 idx;
2603 CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector((float)x, (float)y, (float)z), c, u, false, 0, idx);
2604 UInstance instance = instref.Instance;
2606 if(!instance.empty())
2608 for(uint j=0;j<instance.getNumMaterials();j++)
2610 if (highlight.empty())
2612 instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
2613 instance.getMaterial(j).setShininess( 10.0f );
2614 instance.getMaterial(j).setEmissive(CRGBA(255,255,255,255));
2616 else
2618 instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
2619 instance.getMaterial(j).setEmissive(CRGBA(255,0,0,255));
2620 instance.getMaterial(j).setShininess( 1000.0f );
2623 if (!texture_name.empty())
2625 sint numStages = instance.getMaterial(j).getLastTextureStage() + 1;
2626 for(sint l = 0; l < numStages; l++)
2628 if (instance.getMaterial(j).isTextureFile((uint) l))
2630 instance.getMaterial(j).setTextureFileName(texture_name, (uint) l);
2636 if (transparency.empty())
2637 ::makeInstanceTransparent(instance, 255, false);
2638 else
2639 ::makeInstanceTransparent(instance, 100, true);
2641 instance.setClusterSystem(UserEntity->getClusterSystem()); // for simplicity, assume it is in the same
2642 // cluster system than the user
2643 // Compute the direction Matrix
2644 CMatrix dir;
2645 dir.identity();
2646 CVector vi = userDir^CVector(0.f, 0.f, 1.f);
2647 CVector vk = vi^userDir;
2648 dir.setRot(vi, userDir, vk, true);
2649 // Set Orientation : User Direction should be normalized.
2650 if (!skeleton.empty())
2652 USkeleton skel = Scene->createSkeleton(skeleton);
2653 if (!skel.empty())
2655 skel.bindSkin(instance);
2656 skel.setClusterSystem(UserEntity->getClusterSystem());
2657 skel.setScale(skel.getScale()*s);
2658 skel.setPos(CVector((float)x, (float)y, (float)z));
2659 skel.setRotQuat(dir.getRot());
2662 else
2664 instance.setScale(instance.getScale()*s);
2665 instance.setPos(CVector((float)x, (float)y, (float)z));
2666 instance.setRotQuat(dir.getRot());
2669 instance.setTransformMode(UTransformable::RotEuler);
2671 // if the shape is a particle system, additionnal parameters are user params
2672 UParticleSystemInstance psi;
2673 psi.cast (instance);
2674 /*if (!psi.empty())
2676 // set each user param that is present
2677 for(uint k = 0; k < 4; ++k)
2679 if (args.size() >= (k + 2))
2681 float uparam;
2682 if (fromString(args[k + 1], uparam))
2684 psi.setUserParam(k, uparam);
2686 else
2688 nlwarning("Cant read param %d", k);
2694 else
2695 nlwarning("Command 'add_shape': cannot find the shape %s.", sShape.c_str());
2698 return;
2701 REGISTER_ACTION_HANDLER (CAHAddShape, "add_shape");
2703 class CAHRemoveShapes : public IActionHandler
2705 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2707 EntitiesMngr.removeInstances();
2710 REGISTER_ACTION_HANDLER (CAHRemoveShapes, "remove_shapes");
2712 // ***************************************************************************
2713 // See also CHandlerTeamTarget
2714 class CAHTargetTeammateShortcut : public IActionHandler
2716 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2718 // Get shortcut parameter
2719 uint indexInTeam;
2720 fromString(getParam( Params, "indexInTeam" ), indexInTeam);
2721 --indexInTeam;
2723 if ( indexInTeam >= PeopleInterraction.TeamList.getNumPeople() )
2724 return;
2726 // Index is the database index (serverIndex() not used for team list)
2727 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp( NLMISC::toString( TEAM_DB_PATH ":%hu:NAME", indexInTeam ), false );
2728 if ( ! pNL )
2729 return;
2730 if ( pNL->getValueBool() )
2732 // There is a character corresponding to this index
2733 pNL = NLGUI::CDBManager::getInstance()->getDbProp( NLMISC::toString( TEAM_DB_PATH ":%hu:UID", indexInTeam ), false );
2734 if ( ! pNL )
2735 return;
2736 CLFECOMMON::TClientDataSetIndex compressedIndex = pNL->getValue32();
2738 // Search entity in vision
2739 CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex( compressedIndex );
2740 if ( entity )
2742 UserEntity->selection( entity->slot() );
2744 else
2746 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2747 pIM->displaySystemInfo(CI18N::get("uiTeamSelectNotInVision"), "CHK");
2752 REGISTER_ACTION_HANDLER(CAHTargetTeammateShortcut, "target_teammate_shortcut");
2754 // ***************************************************************************
2755 class CAHAssist : public IActionHandler
2757 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2759 // Get the entity name to target
2760 string entityName = getParam (Params, "entity");
2761 if (!entityName.empty())
2763 // Get the entity
2764 CEntityCL *entity = EntitiesMngr.getEntityByName (entityName, false, false);
2765 if (entity)
2767 // Select the entity
2768 UserEntity->assist(entity->slot());
2770 else
2772 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2773 pIM->displaySystemInfo(CI18N::get("uiTargetErrorCmd"));
2778 REGISTER_ACTION_HANDLER (CAHAssist, "assist");
2780 // ***************************************************************************
2781 class CAHAssistTarget : public IActionHandler
2783 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2785 // Select the entity
2786 UserEntity->assist();
2789 REGISTER_ACTION_HANDLER (CAHAssistTarget, "assist_target");
2791 // ***************************************************************************
2792 class CAHToggleCombat : public IActionHandler
2794 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2796 // Toggle from Combat to Disengage
2797 if(UserEntity->isFighting())
2798 UserEntity->disengage();
2799 // Toggle from Normal to Combat
2800 else
2802 if( UserEntity->canEngageCombat() )
2804 UserEntity->attack();
2810 REGISTER_ACTION_HANDLER (CAHToggleCombat, "toggle_combat");
2812 // ***************************************************************************
2813 class CAHSetDesktop : public IActionHandler
2815 public:
2816 CAHSetDesktop()
2818 _FirstTime = true;
2821 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2823 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2824 CGroupContainer *pGC = dynamic_cast<CGroupContainer*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:gestion_windows"));
2825 if (pGC == NULL)
2827 nlwarning("gestion_windows not found as a container");
2828 return;
2830 CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId("ui:interface:gestion_windows:close");
2831 if (pIE != NULL) pIE->setActive(false);
2833 bool switchDesktop = false;
2835 CActionsManager *pAM = &Actions;
2836 if (!pAM->valide(CAction::CName("set_desktop",Params.c_str())))
2838 pGC->setActive(false);
2839 _FirstTime = true;
2840 switchDesktop = true;
2842 else // Key is down
2844 // For the first time ?
2845 if (_FirstTime)
2847 _FirstTime = false;
2848 switchDesktop = true;
2850 else // Not the first time
2852 // Show the container
2853 pGC->setActive(true);
2854 // Yoyo: important to setTopWindow ONLY if needed, else save of the TopWindow doesn't work when you switch it.
2855 CWidgetManager::getInstance()->setTopWindow(pGC);
2858 if (switchDesktop)
2860 vector<string> vecStr;
2861 vecStr.push_back("tb_setdesktop");
2862 vecStr.push_back(Params);
2863 CWidgetManager::getInstance()->runProcedure("tb_setdesktop", NULL, vecStr);
2866 private:
2867 bool _FirstTime;
2869 REGISTER_ACTION_HANDLER (CAHSetDesktop, "set_desktop");
2871 // ***************************************************************************
2872 class CAHCopyToDesktop : public IActionHandler
2874 public:
2876 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2878 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2879 uint8 newMode;
2880 fromString(Params, newMode);
2881 pIM->resetMode(newMode);
2882 uint8 nLastMode = pIM->getMode();
2883 pIM->setMode(newMode);
2884 pIM->setMode(nLastMode);
2887 REGISTER_ACTION_HANDLER (CAHCopyToDesktop, "copy_to_desktop");
2890 // ***************************************************************************
2891 class CHandlerCloseAllLabosBut : public IActionHandler
2893 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2895 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2897 // list of labo windows
2898 const char* laboWindows[]= {
2899 "ui:interface:faber_create",
2900 "ui:interface:faber_repair",
2901 "ui:interface:faber_refine",
2902 "ui:interface:combat",
2903 "ui:interface:magic",
2904 "ui:interface:special_labo",
2905 "ui:interface:commerce",
2906 "ui:interface:tracking",
2908 uint numLabos= sizeof(laboWindows)/sizeof(laboWindows[0]);
2910 // For all labos
2911 for(uint i=0;i<numLabos;i++)
2913 // if not the excluded one
2914 if( Params != laboWindows[i] )
2916 CInterfaceElement *pElt= CWidgetManager::getInstance()->getElementFromId(laboWindows[i]);
2917 if(pElt)
2918 pElt->setActive(false);
2923 REGISTER_ACTION_HANDLER (CHandlerCloseAllLabosBut, "close_all_labos_but");
2926 // ***************************************************************************
2927 class CHandlerToggleInventory : public IActionHandler
2929 virtual void execute (CCtrlBase *pCaller, const string &Params)
2931 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2933 // list of labo windows
2934 const char* inventoryWindows[]= {
2935 "ui:interface:gestionsets",
2936 "ui:interface:userbags",
2937 "ui:interface:usermoney",
2938 "ui:interface:userarmors",
2939 "ui:interface:userjewelry",
2941 uint numWins= sizeof(inventoryWindows)/sizeof(inventoryWindows[0]);
2943 // For all labos
2944 bool state = false;
2945 CInterfaceElement *pElt= CWidgetManager::getInstance()->getElementFromId(inventoryWindows[0]);
2946 if (pElt)
2947 state = !pElt->getActive();
2948 for(uint i=0;i<numWins;i++)
2950 pElt= CWidgetManager::getInstance()->getElementFromId(inventoryWindows[i]);
2951 if(pElt)
2952 pElt->setActive(state);
2956 REGISTER_ACTION_HANDLER (CHandlerToggleInventory, "toggle_inventory");
2958 // ***************************************************************************
2959 // ***************************************************************************
2960 // GAME CONFIG
2961 // ***************************************************************************
2962 // ***************************************************************************
2964 #define GAME_CONFIG_DDX "ui:interface:game_config:content:all"
2965 #define GAME_CONFIG_TREE_LIST "ui:interface:game_config:content:sbtree:tree_list"
2967 static vector<UDriver::CMode> VideoModes;
2968 #define GAME_CONFIG_VIDEO_MODES_COMBO "ui:interface:game_config:content:general:video_modes"
2969 #define GAME_CONFIG_VIDEO_FREQS_COMBO "ui:interface:game_config:content:general:video_freqs"
2970 #define GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON "ui:interface:game_config:content:general:fullscreen:c"
2971 #define GAME_CONFIG_VIDEO_MODE_DB "UI:TEMP:VID_MODE"
2972 #define GAME_CONFIG_VIDEO_FREQ_DB "UI:TEMP:VID_FREQ"
2973 #define GAME_CONFIG_LANGUAGE "UI:TEMP:LANGUAGE"
2974 // We allow only this RGB depth to be taken
2975 #define GAME_CONFIG_VIDEO_DEPTH_REQ 32
2977 // VR_CONFIG
2978 #define GAME_CONFIG_VR_ENABLE_BUTTON "ui:interface:game_config:content:vr:enabler:c"
2979 #define GAME_CONFIG_VR_DEVICES_COMBO "ui:interface:game_config:content:vr:vr_devices"
2980 #define GAME_CONFIG_VR_DEVICE_DB "UI:TEMP:VR_DEVICE"
2982 // The combo for Texture Mode selected
2983 #define GAME_CONFIG_TEXTURE_MODE_COMBO "ui:interface:game_config:content:general:texture_mode:combo"
2984 #define GAME_CONFIG_TEXTURE_MODE_DB "UI:TEMP:TEXTURE_MODE"
2986 // Anisotropic Filtering controls
2987 #define GAME_CONFIG_ANISOTROPIC_COMBO "ui:interface:game_config:content:fx:anisotropic_gr:anisotropic"
2988 #define GAME_CONFIG_ANISOTROPIC_DB "UI:TEMP:ANISOTROPIC"
2990 // The 3 possible modes editable (NB: do not allow client.cfg HDEntityTexture==1 and DivideTextureSizeBy2=2
2991 enum TTextureMode {LowTextureMode= 0, NormalTextureMode= 1, HighTextureMode= 2};
2993 void cacheStereoDisplayDevices(); // from init.cpp
2995 void updateVRDevicesComboUI(bool enable)
2997 // VR_CONFIG
2998 nldebug("Init VR device name list from cache into UI");
2999 // init vr device name list from cache
3000 CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_DEVICES_COMBO));
3001 if (pCB)
3003 pCB->setActive(enable);
3004 if (enable)
3006 nldebug("pCB ok");
3007 cacheStereoDisplayDevices();
3008 pCB->resetTexts();
3009 sint32 selectedDevice = -1;
3010 for (uint i = 0; i < VRDeviceCache.size(); ++i)
3012 std::stringstream displayname;
3013 displayname << std::string("[") << VRDeviceCache[i].first << "] [" << VRDeviceCache[i].second << "]";
3014 pCB->addText(displayname.str());
3015 if (ClientCfg.VRDisplayDevice == VRDeviceCache[i].first)
3017 if (selectedDevice == -1 || ClientCfg.VRDisplayDeviceId == VRDeviceCache[i].second)
3019 selectedDevice = i;
3023 if (selectedDevice == -1)
3025 // configured device not found, add a dummy
3026 std::stringstream displayname;
3027 displayname << std::string("[") << ClientCfg.VRDisplayDevice << "] [" << ClientCfg.VRDisplayDeviceId<< "] [DEVICE NOT FOUND]";
3028 pCB->addText(displayname.str());
3029 selectedDevice = VRDeviceCache.size();
3031 NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->setValue32(-1);
3032 NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->setValue32(selectedDevice);
3037 // ***************************************************************************
3038 class CHandlerGameConfigInit : public IActionHandler
3040 public:
3041 // Value used to restore the screen AR in case of a cancel
3042 static float BkupScreenAspectRatio;
3044 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3046 if (Driver == NULL) return;
3048 VideoModes.clear();
3049 vector<string> stringModeList, stringFreqList;
3050 sint nFoundMode, nFoundFreq;
3052 getRyzomModes(VideoModes, stringModeList, stringFreqList, nFoundMode, nFoundFreq);
3054 // Initialize interface combo box
3055 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3057 // resolutions
3058 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3059 if( pCB )
3061 pCB->resetTexts();
3062 for (sint j = 0; j < (sint)stringModeList.size(); j++)
3063 pCB->addText(stringModeList[j]);
3066 // frequencies
3067 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3068 if( pCB )
3070 pCB->resetTexts();
3071 for (sint j = 0; j < (sint)stringFreqList.size(); j++)
3072 pCB->addText(stringFreqList[j]);
3075 // -1 is important to indicate we set this value in edit mode
3076 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->setValue32(-1);
3077 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->setValue32(nFoundMode);
3079 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(-1);
3080 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(nFoundFreq);
3082 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON ));
3083 if (pBut)
3085 pBut->setPushed(!ClientCfg.Windowed);
3087 CAHManager::getInstance()->runActionHandler("game_config_change_vid_fullscreen",NULL);
3089 // **** Init Texture Size Modes
3090 // init the combo box, according to Texture Installed or not
3091 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_TEXTURE_MODE_COMBO ));
3092 if( pCB )
3094 pCB->resetTexts();
3095 pCB->addText(CI18N::get("uigcLowTextureMode"));
3096 pCB->addText(CI18N::get("uigcNormalTextureMode"));
3097 if(ClientCfg.HDTextureInstalled)
3098 pCB->addText(CI18N::get("uigcHighTextureMode"));
3101 // Anisotropic Filtering
3102 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_ANISOTROPIC_COMBO));
3104 sint nAnisotropic = 0;
3106 if (pCB)
3108 sint maxAnisotropic = (sint)Driver->getAnisotropicFilterMaximum();
3110 pCB->resetTexts();
3111 pCB->addText(CI18N::get("uigcFxAnisotropicFilterNone"));
3113 sint anisotropic = 2;
3114 uint i = 1;
3116 while (anisotropic <= maxAnisotropic)
3118 pCB->addText(NLMISC::toString("%dx", anisotropic));
3120 if (ClientCfg.AnisotropicFilter == anisotropic)
3121 nAnisotropic = i;
3123 anisotropic <<= 1;
3124 ++i;
3128 // -1 is important to indicate we set this value in edit mode
3129 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_ANISOTROPIC_DB )->setValue32(-1);
3130 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_ANISOTROPIC_DB )->setValue32(nAnisotropic);
3132 // VR_CONFIG
3133 pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_ENABLE_BUTTON));
3134 if (pBut)
3136 pBut->setPushed(ClientCfg.VREnable);
3139 updateVRDevicesComboUI(ClientCfg.VREnable);
3141 // init the mode in DB
3142 TTextureMode texMode;
3143 if(ClientCfg.DivideTextureSizeBy2)
3144 texMode= LowTextureMode;
3145 else if(ClientCfg.HDEntityTexture && ClientCfg.HDTextureInstalled)
3146 texMode= HighTextureMode;
3147 else
3148 texMode= NormalTextureMode;
3150 // -1 is important to indicate we set this value in edit mode
3151 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->setValue32(-1);
3152 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->setValue32(texMode);
3154 // **** Init Screen Aspect Ratio
3155 // Init the combo box, according to the value
3156 pCB= dynamic_cast<CDBGroupComboBox*>( CWidgetManager::getInstance()->getElementFromDefine( "game_config_screen_ratio_cb" ));
3157 if(pCB)
3159 // Bkup for cancel
3160 BkupScreenAspectRatio= ClientCfg.ScreenAspectRatio;
3162 // -1 is here to force var change
3163 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(-1);
3165 // detect with an epsilon to avoid float precision problems
3166 if(fabs(ClientCfg.ScreenAspectRatio - 1.33333f)<=0.00001f)
3167 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(0); // 4/3
3168 else if(fabs(ClientCfg.ScreenAspectRatio - 1.77777f)<=0.00001f)
3169 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(1); // 16/9
3170 else if(ClientCfg.ScreenAspectRatio == 0.f)
3171 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(3); // Auto
3172 else
3173 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(2); // Custom
3176 // **** Init Language : look in game_config.lua
3178 // display or not VR page
3179 NLGUI::CGroupTree* configTree = dynamic_cast<CGroupTree*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_TREE_LIST));
3181 if (configTree)
3183 CGroupTree::SNode *rootNode = configTree->getRootNode();
3185 if (rootNode)
3187 CGroupTree::SNode *graphNode = rootNode->getNodeFromId("graph");
3189 if (graphNode)
3191 CGroupTree::SNode *vrNode = graphNode->getNodeFromId("vr");
3193 if (vrNode)
3195 vrNode->setShow(isStereoAvailable());
3202 REGISTER_ACTION_HANDLER (CHandlerGameConfigInit, "game_config_init");
3203 float CHandlerGameConfigInit::BkupScreenAspectRatio= 1.3333f;
3206 // ***************************************************************************
3207 class CHandlerGameConfigMode : public IActionHandler
3209 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3211 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3213 sint oldVideoMode= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->getOldValue32();
3214 sint nVideModeNb = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->getValue32();
3215 if (nVideModeNb == -1 || oldVideoMode == -1) return;
3217 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3218 if( pCB == NULL ) return;
3220 // Get W, H
3221 sint w,h;
3223 string vidModeStr = pCB->getText(nVideModeNb);
3224 string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1);
3225 fromString(tmp, w);
3226 tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size());
3227 fromString(tmp, h);
3230 // Filter VideoModes list to get freqs
3231 vector<string> stringFreqList;
3232 sint i, j, nFoundFreq = -1;
3233 for (i=0; i < (sint)VideoModes.size(); ++i)
3235 if ((VideoModes[i].Width == w) && (VideoModes[i].Height == h) && (VideoModes[i].Depth == GAME_CONFIG_VIDEO_DEPTH_REQ))
3237 bool bFound = false;
3238 string tmp = toString(VideoModes[i].Frequency);
3239 for (j = 0; j < (sint)stringFreqList.size(); ++j)
3241 if (stringFreqList[j] == tmp)
3243 bFound = true;
3244 break;
3248 if (!bFound)
3250 stringFreqList.push_back(tmp);
3251 if (ClientCfg.Frequency == VideoModes[i].Frequency)
3252 nFoundFreq = j;
3256 if (nFoundFreq == -1) nFoundFreq = 0;
3257 // Initialize interface combo box
3258 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3259 if( pCB )
3261 pCB->resetTexts();
3262 for (j = 0; j < (sint)stringFreqList.size(); j++)
3263 pCB->addText(stringFreqList[j] + " Hz");
3265 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(nFoundFreq);
3267 // **** dirt the apply button of the DDX
3268 // don't do it at init!
3269 if(oldVideoMode!=-1 && nVideModeNb!=-1)
3271 CDDXManager *pDM = CDDXManager::getInstance();
3272 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3273 if(pDDX)
3274 pDDX->validateApplyButton();
3278 REGISTER_ACTION_HANDLER (CHandlerGameConfigMode, "game_config_change_vid_mode");
3280 // ***************************************************************************
3281 class CHandlerGameConfigLanguage : public IActionHandler
3283 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3285 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3287 sint old = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_LANGUAGE )->getOldValue32();
3288 sint newOne = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_LANGUAGE )->getValue32();
3289 if ((old != -1) && (newOne != -1))
3291 // Set the new language
3292 //string newVal = (newOne==2)?"de":(newOne==1)?"fr":"en";
3293 string newVal = convertLanguageIntToLanguageCode(newOne);
3294 if (ClientCfg.LanguageCode != newVal)
3296 CDDXManager *pDM = CDDXManager::getInstance();
3297 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3298 if(pDDX)
3299 pDDX->validateApplyButton();
3304 REGISTER_ACTION_HANDLER (CHandlerGameConfigLanguage, "game_config_change_language");
3306 // ***************************************************************************
3307 class CHandlerGameConfigFreq : public IActionHandler
3309 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3311 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3312 sint oldFreq= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->getOldValue32();
3313 sint newFreq= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->getValue32();
3315 // dirt the apply button of the DDX.
3316 // don't do it at init!
3317 if(oldFreq!=-1 && newFreq!=-1)
3319 CDDXManager *pDM = CDDXManager::getInstance();
3320 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3321 if(pDDX)
3322 pDDX->validateApplyButton();
3326 REGISTER_ACTION_HANDLER (CHandlerGameConfigFreq, "game_config_change_vid_freq");
3328 // ***************************************************************************
3329 class CHandlerGameConfigTextureMode : public IActionHandler
3331 public:
3332 virtual void execute(CCtrlBase * /* pCalller */, const string &/* Params */)
3334 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3335 sint oldTMode= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->getOldValue32();
3336 sint newTMode= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->getValue32();
3338 // dirt the apply button of the DDX
3339 // don't do it at init!
3340 if(oldTMode!=-1 && newTMode!=-1)
3342 CDDXManager *pDM = CDDXManager::getInstance();
3343 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3344 if(pDDX)
3345 pDDX->validateApplyButton();
3349 REGISTER_ACTION_HANDLER (CHandlerGameConfigTextureMode, "game_config_change_texture_mode");
3351 // ***************************************************************************
3352 class CHandlerGameConfigFullscreen : public IActionHandler
3354 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
3356 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3357 bool bFullscreen = false;
3359 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON ));
3360 if (pBut) bFullscreen = pBut->getPushed();
3362 CDBGroupComboBox *pCB;
3363 if (bFullscreen)
3365 // show modes combo
3366 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3367 if (pCB) pCB->setActive(true);
3369 // show frequencies combo
3370 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3371 if (pCB) pCB->setActive(true);
3373 else
3375 // hide modes combo
3376 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3377 if (pCB) pCB->setActive(false);
3379 // hide frequencies combo
3380 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3381 if (pCB) pCB->setActive(false);
3384 // **** dirt the apply button of the DDX
3385 // if caller is NULL, come from init, so don't validate the apply button
3386 if(pCaller)
3388 CDDXManager *pDM = CDDXManager::getInstance();
3389 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3390 if(pDDX)
3391 pDDX->validateApplyButton();
3395 REGISTER_ACTION_HANDLER (CHandlerGameConfigFullscreen, "game_config_change_vid_fullscreen");
3397 // ***************************************************************************
3398 class CHandlerGameConfigVREnable : public IActionHandler
3400 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
3402 // VR_CONFIG
3404 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_ENABLE_BUTTON));
3405 if (pBut)
3407 // hide or show device list depending on enabled or not
3408 updateVRDevicesComboUI(pBut->getPushed());
3411 if (pCaller)
3413 CDDXManager *pDM = CDDXManager::getInstance();
3414 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3415 if(pDDX)
3416 pDDX->validateApplyButton();
3420 REGISTER_ACTION_HANDLER (CHandlerGameConfigVREnable, "game_config_change_vr_enable");
3422 // ***************************************************************************
3423 class CHandlerGameConfigVRDevice : public IActionHandler
3425 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
3427 // VR_CONFIG
3429 sint oldDevice = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->getOldValue32();
3430 sint newDevice = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->getValue32();
3432 if (oldDevice != -1 && newDevice != -1 && pCaller)
3434 // nldebug("TODO_VR switch vr device (from combo box)");
3436 CDDXManager *pDM = CDDXManager::getInstance();
3437 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3438 if(pDDX)
3439 pDDX->validateApplyButton();
3443 REGISTER_ACTION_HANDLER (CHandlerGameConfigVRDevice, "game_config_change_vr_device");
3445 // ***************************************************************************
3446 class CHandlerGameConfigApply : public IActionHandler
3448 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3450 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3452 // **** Apply the video mode
3453 sint nVideModeNb = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->getValue32();
3454 if (nVideModeNb != -1)
3456 sint nVideoFreqNb = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->getValue32();
3457 if (nVideoFreqNb != -1)
3459 // Get W, H
3460 sint w = 1024, h = 768;
3461 string name;
3463 CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3464 if( pCB != NULL )
3466 string vidModeStr = pCB->getText(nVideModeNb);
3467 string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1);
3468 fromString(tmp, w);
3469 tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size());
3470 fromString(tmp, h);
3472 // extract monitor "1024x768 (VGA-1)"
3473 string::size_type pos = vidModeStr.find('(');
3474 if (pos != std::string::npos)
3475 name = vidModeStr.substr(pos + 1, vidModeStr.find(")") - pos - 1);
3479 // Get Frequency
3480 sint freq = 60;
3482 CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3483 if( pCB != NULL )
3485 string vidFreqStr = pCB->getText(nVideoFreqNb);
3486 fromString(vidFreqStr, freq);
3490 // Get Fullscreen
3491 bool bFullscreen = false;
3493 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON ));
3494 if (pBut != NULL)
3495 bFullscreen = pBut->getPushed();
3498 ClientCfg.Windowed = !bFullscreen;
3500 UDriver::CMode screenMode;
3501 Driver->getCurrentScreenMode(screenMode);
3503 if (bFullscreen)
3505 ClientCfg.Depth = screenMode.Depth;
3506 ClientCfg.Frequency = freq;
3508 else
3510 uint32 width, height;
3511 Driver->getWindowSize(width, height);
3512 w = width;
3513 h = height;
3516 ClientCfg.Width = w;
3517 ClientCfg.Height = h;
3518 ClientCfg.MonitorName = name;
3520 // Write the modified client.cfg
3521 ClientCfg.writeBool("FullScreen", bFullscreen);
3522 ClientCfg.writeInt("Width", w);
3523 ClientCfg.writeInt("Height", h);
3525 if (bFullscreen)
3527 ClientCfg.writeString("MonitorName", name, true);
3528 ClientCfg.writeInt("Depth", screenMode.Depth);
3529 ClientCfg.writeInt("Frequency", freq);
3534 // save user created channels options
3535 CCtrlBaseButton *pCS = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromDefine("game_config_save_channel_cb"));
3536 if (pCS)
3537 NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:SAVE_CHANNEL")->setValue32(pCS->getPushed());
3539 pCS = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromDefine("game_config_auto_channel_cb"));
3540 if (pCS)
3541 NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:AUTO_CHANNEL")->setValue32(pCS->getPushed());
3543 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_ENABLE_BUTTON));
3544 if (pBut)
3546 // store the new config variables
3547 ClientCfg.VREnable = pBut->getPushed();
3548 ClientCfg.writeBool("VREnable", pBut->getPushed());
3550 if (ClientCfg.VREnable)
3552 // store the new config variables
3553 sint deviceIdx = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->getValue32();
3554 ClientCfg.VRDisplayDevice = VRDeviceCache[deviceIdx].first;
3555 ClientCfg.VRDisplayDeviceId = VRDeviceCache[deviceIdx].second;
3556 ClientCfg.writeString("VRDisplayDevice", VRDeviceCache[deviceIdx].first);
3557 ClientCfg.writeString("VRDisplayDeviceId", VRDeviceCache[deviceIdx].second);
3560 bool requestReboot = false;
3562 // **** Apply the texture mode
3563 sint nTexMode = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->getValue32();
3564 if (nTexMode>=0 && nTexMode<=HighTextureMode)
3566 if ((ClientCfg.DivideTextureSizeBy2 != (nTexMode==LowTextureMode)) ||
3567 (ClientCfg.HDEntityTexture != (nTexMode==HighTextureMode)))
3569 ClientCfg.DivideTextureSizeBy2= nTexMode==LowTextureMode;
3570 ClientCfg.HDEntityTexture= nTexMode==HighTextureMode;
3571 ClientCfg.writeInt("DivideTextureSizeBy2", ClientCfg.DivideTextureSizeBy2);
3572 ClientCfg.writeInt("HDEntityTexture", ClientCfg.HDEntityTexture);
3573 requestReboot = true;
3577 // **** Apply Anisotropic Filtering
3578 // read value from DB, it's a combo so value is the index of text
3579 sint nAnisotropic = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_ANISOTROPIC_DB )->getValue32();
3581 if (nAnisotropic >= 0)
3583 sint anisotropic = 0;
3585 // compute the real anisotropic value
3586 if (nAnisotropic > 0)
3588 anisotropic = 2;
3590 for(sint i = 1; i < nAnisotropic; ++i)
3592 anisotropic <<= 1;
3596 if (ClientCfg.AnisotropicFilter != anisotropic)
3598 ClientCfg.AnisotropicFilter = anisotropic;
3599 ClientCfg.writeInt("AnisotropicFilter", ClientCfg.AnisotropicFilter);
3600 requestReboot = true;
3604 // *** Apply the Screen AR
3605 // since already set in the config file, need only to bkup the current version
3606 CHandlerGameConfigInit::BkupScreenAspectRatio= ClientCfg.ScreenAspectRatio;
3608 // *** Apply the language code
3609 // only if not in "work" language mode (else strange requestReboot)
3610 if (ClientCfg.LanguageCode!="wk")
3612 sint newOne = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_LANGUAGE )->getValue32();
3613 //string newVal = (newOne==2)?"de":(newOne==1)?"fr":"en";
3614 string newVal = convertLanguageIntToLanguageCode(newOne);
3615 if (ClientCfg.LanguageCode != newVal)
3617 ClientCfg.LanguageCode = newVal;
3618 ClientCfg.writeString("LanguageCode", ClientCfg.LanguageCode);
3619 requestReboot = true;
3623 // Apply the NPC icon display mode
3624 CNPCIconCache::getInstance().setEnabled(!ClientCfg.R2EDEnabled && NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:INSCENE:FRIEND:MISSION_ICON")->getValueBool());
3626 // Request a reboot
3627 if (requestReboot)
3628 pIM->messageBox (CI18N::get ("uigcRequestReboot"));
3630 // **** Save the config
3631 if (ClientCfg.SaveConfig)
3632 ClientCfg.ConfigFile.save ();
3633 ClientCfg.IsInvalidated = true;
3636 REGISTER_ACTION_HANDLER (CHandlerGameConfigApply, "game_config_apply");
3639 // ***************************************************************************
3640 class CHandlerGameConfigCancel: public IActionHandler
3642 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3644 // Has something special to do only with screen aspect ratio:
3645 // - Video Modes changes are only really validated at apply times so cancel => noop
3646 // - All other standard changes are handled upper by ddx_cancel AH called
3648 // restore the bkuped Screen AR and invalidate clientcfg (NB: don't need to save, since canceled)
3649 ClientCfg.ScreenAspectRatio= CHandlerGameConfigInit::BkupScreenAspectRatio;
3650 ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio);
3651 ClientCfg.IsInvalidated = true;
3654 REGISTER_ACTION_HANDLER(CHandlerGameConfigCancel, "game_config_cancel");
3657 // ***************************************************************************
3658 class CHandlerGameConfigChangeScreenRatioMode : public IActionHandler
3660 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3662 if (CInterfaceLink::isUpdatingAllLinks()) return; // don't want to trash the value in client.cfg at init, due to 'updateAllLinks' being called
3664 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3666 // get the current mode
3667 sint oldMode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getOldValue32();
3668 sint mode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getValue32();
3669 if(mode<0 || mode>3)
3670 return;
3672 // If predef value (4/3 or 16/9)
3673 if(mode!=2)
3675 switch(mode)
3677 case 0: ClientCfg.ScreenAspectRatio= 1.33333f; break;
3678 case 1: ClientCfg.ScreenAspectRatio= 1.77777f; break;
3679 case 3: ClientCfg.ScreenAspectRatio= 0.f; break;
3681 ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio);
3683 // set content, and freeze the edit box
3684 CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
3685 if(eb)
3687 eb->setFrozen(true);
3688 eb->setInputStringAsFloat(ClientCfg.ScreenAspectRatio);
3691 // custom value
3692 else
3694 // just unfreeze the edit box, and set correct value
3695 CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
3696 if(eb)
3698 eb->setFrozen(false);
3699 eb->setInputStringAsFloat(ClientCfg.ScreenAspectRatio);
3703 // dirt the apply button of the DDX.
3704 // don't do it at init!
3705 if(oldMode!=-1)
3707 CDDXManager *pDM = CDDXManager::getInstance();
3708 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3709 if(pDDX)
3710 pDDX->validateApplyButton();
3713 // Invalidate the config
3714 ClientCfg.IsInvalidated = true;
3717 REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeScreenRatioMode, "game_config_change_screen_ratio_mode");
3720 // ***************************************************************************
3721 class CHandlerGameConfigChangeAnisotropic : public IActionHandler
3723 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3725 if (CInterfaceLink::isUpdatingAllLinks()) return; // don't want to trash the value in client.cfg at init, due to 'updateAllLinks' being called
3727 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3729 // get values of anisotropic filtering
3730 sint oldAnisotropic = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_ANISOTROPIC_DB)->getOldValue32();
3731 sint anisotropic = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_ANISOTROPIC_DB)->getValue32();
3733 // dirt the apply button of the DDX.
3734 // don't do it at init!
3735 if(oldAnisotropic != anisotropic && oldAnisotropic != -1 && anisotropic != -1)
3737 CDDXManager *pDM = CDDXManager::getInstance();
3738 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3739 if(pDDX)
3740 pDDX->validateApplyButton();
3744 REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeAnisotropic, "game_config_change_anisotropic");
3747 // ***************************************************************************
3748 class CHandlerGameConfigChangeScreenRatioCustom : public IActionHandler
3750 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3752 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3753 sint mode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getValue32();
3754 if (mode != 2) return;
3755 CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
3756 if(eb)
3758 // validate the value
3759 float val= eb->getInputStringAsFloat();
3760 clamp(val, 0.1f, 10.f);
3761 // reset (to clamp precision also), and hence reget
3762 eb->setInputStringAsFloat(val);
3763 val= eb->getInputStringAsFloat();
3765 // change the CFG with this value
3766 ClientCfg.ScreenAspectRatio= val;
3767 ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio);
3769 // dirt the apply button of the DDX.
3771 CDDXManager *pDM = CDDXManager::getInstance();
3772 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3773 if(pDDX)
3774 pDDX->validateApplyButton();
3777 // Invalidate the config
3778 ClientCfg.IsInvalidated = true;
3782 REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeScreenRatioCustom, "game_config_change_screen_ratio_custom");
3784 // ***************************************************************************
3785 class CHandlerSetInterfaceScale : public IActionHandler
3787 virtual void execute (CCtrlBase *pCaller, const string &Params)
3789 std::string s;
3790 s = getParam(Params, "scale");
3791 if (!s.empty()) {
3792 float scale;
3793 if (fromString(s, scale))
3795 if (scale >= ClientCfg.InterfaceScale_min && scale <= ClientCfg.InterfaceScale_max)
3797 ClientCfg.InterfaceScale = scale;
3798 ClientCfg.writeDouble("InterfaceScale", ClientCfg.InterfaceScale);
3800 ClientCfg.IsInvalidated = true;
3801 return;
3806 string help = "/setuiscale "+toString("%.1f .. %.1f", ClientCfg.InterfaceScale_min, ClientCfg.InterfaceScale_max);
3807 CInterfaceManager::getInstance()->displaySystemInfo(help);
3810 REGISTER_ACTION_HANDLER (CHandlerSetInterfaceScale, "set_ui_scale");
3813 // ***************************************************************************
3814 class CHandlerGameMissionAbandon : public IActionHandler
3816 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
3818 uint8 nMissionNb;
3819 fromString(Params, nMissionNb);
3821 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_ABANDON_BUTTON",false);
3822 if (pNL != NULL) pNL->setValue64(0);
3824 sendMsgToServer("JOURNAL:MISSION_ABANDON", nMissionNb);
3827 REGISTER_ACTION_HANDLER (CHandlerGameMissionAbandon, "mission_abandon");
3830 // ***************************************************************************
3831 class CHandlerGameGroupMissionAbandon : public IActionHandler
3833 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
3835 uint8 nMissionNb;
3836 fromString(Params, nMissionNb);
3838 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_ABANDON_BUTTON",false);
3839 if (pNL != NULL) pNL->setValue64(0);
3841 sendMsgToServer("JOURNAL:GROUP_MISSION_ABANDON", nMissionNb);
3844 REGISTER_ACTION_HANDLER (CHandlerGameGroupMissionAbandon, "group_mission_abandon");
3847 // ***************************************************************************
3848 // ***************************************************************************
3849 // Yoyo New BotChat
3850 // ***************************************************************************
3851 // ***************************************************************************
3854 // ***************************************************************************
3855 // GCM Choose ZoneCharge
3856 // ***************************************************************************
3857 class CHandlerContextChooseZoneCharge : public IActionHandler
3859 public:
3860 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3862 sendBotChatStart("START_CHOOSE_DUTY");
3863 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::ZCCharge);
3864 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3867 REGISTER_ACTION_HANDLER(CHandlerContextChooseZoneCharge, "context_choose_zc_charge");
3870 // ***************************************************************************
3871 // GCM Choose Building
3872 // ***************************************************************************
3873 class CHandlerContextChooseBuilding : public IActionHandler
3875 public:
3876 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3878 // Choose a building is like choose a mission
3879 sendBotChatStart("START_CHOOSE_MISSION");
3880 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::Building);
3881 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3884 REGISTER_ACTION_HANDLER(CHandlerContextChooseBuilding, "context_choose_building");
3886 // ***************************************************************************
3887 // GCM Buy RM
3888 // ***************************************************************************
3889 class CHandlerContextBuyRM : public IActionHandler
3891 public:
3892 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3894 // Buy RM is like choose a mission
3895 sendBotChatStart("START_CHOOSE_MISSION");
3896 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::RMBuy);
3897 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3900 REGISTER_ACTION_HANDLER(CHandlerContextBuyRM, "context_buy_rm");
3902 // ***************************************************************************
3903 // GCM Upgrade RM
3904 // ***************************************************************************
3905 class CHandlerContextUpgradeRM : public IActionHandler
3907 public:
3908 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3910 // Upgrde RM is like choose a mission
3911 sendBotChatStart("START_CHOOSE_MISSION");
3912 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::RMUpgrade);
3913 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3916 REGISTER_ACTION_HANDLER(CHandlerContextUpgradeRM, "context_upgrade_rm");
3919 // ***************************************************************************
3920 // GCM Cancel Duty
3921 // ***************************************************************************
3922 class CHandlerContextCancelZoneCharge : public IActionHandler
3924 public:
3925 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3927 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3929 // Check if user really want.
3930 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQCancelZoneCharge"),
3931 "do_cancel_zc_charge");
3934 REGISTER_ACTION_HANDLER(CHandlerContextCancelZoneCharge, "context_cancel_zc_charge");
3936 // The Msg if Ok.
3937 class CHandlerDoCancelZoneCharge : public IActionHandler
3939 public:
3940 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3942 sendMsgToServer("BOTCHAT:DUTY_CANCEL_APPLY");
3945 REGISTER_ACTION_HANDLER(CHandlerDoCancelZoneCharge, "do_cancel_zc_charge");
3948 // ***************************************************************************
3949 // GCM Destroy Building
3950 // ***************************************************************************
3951 class CHandlerContextDestroyBuilding : public IActionHandler
3953 public:
3954 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3956 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3958 // Check if user really want.
3959 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQDestroyBuilding"),
3960 "do_destroy_building");
3963 REGISTER_ACTION_HANDLER(CHandlerContextDestroyBuilding, "context_destroy_building");
3965 // The Msg if Ok.
3966 class CHandlerDoDestroyBuilding : public IActionHandler
3968 public:
3969 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3971 sendMsgToServer("BOTCHAT:DESTROY_BUILDING");
3974 REGISTER_ACTION_HANDLER(CHandlerDoDestroyBuilding, "do_destroy_building");
3977 // ***************************************************************************
3978 // Combat defense interface handlers
3979 // ***************************************************************************
3980 // Select Parry.
3981 class CHandlerSelectParry : public IActionHandler
3983 public:
3984 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3986 sendMsgToServer("COMBAT:PARRY");
3988 // display parry mode msg
3989 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3990 string msg = CI18N::get("msgUserModeParry");
3991 string cat = getStringCategory(msg, msg);
3992 pIM->displaySystemInfo(msg, cat);
3995 REGISTER_ACTION_HANDLER(CHandlerSelectParry, "parry");
3997 // Select dodge.
3998 class CHandlerSelectDodge : public IActionHandler
4000 public:
4001 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4003 sendMsgToServer("COMBAT:DODGE");
4005 // display dodge mode msg
4006 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4007 string msg = CI18N::get("msgUserModeDodge");
4008 string cat = getStringCategory(msg, msg);
4009 pIM->displaySystemInfo(msg, cat);
4012 REGISTER_ACTION_HANDLER(CHandlerSelectDodge, "dodge");
4014 // Select protected slot.
4015 class CHandlerSelectProtectedSlot : public IActionHandler
4017 public:
4018 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4020 uint8 slot = (uint8)SLOT_EQUIPMENT::stringToSlotEquipment(sParams);
4021 sendMsgToServer("COMBAT:PROTECTED_SLOT", slot);
4024 REGISTER_ACTION_HANDLER(CHandlerSelectProtectedSlot, "select_protected_slot");
4027 // ***************************************************************************
4028 // Tooltips for Players Stats, with values printed.
4029 // ***************************************************************************
4032 // ***************************************************************************
4033 // Common code
4034 static void fillPlayerBarText(std::string &str, const string &dbScore, SCORES::TScores score, const string &ttFormat)
4036 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4037 CCDBNodeLeaf *node;
4039 sint val= 0;
4040 sint maxVal= 0;
4041 // Get from local database cause written from CBarManager, from a fast impulse
4042 node= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:" + dbScore, false);
4043 if(node) val= node->getValue32();
4044 // less accurate/speed Max transferred by DB
4045 node= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:CHARACTER_INFO:SCORES%d:", score), false);
4046 if(node) maxVal= node->getValue32();
4047 val= max(val, 0);
4048 maxVal= max(maxVal, 0);
4050 str= CI18N::get(ttFormat);
4051 strFindReplace(str, "%v", toString(val) );
4052 strFindReplace(str, "%m", toString(maxVal) );
4055 // ***************************************************************************
4056 // Life
4057 class CHandlerPlayerTTLife : public IActionHandler
4059 public:
4060 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4062 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4064 string str;
4065 fillPlayerBarText(str, "HP", SCORES::hit_points, "uittPlayerLifeFormat");
4067 CWidgetManager::getInstance()->setContextHelpText(str);
4070 REGISTER_ACTION_HANDLER(CHandlerPlayerTTLife, "player_tt_life");
4072 // ***************************************************************************
4073 // Stamina
4074 class CHandlerPlayerTTStamina : public IActionHandler
4076 public:
4077 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4079 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4081 string str;
4082 fillPlayerBarText(str, "STA", SCORES::stamina, "uittPlayerStaminaFormat");
4084 CWidgetManager::getInstance()->setContextHelpText(str);
4087 REGISTER_ACTION_HANDLER(CHandlerPlayerTTStamina, "player_tt_stamina");
4089 // ***************************************************************************
4090 // Sap
4091 class CHandlerPlayerTTSap : public IActionHandler
4093 public:
4094 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4096 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4098 string str;
4099 fillPlayerBarText(str, "SAP", SCORES::sap, "uittPlayerSapFormat");
4101 CWidgetManager::getInstance()->setContextHelpText(str);
4104 REGISTER_ACTION_HANDLER(CHandlerPlayerTTSap, "player_tt_sap");
4106 // ***************************************************************************
4107 // Focus
4108 class CHandlerPlayerTTFocus : public IActionHandler
4110 public:
4111 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4113 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4115 string str;
4116 fillPlayerBarText(str, "FOCUS", SCORES::focus, "uittPlayerFocusFormat");
4118 CWidgetManager::getInstance()->setContextHelpText(str);
4121 REGISTER_ACTION_HANDLER(CHandlerPlayerTTFocus, "player_tt_focus");
4123 // ***************************************************************************
4124 // Bulk: NB: work for player / animal
4125 class CHandlerGetTTBulk : public IActionHandler
4127 public:
4128 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4130 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4131 string dbBranch= getParam(sParams, "dbbranch");
4132 string dbMax= getParam(sParams, "dbmax");
4134 // Get the sum of the bulk for this db branch
4135 const double epsilon = 0.001;
4136 float val = CInventoryManager::getBranchBulk(dbBranch, 0, 10000) + epsilon;
4138 // Get the Max value
4139 sint32 maxVal= 0;
4140 CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp(dbMax, false);
4141 if(node)
4142 maxVal= node->getValue32();
4144 // Replace in the formated text
4145 string str= CI18N::get("uittBulkFormat");
4146 strFindReplace(str, "%v", toString("%.2f", val) );
4147 strFindReplace(str, "%m", toString(maxVal) );
4148 CWidgetManager::getInstance()->setContextHelpText(str);
4151 REGISTER_ACTION_HANDLER(CHandlerGetTTBulk, "get_tt_bulk");
4153 // ***************************************************************************
4154 #define UI_MISSION_LIST "ui:interface:info_player_journal:content:mission_list"
4156 uint32 getMissionTitle(sint32 nSelected)
4158 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4160 sint32 nNbMission, nNbGroupMission;
4161 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_mission"), nNbMission);
4162 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_group_mission"), nNbGroupMission);
4164 if (nSelected < 0)
4165 return 0;
4166 else if (nSelected < nNbMission)
4167 return NLGUI::CDBManager::getInstance()->getDbProp("SERVER:MISSIONS:"+toString(nSelected)+":TITLE")->getValue32();
4168 else if (nSelected < (nNbMission+nNbGroupMission))
4169 return NLGUI::CDBManager::getInstance()->getDbProp("SERVER:GROUP:MISSIONS:"+toString(nSelected-nNbMission)+":TITLE")->getValue32();
4170 return 0;
4173 void runMissionProc(sint32 nSelected)
4175 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4177 sint32 nNbMission, nNbGroupMission;
4178 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_mission"), nNbMission);
4179 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_group_mission"), nNbGroupMission);
4181 if (nSelected < 0)
4182 return;
4183 else if (nSelected < nNbMission)
4185 string sButtonPath = UI_MISSION_LIST ":b_title"+toString(nSelected);
4186 CCtrlButton *pCB = dynamic_cast<CCtrlButton*>(CWidgetManager::getInstance()->getElementFromId(sButtonPath));
4187 CAHManager::getInstance()->runActionHandler("proc", pCB, "mission_proc_title|"+toString(nSelected));
4189 else if (nSelected < (nNbMission+nNbGroupMission))
4191 string sButtonPath = UI_MISSION_LIST ":b_group_title"+toString(nSelected-nNbMission);
4192 CCtrlButton *pCB = dynamic_cast<CCtrlButton*>(CWidgetManager::getInstance()->getElementFromId(sButtonPath));
4193 CAHManager::getInstance()->runActionHandler("proc", pCB, "group_mission_proc_title|"+toString(nSelected-nNbMission));
4195 return;
4199 class CHandlerMissionChooseNextValid : public IActionHandler
4201 public:
4202 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4204 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4205 sint32 nSelected = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:MISSION_SELECTED")->getValue32();
4207 sint32 nNbMission, nNbGroupMission;
4208 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_mission"), nNbMission);
4209 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_group_mission"), nNbGroupMission);
4211 // If no mission selected or title selected becomes invalid -> search a new title to select
4212 if ((nSelected == -1) || (getMissionTitle(nSelected) == 0))
4214 bool bFound = false;
4215 sint32 nSel = nSelected;
4217 // From the currently selected mission go backward (in the display order)
4218 if (nSel != -1)
4219 while (!bFound)
4221 nSel--;
4222 if (nSel < 0)
4223 break;
4225 // Is there a mission at the position nSel ? Yes ok select !
4226 if (getMissionTitle(nSel) != 0)
4228 runMissionProc(nSel);
4229 return;
4232 // Ok not found a mission in backward mode try now in forward mode until the end of the mission list
4233 while (!bFound)
4235 nSel++;
4236 if (nSel == (nNbMission+nNbGroupMission))
4237 break;
4239 // Is there a mission at the position nSel ? Yes ok select !
4240 if (getMissionTitle(nSel) != 0)
4242 runMissionProc(nSel);
4243 return;
4246 // No mission at all found so there is no mission in the journal
4247 NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:MISSION_SELECTED")->setValue32(-1);
4251 REGISTER_ACTION_HANDLER(CHandlerMissionChooseNextValid, "mission_choose_next_valid");
4253 // ***************************************************************************
4254 // Output a text above the entity like hit points
4255 class CHandlerEntityFlyingText : public IActionHandler
4257 public:
4258 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4260 string text = getParam(sParams, "text");
4262 uint entity;
4263 fromString(getParam(sParams, "entity"), entity);
4265 CRGBA color = CRGBA::stringToRGBA(getParam(sParams, "color").c_str());
4266 if (entity < 256)
4267 EntitiesMngr.entity (entity)->addHPOutput (CI18N::get (text), color);
4270 REGISTER_ACTION_HANDLER(CHandlerEntityFlyingText, "entity_flying_text");
4273 // ***************************************************************************
4274 // play an event music
4275 class CHandlerPlayEventMusic : public IActionHandler
4277 public:
4278 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4280 bool loop = getParam(sParams, "loop")=="1";
4282 uint xFade;
4283 fromString(getParam(sParams, "xfade"), xFade);
4285 string fileName = getParam(sParams, "music");
4287 // don't play if db is in init stage
4288 if (!ClientCfg.Local && IngameDbMngr.initInProgress()) return;
4290 if(SoundMngr)
4291 SoundMngr->playEventMusic(fileName, xFade, loop);
4294 REGISTER_ACTION_HANDLER(CHandlerPlayEventMusic, "play_event_music");
4297 // ***************************************************************************
4298 // stop an event music
4299 class CHandlerStopEventMusic : public IActionHandler
4301 public:
4302 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4304 uint xFade;
4305 fromString(getParam(sParams, "xfade"), xFade);
4307 string fileName= getParam(sParams, "music");
4309 // don't play if db is in init stage
4310 if (!ClientCfg.Local && IngameDbMngr.initInProgress()) return;
4312 if(SoundMngr)
4313 SoundMngr->stopEventMusic(fileName, xFade);
4316 REGISTER_ACTION_HANDLER(CHandlerStopEventMusic, "stop_event_music");
4318 // ***************************************************************************
4319 // enter cr zone for queue
4320 class CEnterCRZone: public IActionHandler
4322 public:
4323 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4325 // hide interface
4326 CInterfaceManager* pIM = CInterfaceManager::getInstance();
4327 CInterfaceGroup *pIG = (CInterfaceGroup*)CWidgetManager::getInstance()->getElementFromId ("ui:interface:enter_crzone_proposal");
4328 if(pIG)
4329 pIG->setActive(false);
4331 bool accept;
4332 fromString(sParams, accept);
4333 CBitMemStream out;
4334 if(GenericMsgHeaderMngr.pushNameToStream("MISSION:ENTER_CRITICAL", out))
4336 //nlinfo("impulseCallBack :MISSION:ENTER_CRITICAL sent");
4337 out.serial(accept);
4338 NetMngr.push(out);
4340 else
4342 nlwarning("command : unknown message name : MISSION:ENTER_CRITICAL");
4346 REGISTER_ACTION_HANDLER(CEnterCRZone, "enter_crzone");
4349 // ***************************************************************************
4350 // wake player
4351 class CWakeForMission : public IActionHandler
4353 public:
4354 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4356 uint8 nMissionNb;
4357 fromString(sParams, nMissionNb);
4359 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_WAKE_BUTTON",false);
4360 if (pNL != NULL) pNL->setValue64(0);
4362 sendMsgToServer("MISSION:WAKE", nMissionNb);
4365 REGISTER_ACTION_HANDLER(CWakeForMission, "mission_wake");
4367 // ***************************************************************************
4368 // wake player
4369 class CWakeForGroupMission : public IActionHandler
4371 public:
4372 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4374 uint8 nMissionNb;
4375 fromString(sParams, nMissionNb);
4377 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_WAKE_BUTTON",false);
4378 if (pNL != NULL) pNL->setValue64(0);
4380 sendMsgToServer("MISSION:GROUP_WAKE", nMissionNb);
4383 REGISTER_ACTION_HANDLER(CWakeForGroupMission, "group_mission_wake");
4386 // ***************************************************************************
4387 // ***************************************************************************
4388 // PVP FACTION
4389 // ***************************************************************************
4390 // ***************************************************************************
4393 // ***************************************************************************
4394 class CBuildTotem : public IActionHandler
4396 public:
4397 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4399 if (UserEntity->selection())
4401 CEntityCL *pSel = EntitiesMngr.entity(UserEntity->selection());
4402 if (pSel != NULL)
4403 UserEntity->moveToTotemBuildingPhrase( UserEntity->selection(), 2.0f, std::numeric_limits<uint>::max(), std::numeric_limits<uint>::max(), true);
4407 REGISTER_ACTION_HANDLER(CBuildTotem, "build_totem");
4410 // ***************************************************************************
4411 class CHandlerFameSetNeutral : public IActionHandler
4413 public:
4414 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4416 if( IngameDbMngr.initInProgress() ) return;
4418 bool force;
4419 fromString(getParam(sParams, "force"), force);
4421 bool isCiv= getParam(sParams, "type")=="civ" || getParam(sParams, "type")=="civ_guild";
4422 bool isGuild= getParam(sParams, "type")=="civ_guild" || getParam(sParams, "type")=="cult_guild";
4424 if(force)
4426 // help the server to know what type of neutral to set (civ or cult). ugly
4427 uint8 u8Type= isCiv?PVP_CLAN::Fyros:PVP_CLAN::Kami;
4428 // send msg to server.
4429 if(isGuild)
4430 sendMsgToServer("PVP:SET_NEUTRAL_ALLEGIANCE_GUILD", u8Type);
4431 else
4432 sendMsgToServer("PVP:SET_NEUTRAL_ALLEGIANCE", u8Type);
4434 else
4436 // confirm first
4437 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4438 if(isGuild)
4440 pIM->validMessageBox(CInterfaceManager::WarningIconMsg,
4441 isCiv?CI18N::get("uiFameAllegianceCivSetNeutralGuildWarning"):
4442 CI18N::get("uiFameAllegianceCultSetNeutralGuildWarning"),
4443 "fame_set_neutral",
4444 isCiv?"type=civ_guild|force=1":"type=cult_guild|force=1" );
4446 else
4448 pIM->validMessageBox(CInterfaceManager::WarningIconMsg,
4449 isCiv?CI18N::get("uiFameAllegianceCivSetNeutralWarning"):
4450 CI18N::get("uiFameAllegianceCultSetNeutralWarning"),
4451 "fame_set_neutral",
4452 isCiv?"type=civ|force=1":"type=cult|force=1" );
4457 REGISTER_ACTION_HANDLER(CHandlerFameSetNeutral, "fame_set_neutral");
4460 // ***************************************************************************
4461 class CHandlerConfigureQuitDialogBox : public IActionHandler
4463 public:
4464 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4466 CInterfaceManager::getInstance()->configureQuitDialogBox();
4469 REGISTER_ACTION_HANDLER(CHandlerConfigureQuitDialogBox, "configure_quit_dialog_box");
4471 // ----------------------------------------------------------------------------
4472 static bool isSwimming()
4474 if (UserEntity != NULL)
4475 return (UserEntity->mode() == MBEHAV::SWIM || UserEntity->mode() == MBEHAV::MOUNT_SWIM);
4476 else
4477 return false;
4480 static bool isStunned()
4482 if (UserEntity != NULL)
4483 return (UserEntity->behaviour() == MBEHAV::STUNNED);
4484 else
4485 return false;
4488 static bool isDead()
4490 if (UserEntity != NULL)
4491 return (UserEntity->mode() == MBEHAV::DEATH);
4492 else
4493 return false;
4496 // ***************************************************************************
4498 class CHandlerEmote : public IActionHandler
4500 public:
4501 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4503 // An emote is 2 things : a phrase and an animation
4504 // Phrase is the phrase that server returns in chat system
4505 // Behav is the animation played
4506 // CustomPhrase is an user phrase which can replace default phrase
4507 string sPhraseNb = getParam(sParams, "nb");
4508 string sBehav = getParam(sParams, "behav");
4509 string sCustomPhrase = getParam(sParams, "custom_phrase");
4511 uint32 phraseNb;
4512 fromString(sPhraseNb, phraseNb);
4513 uint8 behaviour;
4514 fromString(sBehav, behaviour);
4516 MBEHAV::EBehaviour behavToSend = (MBEHAV::EBehaviour)(MBEHAV::EMOTE_BEGIN + behaviour);
4517 uint16 phraseNbToSend = (uint16)phraseNb;
4519 if (EAM)
4521 const uint nbBehav = EAM->getNbEmots(); // Miscalled: this is the number of behaviour for all emotes
4522 if ((behaviour >= nbBehav) || (behaviour == 255))
4523 behavToSend = MBEHAV::IDLE;
4525 else
4527 if (behaviour == 255)
4528 behavToSend = MBEHAV::IDLE;
4531 /* Emotes forbidden when dead, emotes with behav forbidden when
4532 * stunned or swimming */
4533 if ( ( behavToSend != MBEHAV::IDLE && (isSwimming() || isStunned() || isDead() ) ) )
4535 return;
4538 if( sCustomPhrase.empty() )
4540 // Create the message and send.
4541 static const char *msgName = "COMMAND:EMOTE";
4542 CBitMemStream out;
4543 if(GenericMsgHeaderMngr.pushNameToStream(msgName, out))
4545 out.serialEnum(behavToSend);
4546 out.serial(phraseNbToSend);
4547 NetMngr.push(out);
4548 //nlinfo("impulseCallBack : %s %d %d sent", msgName.c_str(), (uint32)behavToSend, phraseNbToSend);
4550 else
4551 nlwarning("command 'emote': unknown message named '%s'.", msgName);
4553 else
4555 // Create the message and send.
4556 static const char *msgName = "COMMAND:CUSTOM_EMOTE";
4557 CBitMemStream out;
4558 if(GenericMsgHeaderMngr.pushNameToStream(msgName, out))
4560 ucstring ucstr; // FIXME: UTF-8 (serial)
4561 ucstr.fromUtf8(sCustomPhrase);
4563 if( sCustomPhrase == "none" )
4565 if( behavToSend == MBEHAV::IDLE )
4567 // display "no animation for emote"
4568 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4569 string msg = CI18N::get("msgCustomizedEmoteNoAnim");
4570 string cat = getStringCategory(msg, msg);
4571 pIM->displaySystemInfo(msg, cat);
4572 return;
4575 else
4577 ucstr = ucstring("&EMT&") + UserEntity->getDisplayName() + ucstring(" ") + ucstr; // FIXME: UTF-8 (serial)
4580 out.serialEnum(behavToSend);
4581 out.serial(ucstr); // FIXME: UTF-8 (serial)
4582 NetMngr.push(out);
4583 //nlinfo("impulseCallBack : %s %d %s sent", msgName.c_str(), (uint32)behavToSend, sCustomPhrase.c_str());
4585 else
4586 nlwarning("command 'emote': unknown message named '%s'.", msgName);
4590 REGISTER_ACTION_HANDLER( CHandlerEmote, "emote");
4592 //=================================================================================================================
4593 class CHandlerSortTribeFame : public IActionHandler
4595 public:
4596 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4598 CGroupList * list = dynamic_cast<CGroupList*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:fame:content:tribes:list"));
4599 if (list && list->getNumChildren() > 1)
4601 uint nbChilds = list->getNumChildren();
4603 // std::collate does not work with ucchar
4604 std::vector<string> names;
4606 for (uint i = 0; i < nbChilds; ++i)
4608 CInterfaceGroup *pIG = dynamic_cast<CInterfaceGroup*>(list->getChild(i));
4609 if (!pIG) break;
4611 CViewText *pVT = dynamic_cast<CViewText *>(pIG->getView("t"));
4612 if (!pVT) break;
4614 names.push_back(toUpper(pVT->getText()));
4617 if (names.size() != nbChilds)
4619 nlwarning("Failed to sort tribe fame list");
4620 return;
4623 std::locale loc("");
4624 const std::collate<char>& coll = std::use_facet<std::collate<char> >(loc); // FIXME: Probably does not work
4626 for(uint i = 0; i < nbChilds - 1; ++i)
4628 uint imin = i;
4629 for(uint j = i; j < nbChilds; j++)
4631 // simple comparison fails with accented letters
4632 if (coll.compare(names[j].c_str(), names[j].c_str() + names[j].size(),
4633 names[imin].c_str(), names[imin].c_str() + names[imin].size()) < 0)
4635 imin = j;
4638 if (imin != i)
4640 list->swapChildren(i, imin);
4641 std::swap(names[i], names[imin]);
4645 list->invalidateCoords();
4649 REGISTER_ACTION_HANDLER( CHandlerSortTribeFame, "sort_tribefame");
4651 // ***************************************************************************
4652 class CHandlerTriggerIconBuffs : public IActionHandler
4654 public:
4655 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4657 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:SHOW_ICON_BUFFS", false);
4658 // no node - show,
4659 // node == false - hide
4660 CDBCtrlSheet::setShowIconBuffs(!node || node->getValueBool());
4663 REGISTER_ACTION_HANDLER(CHandlerTriggerIconBuffs, "trigger_show_icon_buffs");