Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / interface_v3 / action_handler_game.cpp
blob15851758db3c8a70bdb5aff44b2847039d9b469f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2021 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 CHandlerContextOpenMissionOption : 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(CHandlerContextOpenMissionOption, "open_mission_option");
530 class CHandlerContextMissionOption : public IActionHandler
532 public:
533 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
535 std::string id = getParam(sParams, "id");
536 sint intId;
537 if (!fromString(id, intId)) return;
538 UserEntity->moveToMission(UserEntity->targetSlot(), 3.0, intId);
541 REGISTER_ACTION_HANDLER(CHandlerContextMissionOption, "mission_option");
546 // ***************************************************************************
547 // GCM Missions
548 // ***************************************************************************
550 class CHandlerContextMissions : public IActionHandler
552 public:
553 void execute (CCtrlBase *pCaller, const std::string &sParams)
555 CInterfaceManager *im = CInterfaceManager::getInstance();
556 // if there is only a single page available for missions, go to that page directly
557 CCDBNodeLeaf *progs = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:TARGET:PROGRAMMES", false);
558 if (!progs)
560 nlwarning("<CHandlerContextMissions::execute> can't retrieve programs.");
561 return;
563 bool missionsToDo = (progs->getValue32() & (1 << BOTCHATTYPE::AvailableMissionFamily)) != 0;
564 bool missionsToContinue = (progs->getValue32() & (1 << BOTCHATTYPE::CompletedMissionFamily)) != 0;
565 bool missionsTofinish = (progs->getValue32() & (1 << BOTCHATTYPE::ContinuedMissionFamily)) != 0;
566 if (missionsToDo && !missionsToContinue && !missionsTofinish)
568 startBotChatAtPage(BOTCHATTYPE::AvailableMissions);
570 else if (!missionsToDo && missionsToContinue && !missionsTofinish)
572 startBotChatAtPage(BOTCHATTYPE::MissionProgress);
574 else if (!missionsToDo && !missionsToContinue && missionsTofinish)
576 startBotChatAtPage(BOTCHATTYPE::CompletedMissions);
578 else
580 startBotChatAtPage(BOTCHATTYPE::MissionStartPage);
584 REGISTER_ACTION_HANDLER(CHandlerContextMissions, "context_missions");
587 // ***************************************************************************
588 // GCM Available missions
589 // ***************************************************************************
591 class CHandlerContextAvailableMissions : public IActionHandler
593 public:
594 void execute (CCtrlBase *pCaller, const std::string &sParams)
596 startBotChatAtPage(BOTCHATTYPE::AvailableMissions); // missions list page. If only one option, go to this page ?
599 REGISTER_ACTION_HANDLER(CHandlerContextAvailableMissions, "context_available_missions");
601 // ***************************************************************************
602 // GCM Constinue missions
603 // ***************************************************************************
604 class CHandlerContextContinueMissions : public IActionHandler
606 public:
607 void execute (CCtrlBase *pCaller, const std::string &sParams)
609 startBotChatAtPage(BOTCHATTYPE::MissionProgress); // missions list page. If only one option, go to this page ?
612 REGISTER_ACTION_HANDLER(CHandlerContextContinueMissions, "context_continue_missions");
614 // ***************************************************************************
615 // GCM Finish missions
616 // ***************************************************************************
617 class CHandlerContextFinishMissions : public IActionHandler
619 public:
620 void execute (CCtrlBase *pCaller, const std::string &sParams)
622 startBotChatAtPage(BOTCHATTYPE::CompletedMissions); // missions list page. If only one option, go to this page ?
625 REGISTER_ACTION_HANDLER(CHandlerContextFinishMissions, "context_finish_missions");
629 // ***************************************************************************
630 // GCM Attack
631 // ***************************************************************************
633 class CHandlerContextAttack : public IActionHandler
635 public:
636 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
639 if( !UserEntity->canEngageCombat() )
640 return;
642 // Move to the current selection and attack.
643 UserEntity->moveToAttack();
645 protected:
647 REGISTER_ACTION_HANDLER( CHandlerContextAttack, "context_attack");
649 // ***************************************************************************
650 // GCM Duel
651 // ***************************************************************************
653 class CHandlerContextDuel : public IActionHandler
655 public:
656 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
658 sendMsgToServer("DUEL:ASK");
661 REGISTER_ACTION_HANDLER( CHandlerContextDuel, "context_duel");
663 // ***************************************************************************
664 // GCM UnDuel
665 // ***************************************************************************
667 class CHandlerContextUnDuel : public IActionHandler
669 public:
670 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
672 sendMsgToServer("DUEL:ABANDON");
675 REGISTER_ACTION_HANDLER( CHandlerContextUnDuel, "context_unduel");
677 // ***************************************************************************
678 // GCM PVP Challenge
679 // ***************************************************************************
681 class CHandlerContextPVPChallenge : public IActionHandler
683 public:
684 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
686 sendMsgToServer("PVP_CHALLENGE:ASK");
689 REGISTER_ACTION_HANDLER( CHandlerContextPVPChallenge, "context_pvp_challenge");
691 // ***************************************************************************
692 // GCM Un_PVP_Challenge
693 // ***************************************************************************
695 class CHandlerContextUnPVPChallenge : public IActionHandler
697 public:
698 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
700 sendMsgToServer("PVP_CHALLENGE:ABANDON");
703 REGISTER_ACTION_HANDLER( CHandlerContextUnPVPChallenge, "context_unpvp_challenge");
705 // ***************************************************************************
706 // GCM Invit
707 // ***************************************************************************
709 class CHandlerContextInvit : public IActionHandler
711 public:
712 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
714 // Game Specific Code
715 sendMsgToServer("TEAM:JOIN_PROPOSAL");
717 protected:
719 REGISTER_ACTION_HANDLER( CHandlerContextInvit, "context_invit");
721 // ***************************************************************************
722 // GCM Guild Invit
723 // ***************************************************************************
725 class CHandlerContextGuildInvit : public IActionHandler
727 public:
728 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
730 // Game Specific Code
731 sendMsgToServer("GUILD:INVITATION");
733 protected:
735 REGISTER_ACTION_HANDLER( CHandlerContextGuildInvit, "context_guild_invit");
737 // ***************************************************************************
738 // GCM Add to friend list
739 // ***************************************************************************
740 class CHandlerContextAddToFriendList : public IActionHandler
742 public:
743 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
745 CLFECOMMON::TCLEntityId trader = UserEntity->selection();
746 if (trader != CLFECOMMON::INVALID_SLOT)
748 CEntityCL *entity = EntitiesMngr.entity(trader);
749 if (entity)
751 string playerName = entity->getEntityName();
752 if (!playerName.empty())
754 PeopleInterraction.askAddContact(playerName, &PeopleInterraction.FriendList);
760 REGISTER_ACTION_HANDLER( CHandlerContextAddToFriendList, "context_add_to_friend_list");
763 // ***************************************************************************
764 // chooseSheath
765 // ***************************************************************************
767 static void chooseSheath (ITEMFAMILY::EItemFamily eIF, string sAllSkills)
769 // Choose right sheath
770 CInterfaceManager *pIM = CInterfaceManager::getInstance();
771 CCDBNodeLeaf *pNLwrite = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("ui_set_active"));
772 CCDBNodeLeaf *pNLread = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("set_nb"));
773 sint32 nNbSheath = (sint32)pNLread->getValue64();
774 if (nNbSheath == 0) return;
775 pNLread = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("set_active"));
776 sint32 nActiveSheath = (sint32)pNLread->getValue64();
777 bool bFound = false;
778 for (sint32 i = 0; i < ((nNbSheath/2)+1); ++i)
780 for (sint32 j = 0; j < 2; ++j)
782 sint32 nSheathToTest;
783 if (j == 0)
784 nSheathToTest = nActiveSheath + i;
785 else
786 nSheathToTest = nActiveSheath - i;
787 while (nSheathToTest < INVENTORIES::sheath) nSheathToTest += nNbSheath;
788 while (nSheathToTest >= (INVENTORIES::sheath+nNbSheath)) nSheathToTest -= nNbSheath;
790 string sPath;
791 sPath = CWidgetManager::getInstance()->getParser()->getDefine("set_base") + ":" + NLMISC::toString(nSheathToTest) + ":" + CWidgetManager::getInstance()->getParser()->getDefine("set_r") + ":SHEET";
792 pNLread = NLGUI::CDBManager::getInstance()->getDbProp(sPath);
793 sint32 sheetid = (sint32)pNLread->getValue64();
794 CItemSheet *pIS = dynamic_cast<CItemSheet *>(SheetMngr.get(CSheetId(sheetid)));
795 if (pIS != NULL)
797 if (pIS->Family == eIF)
799 // YOYO: Fast search. important because skill_list is too big for "training" buton case
800 string skillList= IActionHandler::getParam (sAllSkills, "skill_list");
801 if( !skillList.empty() )
803 std::vector<string> strList;
804 NLMISC::splitString(skillList, ",", strList);
805 for(uint k=0;k<strList.size();k++)
807 static string sSkillToTrain;
808 sSkillToTrain= strList[k];
809 // remove \n,\t and spaces
810 while( !sSkillToTrain.empty() &&
811 (sSkillToTrain[0]==' ' || sSkillToTrain[0]=='\n' || sSkillToTrain[0]=='\t') )
812 sSkillToTrain.erase(0, 1);
813 // If the tool skill match the skill filter, and if the player know this skill => OK!
814 if (pIS->Tool.Skill == SKILLS::toSkill(sSkillToTrain) && playerKnowSkill(pIS->Tool.Skill) )
816 bFound = true;
817 pNLwrite->setValue64(nSheathToTest);
818 break;
822 if (bFound) break;
826 if (bFound) break;
832 // ***************************************************************************
833 // GCM Exchange
834 // ***************************************************************************
836 class CHandlerContextExchange : public IActionHandler
838 public:
839 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
841 // Game Specific Code
842 sendMsgToServer("EXCHANGE:PROPOSAL");
844 protected:
846 REGISTER_ACTION_HANDLER( CHandlerContextExchange, "context_exchange");
848 // ***************************************************************************
849 // GCM Free look
850 // ***************************************************************************
851 class CHandlerContextFreeLook : public IActionHandler
853 public:
854 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
856 // Free Look Mode Activated.
857 UserControls.startFreeLook();
859 protected:
861 REGISTER_ACTION_HANDLER( CHandlerContextFreeLook, "context_free_look");
863 // ***************************************************************************
864 class CHandlerToggleFreeLook : public IActionHandler
866 public:
867 void execute(CCtrlBase * /* pCaller */, const std::string & /* sParams */)
869 if (UserControls.getFreeLook())
870 UserControls.stopFreeLook();
871 else
872 UserControls.startFreeLook();
875 REGISTER_ACTION_HANDLER( CHandlerToggleFreeLook, "toggle_free_look");
877 // ***************************************************************************
878 // GCM Move
879 // ***************************************************************************
880 class CHandlerMove : public IActionHandler
882 public:
883 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
885 // Autowalk Mode Activated.
886 UserControls.autowalkState(true);
888 protected:
890 REGISTER_ACTION_HANDLER( CHandlerMove, "context_move");
892 // ***************************************************************************
893 // GCM Stop
894 // ***************************************************************************
895 class CHandlerStop : public IActionHandler
897 public:
898 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
900 // Autowalk Mode Activated.
901 UserControls.autowalkState(false);
903 protected:
905 REGISTER_ACTION_HANDLER( CHandlerStop, "context_stop");
907 // ***************************************************************************
908 class CHandlerExitFreeLook : public IActionHandler
910 public:
911 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
913 // Deactivate free look mode
914 UserControls.stopFreeLook();
916 protected:
918 REGISTER_ACTION_HANDLER( CHandlerExitFreeLook, "exit_free_look");
920 // ***************************************************************************
921 // GCM Loot Action
922 // ***************************************************************************
923 class CHandlerContextLootAction : public IActionHandler
925 public:
926 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
928 NetMngr.pushPickup(UserEntity->selection(), LHSTATE::LOOTABLE);
930 // For loot open directly temporary inventory
931 CTempInvManager::getInstance()->open(TEMP_INV_MODE::Loot);
933 protected:
935 REGISTER_ACTION_HANDLER( CHandlerContextLootAction, "context_loot");
937 // ***************************************************************************
938 // GCM Quartering Action
939 // ***************************************************************************
940 class CHandlerContextHarvestAction : public IActionHandler
942 public:
943 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
945 NetMngr.pushPickup(UserEntity->selection(), LHSTATE::HARVESTABLE);
946 // For quartering and forage open directly temporary inventory
947 CTempInvManager::getInstance()->open(TEMP_INV_MODE::Quarter);
949 protected:
951 REGISTER_ACTION_HANDLER( CHandlerContextHarvestAction, "context_quartering");
953 // ***************************************************************************
954 // GCM Forage Action
955 // ***************************************************************************
956 class CHandlerContextForageExtract : public IActionHandler
958 public:
959 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
961 if (UserEntity->selection())
963 CEntityCL *pSel = EntitiesMngr.entity(UserEntity->selection());
964 if (pSel != NULL)
965 if (pSel->isForageSource())
966 UserEntity->moveToExtractionPhrase(UserEntity->selection(), MaxExtractionDistance, std::numeric_limits<uint>::max(), std::numeric_limits<uint>::max(), true);
970 REGISTER_ACTION_HANDLER( CHandlerContextForageExtract, "context_extract_rm");
973 // ***************************************************************************
974 // GCM Quit Team
975 // ***************************************************************************
977 class CHandlerContextQuitTeam : public IActionHandler
979 public:
980 void execute (CCtrlBase *pCaller, const std::string &sParams)
982 // directly launch the quit_team AH.
983 CInterfaceManager *pIM= CInterfaceManager::getInstance();
984 CAHManager::getInstance()->runActionHandler("quit_team",pCaller, sParams);
986 protected:
988 REGISTER_ACTION_HANDLER( CHandlerContextQuitTeam, "context_quit_team");
991 // ***************************************************************************
992 // GCM Quit Guild
993 // ***************************************************************************
995 class CHandlerContextQuitGuild : public IActionHandler
997 public:
998 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1000 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1002 // Ask if ok before.
1003 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQQuitGuild"), "do_quit_guild");
1005 protected:
1007 REGISTER_ACTION_HANDLER( CHandlerContextQuitGuild, "context_quit_guild");
1010 // If Ok.
1011 class CHandlerDoQuitGuild : public IActionHandler
1013 public:
1014 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1016 // Create the message for the server to execute a phrase.
1017 sendMsgToServer("GUILD:QUIT");
1018 CGuildManager::getInstance()->closeAllInterfaces();
1020 if (PeopleInterraction.TheUserChat.Filter.getTargetGroup() == CChatGroup::guild)
1021 ChatMngr.updateChatModeAndButton(CChatGroup::say);
1024 REGISTER_ACTION_HANDLER( CHandlerDoQuitGuild, "do_quit_guild");
1027 // ***************************************************************************
1028 // GCM Disengage
1029 // ***************************************************************************
1031 class CHandlerContextDisengage : public IActionHandler
1033 public:
1034 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1036 // Disengage
1037 UserEntity->disengage();
1039 protected:
1042 REGISTER_ACTION_HANDLER( CHandlerContextDisengage, "context_disengage");
1044 // ***************************************************************************
1045 // GCM Mount
1046 // ***************************************************************************
1048 class CHandlerContextMount : public IActionHandler
1050 public:
1051 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1053 CEntityCL *sel = EntitiesMngr.entity(UserEntity->selection());
1054 if (sel == NULL) return;
1056 // Game Specific Code
1057 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1059 // Look through Database the index of the mount selected
1060 for (uint32 i = 0; i < MAX_INVENTORY_ANIMAL; i++)
1062 CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", i), false);
1063 CCDBNodeLeaf *typeProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:TYPE", i), false);
1064 if ((uidProp != NULL) && (uidProp->getValue32() == (sint32)sel->dataSetId()) &&
1065 (typeProp != NULL) && (typeProp->getValue32() == ANIMAL_TYPE::Mount))
1067 beastOrder("mount", toString(i+1)); // why +1 ? : dixit sendAnimalCommand in EGS : index 0 = all animals, 1 = animal 0 etc
1068 CAHManager::getInstance()->runActionHandler("animal_target", NULL, toString(i+1));
1069 UserEntity->moveTo(UserEntity->selection(),2.0,CUserEntity::None);
1074 REGISTER_ACTION_HANDLER( CHandlerContextMount, "context_mount");
1076 // ***************************************************************************
1077 // GCM Unseat
1078 // ***************************************************************************
1080 class CHandlerContextUnseat : public IActionHandler
1082 public:
1083 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1085 // Game Specific Code
1086 beastOrder("unmount", "0");
1088 // Set the database in local.
1089 if(ClientCfg.Local)
1091 // Prepare the database to unseat
1092 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->slot()) + ":P" + toString(CLFECOMMON::PROPERTY_MODE), MBEHAV::NORMAL);
1093 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->slot()) + ":P" + toString(CLFECOMMON::PROPERTY_ENTITY_MOUNTED_ID), CLFECOMMON::INVALID_SLOT);
1094 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->mount()) + ":P" + toString(CLFECOMMON::PROPERTY_MODE), MBEHAV::NORMAL);
1095 IngameDbMngr.setProp("Entities:E" + toString(UserEntity->mount()) + ":P" + toString(CLFECOMMON::PROPERTY_RIDER_ENTITY_ID), CLFECOMMON::INVALID_SLOT);
1096 // Read the database to unseat.
1097 CEntityCL *mount = EntitiesMngr.entity(UserEntity->mount());
1098 if(mount)
1100 mount->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_MODE);
1101 mount->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_RIDER_ENTITY_ID);
1103 UserEntity->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_MODE);
1104 UserEntity->updateVisualProperty(NetMngr.getCurrentServerTick()+10, CLFECOMMON::PROPERTY_ENTITY_MOUNTED_ID);
1107 protected:
1110 REGISTER_ACTION_HANDLER( CHandlerContextUnseat, "context_unseat");
1113 // ***************************************************************************
1114 class CHandlerContextWebPage : public IActionHandler
1116 public:
1117 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1119 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1121 // start the npc web page
1122 CLuaManager::getInstance().executeLuaScript("game:startNpcWebPage()", true);
1125 REGISTER_ACTION_HANDLER( CHandlerContextWebPage, "context_web_page");
1128 // ***************************************************************************
1129 class CHandlerFullMap : public IActionHandler
1131 public:
1132 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1134 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1136 CLuaManager::getInstance().executeLuaScript("game:openFullMap()", true);
1139 REGISTER_ACTION_HANDLER( CHandlerFullMap, "fullmap");
1144 // ***************************************************************************
1145 // GCM Mission option
1146 // ***************************************************************************
1147 class CHandlerContextMissionRing : public IActionHandler
1149 public:
1150 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
1152 std::string id = getParam(sParams, "id");
1153 sint idInDb;
1154 if (!fromString(id, idInDb)) return;
1156 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1158 // get ID
1159 CCDBNodeLeaf *dbMissionId = NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSION_RING:%d:ID", idInDb), false);
1160 if (!dbMissionId)
1161 return;
1162 uint32 missionId= dbMissionId->getValue32();
1164 // send msg
1165 sendMsgToServer("RING_MISSION:MISSION_RING_SELECT", (uint32)missionId);
1168 REGISTER_ACTION_HANDLER(CHandlerContextMissionRing, "mission_ring");
1171 /**********************************************************************************************************
1173 * game handlers *
1175 ***********************************************************************************************************/
1178 // ***************************************************************************
1179 //quit the game
1180 class CAHQuitGame : public IActionHandler
1182 public:
1183 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1185 /* todo game_exit
1186 game_exit = true;
1187 nlinfo("User Request to Quit the game"); */
1190 REGISTER_ACTION_HANDLER( CAHQuitGame, "quit_game");
1193 // ***************************************************************************
1194 //quit the game
1195 class CAHQuitRyzom : public IActionHandler
1197 public:
1198 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1200 // If we are not connected, quit now
1201 if((!ConnectionReadySent) && (!FarTP.isLeavingEGS()))
1203 game_exit = true;
1204 ryzom_exit = true;
1205 nlinfo("User Request to Quit ryzom");
1207 else
1209 // Don't quit but wait for server Quit
1210 game_exit_request = true;
1211 ryzom_exit_request = true;
1213 const char *msgName = "CONNECTION:CLIENT_QUIT_REQUEST";
1214 CBitMemStream out;
1215 nlverify(GenericMsgHeaderMngr.pushNameToStream(msgName, out));
1216 bool bypassDisconnectionTimer = FarTP.isFastDisconnectGranted() && (!IsInRingSession); // no need on a ring shard, as it's very short
1217 out.serial(bypassDisconnectionTimer);
1218 FarTP.writeSecurityCodeForDisconnection(out); // must always be written because of msg.xml (or could have a special handler in the FS)
1219 NetMngr.push(out);
1220 //nlinfo("impulseCallBack : %s sent", msgName.c_str());
1224 REGISTER_ACTION_HANDLER( CAHQuitRyzom, "quit_ryzom");
1226 // ***************************************************************************
1227 //paying account for Free Trial
1228 class CAHPayingAccount : public IActionHandler
1230 public:
1231 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1233 paying_account_request = FreeTrial;
1234 if(!FreeTrial)
1236 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1237 CAHManager::getInstance()->runActionHandler("quit_ryzom", NULL);
1241 REGISTER_ACTION_HANDLER( CAHPayingAccount, "paying_account");
1243 // ***************************************************************************
1244 //force quit the game
1245 class CAHQuitRyzomNow : public IActionHandler
1247 public:
1248 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1250 if(!paying_account_already_request && FreeTrial)
1252 paying_account_request = true;
1253 game_exit_after_paying_account_request = true;
1255 else
1257 game_exit = true;
1258 ryzom_exit = true;
1260 paying_account_already_request = false;
1262 //game_exit = true;
1263 //ryzom_exit = true;
1265 nlinfo("User Force to Quit ryzom");
1268 REGISTER_ACTION_HANDLER( CAHQuitRyzomNow, "quit_ryzom_now");
1271 // ***************************************************************************
1272 //Abort quit the game
1273 class CAHQuitRyzomAbort : public IActionHandler
1275 public:
1276 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1278 if(ClientCfg.Local)
1280 game_exit_request = false;
1281 ryzom_exit_request = false;
1282 nlinfo("User Abort to Quit ryzom");
1284 else
1286 // send a message to server, thru cancel cast
1287 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1288 CAHManager::getInstance()->runActionHandler("phrase_cancel_cast", NULL);
1290 paying_account_request = false;
1291 paying_account_already_request = false;
1294 REGISTER_ACTION_HANDLER( CAHQuitRyzomAbort, "quit_ryzom_abort");
1296 // ***************************************************************************
1297 //Abort quit the game
1298 class CAHCloseFreeTrialQuitting : public IActionHandler
1300 public:
1301 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1303 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1305 paying_account_request = false;
1307 if(game_exit_after_paying_account_request)
1309 game_exit = true;
1310 ryzom_exit = true;
1311 game_exit_after_paying_account_request = false;
1313 else
1315 paying_account_already_request = true;
1316 CAHManager::getInstance()->runActionHandler("quit_ryzom", NULL);
1319 CAHManager::getInstance()->runActionHandler("leave_modal", NULL);
1322 REGISTER_ACTION_HANDLER( CAHCloseFreeTrialQuitting, "close_free_trial_game_quitting");
1325 // ***************************************************************************
1326 // quit the ring session and return to mainland Ryzom
1327 class CAHReturnToMainland : public IActionHandler
1329 public:
1330 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1332 FarTP.requestReturnToPreviousSession();
1335 REGISTER_ACTION_HANDLER( CAHReturnToMainland, "return_to_mainland");
1337 // ***************************************************************************
1338 // quit the ring session and return to character selection
1339 class CAHReselectCharacter : public IActionHandler
1341 public:
1342 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
1344 nlinfo("User request to reselect character");
1345 FarTP.requestReconnection();
1348 REGISTER_ACTION_HANDLER( CAHReselectCharacter, "reselect_character");
1350 // ***************************************************************************
1351 /** Select an item in a selection group
1353 class CSelectItemSheet : public IActionHandler
1355 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
1357 CDBCtrlSheet *ctrlSheet = dynamic_cast<CDBCtrlSheet *>(pCaller);
1358 if (!ctrlSheet) return;
1359 sint selectionGroup = ctrlSheet->getSelectionGroup();
1360 CInterfaceManager *im = CInterfaceManager::getInstance();
1361 const CCtrlSheetSelection &css = CWidgetManager::getInstance()->getParser()->getCtrlSheetSelection();
1362 const CSheetSelectionGroup *csg = css.getGroup(selectionGroup);
1363 if (csg && csg->isActive())
1365 if (ctrlSheet->getSheetId() != 0)
1367 // set the slot as the current selection
1368 CDBCtrlSheet::setCurrSelection(ctrlSheet);
1370 else
1372 CDBCtrlSheet::setCurrSelection(NULL);
1375 bool canUse = true;
1376 bool canBuild = true;
1377 bool canUseBuiltItem = true;
1378 // check if user has the level to use the item (applies to item & plans)
1379 if (ctrlSheet->getSheetCategory() == CDBCtrlSheet::Item)
1381 if (csg && csg->getName() == "buy_selection")
1383 const CItemSheet *is = ctrlSheet->asItemSheet();
1384 if (is)
1386 // get the needed skill to use the item
1387 SKILLS::ESkills rs = is->getRequiredSkill();
1388 if (rs < SKILLS::unknown)
1390 #define SKILL_PATH "SERVER:CHARACTER_INFO:SKILLS:"
1391 string path = toString(SKILL_PATH "%d:SKILL", (int) rs);
1392 CCDBNodeLeaf *nl = NLGUI::CDBManager::getInstance()->getDbProp(path,false);
1393 if (nl)
1395 if (nl->getValue32() == 0)
1397 canUse = false;
1402 // display msg in the system infos
1403 if (!canUse)
1405 string msg = CI18N::get("msgCantUseItem");
1406 string cat = getStringCategory(msg, msg);
1407 im->displaySystemInfo(msg, cat);
1409 if (!canBuild)
1411 string msg = CI18N::get("msgCantBuild");
1412 string cat = getStringCategory(msg, msg);
1413 im->displaySystemInfo(msg, cat);
1415 if (!canUseBuiltItem)
1417 string msg = CI18N::get("msgCantUseBuiltItem");
1418 string cat = getStringCategory(msg, msg);
1419 im->displaySystemInfo(msg, cat);
1424 showItemFlags(im, canUse, canBuild, canUseBuiltItem);
1429 /** On the trade windows, display or not : can use item, can build item, can use built item
1431 void showItemFlags(CInterfaceManager *im, bool canUse, bool canBuild, bool canUseBuiltItem);
1433 REGISTER_ACTION_HANDLER (CSelectItemSheet, "select_item");
1435 void CSelectItemSheet::showItemFlags(CInterfaceManager *im,bool canUse,bool canBuild,bool canUseBuiltItem)
1437 if (!im) return;
1438 CInterfaceGroup *gr;
1439 #define BOT_CHAT_TRADE_PATH "ui:interface:bot_chat_trade:header_opened:trade_content:"
1440 gr = dynamic_cast<CInterfaceGroup *>( CWidgetManager::getInstance()->getElementFromId(BOT_CHAT_TRADE_PATH "cant_use_item"));
1441 if (gr) gr->setActive(!canUse);
1442 gr = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(BOT_CHAT_TRADE_PATH "cant_use_built_item"));
1443 if (gr) gr->setActive(!canUseBuiltItem);
1444 gr = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(BOT_CHAT_TRADE_PATH "cant_build_item"));
1445 if (gr) gr->setActive(!canBuild);
1449 // ***************************************************************************
1450 /** Set a price in the given DB entries
1453 class CSetPriceInDB : public IActionHandler
1455 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1457 std::string ls = getParam(Params, "ls");
1458 std::string ms = getParam(Params, "ms");
1459 std::string bs = getParam(Params, "bs");
1460 std::string vbs = getParam(Params, "vbs");
1461 std::string value = getParam(Params, "value");
1462 if (ls.empty() || ms.empty() || bs.empty() || vbs.empty() || value.empty())
1464 nlwarning("<CSetItemPriceInDB::execute> can't get db address for all kind of seeds, or can't get value");
1465 return;
1467 CInterfaceExprValue price;
1468 if (!CInterfaceExpr::eval(value, price) || !price.toInteger())
1470 nlwarning("<CSetPriceInDB::execute> : Can't evaluate price");
1471 return;
1473 CInterfaceManager *im = CInterfaceManager::getInstance();
1474 if (price.getInteger() >= 0)
1476 CSeeds money;
1477 money.setTotal(price.getInteger());
1478 NLGUI::CDBManager::getInstance()->getDbProp(ls)->setValue64(money.getLS());
1479 NLGUI::CDBManager::getInstance()->getDbProp(ms)->setValue64(money.getMS());
1480 NLGUI::CDBManager::getInstance()->getDbProp(bs)->setValue64(money.getBS());
1481 NLGUI::CDBManager::getInstance()->getDbProp(vbs)->setValue64(money.getVBS());
1483 else
1485 // undefined price
1486 NLGUI::CDBManager::getInstance()->getDbProp(ls)->setValue64(-1);
1487 NLGUI::CDBManager::getInstance()->getDbProp(ms)->setValue64(-1);
1488 NLGUI::CDBManager::getInstance()->getDbProp(bs)->setValue64(-1);
1489 NLGUI::CDBManager::getInstance()->getDbProp(vbs)->setValue64(-1);
1493 REGISTER_ACTION_HANDLER (CSetPriceInDB, "set_price_in_db");
1496 // ***************************************************************************
1497 /** Pack animal orders
1499 //give an order to the beast
1500 void beastOrder (const std::string &orderStr, const std::string &beastIndexStr, bool confirmFree)
1502 uint8 order = (uint8) ANIMALS_ORDERS::stringToBeastOrder(orderStr);
1503 if (order == ANIMALS_ORDERS::UNKNOWN_BEAST_ORDER)
1505 nlwarning("<beastOrder> : invalid beast order : %s", orderStr.c_str());
1506 return;
1508 sint64 beastIndex;
1509 if (!CInterfaceExpr::evalAsInt(beastIndexStr, beastIndex))
1511 nlwarning("<beastOrder> : can't read beast index");
1512 return;
1514 // 0 is for all beasts => MAX_INVENTORY_ANIMAL is a valid selection
1515 if (beastIndex > MAX_INVENTORY_ANIMAL)
1517 nlwarning("<beastOrder> : invalid animal index %d, maximum is %d", beastIndex, (int) MAX_INVENTORY_ANIMAL);
1518 return;
1521 // if the order is a free, and if confirm, open a message first
1522 if(order == ANIMALS_ORDERS::FREE && confirmFree)
1524 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1525 if(beastIndex==0)
1526 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQConfirmFreeAllAnimal"),
1527 "do_beast_free", toString(beastIndex) );
1528 else
1529 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQConfirmFreeAnimal"),
1530 "do_beast_free", toString(beastIndex) );
1532 // else launch the command
1533 else
1535 // execute the order.
1536 const char *msgName = "ANIMALS:BEAST";
1537 CBitMemStream out;
1538 if(GenericMsgHeaderMngr.pushNameToStream(msgName, out))
1540 uint8 u8BeastIndex = (uint8) beastIndex;
1541 out.serial(u8BeastIndex); // to activate on server side
1542 // 0 -> all beasts, otherwise, the index of the beast
1543 out.serial(order);
1544 NetMngr.push(out);
1546 else
1547 nlwarning("<beastOrder> : unknown message name : '%s'.", msgName);
1551 // ***************************************************************************
1552 class CHandlerBeastOrder : public IActionHandler
1554 public:
1555 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1557 string orderStr = getParam(Params,"order");
1558 if( orderStr == "mount" )
1560 // target the beast
1561 CInterfaceManager * pIM= CInterfaceManager::getInstance();
1562 string beastIndex;
1563 if( CInterfaceExpr::evalAsString(getParam(Params,"beast_index"), beastIndex) )
1565 CAHManager::getInstance()->runActionHandler("animal_target", NULL, beastIndex);
1567 // move to the beast
1568 UserEntity->moveTo(UserEntity->selection(),3.0,CUserEntity::Mount);
1570 else
1571 beastOrder (getParam(Params,"order"), getParam(Params,"beast_index"), true);
1574 REGISTER_ACTION_HANDLER( CHandlerBeastOrder, "beast_order")
1577 // ***************************************************************************
1578 class CHandlerDoBeastFree : public IActionHandler
1580 public:
1581 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1583 // free with no confirm
1584 if (!UserEntity->isBusy())
1585 beastOrder ("free", Params, false);
1588 REGISTER_ACTION_HANDLER( CHandlerDoBeastFree, "do_beast_free")
1591 // ***************************************************************************
1592 // Change Possible Orders
1593 class CHandlerAnimalMenuOption : public IActionHandler
1595 public:
1596 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
1598 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1599 CInterfaceGroup *pMenu= dynamic_cast<CInterfaceGroup*>(pCaller);
1600 if(!pMenu) return;
1602 CViewTextMenu *pFollow = dynamic_cast<CViewTextMenu*>(pMenu->getView("follow"));
1603 CViewTextMenu *pStop = dynamic_cast<CViewTextMenu*>(pMenu->getView("stop"));
1604 CViewTextMenu *pFree = dynamic_cast<CViewTextMenu*>(pMenu->getView("free"));
1605 CViewTextMenu *pEnterStable = dynamic_cast<CViewTextMenu*>(pMenu->getView("enter_stable"));
1606 CViewTextMenu *pLeaveStable = dynamic_cast<CViewTextMenu*>(pMenu->getView("leave_stable"));
1607 CViewTextMenu *pEnterBag = dynamic_cast<CViewTextMenu*>(pMenu->getView("enter_bag"));
1608 CViewTextMenu *pLeaveBag = dynamic_cast<CViewTextMenu*>(pMenu->getView("leave_bag"));
1609 CViewTextMenu *pMount = dynamic_cast<CViewTextMenu*>(pMenu->getView("mount"));
1610 CViewTextMenu *pUnseat = dynamic_cast<CViewTextMenu*>(pMenu->getView("unseat"));
1612 // Get the animal Selected. 0 for Alls, 1,2,3,4,5 for each pack animal
1613 CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:BEAST_SELECTED", false);
1614 if(!node) return;
1615 sint selected= node->getValue32();
1617 // Enable menu entries according to each beast
1618 // All Mode
1619 if(selected==0)
1621 // Test all menu option ('OR': display even if *all* animals don't comply with the commands)
1622 for(uint i=0;i<MAX_INVENTORY_ANIMAL;i++)
1624 // Get the entity if it is in vision
1625 CEntityCL* selectedAnimalInVision = NULL;
1626 CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", i), false);
1627 if ( uidProp )
1629 CLFECOMMON::TClientDataSetIndex datasetIndex = uidProp->getValue32();
1630 selectedAnimalInVision = EntitiesMngr.getEntityByCompressedIndex( datasetIndex );
1633 // Enable menu items
1634 testMenuOptionForPackAnimal(selectedAnimalInVision, i, (i==0),
1635 pFollow, pStop, pFree, pEnterStable, pLeaveStable, pMount, pUnseat, pEnterBag, pLeaveBag);
1638 else if(selected>=1 && selected<=MAX_INVENTORY_ANIMAL)
1640 // Get the entity if it is in vision
1641 CEntityCL* selectedAnimalInVision = NULL;
1642 CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", selected-1), false);
1643 if ( uidProp )
1645 CLFECOMMON::TClientDataSetIndex datasetIndex = uidProp->getValue32();
1646 selectedAnimalInVision = EntitiesMngr.getEntityByCompressedIndex( datasetIndex );
1649 // Enable menu items
1650 testMenuOptionForPackAnimal(selectedAnimalInVision, selected-1, true,
1651 pFollow, pStop, pFree, pEnterStable, pLeaveStable, pMount, pUnseat, pEnterBag, pLeaveBag);
1655 REGISTER_ACTION_HANDLER( CHandlerAnimalMenuOption, "animal_menu_option")
1658 // ***************************************************************************
1659 // Target an animal
1660 class CHandlerAnimalTarget : public IActionHandler
1662 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
1664 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1666 // retrieve the index of the animal
1667 sint animalIndex = 0;
1668 bool ok = false;
1669 // If comes from the button, get direct index
1670 if( !sParams.empty() )
1672 fromString(sParams, animalIndex);
1673 ok = true;
1676 // If success to get the animal id
1677 if(ok)
1679 // Get the animal id.
1680 CLFECOMMON::TClientDataSetIndex entityUid= CLFECOMMON::INVALID_CLIENT_DATASET_INDEX;
1682 if(animalIndex>=1 && animalIndex<=MAX_INVENTORY_ANIMAL)
1684 CCDBNodeLeaf *prop = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", animalIndex-1), false);
1685 if(prop) entityUid= prop->getValue32();
1688 if(entityUid != CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
1690 // get the entity by its received UID
1691 CEntityCL *entity= EntitiesMngr.getEntityByCompressedIndex(entityUid);
1692 if(entity)
1693 // Select this entity.
1694 UserEntity->selection(entity->slot());
1695 else
1697 // the entity is not in vision, can't select it
1698 pIM->displaySystemInfo(CI18N::get("uiAnimalSelectNotInVision"), "CHK");
1704 REGISTER_ACTION_HANDLER( CHandlerAnimalTarget, "animal_target" );
1707 // ***************************************************************************
1708 // Open an animal inventory
1709 class CHandlerAnimalOpenInventory : public IActionHandler
1711 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
1713 CInterfaceManager *pIM= CInterfaceManager::getInstance();
1715 // retrieve the index of the animal
1716 sint animalIndex= 0;
1717 bool ok= false;
1718 // If comes from the button, get direct index
1719 if( !sParams.empty() )
1721 fromString(sParams, animalIndex);
1722 ok= true;
1725 // If success to get the animal id
1726 if(ok)
1728 if(animalIndex>=1 && animalIndex<=MAX_INVENTORY_ANIMAL)
1730 // show/hide the inventory
1731 CInterfaceElement *group= CWidgetManager::getInstance()->getElementFromId(toString("ui:interface:inv_pa%d", animalIndex-1) );
1733 if(group) group->setActive(!group->getActive());
1738 REGISTER_ACTION_HANDLER( CHandlerAnimalOpenInventory, "animal_open_inventory" );
1741 // ***************************************************************************
1742 // closeGroup Helper
1743 // ***************************************************************************
1744 static void closeGroup(const string &groupName)
1746 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1747 CInterfaceGroup *pIG = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(groupName));
1748 if (pIG == NULL) return;
1749 pIG->setActive(false);
1752 // ***************************************************************************
1753 // ACCEPT TEAM INVITE
1754 // ***************************************************************************
1756 class CHandlerAcceptTeamInvitation : public IActionHandler
1758 public:
1759 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1761 closeGroup("ui:interface:join_team_proposal");
1762 sendMsgToServer("TEAM:JOIN");
1764 protected:
1767 REGISTER_ACTION_HANDLER( CHandlerAcceptTeamInvitation, "accept_team_invitation");
1769 // ***************************************************************************
1770 // REFUSE TEAM INVITE
1771 // ***************************************************************************
1773 class CHandlerRefuseTeamInvitation : public IActionHandler
1775 public:
1776 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1778 closeGroup("ui:interface:join_team_proposal");
1779 sendMsgToServer("TEAM:JOIN_PROPOSAL_DECLINE");
1781 protected:
1784 REGISTER_ACTION_HANDLER( CHandlerRefuseTeamInvitation, "refuse_team_invitation");
1786 // ***************************************************************************
1787 // ACCEPT GUILD INVITE
1788 // ***************************************************************************
1790 class CHandlerAcceptGuildInvitation : public IActionHandler
1792 public:
1793 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1795 sendMsgToServer("GUILD:ACCEPT_INVITATION");
1796 CGuildManager::getInstance()->quitJoinProposal();
1800 REGISTER_ACTION_HANDLER( CHandlerAcceptGuildInvitation, "accept_guild_invitation");
1802 // ***************************************************************************
1803 // REFUSE GUILD INVITE
1804 // ***************************************************************************
1806 class CHandlerRefuseGuildInvitation : public IActionHandler
1808 public:
1809 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1811 sendMsgToServer("GUILD:REFUSE_INVITATION");
1812 CGuildManager::getInstance()->quitJoinProposal();
1815 REGISTER_ACTION_HANDLER( CHandlerRefuseGuildInvitation, "refuse_guild_invitation");
1817 // ***************************************************************************
1818 // ACCEPT DUEL INVITE
1819 // ***************************************************************************
1821 class CHandlerAcceptDuelInvitation : public IActionHandler
1823 public:
1824 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1826 closeGroup("ui:interface:join_duel_proposal");
1827 sendMsgToServer("DUEL:ACCEPT");
1831 REGISTER_ACTION_HANDLER( CHandlerAcceptDuelInvitation, "accept_duel_invitation");
1833 // ***************************************************************************
1834 // REFUSE DUEL INVITE
1835 // ***************************************************************************
1837 class CHandlerRefuseDuelInvitation : public IActionHandler
1839 public:
1840 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1842 closeGroup("ui:interface:join_duel_proposal");
1843 sendMsgToServer("DUEL:REFUSE");
1846 REGISTER_ACTION_HANDLER( CHandlerRefuseDuelInvitation, "refuse_duel_invitation");
1848 // ***************************************************************************
1849 // ACCEPT PVP CHALLENGE INVITE
1850 // ***************************************************************************
1852 class CHandlerAcceptPVPChallengeInvitation : public IActionHandler
1854 public:
1855 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1857 closeGroup("ui:interface:join_pvp_challenge_proposal");
1858 sendMsgToServer("PVP_CHALLENGE:ACCEPT");
1862 REGISTER_ACTION_HANDLER( CHandlerAcceptPVPChallengeInvitation, "accept_pvp_challenge_invitation");
1864 // ***************************************************************************
1865 // REFUSE PVP CHALLENGE INVITE
1866 // ***************************************************************************
1868 class CHandlerRefusePVPChallengeInvitation : public IActionHandler
1870 public:
1871 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1873 closeGroup("ui:interface:join_pvp_challenge_proposal");
1874 sendMsgToServer("PVP_CHALLENGE:REFUSE");
1877 REGISTER_ACTION_HANDLER( CHandlerRefusePVPChallengeInvitation, "refuse_pvp_challenge_invitation");
1879 // ***************************************************************************
1880 // CHOOSE PVP CLAN
1881 // ***************************************************************************
1883 class CHandlerChoosePVPClan : public IActionHandler
1885 public:
1886 virtual void execute (CCtrlBase *pCaller, const string &Params)
1888 closeGroup("ui:interface:join_pvp_clan_proposal");
1890 uint8 clan = 0;
1891 if( Params == "neutral" )
1892 clan = 0;
1893 else if( Params == "clan1" )
1894 clan = 1;
1895 else if( Params == "clan2" )
1896 clan = 2;
1898 sendMsgToServer("PVP_VERSUS:CLAN", clan);
1901 REGISTER_ACTION_HANDLER( CHandlerChoosePVPClan, "pvp_clan_join");
1904 // ***************************************************************************
1905 // Launch Bug Reporting Tool
1906 // ***************************************************************************
1908 class CAHLaunchBugReport : public IActionHandler
1910 public:
1911 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
1913 if (ClientCfg.Light)
1915 vector<string> v;
1916 CWidgetManager::getInstance()->runProcedure ("proc_reset_interface", NULL, v);
1918 //CInterfaceManager::getInstance()->launchContextMenuInGame("ui:interface:game_context_menu");
1920 ICommand::execute("bugReport 80", g_log);
1923 REGISTER_ACTION_HANDLER( CAHLaunchBugReport, "launch_bug_report");
1925 // ***************************************************************************
1926 // Launch Help Tool
1927 // ***************************************************************************
1929 class CAHLaunchHelp : public IActionHandler
1931 public:
1933 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
1935 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1937 string url = getParam (Params, "url");
1938 string helpContainer = getParam (Params, "help_container");
1939 if (helpContainer.empty ())
1940 helpContainer = "ui:interface:help_browser";
1942 // open the help browser
1943 CInterfaceElement *pIG= CWidgetManager::getInstance()->getElementFromId(helpContainer);
1944 if(pIG)
1945 pIG->setActive(true);
1947 // browse the url
1948 CAHManager::getInstance()->runActionHandler("browse", NULL, "name="+helpContainer+":content:html|url="+url);
1951 REGISTER_ACTION_HANDLER( CAHLaunchHelp, "launch_help");
1953 // ***************************************************************************
1954 static bool findInterfacePath(string &sPath, CCtrlBase *pCaller)
1956 if (sPath.rfind(':') == string::npos)
1958 if (pCaller == NULL) return false;
1959 sPath = pCaller->getId() + ":" + sPath;
1961 else
1963 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1964 string elt = sPath.substr(0,sPath.rfind(':'));
1965 CInterfaceElement *pIE;
1966 if (pCaller != NULL)
1967 pIE = CWidgetManager::getInstance()->getElementFromId(pCaller->getId(), elt);
1968 else
1969 pIE = CWidgetManager::getInstance()->getElementFromId(elt);
1970 if (pIE == NULL) return false;
1971 sPath = pIE->getId() + ":" + sPath.substr(sPath.rfind(':')+1,sPath.size());
1973 return true;
1976 // ***************************************************************************
1977 // TARGET NAME AND TITLE MANAGEMENT
1978 // ***************************************************************************
1980 // Callbacks that check that while we are waiting for the string to display the
1981 // user has not changed its target
1983 // *** check for user selection and remove title
1984 class CSPPRemoveTitleAndCheckSelection : public CStringPostProcessRemoveTitle
1986 public:
1988 sint32 Slot;
1990 bool cbIDStringReceived(string &inout)
1992 if (UserEntity != NULL)
1994 if (UserEntity->selection() == Slot)
1996 string copyInout = inout;
1997 CStringPostProcessRemoveTitle::cbIDStringReceived(inout);
1998 if (inout.empty())
2000 CEntityCL *entity = EntitiesMngr.entity(Slot);
2001 CCharacterCL *pChar = dynamic_cast<CCharacterCL*>(entity);
2002 bool womanTitle = false;
2003 if (pChar != NULL)
2004 womanTitle = pChar->getGender() == GSGENDER::female;
2006 copyInout = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(CEntityCL::getTitleFromName(copyInout), womanTitle);
2008 // Sometimes translation contains another title
2009 string::size_type pos = copyInout.find('$');
2010 if (pos != string::npos)
2012 copyInout = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(CEntityCL::getTitleFromName(copyInout), womanTitle);
2015 CStringPostProcessRemoveTitle::cbIDStringReceived(copyInout);
2016 inout = copyInout;
2019 return true;
2023 return false;
2027 // *** check for user selection and remove name (keep title)
2028 class CSPPRemoveNameAndCheckSelection : public CStringPostProcessRemoveName
2030 public:
2032 sint32 Slot;
2034 bool cbIDStringReceived(string &inout)
2036 if (UserEntity != NULL)
2038 if (UserEntity->selection() == Slot)
2040 CEntityCL *entity = EntitiesMngr.entity(Slot);
2041 CCharacterCL *pChar = dynamic_cast<CCharacterCL*>(entity);
2042 if (pChar != NULL)
2044 const CCharacterSheet *pSheet = pChar->getSheet();
2045 if (pSheet != NULL)
2047 string sFame = pSheet->getFame();
2048 if (strnicmp(sFame.c_str(),"tribe_",6)==0)
2050 inout = STRING_MANAGER::CStringManagerClient::getFactionLocalizedName(sFame);
2051 return true; // return tribe name
2054 Woman = pChar->getGender() == GSGENDER::female;
2057 CStringPostProcessRemoveName::cbIDStringReceived(inout);
2059 return true; // return title
2062 return false;
2066 // *** called when target change or target name change
2067 class CActionHandlerSetTargetName : public IActionHandler
2069 virtual void execute (CCtrlBase *pCaller, const string &Params)
2071 string sSlot = getParam(Params,"slot");
2072 string sNameTarget = getParam(Params,"target");
2073 string sTitleTarget = getParam(Params,"title");
2075 if (sSlot.empty()) return;
2077 if (!findInterfacePath(sNameTarget, pCaller)) return;
2078 findInterfacePath(sTitleTarget, pCaller);
2080 CInterfaceExprValue evValue;
2081 if (CInterfaceExpr::eval(sSlot, evValue, NULL))
2083 sint32 nSlot = (sint32)evValue.getInteger();
2085 string TargetName;
2086 string TargetTitle;
2088 // Get from nSlot
2089 if (nSlot > -1)
2091 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2092 // uint32 nDBid = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString(nSlot)+":P6")->getValue32();
2093 uint32 nDBid = 0;
2094 if (nSlot < sint32(EntitiesMngr.entities().size()) && EntitiesMngr.entities()[nSlot] != NULL)
2096 nDBid = EntitiesMngr.entities()[nSlot]->getNameId();
2099 if (nDBid != 0)
2101 CSPPRemoveTitleAndCheckSelection *pSPPRT = new CSPPRemoveTitleAndCheckSelection;
2102 pSPPRT->Slot = nSlot;
2103 CSPPRemoveNameAndCheckSelection *pSPPRN = new CSPPRemoveNameAndCheckSelection;
2104 pSPPRN->Slot = nSlot;
2105 pIM->addServerID(sNameTarget, nDBid, pSPPRT);
2106 pIM->addServerID(sTitleTarget, nDBid, pSPPRN);
2108 else
2110 CEntityCL *pE = EntitiesMngr.entity(nSlot);
2111 if (pE != NULL)
2113 TargetName = pE->getDisplayName();
2114 TargetTitle = pE->getTitle();
2118 // Set to target
2119 CInterfaceExprValue evUCStr;
2120 TargetName = STRING_MANAGER::CStringManagerClient::getLocalizedName(TargetName);
2121 evUCStr.setString(TargetName);
2122 CInterfaceLink::setTargetProperty(sNameTarget, evUCStr);
2123 evUCStr.setString(TargetTitle);
2124 CInterfaceLink::setTargetProperty(sTitleTarget, evUCStr);
2128 REGISTER_ACTION_HANDLER (CActionHandlerSetTargetName, "set_target_name");
2130 // ***************************************************************************
2131 class CActionHandlerSetTargetForceRegionLevel: public IActionHandler
2133 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2135 string sSlot = getParam(Params,"slot");
2136 string sTargetRegion = getParam(Params,"targetRegion");
2137 string sTargetLevel = getParam(Params,"targetLevel");
2139 // Access UI elements
2140 if (sSlot.empty()) return;
2141 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2142 CViewBitmap *pVBR = dynamic_cast<CViewBitmap*>(CWidgetManager::getInstance()->getElementFromId(sTargetRegion));
2143 if (pVBR == NULL)
2144 return;
2145 CViewBitmap *pVBL = dynamic_cast<CViewBitmap*>(CWidgetManager::getInstance()->getElementFromId(sTargetLevel));
2146 if (pVBL == NULL)
2147 return;
2148 CInterfaceExprValue evValue;
2149 if (!CInterfaceExpr::eval(sSlot, evValue, NULL))
2150 return;
2151 sint32 nSlot = (sint32)evValue.getInteger();
2152 CCtrlBase *pTooltip = dynamic_cast<CCtrlBase*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:header_opened:force"));
2154 // Access target entity
2155 CEntityCL *pE = NULL;
2156 if ( (nSlot == -1) || ((pE = EntitiesMngr.entity(nSlot)) == NULL) )
2158 // If untargetted, clear
2159 pVBL->setTexture(string());
2160 pVBR->setColor(CRGBA(0,0,0,0));
2162 if (pTooltip)
2163 pTooltip->setDefaultContextHelp(std::string());
2165 return;
2168 sint nLevelForce;
2169 sint nForceRegion;
2170 if ( pE->isPlayer() )
2172 // Player => deduce RegionForce & ForceLevel from the database
2173 CCDBNodeLeaf *pDbTargetUid = NLGUI::CDBManager::getInstance()->getDbProp( CWidgetManager::getInstance()->getParser()->getDefine("target_uid") );
2174 if ( ! pDbTargetUid )
2175 return;
2176 // Hide the target level if the USER is not in PVP FACTION
2177 // Hide the target level if the TARGET is not in PVP FACTION
2178 // Also, hide it If the database is not in sync with the local target slot
2179 if (!UserEntity || !(UserEntity->getPvpMode()&PVP_MODE::PvpZoneFaction) ||
2180 !(pE->getPvpMode()&PVP_MODE::PvpZoneFaction) ||
2181 pE->dataSetId() != (CLFECOMMON::TClientDataSetIndex)pDbTargetUid->getValue32() )
2183 pVBL->setTexture(string());
2184 pVBR->setColor(CRGBA(0,0,0,0));
2186 if (pTooltip)
2187 pTooltip->setDefaultContextHelp(CI18N::get("uittTargetUnknown"));
2189 return;
2191 CCDBNodeLeaf *pDbPlayerLevel = NLGUI::CDBManager::getInstance()->getDbProp( CWidgetManager::getInstance()->getParser()->getDefine("target_player_level") );
2192 if ( ! pDbPlayerLevel )
2193 return;
2194 sint nLevel = pDbPlayerLevel->getValue32();
2195 if ( nLevel < 250 )
2197 nLevelForce = ((nLevel % 50) * 5 / 50) + 1;
2198 nForceRegion = (nLevel < 20) ? 1 : (nLevel / 50) + 2;
2200 else
2202 nLevelForce = 6; // same as named creatures
2203 nForceRegion = 8;
2206 else
2208 // Creature => RegionForce & ForceLevel are in its sheet
2209 CCharacterSheet *pCS = dynamic_cast<CCharacterSheet*>(SheetMngr.get(pE->sheetId()));
2210 if (pCS == NULL || pCS->RegionForce==-1)
2212 pVBL->setTexture(string());
2213 pVBR->setColor(CRGBA(0,0,0,0));
2215 if (pTooltip)
2216 pTooltip->setDefaultContextHelp(std::string());
2218 return;
2221 nForceRegion = pCS->RegionForce;
2222 nLevelForce = pCS->ForceLevel;
2225 // Set color
2226 if (nForceRegion > 6) nForceRegion = 6;
2227 if (nForceRegion < 1) nForceRegion = 1;
2228 CRGBA col = CInterfaceElement::convertColor(CWidgetManager::getInstance()->getParser()->getDefine("region_force_"+toString(nForceRegion)).c_str());
2229 pVBR->setColor(col);
2231 // Set texture
2232 if (nLevelForce > 8) nLevelForce = 8;
2233 if (nLevelForce < 1) nLevelForce = 1;
2234 string sTexture = CWidgetManager::getInstance()->getParser()->getDefine("force_level_"+toString(nLevelForce));
2235 pVBL->setTexture(sTexture);
2237 // Set tooltip
2238 CCtrlBase *tooltip = dynamic_cast<CCtrlBase*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:header_opened:force"));
2239 if (tooltip)
2241 string str;
2243 if (nForceRegion == 1)
2244 nForceRegion = 2;
2246 // Normal
2247 if (nLevelForce < 6)
2249 sint min = (nForceRegion-2) * 50 + (nLevelForce-1) * 10 + 1;
2250 sint max = (nForceRegion-2) * 50 + nLevelForce * 10;
2252 str= CI18N::get("uittTargetLevel");
2253 strFindReplace(str, "%min", toString(min));
2254 strFindReplace(str, "%max", toString(max));
2256 // Boss
2257 else if (nLevelForce == 8)
2259 sint n = (nForceRegion-1) * 50;
2260 if (pE->isNPC())
2261 str= CI18N::get("uittTargetGuardBoss");
2262 else
2263 str= CI18N::get("uittTargetBoss");
2264 strFindReplace(str, "%n", toString("%d", n) );
2266 // Named
2267 else
2269 sint n = (nForceRegion-1) * 50;
2270 str= CI18N::get("uittTargetNamed");
2271 strFindReplace(str, "%n", toString("%d", n) );
2274 tooltip->setDefaultContextHelp(str);
2278 REGISTER_ACTION_HANDLER (CActionHandlerSetTargetForceRegionLevel, "set_force_region_level");
2280 // ***************************************************************************
2281 class CAHUpdateCurrentMode : public IActionHandler
2283 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2285 string sValue = getParam(Params,"value");
2286 string sDBLink = getParam(Params,"dblink");
2287 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2288 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sDBLink, false);
2289 if (pNL == NULL) return;
2291 CInterfaceExprValue eVal;
2292 if (!CInterfaceExpr::eval(sValue, eVal, NULL)) return;
2294 sint32 nNewMode = (sint32)eVal.getInteger();
2296 sint32 nModeMinInf, nModeMaxInf, nModeMinLab, nModeMaxLab, nModeMinKey, nModeMaxKey;
2297 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_min_info"), nModeMinInf);
2298 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_max_info"), nModeMaxInf);
2299 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_min_lab"), nModeMinLab);
2300 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_max_lab"), nModeMaxLab);
2301 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_min_keys"), nModeMinKey);
2302 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_max_keys"), nModeMaxKey);
2304 sint32 nMode = 0;
2305 if ((nNewMode >= nModeMinInf) && (nNewMode <= nModeMaxInf))
2306 nMode = 1;
2307 if ((nNewMode >= nModeMinLab) && (nNewMode <= nModeMaxLab))
2308 nMode = 2;
2309 if ((nNewMode >= nModeMinKey) && (nNewMode <= nModeMaxKey))
2310 nMode = 3;
2313 if (nNewMode != 0)
2314 if (nNewMode == pNL->getValue32())
2316 // We have pushed 2 times the same button
2317 nNewMode ++;
2318 if (nMode == 1)
2320 if (nNewMode > nModeMaxInf) nNewMode = nModeMinInf;
2322 else if (nMode == 2)
2324 if (nNewMode > nModeMaxLab) nNewMode = nModeMinLab;
2326 else if (nMode == 3)
2328 if (nNewMode > nModeMaxKey) nNewMode = nModeMinKey;
2332 // Found the first active entry in db
2333 if (nMode == 2)
2335 bool bFound = false;
2336 while (!bFound)
2338 CCDBNodeLeaf *pIntFlags = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INTERFACES:FLAGS", false);
2339 if (pIntFlags == NULL) return;
2340 sint64 nIntFlags = pIntFlags->getValue64();
2342 sint32 tmpMode;
2344 // Is NewMode entry active ?
2345 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_magic"), tmpMode);
2346 if (nNewMode == tmpMode)
2347 if ((nIntFlags & (1<<INTERFACE_FLAGS::Magic)) != 0)
2348 bFound = true;
2350 if (!bFound)
2352 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_combat"), tmpMode);
2353 if (nNewMode == tmpMode)
2354 if ((nIntFlags & (1<<INTERFACE_FLAGS::Combat)) != 0)
2355 bFound = true;
2358 if (!bFound)
2360 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_faber_create"), tmpMode);
2361 if (nNewMode == tmpMode)
2362 if ((nIntFlags & (1<<INTERFACE_FLAGS::FaberCreate)) != 0)
2363 bFound = true;
2366 if (!bFound)
2368 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_faber_repair"), tmpMode);
2369 if (nNewMode == tmpMode)
2370 if ((nIntFlags & (1<<INTERFACE_FLAGS::FaberRepair)) != 0)
2371 bFound = true;
2374 if (!bFound)
2376 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_faber_refine"), tmpMode);
2377 if (nNewMode == tmpMode)
2378 if ((nIntFlags & (1<<INTERFACE_FLAGS::FaberRefine)) != 0)
2379 bFound = true;
2382 if (!bFound)
2384 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_commerce"), tmpMode);
2385 if (nNewMode == tmpMode)
2386 if ((nIntFlags & (1<<INTERFACE_FLAGS::Commerce)) != 0)
2387 bFound = true;
2390 if (!bFound)
2392 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_macros"), tmpMode);
2393 if (nNewMode == tmpMode)
2394 bFound = true; // Not in DB !!!
2397 if (!bFound)
2399 fromString(CWidgetManager::getInstance()->getParser()->getDefine("mode_special_labo"), tmpMode);
2400 if (nNewMode == tmpMode)
2401 if ((nIntFlags & (1<<INTERFACE_FLAGS::Special)) != 0)
2402 bFound = true;
2405 if (!bFound)
2407 nNewMode++;
2408 if (nNewMode > nModeMaxLab) nNewMode = nModeMinLab;
2409 if (nNewMode == pNL->getValue32()) return;
2414 pNL->setValue32(nNewMode);
2417 REGISTER_ACTION_HANDLER (CAHUpdateCurrentMode, "update_current_mode");
2419 // ***************************************************************************
2420 class CAHToggleChat : public IActionHandler
2422 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2424 ShowInterface = !ShowInterface;
2427 REGISTER_ACTION_HANDLER (CAHToggleChat, "toggle_chat");
2429 // ***************************************************************************
2430 class CAHToggleHelp : public IActionHandler
2432 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2434 #if FINAL_VERSION
2435 if( ClientCfg.Local || hasPrivilegeDEV() || hasPrivilegeSGM() || hasPrivilegeGM() )
2436 #endif
2438 ShowHelp = !ShowHelp;
2442 REGISTER_ACTION_HANDLER (CAHToggleHelp, "toggle_help");
2444 // ***************************************************************************
2445 class CAHSelfTarget : public IActionHandler
2447 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2449 // Select the entity
2450 UserEntity->selection(0);
2453 REGISTER_ACTION_HANDLER (CAHSelfTarget, "self_target");
2455 // ***************************************************************************
2456 class CAHNoTarget : public IActionHandler
2458 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2460 // Select the entity
2461 UserEntity->selection(CLFECOMMON::INVALID_SLOT);
2464 REGISTER_ACTION_HANDLER (CAHNoTarget, "no_target");
2466 // ***************************************************************************
2467 class CAHTarget : public IActionHandler
2469 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2471 string entityName = getParam(Params, "entity");
2472 if (entityName.empty()) return;
2474 string completeMatch = getParam(Params, "prefer_complete_match");
2475 bool quiet = (getParam (Params, "quiet") == "true");
2477 vector<string> keywords;
2478 NLMISC::splitString(entityName, " ", keywords);
2479 if (!keywords.empty() && keywords[0].size() > 0 && keywords[0][0] == '"')
2481 // entity name is in quotes, do old style match with 'starts with' filter
2482 // search for optional second parameter from old command for prefer_complete_match param
2483 keywords.clear();
2485 string::size_type lastOf = entityName.rfind("\"");
2486 if (lastOf == 0)
2487 lastOf = string::npos;
2489 // override the value only when there is no 'prefer_complete_match' parameter set
2490 if (completeMatch.empty() && lastOf < entityName.size())
2491 completeMatch = trim(entityName.substr(lastOf+1));
2493 entityName = entityName.substr(1, lastOf-1);
2496 // late check because only possible if doing 'starts-with' search
2497 bool preferCompleteMatch = (completeMatch != "0");
2499 CEntityCL *entity = NULL;
2500 if (preferCompleteMatch)
2502 // Try to get the entity with complete match first
2503 entity = EntitiesMngr.getEntityByName (entityName, false, true);
2506 if (entity == NULL && !keywords.empty())
2508 entity = EntitiesMngr.getEntityByKeywords(keywords, true);
2511 if (entity == NULL)
2513 // Get the entity with a partial match using 'starts with' search
2514 entity = EntitiesMngr.getEntityByName(entityName, false, false);
2517 if (entity == NULL)
2519 //Get the entity with a sheetName
2520 entity = EntitiesMngr.getEntityBySheetName(entityName);
2523 if (entity && entity->properties().selectable() && !entity->getDisplayName().empty())
2525 UserEntity->selection(entity->slot());
2526 if (ClientCfg.TargetChangeCompass)
2528 CGroupCompas *gc = dynamic_cast<CGroupCompas *>(CWidgetManager::getInstance()->getElementFromId("ui:interface:compass"));
2529 if (gc)
2531 CCompassTarget ct;
2532 ct.setType(CCompassTarget::Selection);
2534 gc->setActive(true);
2535 gc->setTarget(ct);
2536 gc->blink();
2537 CWidgetManager::getInstance()->setTopWindow(gc);
2541 else if (!quiet)
2543 CInterfaceManager::getInstance()->displaySystemInfo(CI18N::get("uiTargetErrorCmd"));
2547 REGISTER_ACTION_HANDLER (CAHTarget, "target");
2549 // ***************************************************************************
2550 class CAHTargetLandmark : public IActionHandler
2552 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2554 string search = getParam(Params, "search");
2555 if (search.empty()) return;
2557 bool startsWith = false;
2558 if (search.size() > 0 && (search[0] == '\'' || search[0] == '"') && search[0] == search[search.size()-1])
2560 startsWith = true;
2561 search = trimQuotes(search);
2564 const std::string mapid = "ui:interface:map:content:map_content:actual_map";
2565 CGroupMap* cgMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId(mapid));
2566 if (cgMap)
2568 if (!cgMap->targetLandmarkByName(search, startsWith))
2570 CInterfaceManager::getInstance()->displaySystemInfo(CI18N::get("uiTargetErrorCmd"));
2575 REGISTER_ACTION_HANDLER (CAHTargetLandmark, "target_landmark");
2578 class CAHAddShape : public IActionHandler
2580 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2582 string sShape = getParam(Params, "shape");
2584 if (sShape.empty())
2586 nlwarning("Command 'add_shape': need at least the parameter shape.");
2587 return;
2590 if (!Scene)
2592 nlwarning("No scene available");
2593 return;
2596 if (!UserEntity)
2598 nlwarning("UserEntity not yet defined, possibly called runAH from Lua");
2599 return;
2602 double x = UserEntity->pos().x;
2603 double y = UserEntity->pos().y;
2604 double z = UserEntity->pos().z;
2605 CVector userDir = UserEntity->dir();
2606 float s = 1.0f;
2607 string skeleton = getParam(Params, "skeleton");
2608 string c = getParam(Params, "text");
2609 string u = getParam(Params, "url");
2610 string texture_name = getParam(Params, "texture");
2611 string highlight = getParam(Params, "highlight");
2612 string transparency = getParam(Params, "transparency");
2614 if (!getParam(Params, "x").empty())
2615 fromString(getParam(Params, "x"), x);
2616 if (!getParam(Params, "y").empty())
2617 fromString(getParam(Params, "y"), y);
2618 if (!getParam(Params, "z").empty())
2619 fromString(getParam(Params, "z"), z);
2620 if (!getParam(Params, "scale").empty())
2621 fromString(getParam(Params, "scale"), s);
2622 if (!getParam(Params, "angle").empty())
2624 float a;
2625 fromString(getParam(Params, "angle"), a);
2626 userDir = CVector(sin(a), cos(a), 0.f);
2629 bool have_shapes = true;
2630 while(have_shapes)
2632 string shape;
2633 string::size_type index = sShape.find(string(" "));
2634 // multiple shapes/fx
2635 if (index != string::npos)
2637 shape = sShape.substr(0, index);
2638 sShape = sShape.substr(index+1);
2640 else
2642 shape = sShape;
2643 have_shapes = false;
2646 sint32 idx;
2647 CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector((float)x, (float)y, (float)z), c, u, false, 0, idx);
2648 UInstance instance = instref.Instance;
2650 if(!instance.empty())
2652 for(uint j=0;j<instance.getNumMaterials();j++)
2654 if (highlight.empty())
2656 instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
2657 instance.getMaterial(j).setShininess( 10.0f );
2658 instance.getMaterial(j).setEmissive(CRGBA(255,255,255,255));
2660 else
2662 instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
2663 instance.getMaterial(j).setEmissive(CRGBA(255,0,0,255));
2664 instance.getMaterial(j).setShininess( 1000.0f );
2667 if (!texture_name.empty())
2669 sint numStages = instance.getMaterial(j).getLastTextureStage() + 1;
2670 for(sint l = 0; l < numStages; l++)
2672 if (instance.getMaterial(j).isTextureFile((uint) l))
2674 instance.getMaterial(j).setTextureFileName(texture_name, (uint) l);
2680 if (transparency.empty())
2681 ::makeInstanceTransparent(instance, 255, false);
2682 else
2683 ::makeInstanceTransparent(instance, 100, true);
2685 instance.setClusterSystem(UserEntity->getClusterSystem()); // for simplicity, assume it is in the same
2686 // cluster system than the user
2687 // Compute the direction Matrix
2688 CMatrix dir;
2689 dir.identity();
2690 CVector vi = userDir^CVector(0.f, 0.f, 1.f);
2691 CVector vk = vi^userDir;
2692 dir.setRot(vi, userDir, vk, true);
2693 // Set Orientation : User Direction should be normalized.
2694 if (!skeleton.empty())
2696 USkeleton skel = Scene->createSkeleton(skeleton);
2697 if (!skel.empty())
2699 skel.bindSkin(instance);
2700 skel.setClusterSystem(UserEntity->getClusterSystem());
2701 skel.setScale(skel.getScale()*s);
2702 skel.setPos(CVector((float)x, (float)y, (float)z));
2703 skel.setRotQuat(dir.getRot());
2706 else
2708 instance.setScale(instance.getScale()*s);
2709 instance.setPos(CVector((float)x, (float)y, (float)z));
2710 instance.setRotQuat(dir.getRot());
2713 instance.setTransformMode(UTransformable::RotEuler);
2715 // if the shape is a particle system, additionnal parameters are user params
2716 UParticleSystemInstance psi;
2717 psi.cast (instance);
2718 /*if (!psi.empty())
2720 // set each user param that is present
2721 for(uint k = 0; k < 4; ++k)
2723 if (args.size() >= (k + 2))
2725 float uparam;
2726 if (fromString(args[k + 1], uparam))
2728 psi.setUserParam(k, uparam);
2730 else
2732 nlwarning("Cant read param %d", k);
2738 else
2739 nlwarning("Command 'add_shape': cannot find the shape %s.", sShape.c_str());
2742 return;
2745 REGISTER_ACTION_HANDLER (CAHAddShape, "add_shape");
2747 class CAHRemoveShapes : public IActionHandler
2749 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2751 EntitiesMngr.removeInstances();
2754 REGISTER_ACTION_HANDLER (CAHRemoveShapes, "remove_shapes");
2756 // ***************************************************************************
2757 // See also CHandlerTeamTarget
2758 class CAHTargetTeammateShortcut : public IActionHandler
2760 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2762 // Get shortcut parameter
2763 uint indexInTeam;
2764 fromString(getParam( Params, "indexInTeam" ), indexInTeam);
2765 --indexInTeam;
2767 if ( indexInTeam >= PeopleInterraction.TeamList.getNumPeople() )
2768 return;
2770 // Index is the database index (serverIndex() not used for team list)
2771 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp( NLMISC::toString( TEAM_DB_PATH ":%hu:NAME", indexInTeam ), false );
2772 if ( ! pNL )
2773 return;
2774 if ( pNL->getValueBool() )
2776 // There is a character corresponding to this index
2777 pNL = NLGUI::CDBManager::getInstance()->getDbProp( NLMISC::toString( TEAM_DB_PATH ":%hu:UID", indexInTeam ), false );
2778 if ( ! pNL )
2779 return;
2780 CLFECOMMON::TClientDataSetIndex compressedIndex = pNL->getValue32();
2782 // Search entity in vision
2783 CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex( compressedIndex );
2784 if ( entity )
2786 UserEntity->selection( entity->slot() );
2788 else
2790 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2791 pIM->displaySystemInfo(CI18N::get("uiTeamSelectNotInVision"), "CHK");
2796 REGISTER_ACTION_HANDLER(CAHTargetTeammateShortcut, "target_teammate_shortcut");
2798 // ***************************************************************************
2799 class CAHAssist : public IActionHandler
2801 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2803 // Get the entity name to target
2804 string entityName = getParam (Params, "entity");
2805 if (!entityName.empty())
2807 // Get the entity
2808 CEntityCL *entity = EntitiesMngr.getEntityByName (entityName, false, false);
2809 if (entity)
2811 // Select the entity
2812 UserEntity->assist(entity->slot());
2814 else
2816 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2817 pIM->displaySystemInfo(CI18N::get("uiTargetErrorCmd"));
2822 REGISTER_ACTION_HANDLER (CAHAssist, "assist");
2824 // ***************************************************************************
2825 class CAHAssistTarget : public IActionHandler
2827 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2829 // Select the entity
2830 UserEntity->assist();
2833 REGISTER_ACTION_HANDLER (CAHAssistTarget, "assist_target");
2835 // ***************************************************************************
2836 class CAHToggleCombat : public IActionHandler
2838 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
2840 // Toggle from Combat to Disengage
2841 if(UserEntity->isFighting())
2842 UserEntity->disengage();
2843 // Toggle from Normal to Combat
2844 else
2846 if( UserEntity->canEngageCombat() )
2848 UserEntity->attack();
2854 REGISTER_ACTION_HANDLER (CAHToggleCombat, "toggle_combat");
2856 // ***************************************************************************
2857 class CAHSetDesktop : public IActionHandler
2859 public:
2860 CAHSetDesktop()
2862 _FirstTime = true;
2865 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2867 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2868 CGroupContainer *pGC = dynamic_cast<CGroupContainer*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:gestion_windows"));
2869 if (pGC == NULL)
2871 nlwarning("gestion_windows not found as a container");
2872 return;
2874 CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId("ui:interface:gestion_windows:close");
2875 if (pIE != NULL) pIE->setActive(false);
2877 bool switchDesktop = false;
2879 CActionsManager *pAM = &Actions;
2880 if (!pAM->valide(CAction::CName("set_desktop",Params.c_str())))
2882 pGC->setActive(false);
2883 _FirstTime = true;
2884 switchDesktop = true;
2886 else // Key is down
2888 // For the first time ?
2889 if (_FirstTime)
2891 _FirstTime = false;
2892 switchDesktop = true;
2894 else // Not the first time
2896 // Show the container
2897 pGC->setActive(true);
2898 // Yoyo: important to setTopWindow ONLY if needed, else save of the TopWindow doesn't work when you switch it.
2899 CWidgetManager::getInstance()->setTopWindow(pGC);
2902 if (switchDesktop)
2904 vector<string> vecStr;
2905 vecStr.push_back("tb_setdesktop");
2906 vecStr.push_back(Params);
2907 CWidgetManager::getInstance()->runProcedure("tb_setdesktop", NULL, vecStr);
2910 private:
2911 bool _FirstTime;
2913 REGISTER_ACTION_HANDLER (CAHSetDesktop, "set_desktop");
2915 // ***************************************************************************
2916 class CAHCopyToDesktop : public IActionHandler
2918 public:
2920 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2922 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2923 uint8 newMode;
2924 fromString(Params, newMode);
2925 pIM->resetMode(newMode);
2926 uint8 nLastMode = pIM->getMode();
2927 pIM->setMode(newMode);
2928 pIM->setMode(nLastMode);
2931 REGISTER_ACTION_HANDLER (CAHCopyToDesktop, "copy_to_desktop");
2934 // ***************************************************************************
2935 class CHandlerCloseAllLabosBut : public IActionHandler
2937 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
2939 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2941 // list of labo windows
2942 const char* laboWindows[]= {
2943 "ui:interface:faber_create",
2944 "ui:interface:faber_repair",
2945 "ui:interface:faber_refine",
2946 "ui:interface:combat",
2947 "ui:interface:magic",
2948 "ui:interface:special_labo",
2949 "ui:interface:commerce",
2950 "ui:interface:tracking",
2952 uint numLabos= sizeof(laboWindows)/sizeof(laboWindows[0]);
2954 // For all labos
2955 for(uint i=0;i<numLabos;i++)
2957 // if not the excluded one
2958 if( Params != laboWindows[i] )
2960 CInterfaceElement *pElt= CWidgetManager::getInstance()->getElementFromId(laboWindows[i]);
2961 if(pElt)
2962 pElt->setActive(false);
2967 REGISTER_ACTION_HANDLER (CHandlerCloseAllLabosBut, "close_all_labos_but");
2970 // ***************************************************************************
2971 class CHandlerToggleInventory : public IActionHandler
2973 virtual void execute (CCtrlBase *pCaller, const string &Params)
2975 CInterfaceManager *pIM= CInterfaceManager::getInstance();
2977 // list of labo windows
2978 const char* inventoryWindows[]= {
2979 "ui:interface:gestionsets",
2980 "ui:interface:userbags",
2981 "ui:interface:usermoney",
2982 "ui:interface:userarmors",
2983 "ui:interface:userjewelry",
2985 uint numWins= sizeof(inventoryWindows)/sizeof(inventoryWindows[0]);
2987 // For all labos
2988 bool state = false;
2989 CInterfaceElement *pElt= CWidgetManager::getInstance()->getElementFromId(inventoryWindows[0]);
2990 if (pElt)
2991 state = !pElt->getActive();
2992 for(uint i=0;i<numWins;i++)
2994 pElt= CWidgetManager::getInstance()->getElementFromId(inventoryWindows[i]);
2995 if(pElt)
2996 pElt->setActive(state);
3000 REGISTER_ACTION_HANDLER (CHandlerToggleInventory, "toggle_inventory");
3002 // ***************************************************************************
3003 // ***************************************************************************
3004 // GAME CONFIG
3005 // ***************************************************************************
3006 // ***************************************************************************
3008 #define GAME_CONFIG_DDX "ui:interface:game_config:content:all"
3009 #define GAME_CONFIG_TREE_LIST "ui:interface:game_config:content:sbtree:tree_list"
3011 static vector<UDriver::CMode> VideoModes;
3012 #define GAME_CONFIG_VIDEO_MODES_COMBO "ui:interface:game_config:content:general:video_modes"
3013 #define GAME_CONFIG_VIDEO_FREQS_COMBO "ui:interface:game_config:content:general:video_freqs"
3014 #define GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON "ui:interface:game_config:content:general:fullscreen:c"
3015 #define GAME_CONFIG_VIDEO_MODE_DB "UI:TEMP:VID_MODE"
3016 #define GAME_CONFIG_VIDEO_FREQ_DB "UI:TEMP:VID_FREQ"
3017 #define GAME_CONFIG_LANGUAGE "UI:TEMP:LANGUAGE"
3018 // We allow only this RGB depth to be taken
3019 #define GAME_CONFIG_VIDEO_DEPTH_REQ 32
3021 // VR_CONFIG
3022 #define GAME_CONFIG_VR_ENABLE_BUTTON "ui:interface:game_config:content:vr:enabler:c"
3023 #define GAME_CONFIG_VR_DEVICES_COMBO "ui:interface:game_config:content:vr:vr_devices"
3024 #define GAME_CONFIG_VR_DEVICE_DB "UI:TEMP:VR_DEVICE"
3026 // The combo for Texture Mode selected
3027 #define GAME_CONFIG_TEXTURE_MODE_COMBO "ui:interface:game_config:content:general:texture_mode:combo"
3028 #define GAME_CONFIG_TEXTURE_MODE_DB "UI:TEMP:TEXTURE_MODE"
3030 // Anisotropic Filtering controls
3031 #define GAME_CONFIG_ANISOTROPIC_COMBO "ui:interface:game_config:content:fx:anisotropic_gr:anisotropic"
3032 #define GAME_CONFIG_ANISOTROPIC_DB "UI:TEMP:ANISOTROPIC"
3034 // The 3 possible modes editable (NB: do not allow client.cfg HDEntityTexture==1 and DivideTextureSizeBy2=2
3035 enum TTextureMode {LowTextureMode= 0, NormalTextureMode= 1, HighTextureMode= 2};
3037 void cacheStereoDisplayDevices(); // from init.cpp
3039 void updateVRDevicesComboUI(bool enable)
3041 // VR_CONFIG
3042 nldebug("Init VR device name list from cache into UI");
3043 // init vr device name list from cache
3044 CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_DEVICES_COMBO));
3045 if (pCB)
3047 pCB->setActive(enable);
3048 if (enable)
3050 nldebug("pCB ok");
3051 cacheStereoDisplayDevices();
3052 pCB->resetTexts();
3053 sint32 selectedDevice = -1;
3054 for (uint i = 0; i < VRDeviceCache.size(); ++i)
3056 std::stringstream displayname;
3057 displayname << std::string("[") << VRDeviceCache[i].first << "] [" << VRDeviceCache[i].second << "]";
3058 pCB->addText(displayname.str());
3059 if (ClientCfg.VRDisplayDevice == VRDeviceCache[i].first)
3061 if (selectedDevice == -1 || ClientCfg.VRDisplayDeviceId == VRDeviceCache[i].second)
3063 selectedDevice = i;
3067 if (selectedDevice == -1)
3069 // configured device not found, add a dummy
3070 std::stringstream displayname;
3071 displayname << std::string("[") << ClientCfg.VRDisplayDevice << "] [" << ClientCfg.VRDisplayDeviceId<< "] [DEVICE NOT FOUND]";
3072 pCB->addText(displayname.str());
3073 selectedDevice = VRDeviceCache.size();
3075 NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->setValue32(-1);
3076 NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->setValue32(selectedDevice);
3081 // ***************************************************************************
3082 class CHandlerGameConfigInit : public IActionHandler
3084 public:
3085 // Value used to restore the screen AR in case of a cancel
3086 static float BkupScreenAspectRatio;
3088 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3090 if (Driver == NULL) return;
3092 VideoModes.clear();
3093 vector<string> stringModeList, stringFreqList;
3094 sint nFoundMode, nFoundFreq;
3096 getRyzomModes(VideoModes, stringModeList, stringFreqList, nFoundMode, nFoundFreq);
3098 // Initialize interface combo box
3099 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3101 // resolutions
3102 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3103 if( pCB )
3105 pCB->resetTexts();
3106 for (sint j = 0; j < (sint)stringModeList.size(); j++)
3107 pCB->addText(stringModeList[j]);
3110 // frequencies
3111 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3112 if( pCB )
3114 pCB->resetTexts();
3115 for (sint j = 0; j < (sint)stringFreqList.size(); j++)
3116 pCB->addText(stringFreqList[j]);
3119 // -1 is important to indicate we set this value in edit mode
3120 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->setValue32(-1);
3121 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->setValue32(nFoundMode);
3123 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(-1);
3124 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(nFoundFreq);
3126 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON ));
3127 if (pBut)
3129 pBut->setPushed(!ClientCfg.Windowed);
3131 CAHManager::getInstance()->runActionHandler("game_config_change_vid_fullscreen",NULL);
3133 // **** Init Texture Size Modes
3134 // init the combo box, according to Texture Installed or not
3135 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_TEXTURE_MODE_COMBO ));
3136 if( pCB )
3138 pCB->resetTexts();
3139 pCB->addText(CI18N::get("uigcLowTextureMode"));
3140 pCB->addText(CI18N::get("uigcNormalTextureMode"));
3141 if(ClientCfg.HDTextureInstalled)
3142 pCB->addText(CI18N::get("uigcHighTextureMode"));
3145 // Anisotropic Filtering
3146 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_ANISOTROPIC_COMBO));
3148 sint nAnisotropic = 0;
3150 if (pCB)
3152 sint maxAnisotropic = (sint)Driver->getAnisotropicFilterMaximum();
3154 pCB->resetTexts();
3155 pCB->addText(CI18N::get("uigcFxAnisotropicFilterNone"));
3157 sint anisotropic = 2;
3158 uint i = 1;
3160 while (anisotropic <= maxAnisotropic)
3162 pCB->addText(NLMISC::toString("%dx", anisotropic));
3164 if (ClientCfg.AnisotropicFilter == anisotropic)
3165 nAnisotropic = i;
3167 anisotropic <<= 1;
3168 ++i;
3172 // -1 is important to indicate we set this value in edit mode
3173 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_ANISOTROPIC_DB )->setValue32(-1);
3174 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_ANISOTROPIC_DB )->setValue32(nAnisotropic);
3176 // VR_CONFIG
3177 pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_ENABLE_BUTTON));
3178 if (pBut)
3180 pBut->setPushed(ClientCfg.VREnable);
3183 updateVRDevicesComboUI(ClientCfg.VREnable);
3185 // init the mode in DB
3186 TTextureMode texMode;
3187 if(ClientCfg.DivideTextureSizeBy2)
3188 texMode= LowTextureMode;
3189 else if(ClientCfg.HDEntityTexture && ClientCfg.HDTextureInstalled)
3190 texMode= HighTextureMode;
3191 else
3192 texMode= NormalTextureMode;
3194 // -1 is important to indicate we set this value in edit mode
3195 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->setValue32(-1);
3196 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->setValue32(texMode);
3198 // **** Init Screen Aspect Ratio
3199 // Init the combo box, according to the value
3200 pCB= dynamic_cast<CDBGroupComboBox*>( CWidgetManager::getInstance()->getElementFromDefine( "game_config_screen_ratio_cb" ));
3201 if(pCB)
3203 // Bkup for cancel
3204 BkupScreenAspectRatio= ClientCfg.ScreenAspectRatio;
3206 // -1 is here to force var change
3207 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(-1);
3209 // detect with an epsilon to avoid float precision problems
3210 if(fabs(ClientCfg.ScreenAspectRatio - 1.33333f)<=0.00001f)
3211 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(0); // 4/3
3212 else if(fabs(ClientCfg.ScreenAspectRatio - 1.77777f)<=0.00001f)
3213 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(1); // 16/9
3214 else if(ClientCfg.ScreenAspectRatio == 0.f)
3215 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(3); // Auto
3216 else
3217 NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:SCREEN_RATIO_MODE" )->setValue32(2); // Custom
3220 // **** Init Language : look in game_config.lua
3222 // display or not VR page
3223 NLGUI::CGroupTree* configTree = dynamic_cast<CGroupTree*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_TREE_LIST));
3225 if (configTree)
3227 CGroupTree::SNode *rootNode = configTree->getRootNode();
3229 if (rootNode)
3231 CGroupTree::SNode *graphNode = rootNode->getNodeFromId("graph");
3233 if (graphNode)
3235 CGroupTree::SNode *vrNode = graphNode->getNodeFromId("vr");
3237 if (vrNode)
3239 vrNode->setShow(isStereoAvailable());
3246 REGISTER_ACTION_HANDLER (CHandlerGameConfigInit, "game_config_init");
3247 float CHandlerGameConfigInit::BkupScreenAspectRatio= 1.3333f;
3250 // ***************************************************************************
3251 class CHandlerGameConfigMode : public IActionHandler
3253 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3255 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3257 sint oldVideoMode= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->getOldValue32();
3258 sint nVideModeNb = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->getValue32();
3259 if (nVideModeNb == -1 || oldVideoMode == -1) return;
3261 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3262 if( pCB == NULL ) return;
3264 // Get W, H
3265 sint w,h;
3267 string vidModeStr = pCB->getText(nVideModeNb);
3268 string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1);
3269 fromString(tmp, w);
3270 tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size());
3271 fromString(tmp, h);
3274 // Filter VideoModes list to get freqs
3275 vector<string> stringFreqList;
3276 sint i, j, nFoundFreq = -1;
3277 for (i=0; i < (sint)VideoModes.size(); ++i)
3279 if ((VideoModes[i].Width == w) && (VideoModes[i].Height == h) && (VideoModes[i].Depth == GAME_CONFIG_VIDEO_DEPTH_REQ))
3281 bool bFound = false;
3282 string tmp = toString(VideoModes[i].Frequency);
3283 for (j = 0; j < (sint)stringFreqList.size(); ++j)
3285 if (stringFreqList[j] == tmp)
3287 bFound = true;
3288 break;
3292 if (!bFound)
3294 stringFreqList.push_back(tmp);
3295 if (ClientCfg.Frequency == VideoModes[i].Frequency)
3296 nFoundFreq = j;
3300 if (nFoundFreq == -1) nFoundFreq = 0;
3301 // Initialize interface combo box
3302 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3303 if( pCB )
3305 pCB->resetTexts();
3306 for (j = 0; j < (sint)stringFreqList.size(); j++)
3307 pCB->addText(stringFreqList[j] + " Hz");
3309 NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(nFoundFreq);
3311 // **** dirt the apply button of the DDX
3312 // don't do it at init!
3313 if(oldVideoMode!=-1 && nVideModeNb!=-1)
3315 CDDXManager *pDM = CDDXManager::getInstance();
3316 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3317 if(pDDX)
3318 pDDX->validateApplyButton();
3322 REGISTER_ACTION_HANDLER (CHandlerGameConfigMode, "game_config_change_vid_mode");
3324 // ***************************************************************************
3325 class CHandlerGameConfigLanguage : public IActionHandler
3327 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3329 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3331 sint old = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_LANGUAGE )->getOldValue32();
3332 sint newOne = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_LANGUAGE )->getValue32();
3333 if ((old != -1) && (newOne != -1))
3335 // Set the new language
3336 //string newVal = (newOne==2)?"de":(newOne==1)?"fr":"en";
3337 string newVal = convertLanguageIntToLanguageCode(newOne);
3338 if (ClientCfg.LanguageCode != newVal)
3340 CDDXManager *pDM = CDDXManager::getInstance();
3341 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3342 if(pDDX)
3343 pDDX->validateApplyButton();
3348 REGISTER_ACTION_HANDLER (CHandlerGameConfigLanguage, "game_config_change_language");
3350 // ***************************************************************************
3351 class CHandlerGameConfigFreq : public IActionHandler
3353 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3355 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3356 sint oldFreq= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->getOldValue32();
3357 sint newFreq= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->getValue32();
3359 // dirt the apply button of the DDX.
3360 // don't do it at init!
3361 if(oldFreq!=-1 && newFreq!=-1)
3363 CDDXManager *pDM = CDDXManager::getInstance();
3364 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3365 if(pDDX)
3366 pDDX->validateApplyButton();
3370 REGISTER_ACTION_HANDLER (CHandlerGameConfigFreq, "game_config_change_vid_freq");
3372 // ***************************************************************************
3373 class CHandlerGameConfigTextureMode : public IActionHandler
3375 public:
3376 virtual void execute(CCtrlBase * /* pCalller */, const string &/* Params */)
3378 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3379 sint oldTMode= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->getOldValue32();
3380 sint newTMode= NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->getValue32();
3382 // dirt the apply button of the DDX
3383 // don't do it at init!
3384 if(oldTMode!=-1 && newTMode!=-1)
3386 CDDXManager *pDM = CDDXManager::getInstance();
3387 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3388 if(pDDX)
3389 pDDX->validateApplyButton();
3393 REGISTER_ACTION_HANDLER (CHandlerGameConfigTextureMode, "game_config_change_texture_mode");
3395 // ***************************************************************************
3396 class CHandlerGameConfigFullscreen : public IActionHandler
3398 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
3400 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3401 bool bFullscreen = false;
3403 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON ));
3404 if (pBut) bFullscreen = pBut->getPushed();
3406 CDBGroupComboBox *pCB;
3407 if (bFullscreen)
3409 // show modes combo
3410 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3411 if (pCB) pCB->setActive(true);
3413 // show frequencies combo
3414 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3415 if (pCB) pCB->setActive(true);
3417 else
3419 // hide modes combo
3420 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3421 if (pCB) pCB->setActive(false);
3423 // hide frequencies combo
3424 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3425 if (pCB) pCB->setActive(false);
3428 // **** dirt the apply button of the DDX
3429 // if caller is NULL, come from init, so don't validate the apply button
3430 if(pCaller)
3432 CDDXManager *pDM = CDDXManager::getInstance();
3433 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3434 if(pDDX)
3435 pDDX->validateApplyButton();
3439 REGISTER_ACTION_HANDLER (CHandlerGameConfigFullscreen, "game_config_change_vid_fullscreen");
3441 // ***************************************************************************
3442 class CHandlerGameConfigVREnable : public IActionHandler
3444 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
3446 // VR_CONFIG
3448 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_ENABLE_BUTTON));
3449 if (pBut)
3451 // hide or show device list depending on enabled or not
3452 updateVRDevicesComboUI(pBut->getPushed());
3455 if (pCaller)
3457 CDDXManager *pDM = CDDXManager::getInstance();
3458 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3459 if(pDDX)
3460 pDDX->validateApplyButton();
3464 REGISTER_ACTION_HANDLER (CHandlerGameConfigVREnable, "game_config_change_vr_enable");
3466 // ***************************************************************************
3467 class CHandlerGameConfigVRDevice : public IActionHandler
3469 virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
3471 // VR_CONFIG
3473 sint oldDevice = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->getOldValue32();
3474 sint newDevice = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->getValue32();
3476 if (oldDevice != -1 && newDevice != -1 && pCaller)
3478 // nldebug("TODO_VR switch vr device (from combo box)");
3480 CDDXManager *pDM = CDDXManager::getInstance();
3481 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3482 if(pDDX)
3483 pDDX->validateApplyButton();
3487 REGISTER_ACTION_HANDLER (CHandlerGameConfigVRDevice, "game_config_change_vr_device");
3489 // ***************************************************************************
3490 class CHandlerGameConfigApply : public IActionHandler
3492 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3494 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3496 // **** Apply the video mode
3497 sint nVideModeNb = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_MODE_DB )->getValue32();
3498 if (nVideModeNb != -1)
3500 sint nVideoFreqNb = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->getValue32();
3501 if (nVideoFreqNb != -1)
3503 // Get W, H
3504 sint w = 1024, h = 768;
3505 string name;
3507 CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
3508 if( pCB != NULL )
3510 string vidModeStr = pCB->getText(nVideModeNb);
3511 string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1);
3512 fromString(tmp, w);
3513 tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size());
3514 fromString(tmp, h);
3516 // extract monitor "1024x768 (VGA-1)"
3517 string::size_type pos = vidModeStr.find('(');
3518 if (pos != std::string::npos)
3519 name = vidModeStr.substr(pos + 1, vidModeStr.find(")") - pos - 1);
3523 // Get Frequency
3524 sint freq = 60;
3526 CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
3527 if( pCB != NULL )
3529 string vidFreqStr = pCB->getText(nVideoFreqNb);
3530 fromString(vidFreqStr, freq);
3534 // Get Fullscreen
3535 bool bFullscreen = false;
3537 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FULLSCREEN_BUTTON ));
3538 if (pBut != NULL)
3539 bFullscreen = pBut->getPushed();
3542 ClientCfg.Windowed = !bFullscreen;
3544 UDriver::CMode screenMode;
3545 Driver->getCurrentScreenMode(screenMode);
3547 if (bFullscreen)
3549 ClientCfg.Depth = screenMode.Depth;
3550 ClientCfg.Frequency = freq;
3552 else
3554 uint32 width, height;
3555 Driver->getWindowSize(width, height);
3556 w = width;
3557 h = height;
3560 ClientCfg.Width = w;
3561 ClientCfg.Height = h;
3562 ClientCfg.MonitorName = name;
3564 // Write the modified client.cfg
3565 ClientCfg.writeBool("FullScreen", bFullscreen);
3566 ClientCfg.writeInt("Width", w);
3567 ClientCfg.writeInt("Height", h);
3569 if (bFullscreen)
3571 ClientCfg.writeString("MonitorName", name, true);
3572 ClientCfg.writeInt("Depth", screenMode.Depth);
3573 ClientCfg.writeInt("Frequency", freq);
3578 // save user created channels options
3579 CCtrlBaseButton *pCS = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromDefine("game_config_save_channel_cb"));
3580 if (pCS)
3581 NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:SAVE_CHANNEL")->setValue32(pCS->getPushed());
3583 pCS = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromDefine("game_config_auto_channel_cb"));
3584 if (pCS)
3585 NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:AUTO_CHANNEL")->setValue32(pCS->getPushed());
3587 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(GAME_CONFIG_VR_ENABLE_BUTTON));
3588 if (pBut)
3590 // store the new config variables
3591 ClientCfg.VREnable = pBut->getPushed();
3592 ClientCfg.writeBool("VREnable", pBut->getPushed());
3594 if (ClientCfg.VREnable)
3596 // store the new config variables
3597 sint deviceIdx = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->getValue32();
3598 ClientCfg.VRDisplayDevice = VRDeviceCache[deviceIdx].first;
3599 ClientCfg.VRDisplayDeviceId = VRDeviceCache[deviceIdx].second;
3600 ClientCfg.writeString("VRDisplayDevice", VRDeviceCache[deviceIdx].first);
3601 ClientCfg.writeString("VRDisplayDeviceId", VRDeviceCache[deviceIdx].second);
3604 bool requestReboot = false;
3606 // **** Apply the texture mode
3607 sint nTexMode = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_TEXTURE_MODE_DB )->getValue32();
3608 if (nTexMode>=0 && nTexMode<=HighTextureMode)
3610 if ((ClientCfg.DivideTextureSizeBy2 != (nTexMode==LowTextureMode)) ||
3611 (ClientCfg.HDEntityTexture != (nTexMode==HighTextureMode)))
3613 ClientCfg.DivideTextureSizeBy2= nTexMode==LowTextureMode;
3614 ClientCfg.HDEntityTexture= nTexMode==HighTextureMode;
3615 ClientCfg.writeInt("DivideTextureSizeBy2", ClientCfg.DivideTextureSizeBy2);
3616 ClientCfg.writeInt("HDEntityTexture", ClientCfg.HDEntityTexture);
3617 requestReboot = true;
3621 // **** Apply Anisotropic Filtering
3622 // read value from DB, it's a combo so value is the index of text
3623 sint nAnisotropic = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_ANISOTROPIC_DB )->getValue32();
3625 if (nAnisotropic >= 0)
3627 sint anisotropic = 0;
3629 // compute the real anisotropic value
3630 if (nAnisotropic > 0)
3632 anisotropic = 2;
3634 for(sint i = 1; i < nAnisotropic; ++i)
3636 anisotropic <<= 1;
3640 if (ClientCfg.AnisotropicFilter != anisotropic)
3642 ClientCfg.AnisotropicFilter = anisotropic;
3643 ClientCfg.writeInt("AnisotropicFilter", ClientCfg.AnisotropicFilter);
3644 requestReboot = true;
3648 // *** Apply the Screen AR
3649 // since already set in the config file, need only to bkup the current version
3650 CHandlerGameConfigInit::BkupScreenAspectRatio= ClientCfg.ScreenAspectRatio;
3652 // *** Apply the language code
3653 // only if not in "work" language mode (else strange requestReboot)
3654 if (ClientCfg.LanguageCode!="wk")
3656 sint newOne = NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_LANGUAGE )->getValue32();
3657 //string newVal = (newOne==2)?"de":(newOne==1)?"fr":"en";
3658 string newVal = convertLanguageIntToLanguageCode(newOne);
3659 if (ClientCfg.LanguageCode != newVal)
3661 ClientCfg.LanguageCode = newVal;
3662 ClientCfg.writeString("LanguageCode", ClientCfg.LanguageCode);
3663 requestReboot = true;
3667 // Apply the NPC icon display mode
3668 CNPCIconCache::getInstance().setEnabled(!ClientCfg.R2EDEnabled && NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:INSCENE:FRIEND:MISSION_ICON")->getValueBool());
3670 // Request a reboot
3671 if (requestReboot)
3672 pIM->messageBox (CI18N::get ("uigcRequestReboot"));
3674 // **** Save the config
3675 if (ClientCfg.SaveConfig)
3676 ClientCfg.ConfigFile.save ();
3677 ClientCfg.IsInvalidated = true;
3680 REGISTER_ACTION_HANDLER (CHandlerGameConfigApply, "game_config_apply");
3683 // ***************************************************************************
3684 class CHandlerGameConfigCancel: public IActionHandler
3686 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3688 // Has something special to do only with screen aspect ratio:
3689 // - Video Modes changes are only really validated at apply times so cancel => noop
3690 // - All other standard changes are handled upper by ddx_cancel AH called
3692 // restore the bkuped Screen AR and invalidate clientcfg (NB: don't need to save, since canceled)
3693 ClientCfg.ScreenAspectRatio= CHandlerGameConfigInit::BkupScreenAspectRatio;
3694 ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio);
3695 ClientCfg.IsInvalidated = true;
3698 REGISTER_ACTION_HANDLER(CHandlerGameConfigCancel, "game_config_cancel");
3701 // ***************************************************************************
3702 class CHandlerGameConfigChangeScreenRatioMode : public IActionHandler
3704 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3706 if (CInterfaceLink::isUpdatingAllLinks()) return; // don't want to trash the value in client.cfg at init, due to 'updateAllLinks' being called
3708 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3710 // get the current mode
3711 sint oldMode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getOldValue32();
3712 sint mode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getValue32();
3713 if(mode<0 || mode>3)
3714 return;
3716 // If predef value (4/3 or 16/9)
3717 if(mode!=2)
3719 switch(mode)
3721 case 0: ClientCfg.ScreenAspectRatio= 1.33333f; break;
3722 case 1: ClientCfg.ScreenAspectRatio= 1.77777f; break;
3723 case 3: ClientCfg.ScreenAspectRatio= 0.f; break;
3725 ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio);
3727 // set content, and freeze the edit box
3728 CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
3729 if(eb)
3731 eb->setFrozen(true);
3732 eb->setInputStringAsFloat(ClientCfg.ScreenAspectRatio);
3735 // custom value
3736 else
3738 // just unfreeze the edit box, and set correct value
3739 CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
3740 if(eb)
3742 eb->setFrozen(false);
3743 eb->setInputStringAsFloat(ClientCfg.ScreenAspectRatio);
3747 // dirt the apply button of the DDX.
3748 // don't do it at init!
3749 if(oldMode!=-1)
3751 CDDXManager *pDM = CDDXManager::getInstance();
3752 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3753 if(pDDX)
3754 pDDX->validateApplyButton();
3757 // Invalidate the config
3758 ClientCfg.IsInvalidated = true;
3761 REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeScreenRatioMode, "game_config_change_screen_ratio_mode");
3764 // ***************************************************************************
3765 class CHandlerGameConfigChangeAnisotropic : public IActionHandler
3767 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3769 if (CInterfaceLink::isUpdatingAllLinks()) return; // don't want to trash the value in client.cfg at init, due to 'updateAllLinks' being called
3771 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3773 // get values of anisotropic filtering
3774 sint oldAnisotropic = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_ANISOTROPIC_DB)->getOldValue32();
3775 sint anisotropic = NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_ANISOTROPIC_DB)->getValue32();
3777 // dirt the apply button of the DDX.
3778 // don't do it at init!
3779 if(oldAnisotropic != anisotropic && oldAnisotropic != -1 && anisotropic != -1)
3781 CDDXManager *pDM = CDDXManager::getInstance();
3782 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3783 if(pDDX)
3784 pDDX->validateApplyButton();
3788 REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeAnisotropic, "game_config_change_anisotropic");
3791 // ***************************************************************************
3792 class CHandlerGameConfigChangeScreenRatioCustom : public IActionHandler
3794 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
3796 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3797 sint mode= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SCREEN_RATIO_MODE")->getValue32();
3798 if (mode != 2) return;
3799 CGroupEditBox *eb= dynamic_cast<CGroupEditBox*>( CWidgetManager::getInstance()->getElementFromDefine("game_config_screen_ratio_eb"));
3800 if(eb)
3802 // validate the value
3803 float val= eb->getInputStringAsFloat();
3804 clamp(val, 0.1f, 10.f);
3805 // reset (to clamp precision also), and hence reget
3806 eb->setInputStringAsFloat(val);
3807 val= eb->getInputStringAsFloat();
3809 // change the CFG with this value
3810 ClientCfg.ScreenAspectRatio= val;
3811 ClientCfg.writeDouble("ScreenAspectRatio", ClientCfg.ScreenAspectRatio);
3813 // dirt the apply button of the DDX.
3815 CDDXManager *pDM = CDDXManager::getInstance();
3816 CInterfaceDDX *pDDX = pDM->get(GAME_CONFIG_DDX);
3817 if(pDDX)
3818 pDDX->validateApplyButton();
3821 // Invalidate the config
3822 ClientCfg.IsInvalidated = true;
3826 REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeScreenRatioCustom, "game_config_change_screen_ratio_custom");
3828 // ***************************************************************************
3829 class CHandlerSetInterfaceScale : public IActionHandler
3831 virtual void execute (CCtrlBase *pCaller, const string &Params)
3833 std::string s;
3834 s = getParam(Params, "scale");
3835 if (!s.empty()) {
3836 float scale;
3837 if (fromString(s, scale))
3839 if (scale >= ClientCfg.InterfaceScale_min && scale <= ClientCfg.InterfaceScale_max)
3841 ClientCfg.InterfaceScale = scale;
3842 ClientCfg.writeDouble("InterfaceScale", ClientCfg.InterfaceScale);
3844 ClientCfg.IsInvalidated = true;
3845 return;
3850 string help = "/setuiscale "+toString("%.1f .. %.1f", ClientCfg.InterfaceScale_min, ClientCfg.InterfaceScale_max);
3851 CInterfaceManager::getInstance()->displaySystemInfo(help);
3854 REGISTER_ACTION_HANDLER (CHandlerSetInterfaceScale, "set_ui_scale");
3857 // ***************************************************************************
3858 class CHandlerGameMissionAbandon : public IActionHandler
3860 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
3862 uint8 nMissionNb;
3863 fromString(Params, nMissionNb);
3865 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_ABANDON_BUTTON",false);
3866 if (pNL != NULL) pNL->setValue64(0);
3868 sendMsgToServer("JOURNAL:MISSION_ABANDON", nMissionNb);
3871 REGISTER_ACTION_HANDLER (CHandlerGameMissionAbandon, "mission_abandon");
3874 // ***************************************************************************
3875 class CHandlerGameGroupMissionAbandon : public IActionHandler
3877 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
3879 uint8 nMissionNb;
3880 fromString(Params, nMissionNb);
3882 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_ABANDON_BUTTON",false);
3883 if (pNL != NULL) pNL->setValue64(0);
3885 sendMsgToServer("JOURNAL:GROUP_MISSION_ABANDON", nMissionNb);
3888 REGISTER_ACTION_HANDLER (CHandlerGameGroupMissionAbandon, "group_mission_abandon");
3891 // ***************************************************************************
3892 // ***************************************************************************
3893 // Yoyo New BotChat
3894 // ***************************************************************************
3895 // ***************************************************************************
3898 // ***************************************************************************
3899 // GCM Choose ZoneCharge
3900 // ***************************************************************************
3901 class CHandlerContextChooseZoneCharge : public IActionHandler
3903 public:
3904 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3906 sendBotChatStart("START_CHOOSE_DUTY");
3907 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::ZCCharge);
3908 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3911 REGISTER_ACTION_HANDLER(CHandlerContextChooseZoneCharge, "context_choose_zc_charge");
3914 // ***************************************************************************
3915 // GCM Choose Building
3916 // ***************************************************************************
3917 class CHandlerContextChooseBuilding : public IActionHandler
3919 public:
3920 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3922 // Choose a building is like choose a mission
3923 sendBotChatStart("START_CHOOSE_MISSION");
3924 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::Building);
3925 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3928 REGISTER_ACTION_HANDLER(CHandlerContextChooseBuilding, "context_choose_building");
3930 // ***************************************************************************
3931 // GCM Buy RM
3932 // ***************************************************************************
3933 class CHandlerContextBuyRM : public IActionHandler
3935 public:
3936 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3938 // Buy RM is like choose a mission
3939 sendBotChatStart("START_CHOOSE_MISSION");
3940 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::RMBuy);
3941 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3944 REGISTER_ACTION_HANDLER(CHandlerContextBuyRM, "context_buy_rm");
3946 // ***************************************************************************
3947 // GCM Upgrade RM
3948 // ***************************************************************************
3949 class CHandlerContextUpgradeRM : public IActionHandler
3951 public:
3952 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3954 // Upgrde RM is like choose a mission
3955 sendBotChatStart("START_CHOOSE_MISSION");
3956 BotChatPageAll->ChooseMission->setMissionClientType(MISSION_DESC::RMUpgrade);
3957 CBotChatManager::getInstance()->setCurrPage(BotChatPageAll->ChooseMission);
3960 REGISTER_ACTION_HANDLER(CHandlerContextUpgradeRM, "context_upgrade_rm");
3963 // ***************************************************************************
3964 // GCM Cancel Duty
3965 // ***************************************************************************
3966 class CHandlerContextCancelZoneCharge : public IActionHandler
3968 public:
3969 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3971 CInterfaceManager *pIM= CInterfaceManager::getInstance();
3973 // Check if user really want.
3974 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQCancelZoneCharge"),
3975 "do_cancel_zc_charge");
3978 REGISTER_ACTION_HANDLER(CHandlerContextCancelZoneCharge, "context_cancel_zc_charge");
3980 // The Msg if Ok.
3981 class CHandlerDoCancelZoneCharge : public IActionHandler
3983 public:
3984 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
3986 sendMsgToServer("BOTCHAT:DUTY_CANCEL_APPLY");
3989 REGISTER_ACTION_HANDLER(CHandlerDoCancelZoneCharge, "do_cancel_zc_charge");
3992 // ***************************************************************************
3993 // GCM Destroy Building
3994 // ***************************************************************************
3995 class CHandlerContextDestroyBuilding : public IActionHandler
3997 public:
3998 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4000 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4002 // Check if user really want.
4003 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQDestroyBuilding"),
4004 "do_destroy_building");
4007 REGISTER_ACTION_HANDLER(CHandlerContextDestroyBuilding, "context_destroy_building");
4009 // The Msg if Ok.
4010 class CHandlerDoDestroyBuilding : public IActionHandler
4012 public:
4013 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4015 sendMsgToServer("BOTCHAT:DESTROY_BUILDING");
4018 REGISTER_ACTION_HANDLER(CHandlerDoDestroyBuilding, "do_destroy_building");
4021 // ***************************************************************************
4022 // Combat defense interface handlers
4023 // ***************************************************************************
4024 // Select Parry.
4025 class CHandlerSelectParry : public IActionHandler
4027 public:
4028 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4030 sendMsgToServer("COMBAT:PARRY");
4032 // display parry mode msg
4033 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4034 string msg = CI18N::get("msgUserModeParry");
4035 string cat = getStringCategory(msg, msg);
4036 pIM->displaySystemInfo(msg, cat);
4039 REGISTER_ACTION_HANDLER(CHandlerSelectParry, "parry");
4041 // Select dodge.
4042 class CHandlerSelectDodge : public IActionHandler
4044 public:
4045 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4047 sendMsgToServer("COMBAT:DODGE");
4049 // display dodge mode msg
4050 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4051 string msg = CI18N::get("msgUserModeDodge");
4052 string cat = getStringCategory(msg, msg);
4053 pIM->displaySystemInfo(msg, cat);
4056 REGISTER_ACTION_HANDLER(CHandlerSelectDodge, "dodge");
4058 // Select protected slot.
4059 class CHandlerSelectProtectedSlot : public IActionHandler
4061 public:
4062 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4064 uint8 slot = (uint8)SLOT_EQUIPMENT::stringToSlotEquipment(sParams);
4065 sendMsgToServer("COMBAT:PROTECTED_SLOT", slot);
4068 REGISTER_ACTION_HANDLER(CHandlerSelectProtectedSlot, "select_protected_slot");
4071 // ***************************************************************************
4072 // Tooltips for Players Stats, with values printed.
4073 // ***************************************************************************
4076 // ***************************************************************************
4077 // Common code
4078 static void fillPlayerBarText(std::string &str, const string &dbScore, SCORES::TScores score, const string &ttFormat)
4080 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4081 CCDBNodeLeaf *node;
4083 sint val= 0;
4084 sint maxVal= 0;
4085 // Get from local database cause written from CBarManager, from a fast impulse
4086 node= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:" + dbScore, false);
4087 if(node) val= node->getValue32();
4088 // less accurate/speed Max transferred by DB
4089 node= NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:CHARACTER_INFO:SCORES%d:", score), false);
4090 if(node) maxVal= node->getValue32();
4091 val= max(val, 0);
4092 maxVal= max(maxVal, 0);
4094 str= CI18N::get(ttFormat);
4095 strFindReplace(str, "%v", toString(val) );
4096 strFindReplace(str, "%m", toString(maxVal) );
4099 // ***************************************************************************
4100 // Life
4101 class CHandlerPlayerTTLife : public IActionHandler
4103 public:
4104 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4106 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4108 string str;
4109 fillPlayerBarText(str, "HP", SCORES::hit_points, "uittPlayerLifeFormat");
4111 CWidgetManager::getInstance()->setContextHelpText(str);
4114 REGISTER_ACTION_HANDLER(CHandlerPlayerTTLife, "player_tt_life");
4116 // ***************************************************************************
4117 // Stamina
4118 class CHandlerPlayerTTStamina : public IActionHandler
4120 public:
4121 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4123 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4125 string str;
4126 fillPlayerBarText(str, "STA", SCORES::stamina, "uittPlayerStaminaFormat");
4128 CWidgetManager::getInstance()->setContextHelpText(str);
4131 REGISTER_ACTION_HANDLER(CHandlerPlayerTTStamina, "player_tt_stamina");
4133 // ***************************************************************************
4134 // Sap
4135 class CHandlerPlayerTTSap : public IActionHandler
4137 public:
4138 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4140 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4142 string str;
4143 fillPlayerBarText(str, "SAP", SCORES::sap, "uittPlayerSapFormat");
4145 CWidgetManager::getInstance()->setContextHelpText(str);
4148 REGISTER_ACTION_HANDLER(CHandlerPlayerTTSap, "player_tt_sap");
4150 // ***************************************************************************
4151 // Focus
4152 class CHandlerPlayerTTFocus : public IActionHandler
4154 public:
4155 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4157 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4159 string str;
4160 fillPlayerBarText(str, "FOCUS", SCORES::focus, "uittPlayerFocusFormat");
4162 CWidgetManager::getInstance()->setContextHelpText(str);
4165 REGISTER_ACTION_HANDLER(CHandlerPlayerTTFocus, "player_tt_focus");
4167 // ***************************************************************************
4168 // Bulk: NB: work for player / animal
4169 class CHandlerGetTTBulk : public IActionHandler
4171 public:
4172 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4174 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4175 string dbBranch= getParam(sParams, "dbbranch");
4176 string dbMax= getParam(sParams, "dbmax");
4178 // Get the sum of the bulk for this db branch
4179 const double epsilon = 0.001;
4180 float val = CInventoryManager::getBranchBulk(dbBranch, 0, 10000) + epsilon;
4182 // Get the Max value
4183 sint32 maxVal= 0;
4184 CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp(dbMax, false);
4185 if(node)
4186 maxVal= node->getValue32();
4188 // Replace in the formated text
4189 string str= CI18N::get("uittBulkFormat");
4190 strFindReplace(str, "%v", toString("%.2f", val) );
4191 strFindReplace(str, "%m", toString(maxVal) );
4192 CWidgetManager::getInstance()->setContextHelpText(str);
4195 REGISTER_ACTION_HANDLER(CHandlerGetTTBulk, "get_tt_bulk");
4197 // ***************************************************************************
4198 #define UI_MISSION_LIST "ui:interface:info_player_journal:content:mission_list"
4200 uint32 getMissionTitle(sint32 nSelected)
4202 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4204 sint32 nNbMission, nNbGroupMission;
4205 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_mission"), nNbMission);
4206 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_group_mission"), nNbGroupMission);
4208 if (nSelected < 0)
4209 return 0;
4210 else if (nSelected < nNbMission)
4211 return NLGUI::CDBManager::getInstance()->getDbProp("SERVER:MISSIONS:"+toString(nSelected)+":TITLE")->getValue32();
4212 else if (nSelected < (nNbMission+nNbGroupMission))
4213 return NLGUI::CDBManager::getInstance()->getDbProp("SERVER:GROUP:MISSIONS:"+toString(nSelected-nNbMission)+":TITLE")->getValue32();
4214 return 0;
4217 void runMissionProc(sint32 nSelected)
4219 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4221 sint32 nNbMission, nNbGroupMission;
4222 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_mission"), nNbMission);
4223 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_group_mission"), nNbGroupMission);
4225 if (nSelected < 0)
4226 return;
4227 else if (nSelected < nNbMission)
4229 string sButtonPath = UI_MISSION_LIST ":b_title"+toString(nSelected);
4230 CCtrlButton *pCB = dynamic_cast<CCtrlButton*>(CWidgetManager::getInstance()->getElementFromId(sButtonPath));
4231 CAHManager::getInstance()->runActionHandler("proc", pCB, "mission_proc_title|"+toString(nSelected));
4233 else if (nSelected < (nNbMission+nNbGroupMission))
4235 string sButtonPath = UI_MISSION_LIST ":b_group_title"+toString(nSelected-nNbMission);
4236 CCtrlButton *pCB = dynamic_cast<CCtrlButton*>(CWidgetManager::getInstance()->getElementFromId(sButtonPath));
4237 CAHManager::getInstance()->runActionHandler("proc", pCB, "group_mission_proc_title|"+toString(nSelected-nNbMission));
4239 return;
4243 class CHandlerMissionChooseNextValid : public IActionHandler
4245 public:
4246 void execute(CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4248 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4249 sint32 nSelected = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:MISSION_SELECTED")->getValue32();
4251 sint32 nNbMission, nNbGroupMission;
4252 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_mission"), nNbMission);
4253 fromString(CWidgetManager::getInstance()->getParser()->getDefine("ipj_nb_group_mission"), nNbGroupMission);
4255 // If no mission selected or title selected becomes invalid -> search a new title to select
4256 if ((nSelected == -1) || (getMissionTitle(nSelected) == 0))
4258 bool bFound = false;
4259 sint32 nSel = nSelected;
4261 // From the currently selected mission go backward (in the display order)
4262 if (nSel != -1)
4263 while (!bFound)
4265 nSel--;
4266 if (nSel < 0)
4267 break;
4269 // Is there a mission at the position nSel ? Yes ok select !
4270 if (getMissionTitle(nSel) != 0)
4272 runMissionProc(nSel);
4273 return;
4276 // Ok not found a mission in backward mode try now in forward mode until the end of the mission list
4277 while (!bFound)
4279 nSel++;
4280 if (nSel == (nNbMission+nNbGroupMission))
4281 break;
4283 // Is there a mission at the position nSel ? Yes ok select !
4284 if (getMissionTitle(nSel) != 0)
4286 runMissionProc(nSel);
4287 return;
4290 // No mission at all found so there is no mission in the journal
4291 NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:MISSION_SELECTED")->setValue32(-1);
4295 REGISTER_ACTION_HANDLER(CHandlerMissionChooseNextValid, "mission_choose_next_valid");
4297 // ***************************************************************************
4298 // Output a text above the entity like hit points
4299 class CHandlerEntityFlyingText : public IActionHandler
4301 public:
4302 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4304 string text = getParam(sParams, "text");
4306 uint entity;
4307 fromString(getParam(sParams, "entity"), entity);
4309 CRGBA color = CRGBA::stringToRGBA(getParam(sParams, "color").c_str());
4310 if (entity < 256)
4311 EntitiesMngr.entity (entity)->addHPOutput (CI18N::get (text), color);
4314 REGISTER_ACTION_HANDLER(CHandlerEntityFlyingText, "entity_flying_text");
4317 // ***************************************************************************
4318 // play an event music
4319 class CHandlerPlayEventMusic : public IActionHandler
4321 public:
4322 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4324 bool loop = getParam(sParams, "loop")=="1";
4326 uint xFade;
4327 fromString(getParam(sParams, "xfade"), xFade);
4329 string fileName = getParam(sParams, "music");
4331 // don't play if db is in init stage
4332 if (!ClientCfg.Local && IngameDbMngr.initInProgress()) return;
4334 if(SoundMngr)
4335 SoundMngr->playEventMusic(fileName, xFade, loop);
4338 REGISTER_ACTION_HANDLER(CHandlerPlayEventMusic, "play_event_music");
4341 // ***************************************************************************
4342 // stop an event music
4343 class CHandlerStopEventMusic : public IActionHandler
4345 public:
4346 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4348 uint xFade;
4349 fromString(getParam(sParams, "xfade"), xFade);
4351 string fileName= getParam(sParams, "music");
4353 // don't play if db is in init stage
4354 if (!ClientCfg.Local && IngameDbMngr.initInProgress()) return;
4356 if(SoundMngr)
4357 SoundMngr->stopEventMusic(fileName, xFade);
4360 REGISTER_ACTION_HANDLER(CHandlerStopEventMusic, "stop_event_music");
4362 // ***************************************************************************
4363 // enter cr zone for queue
4364 class CEnterCRZone: public IActionHandler
4366 public:
4367 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4369 // hide interface
4370 CInterfaceManager* pIM = CInterfaceManager::getInstance();
4371 CInterfaceGroup *pIG = (CInterfaceGroup*)CWidgetManager::getInstance()->getElementFromId ("ui:interface:enter_crzone_proposal");
4372 if(pIG)
4373 pIG->setActive(false);
4375 bool accept;
4376 fromString(sParams, accept);
4377 CBitMemStream out;
4378 if(GenericMsgHeaderMngr.pushNameToStream("MISSION:ENTER_CRITICAL", out))
4380 //nlinfo("impulseCallBack :MISSION:ENTER_CRITICAL sent");
4381 out.serial(accept);
4382 NetMngr.push(out);
4384 else
4386 nlwarning("command : unknown message name : MISSION:ENTER_CRITICAL");
4390 REGISTER_ACTION_HANDLER(CEnterCRZone, "enter_crzone");
4393 // ***************************************************************************
4394 // wake player
4395 class CWakeForMission : public IActionHandler
4397 public:
4398 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4400 uint8 nMissionNb;
4401 fromString(sParams, nMissionNb);
4403 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_WAKE_BUTTON",false);
4404 if (pNL != NULL) pNL->setValue64(0);
4406 sendMsgToServer("MISSION:WAKE", nMissionNb);
4409 REGISTER_ACTION_HANDLER(CWakeForMission, "mission_wake");
4411 // ***************************************************************************
4412 // wake player
4413 class CWakeForGroupMission : public IActionHandler
4415 public:
4416 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4418 uint8 nMissionNb;
4419 fromString(sParams, nMissionNb);
4421 CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_WAKE_BUTTON",false);
4422 if (pNL != NULL) pNL->setValue64(0);
4424 sendMsgToServer("MISSION:GROUP_WAKE", nMissionNb);
4427 REGISTER_ACTION_HANDLER(CWakeForGroupMission, "group_mission_wake");
4430 // ***************************************************************************
4431 // ***************************************************************************
4432 // PVP FACTION
4433 // ***************************************************************************
4434 // ***************************************************************************
4437 // ***************************************************************************
4438 class CBuildTotem : public IActionHandler
4440 public:
4441 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4443 if (UserEntity->selection())
4445 CEntityCL *pSel = EntitiesMngr.entity(UserEntity->selection());
4446 if (pSel != NULL)
4447 UserEntity->moveToTotemBuildingPhrase( UserEntity->selection(), 2.0f, std::numeric_limits<uint>::max(), std::numeric_limits<uint>::max(), true);
4451 REGISTER_ACTION_HANDLER(CBuildTotem, "build_totem");
4454 // ***************************************************************************
4455 class CHandlerFameSetNeutral : public IActionHandler
4457 public:
4458 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4460 if( IngameDbMngr.initInProgress() ) return;
4462 bool force;
4463 fromString(getParam(sParams, "force"), force);
4465 bool isCiv= getParam(sParams, "type")=="civ" || getParam(sParams, "type")=="civ_guild";
4466 bool isGuild= getParam(sParams, "type")=="civ_guild" || getParam(sParams, "type")=="cult_guild";
4468 if(force)
4470 // help the server to know what type of neutral to set (civ or cult). ugly
4471 uint8 u8Type= isCiv?PVP_CLAN::Fyros:PVP_CLAN::Kami;
4472 // send msg to server.
4473 if(isGuild)
4474 sendMsgToServer("PVP:SET_NEUTRAL_ALLEGIANCE_GUILD", u8Type);
4475 else
4476 sendMsgToServer("PVP:SET_NEUTRAL_ALLEGIANCE", u8Type);
4478 else
4480 // confirm first
4481 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4482 if(isGuild)
4484 pIM->validMessageBox(CInterfaceManager::WarningIconMsg,
4485 isCiv?CI18N::get("uiFameAllegianceCivSetNeutralGuildWarning"):
4486 CI18N::get("uiFameAllegianceCultSetNeutralGuildWarning"),
4487 "fame_set_neutral",
4488 isCiv?"type=civ_guild|force=1":"type=cult_guild|force=1" );
4490 else
4492 pIM->validMessageBox(CInterfaceManager::WarningIconMsg,
4493 isCiv?CI18N::get("uiFameAllegianceCivSetNeutralWarning"):
4494 CI18N::get("uiFameAllegianceCultSetNeutralWarning"),
4495 "fame_set_neutral",
4496 isCiv?"type=civ|force=1":"type=cult|force=1" );
4501 REGISTER_ACTION_HANDLER(CHandlerFameSetNeutral, "fame_set_neutral");
4504 // ***************************************************************************
4505 class CHandlerConfigureQuitDialogBox : public IActionHandler
4507 public:
4508 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4510 CInterfaceManager::getInstance()->configureQuitDialogBox();
4513 REGISTER_ACTION_HANDLER(CHandlerConfigureQuitDialogBox, "configure_quit_dialog_box");
4515 // ----------------------------------------------------------------------------
4516 static bool isSwimming()
4518 if (UserEntity != NULL)
4519 return (UserEntity->mode() == MBEHAV::SWIM || UserEntity->mode() == MBEHAV::MOUNT_SWIM);
4520 else
4521 return false;
4524 static bool isStunned()
4526 if (UserEntity != NULL)
4527 return (UserEntity->behaviour() == MBEHAV::STUNNED);
4528 else
4529 return false;
4532 static bool isDead()
4534 if (UserEntity != NULL)
4535 return (UserEntity->mode() == MBEHAV::DEATH);
4536 else
4537 return false;
4540 // ***************************************************************************
4542 class CHandlerEmote : public IActionHandler
4544 public:
4545 void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
4547 // An emote is 2 things : a phrase and an animation
4548 // Phrase is the phrase that server returns in chat system
4549 // Behav is the animation played
4550 // CustomPhrase is an user phrase which can replace default phrase
4551 string sPhraseNb = getParam(sParams, "nb");
4552 string sBehav = getParam(sParams, "behav");
4553 string sCustomPhrase = getParam(sParams, "custom_phrase");
4555 uint32 phraseNb;
4556 fromString(sPhraseNb, phraseNb);
4557 uint8 behaviour;
4558 fromString(sBehav, behaviour);
4560 MBEHAV::EBehaviour behavToSend = (MBEHAV::EBehaviour)(MBEHAV::EMOTE_BEGIN + behaviour);
4561 uint16 phraseNbToSend = (uint16)phraseNb;
4563 if (EAM)
4565 const uint nbBehav = EAM->getNbEmots(); // Miscalled: this is the number of behaviour for all emotes
4566 if ((behaviour >= nbBehav) || (behaviour == 255))
4567 behavToSend = MBEHAV::IDLE;
4569 else
4571 if (behaviour == 255)
4572 behavToSend = MBEHAV::IDLE;
4575 /* Emotes forbidden when dead, emotes with behav forbidden when
4576 * stunned or swimming */
4577 if ( ( behavToSend != MBEHAV::IDLE && (isSwimming() || isStunned() || isDead() ) ) )
4579 return;
4582 if( sCustomPhrase.empty() )
4584 // Create the message and send.
4585 static const char *msgName = "COMMAND:EMOTE";
4586 CBitMemStream out;
4587 if(GenericMsgHeaderMngr.pushNameToStream(msgName, out))
4589 out.serialEnum(behavToSend);
4590 out.serial(phraseNbToSend);
4591 NetMngr.push(out);
4592 //nlinfo("impulseCallBack : %s %d %d sent", msgName.c_str(), (uint32)behavToSend, phraseNbToSend);
4594 else
4595 nlwarning("command 'emote': unknown message named '%s'.", msgName);
4597 else
4599 // Create the message and send.
4600 static const char *msgName = "COMMAND:CUSTOM_EMOTE";
4601 CBitMemStream out;
4602 if(GenericMsgHeaderMngr.pushNameToStream(msgName, out))
4604 ucstring ucstr; // FIXME: UTF-8 (serial)
4605 ucstr.fromUtf8(sCustomPhrase);
4607 if( sCustomPhrase == "none" )
4609 if( behavToSend == MBEHAV::IDLE )
4611 // display "no animation for emote"
4612 CInterfaceManager *pIM= CInterfaceManager::getInstance();
4613 string msg = CI18N::get("msgCustomizedEmoteNoAnim");
4614 string cat = getStringCategory(msg, msg);
4615 pIM->displaySystemInfo(msg, cat);
4616 return;
4619 else
4621 ucstr = ucstring("&EMT&") + UserEntity->getDisplayName() + ucstring(" ") + ucstr; // FIXME: UTF-8 (serial)
4624 out.serialEnum(behavToSend);
4625 out.serial(ucstr); // FIXME: UTF-8 (serial)
4626 NetMngr.push(out);
4627 //nlinfo("impulseCallBack : %s %d %s sent", msgName.c_str(), (uint32)behavToSend, sCustomPhrase.c_str());
4629 else
4630 nlwarning("command 'emote': unknown message named '%s'.", msgName);
4634 REGISTER_ACTION_HANDLER( CHandlerEmote, "emote");
4636 //=================================================================================================================
4637 class CHandlerSortTribeFame : public IActionHandler
4639 public:
4640 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4642 CGroupList * list = dynamic_cast<CGroupList*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:fame:content:tribes:list"));
4643 if (list && list->getNumChildren() > 1)
4645 uint nbChilds = list->getNumChildren();
4647 // std::collate does not work with ucchar
4648 std::vector<string> names;
4650 for (uint i = 0; i < nbChilds; ++i)
4652 CInterfaceGroup *pIG = dynamic_cast<CInterfaceGroup*>(list->getChild(i));
4653 if (!pIG) break;
4655 CViewText *pVT = dynamic_cast<CViewText *>(pIG->getView("t"));
4656 if (!pVT) break;
4658 names.push_back(toUpper(pVT->getText()));
4661 if (names.size() != nbChilds)
4663 nlwarning("Failed to sort tribe fame list");
4664 return;
4667 std::locale loc("");
4668 const std::collate<char>& coll = std::use_facet<std::collate<char> >(loc); // FIXME: Probably does not work
4670 for(uint i = 0; i < nbChilds - 1; ++i)
4672 uint imin = i;
4673 for(uint j = i; j < nbChilds; j++)
4675 // simple comparison fails with accented letters
4676 if (coll.compare(names[j].c_str(), names[j].c_str() + names[j].size(),
4677 names[imin].c_str(), names[imin].c_str() + names[imin].size()) < 0)
4679 imin = j;
4682 if (imin != i)
4684 list->swapChildren(i, imin);
4685 std::swap(names[i], names[imin]);
4689 list->invalidateCoords();
4693 REGISTER_ACTION_HANDLER( CHandlerSortTribeFame, "sort_tribefame");
4695 // ***************************************************************************
4696 class CHandlerOutgameNaviGetKeys : public IActionHandler
4698 virtual void execute (CCtrlBase *pCaller, const std::string &Params)
4700 if (!pCaller->getParent())
4701 return;
4703 if (pCaller->getParent()->getId() != "ui:outgame")
4704 return;
4706 if (Params.empty())
4708 sint32 event = -1;
4710 if (Driver->AsyncListener.isKeyPushed(KeyESCAPE)) event = 0;
4711 if (Driver->AsyncListener.isKeyPushed(KeyDELETE)) event = 1;
4712 if (Driver->AsyncListener.isKeyPushed(KeyRETURN)) event = 2;
4713 if (Driver->AsyncListener.isKeyPushed(KeyDOWN)) event = 3;
4714 if (Driver->AsyncListener.isKeyPushed(KeyUP)) event = 4;
4715 if (Driver->AsyncListener.isKeyPushed(KeyI)) event = 5;
4716 if (Driver->AsyncListener.isKeyPushed(KeyP)) event = 6;
4717 if (Driver->AsyncListener.isKeyPushed(KeyE)) event = 7;
4718 if (Driver->AsyncListener.isKeyPushed(KeyLEFT)) event = 8;
4719 if (Driver->AsyncListener.isKeyPushed(KeyRIGHT)) event = 9;
4721 std::string id = "create";
4722 if (pCaller->getId() == "ui:outgame:charsel")
4723 id = "sel";
4725 if (event != -1)
4726 CLuaManager::getInstance().executeLuaScript(toString("outgame:eventChar%sKeyGet(%i)", id.c_str(), event));
4728 // reset previous input
4729 Driver->AsyncListener.reset();
4732 REGISTER_ACTION_HANDLER( CHandlerOutgameNaviGetKeys, "navigate_outgame" );
4734 // ***************************************************************************
4735 class CHandlerTriggerIconBuffs : public IActionHandler
4737 public:
4738 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
4740 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:SHOW_ICON_BUFFS", false);
4741 // no node - show,
4742 // node == false - hide
4743 CDBCtrlSheet::setShowIconBuffs(!node || node->getValueBool());
4746 REGISTER_ACTION_HANDLER(CHandlerTriggerIconBuffs, "trigger_show_icon_buffs");