Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / lua_ihm_ryzom.cpp
blobc1c9315288f79b4ab2c7a1ed005d9de566d76f03
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 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/>.
21 #include "stdpch.h"
23 #include <algorithm>
25 // to get rid of you_must_not_use_assert___use_nl_assert___read_debug_h_file messages
26 #include <cassert>
27 #ifdef assert
28 #undef assert
29 #endif
31 // Warning: cannot use namespace std, when using luabind
32 #ifdef NL_OS_WINDOWS
33 # ifndef NL_EXTENDED_FOR_SCOPE
34 # undef for
35 # endif
36 #endif
38 #ifdef NL_DEBUG
39 # define assert(x) nlassert(x)
40 #else
41 # define assert(x)
42 #endif
44 // Always use unique_ptr with ValyriaTear/luabind on Ubuntu 20,
45 // since the setting is not stored in build_information.hpp
46 #ifndef LUABIND_USE_CXX11
47 #define LUABIND_USE_CXX11
48 #endif
50 #include <luabind/luabind.hpp>
51 // in luabind > 0.6, LUABIND_MAX_ARITY is set to 10
52 #if LUABIND_MAX_ARITY == 10
53 # include <luabind/operator.hpp>
54 // only luabind > 0.7 have version.hpp (file checked with build system)
55 # ifdef HAVE_LUABIND_VERSION
56 # include <luabind/version.hpp>
57 # endif
58 # ifndef LUABIND_VERSION
59 // luabind 0.7 doesn't define LUABIND_VERSION
60 # define LUABIND_VERSION 700
61 # endif
62 // luabind 0.6 doesn't define LUABIND_VERSION but LUABIND_MAX_ARITY is set to 5
63 #elif LUABIND_MAX_ARITY == 5
64 # define LUABIND_VERSION 600
65 #else
66 # pragma error("luabind version not recognized")
67 #endif
69 #include "lua_ihm_ryzom.h"
70 #include "interface_manager.h"
71 #include "nel/gui/lua_helper.h"
72 #include "nel/gui/lua_object.h"
74 #include "nel/gui/lua_ihm.h"
75 #include "nel/gui/reflect.h"
76 #include "nel/gui/action_handler.h"
77 #include "action_handler_tools.h"
78 #include "interface_manager.h"
79 #include "nel/gui/interface_group.h"
80 #include "nel/gui/view_text.h"
81 #include "game_share/people_pd.h"
82 #include "nel/gui/group_tree.h"
83 #include "nel/gui/interface_link.h"
84 #include "nel/gui/interface_expr.h"
85 #include "people_interraction.h"
86 #include "nel/misc/algo.h"
87 #include "nel/misc/file.h"
88 #include "nel/misc/i18n.h"
89 #include "nel/misc/time_nl.h"
90 #include "skill_manager.h"
91 #include "nel/gui/group_html.h"
92 #include "../net_manager.h"
93 #include "../user_entity.h"
94 #include "sphrase_manager.h"
95 #include "guild_manager.h"
96 #include "../client_cfg.h"
97 #include "../sheet_manager.h"
98 #include "nel/gui/lua_object.h"
99 #include "game_share/emote_list_parser.h"
100 #include "game_share/pvp_clan.h"
101 #include "../weather.h"
102 #include "../continent_manager.h"
103 #include "../zone_util.h"
104 #include "../motion/user_controls.h"
105 #include "group_html_cs.h"
106 #include "group_map.h"
107 #include "bonus_malus.h"
108 #include "nel/gui/group_editbox.h"
109 #include "../entities.h"
110 #include "../sheet_manager.h" // for emotes
111 #include "../global.h" // for emotes
112 #include "../entity_animation_manager.h" // for emotes
113 #include "../net_manager.h" // for emotes
114 #include "../client_chat_manager.h" // for emotes
115 #include "../login.h"
116 #include "nel/gui/lua_object.h"
117 #include "../actions.h"
118 #include "../bg_downloader_access.h"
119 #include "../connection.h"
120 #include "../login_patch.h"
121 #include "../r2/tool.h"
122 #include "../entities.h"
123 #include "../misc.h"
125 #include "bot_chat_page_all.h"
126 #include "bot_chat_page_ring_sessions.h"
127 #include "nel/georges/u_form_loader.h"
128 #include "nel/georges/u_form.h"
129 #include "nel/georges/u_form_elm.h"
130 #include "nel/misc/polygon.h"
131 #include "nel/misc/i_xml.h"
132 #include "nel/misc/o_xml.h"
133 #include "game_share/scenario_entry_points.h"
134 #include "game_share/bg_downloader_msg.h"
135 #include "game_share/constants.h"
136 #include "game_share/visual_slot_manager.h"
137 #include "nel/gui/lua_manager.h"
138 #include "pacs_client.h"
140 #ifdef LUA_NEVRAX_VERSION
141 #include "lua_ide_dll_nevrax/include/lua_ide_dll/ide_interface.h" // external debugger
142 #endif
145 #ifdef LUA_NEVRAX_VERSION
146 extern ILuaIDEInterface* LuaDebuggerIDE;
147 #endif
149 using namespace NLMISC;
150 using namespace NLGUI;
151 using namespace NL3D;
152 using namespace NLPACS;
153 using namespace R2;
155 extern NLMISC::CLog g_log;
156 extern CContinentManager ContinentMngr;
157 extern CClientChatManager ChatMngr;
159 // ***************************************************************************
160 class CHandlerLUA : public IActionHandler
162 public:
163 void execute(CCtrlBase *pCaller, const std::string &sParams)
165 CInterfaceManager *pIM = CInterfaceManager::getInstance();
167 // For getUI() LUA function, push the UI caller
168 if (pCaller)
169 _UICallerStack.push_back(pCaller);
171 // execute a small script. NB: use a small script here because
172 // most often action handlers are called from xml files => lot of redundant script
173 CLuaManager::getInstance().executeLuaScript(sParams, true);
175 // pop UI caller
176 if (pCaller)
177 _UICallerStack.pop_back();
180 // get the top of stack Caller to this LUA script
181 static CCtrlBase* getUICaller();
183 private:
184 static std::deque<CRefPtr<CCtrlBase> > _UICallerStack;
186 REGISTER_ACTION_HANDLER(CHandlerLUA, "lua");
187 std::deque<CRefPtr<CCtrlBase> > CHandlerLUA::_UICallerStack;
189 // ***************************************************************************
190 // Allow also to call script from expression
191 static DECLARE_INTERFACE_USER_FCT(lua)
193 if (args.size() != 1 || !args[0].toString())
195 nlwarning("<lua> requires 1 arg (string=script)");
196 return false;
199 // Retrieve lua state
200 CInterfaceManager *pIM = CInterfaceManager::getInstance();
201 CLuaState *state = CLuaManager::getInstance().getLuaState();
203 if (!state)
204 return false;
206 CLuaState &ls = *state;
207 // *** clear return value
208 const std::string retId = "__ui_internal_ret_";
209 CLuaStackChecker lsc(&ls);
210 ls.pushGlobalTable();
211 ls.push(retId);
212 ls.pushNil();
213 ls.setTable(-3); //pop pop
214 ls.pop();
216 // *** execute script
217 std::string script = args[0].getString();
218 // assign return value in retId.
219 script = retId + "= " + script;
220 // execute a small script here, because most often exprs are called from xml files => lot of redundant script
221 CLuaManager::getInstance().executeLuaScript(script, true);
223 // *** retrieve and convert return value
224 ls.pushGlobalTable();
225 ls.push(retId);
226 ls.getTable(-2);
227 ls.remove(-2);
228 bool ok = false;
229 sint type = ls.type();
231 if (type == LUA_TBOOLEAN)
233 // get and pop
234 bool val = ls.toBoolean();
235 ls.pop();
236 // set result
237 result.setBool(val);
238 ok = true;
240 else if (type == LUA_TNUMBER)
242 if (ls.isInteger())
244 // get and pop
245 sint64 val = ls.toInteger();
246 ls.pop();
247 result.setInteger(val);
248 ok = true;
250 else
252 // get and pop
253 double val = ls.toNumber();
254 ls.pop();
255 result.setDouble(val);
256 ok = true;
259 else if (type == LUA_TSTRING)
261 // get and pop
262 std::string val;
263 ls.toString(-1, val);
264 ls.pop();
265 // set result
266 result.setString(val);
267 ok = true;
269 else if (type == LUA_TUSERDATA)
271 // NB: the value is poped in obj.set() (no need to do ls.pop());
273 // try with ucstring
274 #ifdef RYZOM_LUA_UCSTRING
275 ucstring ucstrVal;
277 if (CLuaIHM::pop(ls, ucstrVal))
279 result.setString(ucstrVal.toUtf8());
280 ok = true;
283 if (!ok)
284 #endif
286 // try with RGBA
287 NLMISC::CRGBA rgbaVal;
289 if (CLuaIHM::pop(ls, rgbaVal))
291 result.setRGBA(rgbaVal);
292 ok = true;
296 else
298 // error (nil for instance)
299 ls.pop();
302 return ok;
304 REGISTER_INTERFACE_USER_FCT("lua", lua)
307 CCtrlBase* CHandlerLUA::getUICaller()
309 if (_UICallerStack.empty())
310 return NULL;
311 else
312 return _UICallerStack.back();
315 #define LUABIND_ENUM(__enum__, __name__, __num__, __toStringFunc__) \
316 createLuaEnumTable(ls, __name__); \
317 for (uint e=0 ; e<__num__ ; e++) \
319 std::string str = __toStringFunc__((__enum__)e); \
320 std::string temp = __name__ + toString(".") + __toStringFunc__((__enum__)e) + " = " + toString("%d;", e); \
321 ls.executeScript(temp); \
326 #define LUABIND_FUNC(__func__) luabind::def(#__func__, &__func__)
328 // ***************************************************************************
329 int CLuaIHMRyzom::luaClientCfgIndex(CLuaState &ls)
331 //H_AUTO(Lua_CLuaIHM_luaClientCfgIndex)
332 CConfigFile::CVar *v = ClientCfg.ConfigFile.getVarPtr(ls.toString(2));
334 if (!v) return 0;
336 if (v->size() != 1)
338 // arrays not implemented (would require a second metatable)....
339 throw ELuaWrappedFunctionException(&ls, "Access to array inside client.cfg not supported.");
342 switch (v->Type)
344 case CConfigFile::CVar::T_REAL:
345 ls.push(v->asDouble());
346 return 1;
347 break;
349 case CConfigFile::CVar::T_STRING:
350 ls.push(v->asString());
351 return 1;
352 break;
354 default: // handle both T_INT && T_BOOL
355 case CConfigFile::CVar::T_INT:
356 ls.push(v->asInt());
357 return 1;
358 break;
361 return 0;
364 // ***************************************************************************
365 int CLuaIHMRyzom::luaClientCfgNewIndex(CLuaState &ls)
367 //H_AUTO(Lua_CLuaIHM_luaClientCfgNewIndex)
368 throw ELuaWrappedFunctionException(&ls, "Can't write into config file from lua.");
371 static CLuaString lstr_Env("Env");
372 static CLuaString lstr_isNil("isNil");
374 // ***************************************************************************
375 void CLuaIHMRyzom::createLuaEnumTable(CLuaState &ls, const std::string &str)
377 //H_AUTO(Lua_CLuaIHM_createLuaEnumTable)
378 std::string path, script, p;
379 CSString s = str;
380 // Create table recursively (ex: 'game.TPVPClan' will check/create the table 'game' and 'game.TPVPClan')
381 p = s.splitTo('.', true);
383 while (!p.empty())
385 if (path.empty())
386 path = p;
387 else
388 path += "." + p;
390 script = "if (" + path + " == nil) then " + path + " = {}; end";
391 ls.executeScript(script);
392 p = s.splitTo('.', true);
396 void CLuaIHMRyzom::RegisterRyzomFunctions(NLGUI::CLuaState &ls)
398 CLuaStackChecker lsc(&ls);
400 // MISC ui ctors
401 struct CUICtor
403 // CGroupTree::SNode
404 static int SNode(CLuaState &ls)
406 CLuaIHM::checkArgCount(ls, "SNode", 0);
407 CLuaIHM::pushReflectableOnStack(ls, new CGroupTree::SNode);
408 return 1;
412 ls.registerFunc("SNode", CUICtor::SNode);
414 // *** Register the metatable for access to client.cfg (nb nico this may be more general later -> access to any config file ...)
415 ls.pushGlobalTable();
416 CLuaObject globals(ls);
417 CLuaObject clientCfg = globals.newTable("config");
418 CLuaObject mt = globals.newTable("__cfmt");
419 nlverify(clientCfg.setMetaTable(mt));
420 mt.setValue("__index", luaClientCfgIndex);
421 mt.setValue("__newindex", luaClientCfgNewIndex);
422 globals.setNil("__cfmt"); // remove temp metatable
424 ls.registerFunc("getUI", getUI);
425 ls.registerFunc("validMessageBox", validMessageBox);
426 ls.registerFunc("getUICaller", getUICaller);
427 ls.registerFunc("getUI", getUI);
428 ls.registerFunc("getIndexInDB", getIndexInDB);
429 ls.registerFunc("createGroupInstance", createGroupInstance);
430 ls.registerFunc("createRootGroupInstance", createRootGroupInstance);
431 ls.registerFunc("createUIElement", createUIElement);
432 ls.registerFunc("launchContextMenuInGame", launchContextMenuInGame);
433 ls.registerFunc("parseInterfaceFromString", parseInterfaceFromString);
434 ls.registerFunc("updateAllLocalisedElements", updateAllLocalisedElements);
435 ls.registerFunc("formatUI", formatUI);
436 ls.registerFunc("formatDB", formatDB);
437 ls.registerFunc("dumpUI", dumpUI);
438 ls.registerFunc("setKeyboardContext", setKeyboardContext);
439 ls.registerFunc("breakPoint", breakPoint);
440 ls.registerFunc("setTextFormatTaged", setTextFormatTaged);
441 ls.registerFunc("initEmotesMenu", initEmotesMenu);
442 ls.registerFunc("hideAllWindows", hideAllWindows);
443 ls.registerFunc("hideAllNonSavableWindows", hideAllNonSavableWindows);
444 ls.registerFunc("getDesktopIndex", getDesktopIndex);
445 ls.registerFunc("setLuaBreakPoint", setLuaBreakPoint);
446 ls.registerFunc("getMainPageURL", getMainPageURL);
447 ls.registerFunc("getCharSlot", getCharSlot);
448 ls.registerFunc("getServerSeason", getServerSeason);
449 ls.registerFunc("computeCurrSeason", computeCurrSeason);
450 ls.registerFunc("getAutoSeason", getAutoSeason);
451 ls.registerFunc("enableModalWindow", enableModalWindow);
452 ls.registerFunc("getPlayerPos", getPlayerPos);
453 ls.registerFunc("getGroundAtMouse", getGroundAtMouse),
454 ls.registerFunc("getMousePos", getMousePos),
455 ls.registerFunc("getMouseDown", getMouseDown),
456 ls.registerFunc("getMouseMiddleDown", getMouseMiddleDown),
457 ls.registerFunc("getMouseRightDown", getMouseRightDown),
458 ls.registerFunc("getShapeIdAt", getShapeIdAt),
459 ls.registerFunc("getPlayerFront", getPlayerFront);
460 ls.registerFunc("getPlayerDirection", getPlayerDirection);
461 ls.registerFunc("getPlayerGender", getPlayerGender);
462 ls.registerFunc("getPlayerName", getPlayerName);
463 ls.registerFunc("getPlayerTitleRaw", getPlayerTitleRaw);
464 ls.registerFunc("getPlayerTitle", getPlayerTitle);
465 ls.registerFunc("getTargetPos", getTargetPos);
466 ls.registerFunc("getTargetFront", getTargetFront);
467 ls.registerFunc("getTargetDirection", getTargetDirection);
468 ls.registerFunc("getTargetGender", getTargetGender);
469 ls.registerFunc("getTargetName", getTargetName);
470 ls.registerFunc("getTargetTitleRaw", getTargetTitleRaw);
471 ls.registerFunc("getTargetTitle", getTargetTitle);
472 ls.registerFunc("addSearchPathUser", addSearchPathUser);
473 ls.registerFunc("displaySystemInfo", displaySystemInfo);
474 ls.registerFunc("displayChatMessage", displayChatMessage);
475 ls.registerFunc("disableContextHelpForControl", disableContextHelpForControl);
476 ls.registerFunc("disableContextHelp", disableContextHelp);
477 ls.registerFunc("setWeatherValue", setWeatherValue);
478 ls.registerFunc("getWeatherValue", getWeatherValue);
479 ls.registerFunc("getCompleteIslands", getCompleteIslands);
480 ls.registerFunc("displayBubble", displayBubble);
481 ls.registerFunc("getIslandId", getIslandId);
482 ls.registerFunc("getClientCfgVar", getClientCfgVar);
483 ls.registerFunc("isPlayerFreeTrial", isPlayerFreeTrial);
484 ls.registerFunc("isPlayerNewbie", isPlayerNewbie);
485 ls.registerFunc("isInRingMode", isInRingMode);
486 ls.registerFunc("getUserRace", getUserRace);
487 ls.registerFunc("getSheet2idx", getSheet2idx);
488 ls.registerFunc("getTargetSlot", getTargetSlot);
489 ls.registerFunc("setTargetAsInterlocutor", setTargetAsInterlocutor);
490 ls.registerFunc("unsetTargetAsInterlocutor", unsetTargetAsInterlocutor);
491 ls.registerFunc("getSlotDataSetId", getSlotDataSetId);
492 ls.registerFunc("addShape", addShape);
493 ls.registerFunc("moveShape", moveShape);
494 ls.registerFunc("rotateShape", rotateShape);
495 ls.registerFunc("getShapePos", getShapePos);
496 ls.registerFunc("getShapeScale", getShapeScale);
497 ls.registerFunc("getShapeRot", getShapeRot);
498 ls.registerFunc("getShapeColPos", getShapeColPos);
499 ls.registerFunc("getShapeColScale", getShapeColScale);
500 ls.registerFunc("getShapeColOrient", getShapeColOrient);
501 ls.registerFunc("deleteShape", deleteShape);
502 ls.registerFunc("setupShape", setupShape);
503 ls.registerFunc("removeLandMarks", removeLandMarks);
504 ls.registerFunc("addLandMark", addLandMark);
505 ls.registerFunc("updateUserLandMarks", updateUserLandMarks);
506 ls.registerFunc("delArkPoints", delArkPoints);
507 ls.registerFunc("addRespawnPoint", addRespawnPoint);
508 ls.registerFunc("setArkPowoOptions", setArkPowoOptions);
509 ls.registerFunc("saveUserChannels", saveUserChannels);
510 ls.registerFunc("readUserChannels", readUserChannels);
511 ls.registerFunc("getMaxDynChan", getMaxDynChan);
512 ls.registerFunc("scrollElement", scrollElement);
514 lua_State *L = ls.getStatePointer();
516 LUABIND_ENUM(PVP_CLAN::TPVPClan, "game.TPVPClan", PVP_CLAN::NbClans, PVP_CLAN::toString);
517 LUABIND_ENUM(BONUS_MALUS::TBonusMalusSpecialTT, "game.TBonusMalusSpecialTT", BONUS_MALUS::NbSpecialTT, BONUS_MALUS::toString);
519 luabind::module(L)
521 LUABIND_FUNC(getDbProp),
522 LUABIND_FUNC(getDbProp64),
523 LUABIND_FUNC(setDbProp),
524 LUABIND_FUNC(setDbProp64),
525 LUABIND_FUNC(addDbProp),
526 LUABIND_FUNC(delDbProp),
527 LUABIND_FUNC(getDbRGBA),
528 LUABIND_FUNC(setDbRGBA),
529 LUABIND_FUNC(debugInfo),
530 LUABIND_FUNC(rawDebugInfo),
531 LUABIND_FUNC(dumpCallStack),
532 LUABIND_FUNC(getDefine),
533 LUABIND_FUNC(setContextHelpText),
534 #ifdef RYZOM_LUA_UCSTRING
535 luabind::def("messageBox", (void(*)(const ucstring &)) &messageBox),
536 luabind::def("messageBox", (void(*)(const ucstring &, const std::string &)) &messageBox),
537 luabind::def("messageBox", (void(*)(const ucstring &, const std::string &, int caseMode)) &messageBox),
538 #endif
539 luabind::def("messageBox", (void(*)(const std::string &)) &messageBox),
540 #ifdef RYZOM_LUA_UCSTRING
541 luabind::def("messageBoxWithHelp", (void(*)(const ucstring &)) &messageBoxWithHelp), // TODO: Lua UTF-8
542 luabind::def("messageBoxWithHelp", (void(*)(const ucstring &, const std::string &)) &messageBoxWithHelp), // TODO: Lua UTF-8
543 luabind::def("messageBoxWithHelp", (void(*)(const ucstring &, const std::string &, int caseMode)) &messageBoxWithHelp), // TODO: Lua UTF-8
544 #endif
545 luabind::def("messageBoxWithHelp", (void(*)(const std::string &)) &messageBoxWithHelp),
546 LUABIND_FUNC(replacePvpEffectParam),
547 LUABIND_FUNC(secondsSince1970ToHour),
548 #ifdef RYZOM_BG_DOWNLOADER
549 LUABIND_FUNC(pauseBGDownloader),
550 LUABIND_FUNC(unpauseBGDownloader),
551 LUABIND_FUNC(requestBGDownloaderPriority),
552 LUABIND_FUNC(getBGDownloaderPriority),
553 #endif
554 LUABIND_FUNC(loadBackground),
555 LUABIND_FUNC(getPatchLastErrorMessage),
556 LUABIND_FUNC(getPlayerSelectedSlot),
557 LUABIND_FUNC(isInGame),
558 LUABIND_FUNC(isPlayerSlotNewbieLand),
559 LUABIND_FUNC(getSheetLocalizedName),
560 LUABIND_FUNC(getSheetLocalizedDesc),
561 LUABIND_FUNC(getSkillIdFromName),
562 LUABIND_FUNC(getSkillLocalizedName),
563 LUABIND_FUNC(getMaxSkillValue),
564 LUABIND_FUNC(getBaseSkillValueMaxChildren),
565 LUABIND_FUNC(getMagicResistChance),
566 LUABIND_FUNC(getDodgeParryChance),
567 LUABIND_FUNC(browseNpcWebPage),
568 LUABIND_FUNC(clearHtmlUndoRedo),
569 LUABIND_FUNC(getDynString),
570 LUABIND_FUNC(isDynStringAvailable),
571 LUABIND_FUNC(isFullyPatched),
572 LUABIND_FUNC(getSheetType),
573 LUABIND_FUNC(getSheetFamily),
574 LUABIND_FUNC(getSheetName),
575 LUABIND_FUNC(getFameIndex),
576 LUABIND_FUNC(getFameName),
577 LUABIND_FUNC(getFameDBIndex),
578 LUABIND_FUNC(getFirstTribeFameIndex),
579 LUABIND_FUNC(getNbTribeFameIndex),
580 LUABIND_FUNC(getClientCfg),
581 LUABIND_FUNC(sendMsgToServer),
582 LUABIND_FUNC(sendMsgToServerPvpTag),
583 LUABIND_FUNC(sendMsgToServerAutoPact),
584 LUABIND_FUNC(sendMsgToServerUseItem),
585 LUABIND_FUNC(isGuildQuitAvailable),
586 LUABIND_FUNC(sortGuildMembers),
587 LUABIND_FUNC(getNbGuildMembers),
588 LUABIND_FUNC(getGuildMemberName),
589 LUABIND_FUNC(getGuildMemberGrade),
590 LUABIND_FUNC(isR2Player),
591 LUABIND_FUNC(getR2PlayerRace),
592 LUABIND_FUNC(isR2PlayerMale),
593 LUABIND_FUNC(getCharacterSheetSkel),
594 LUABIND_FUNC(getSheetId),
595 LUABIND_FUNC(getCharacterSheetRegionForce),
596 LUABIND_FUNC(getCharacterSheetRegionLevel),
597 LUABIND_FUNC(getRegionByAlias),
598 LUABIND_FUNC(getGroundZ),
599 LUABIND_FUNC(tell),
600 LUABIND_FUNC(isRingAccessPointInReach),
601 LUABIND_FUNC(updateTooltipCoords),
602 LUABIND_FUNC(isCtrlKeyDown),
603 LUABIND_FUNC(encodeURLUnicodeParam),
604 LUABIND_FUNC(getPlayerLevel),
605 LUABIND_FUNC(getPlayerVpa),
606 LUABIND_FUNC(getPlayerVpb),
607 LUABIND_FUNC(getPlayerVpc),
608 LUABIND_FUNC(getTargetLevel),
609 LUABIND_FUNC(getTargetForceRegion),
610 LUABIND_FUNC(getTargetLevelForce),
611 LUABIND_FUNC(getTargetSheet),
612 LUABIND_FUNC(getTargetVpa),
613 LUABIND_FUNC(getTargetVpb),
614 LUABIND_FUNC(getTargetVpc),
615 LUABIND_FUNC(isTargetNPC),
616 LUABIND_FUNC(isTargetPlayer),
617 LUABIND_FUNC(isTargetUser),
618 LUABIND_FUNC(isPlayerInPVPMode),
619 LUABIND_FUNC(isTargetInPVPMode)
623 // ***************************************************************************
624 static sint32 getTargetSlotNr()
626 const char *dbPath = "UI:VARIABLES:TARGET:SLOT";
627 CInterfaceManager *im = CInterfaceManager::getInstance();
628 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbPath, false);
630 if (!node) return 0;
632 if ((uint8) node->getValue32() == (uint8) CLFECOMMON::INVALID_SLOT)
634 return 0;
637 return node->getValue32();
640 static CEntityCL *getTargetEntity()
642 const char *dbPath = "UI:VARIABLES:TARGET:SLOT";
643 CInterfaceManager *im = CInterfaceManager::getInstance();
644 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbPath, false);
646 if (!node) return NULL;
648 if ((uint8) node->getValue32() == (uint8) CLFECOMMON::INVALID_SLOT)
650 return NULL;
653 return EntitiesMngr.entity((uint) node->getValue32());
657 static CEntityCL *getSlotEntity(uint slot)
659 return EntitiesMngr.entity(slot);
663 int CLuaIHMRyzom::getUI(CLuaState &ls)
665 //H_AUTO(Lua_CLuaIHM_getUI)
666 // params: "ui:interface:...".
667 // return: CInterfaceElement* (nil if error)
668 const char *funcName = "getUI";
669 CLuaIHM::check(ls, ls.getTop() == 1 || ls.getTop() == 2, funcName);
670 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
671 bool verbose = true;
673 if (ls.getTop() > 1)
675 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TBOOLEAN);
676 verbose = ls.toBoolean(2);
679 // get the string
680 std::string eltStr;
681 ls.toString(1, eltStr);
683 // return the element
684 CInterfaceManager *pIM = CInterfaceManager::getInstance();
685 CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(eltStr);
687 if (!pIE)
689 ls.pushNil();
691 if (verbose)
693 std::string stackContext;
694 ls.getStackContext(stackContext, 1);
695 debugInfo(NLMISC::toString("%s : getUI(): '%s' not found", stackContext.c_str(), eltStr.c_str()));
698 else
700 CLuaIHM::pushUIOnStack(ls, pIE);
703 return 1;
707 // ***************************************************************************
708 int CLuaIHMRyzom::formatUI(CLuaState &ls)
710 //H_AUTO(Lua_CLuaIHM_formatUI)
711 CLuaStackChecker lsc(&ls, 1);
713 // params: "expr", param1, param2....
714 // return: string with # and % parsed
715 CLuaIHM::checkArgMin(ls, "formatUI", 1);
716 CLuaIHM::check(ls, ls.isString(1), "formatUI() require a string in param1");
718 // get the string to format
719 std::string propVal;
720 ls.toString(1, propVal);
722 // *** format with %
723 CInterfaceManager *pIM = CInterfaceManager::getInstance();
724 std::string newPropVal, defError;
726 if (!CWidgetManager::getInstance()->getParser()->solveDefine(propVal, newPropVal, defError))
728 throw ELuaIHMException("formatUI(): Can't find define: '%s'", defError.c_str());
731 // *** format with any additional parameter and #1, #2, #3 etc...
732 // search backward, starting from bigger param to replace (thus avoid to replace #1 before #13 for instance...)
733 sint stackIndex = ls.getTop();
735 while (stackIndex > 1)
737 std::string paramValue;
738 ls.toString(stackIndex, paramValue);
740 // For stack param 4, the param index is 3 (because stack param 2 is the param No 1)
741 sint paramIndex = stackIndex - 1;
743 while (NLMISC::strFindReplace(newPropVal, NLMISC::toString("#%d", paramIndex), paramValue));
745 // next
746 stackIndex--;
749 // return result
750 ls.push(newPropVal);
751 return 1;
754 // ***************************************************************************
755 int CLuaIHMRyzom::formatDB(CLuaState &ls)
757 //H_AUTO(Lua_CLuaIHM_formatDB)
758 CLuaStackChecker lsc(&ls, 1);
760 // params: param1, param2....
761 // return: string with @ and , added
762 CLuaIHM::checkArgMin(ls, "formatDB", 1);
763 uint top = ls.getTop();
765 std::string dbRes;
767 for (uint i = 1; i <= top; i++)
769 if (i == 1)
770 dbRes = "@";
771 else
772 dbRes += ", @";
774 std::string paramValue;
775 ls.toString(i, paramValue);
776 dbRes += paramValue;
779 // return result
780 ls.push(dbRes);
781 return 1;
784 // ***************************************************************************
785 int CLuaIHMRyzom::dumpUI(CLuaState &ls)
787 //H_AUTO(Lua_CLuaIHM_dumpUI)
788 CLuaStackChecker lsc(&ls, 0);
790 // params: CInterfaceElement *
791 // return: none
792 CLuaIHM::checkArgCount(ls, "dumpUI", 1);
793 CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "dumpUI() requires a UI object in param 1");
795 // retrieve args
796 CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
798 if (!pIE)
799 debugInfo("UI: NULL");
800 else
802 // Display also Information on RefPtr (warning: don't modify pinfo!!!)
803 nlassert(pIE->pinfo);
804 debugInfo(NLMISC::toString("UI: %x. %s. RefPtrCount: %d", pIE, pIE->getId().c_str(),
805 pIE->pinfo->IsNullPtrInfo ? 0 : pIE->pinfo->RefCount));
808 return 0;
811 // ***************************************************************************
812 int CLuaIHMRyzom::setKeyboardContext(CLuaState &ls)
814 //H_AUTO(Lua_CLuaIHM_setKeyboardContext)
815 const char *funcName = "setKeyboardContext";
816 CLuaIHM::checkArgMin(ls, funcName, 1);
817 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
819 ActionsContext.setContext(ls.toString(1));
821 return 0;
825 // ***************************************************************************
826 int CLuaIHMRyzom::validMessageBox(CLuaState &ls)
828 //H_AUTO(Lua_CLuaIHM_validMessageBox)
829 const char *funcName = "validMessageBox";
830 CLuaIHM::checkArgCount(ls, funcName, 6);
831 #ifdef RYZOM_LUA_UCSTRING
832 ucstring msg;
833 ls.pushValue(1); // copy ucstring at the end of stack to pop it
834 CLuaIHM::check(ls, CLuaIHM::pop(ls, msg), "validMessageBox : ucstring wanted as first parameter");
835 #else
836 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
837 #endif
838 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
839 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING);
840 CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING);
841 CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING);
842 CLuaIHM::checkArgType(ls, funcName, 6, LUA_TSTRING);
843 CInterfaceManager *im = CInterfaceManager::getInstance();
844 #ifdef RYZOM_LUA_UCSTRING
845 im->validMessageBox(CInterfaceManager::QuestionIconMsg, msg.toUtf8(), ls.toString(2), ls.toString(3), ls.toString(4), ls.toString(5), ls.toString(6));
846 #else
847 im->validMessageBox(CInterfaceManager::QuestionIconMsg, ls.toString(1), ls.toString(2), ls.toString(3), ls.toString(4), ls.toString(5), ls.toString(6));
848 #endif
849 return 0;
852 // ***************************************************************************
853 int CLuaIHMRyzom::breakPoint(CLuaState &ls)
855 //H_AUTO(Lua_CLuaIHM_breakPoint)
856 std::string reason;
857 ls.getStackContext(reason, 1); // 1 because 0 is the current C function => return 1 for script called
858 LuaHelperStuff::formatLuaStackContext(reason);
859 NLMISC::InfoLog->displayRawNL(reason.c_str());
860 static volatile bool doAssert = true;
862 if (doAssert) // breakPoint can be discarded in case of looping assert
864 NLMISC_BREAKPOINT;
867 return 0;
871 // ***************************************************************************
872 int CLuaIHMRyzom::setTextFormatTaged(CLuaState &ls)
874 //H_AUTO(Lua_CLuaIHM_setTextFormatTaged)
875 // params: CViewText*, "text" (or ucstring)
876 // return: none
877 CLuaIHM::checkArgCount(ls, "setTextFormatTaged", 2);
879 // *** check and retrieve param 1
880 CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "setTextFormatTaged() requires a UI object in param 1");
881 CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
883 // *** check and retrieve param 2. must be a string or a ucstring
884 #ifdef RYZOM_LUA_UCSTRING
885 ucstring text;
887 if (ls.isString(2))
889 std::string str;
890 ls.toString(2, str);
891 text = str;
893 else
895 // try to pop a ucstring from the stack
896 // fail?
897 if (!CLuaIHM::pop(ls, text))
899 CLuaIHM::check(ls, false, "setTextFormatTaged() requires a string or a ucstring in param 2");
902 #else
903 string text;
904 if (ls.isString(2))
906 ls.toString(2, text);
908 #endif
910 // must be a view text
911 CViewText *vt = dynamic_cast<CViewText*>(pIE);
913 if (!vt)
914 throw ELuaIHMException("setTextFormatTaged(): '%s' is not a CViewText", pIE->getId().c_str());
916 // Set the text as format
917 #ifdef RYZOM_LUA_UCSTRING
918 vt->setTextFormatTaged(text.toUtf8());
919 #else
920 vt->setTextFormatTaged(text);
921 #endif
923 return 0;
927 struct CEmoteStruct
929 string EmoteId;
930 string Path;
931 string Anim;
932 bool UsableFromClientUI;
934 bool operator< (const CEmoteStruct &entry) const
936 string path1 = Path;
937 string path2 = entry.Path;
939 for (;;)
941 string::size_type pos1 = path1.find('|');
942 string::size_type pos2 = path2.find('|');
944 std::string s1 = toUpper(CI18N::get(path1.substr(0, pos1)));
945 std::string s2 = toUpper(CI18N::get(path2.substr(0, pos2)));
947 sint result = s1.compare(s2);
949 if (result != 0)
950 return (result < 0);
952 if (pos1 == string::npos)
953 return (pos2 != string::npos);
955 if (pos2 == string::npos)
956 return false;
958 path1 = path1.substr(pos1 + 1);
959 path2 = path2.substr(pos2 + 1);
962 return false;
966 // ***************************************************************************
967 int CLuaIHMRyzom::initEmotesMenu(CLuaState &ls)
969 //H_AUTO(Lua_CLuaIHM_initEmotesMenu)
970 CLuaIHM::checkArgCount(ls, "initEmotesMenu", 2);
971 CLuaIHM::checkArgType(ls, "initEmotesMenu", 2, LUA_TSTRING);
973 const std::string &emoteMenu = ls.toString(1);
974 const std::string &luaParams = ls.toString(2);
976 ls.newTable();
977 CLuaObject result(ls);
978 std::map<std::string, std::string> emoteList;
979 uint maxVisibleLine = 10;
981 CTextEmotListSheet *pTELS = dynamic_cast<CTextEmotListSheet*>(SheetMngr.get(CSheetId("list.text_emotes")));
982 if (pTELS == NULL)
983 return 0;
985 std::list<CEmoteStruct> entries;
987 if (entries.empty())
989 for (uint i = 0; i < pTELS->TextEmotList.size(); i++)
991 CEmoteStruct entry;
992 entry.EmoteId = pTELS->TextEmotList[i].EmoteId;
993 entry.Path = pTELS->TextEmotList[i].Path;
994 entry.Anim = pTELS->TextEmotList[i].Anim;
995 entry.UsableFromClientUI = pTELS->TextEmotList[i].UsableFromClientUI;
996 entries.push_back(entry);
999 entries.sort();
1002 // The list of behaviour missnames emotList
1003 CEmotListSheet *pEmotList = dynamic_cast<CEmotListSheet*>(SheetMngr.get(CSheetId("list.emot")));
1004 nlassert(pEmotList != NULL);
1005 nlassert(pEmotList->Emots.size() <= 255);
1006 // Get the focus beta tester flag
1007 bool betaTester = false;
1009 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1010 CSkillManager *pSM = CSkillManager::getInstance();
1012 betaTester = pSM->isTitleUnblocked(CHARACTER_TITLE::FBT);
1013 CGroupMenu *pInitRootMenu = dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId(emoteMenu));
1014 pInitRootMenu->reset();
1016 for (std::list<CEmoteStruct>::const_iterator it = entries.begin(); it != entries.end(); it++)
1018 std::string sEmoteId = (*it).EmoteId;
1019 std::string sState = (*it).Anim;
1020 std::string sName = (*it).Path;
1022 // Check that the emote can be added to UI
1023 // ---------------------------------------
1024 if ((*it).UsableFromClientUI == false)
1026 continue;
1029 // Check the emote reserved for FBT (hardcoded)
1030 // --------------------------------------------
1031 if (sState == "FBT" && !betaTester)
1032 continue;
1034 uint32 i, j;
1035 // Add to the game context menu
1036 // ----------------------------
1037 uint32 nbToken = 1;
1039 for (i = 0; i < sName.size(); ++i)
1040 if (sName[i] == '|')
1041 nbToken++;
1043 CGroupMenu *pRootMenu = dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId(emoteMenu));
1044 CGroupSubMenu *pMenu = pRootMenu->getRootMenu();
1046 for (i = 0; i < nbToken; ++i)
1048 if (i == 0)
1050 sName = sName.substr(sName.find('|') + 1, sName.size());
1052 else
1054 string sTmp;
1056 if (i != (nbToken - 1))
1057 sTmp = sName.substr(0, sName.find('|'));
1058 else
1059 sTmp = sName;
1061 // Look if this part of the path is already present
1062 bool bFound = false;
1064 for (j = 0; j < pMenu->getNumLine(); ++j)
1066 if (sTmp == pMenu->getLineId(j))
1068 bFound = true;
1069 break;
1073 if (!bFound) // Create it
1075 if (i != (nbToken - 1))
1077 pMenu->addLine(CI18N::get(sTmp), "", "", sTmp);
1078 // Create a sub menu
1079 CGroupSubMenu* pNewSubMenu = new CGroupSubMenu(CViewBase::TCtorParam());
1080 pMenu->setSubMenu(j, pNewSubMenu);
1082 else
1084 // Create a line
1085 pMenu->addLine(CI18N::get(sTmp), "lua",
1086 luaParams + "('" + sEmoteId + "', '" + toString(CI18N::get(sTmp)) + "')", sTmp);
1087 emoteList[sEmoteId] = (toLower(CI18N::get(sTmp)));
1091 // Jump to sub menu
1092 if (i != (nbToken - 1))
1094 pMenu = pMenu->getSubMenu(j);
1095 sName = sName.substr(sName.find('|') + 1, sName.size());
1100 pMenu->setMaxVisibleLine(maxVisibleLine);
1103 pInitRootMenu->setMaxVisibleLine(maxVisibleLine);
1104 std::map<std::string, std::string>::iterator it;
1106 for (it = emoteList.begin(); it != emoteList.end(); it++)
1108 result.setValue(it->first, it->second);
1111 result.push();
1113 return 1;
1116 // ***************************************************************************
1117 int CLuaIHMRyzom::hideAllWindows(CLuaState &/* ls */)
1119 //H_AUTO(Lua_CLuaIHM_hideAllWindows)
1120 CWidgetManager::getInstance()->hideAllWindows();
1121 return 0;
1124 // ***************************************************************************
1125 int CLuaIHMRyzom::hideAllNonSavableWindows(CLuaState &/* ls */)
1127 //H_AUTO(Lua_CLuaIHM_hideAllNonSavableWindows)
1128 CWidgetManager::getInstance()->hideAllNonSavableWindows();
1129 return 0;
1132 // ***************************************************************************
1133 int CLuaIHMRyzom::getDesktopIndex(CLuaState &ls)
1135 //H_AUTO(Lua_CLuaIHM_getDesktopIndex)
1136 ls.push(CInterfaceManager::getInstance()->getMode());
1137 return 1;
1140 // ***************************************************************************
1141 int CLuaIHMRyzom::setLuaBreakPoint(CLuaState &ls)
1143 //H_AUTO(Lua_CLuaIHM_setLuaBreakPoint)
1144 const char *funcName = "setLuaBreakPoint";
1145 CLuaIHM::checkArgCount(ls, funcName, 2);
1146 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
1147 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TNUMBER);
1148 #ifdef LUA_NEVRAX_VERSION
1150 if (LuaDebuggerIDE)
1152 LuaDebuggerIDE->setBreakPoint(ls.toString(1), (int) ls.toInteger(2));
1155 #endif
1156 return 0;
1159 // ***************************************************************************
1160 int CLuaIHMRyzom::getMainPageURL(CLuaState &ls)
1162 //H_AUTO(Lua_CLuaIHM_getMainPageURL)
1163 const char *funcName = "getMainPageURL";
1164 CLuaIHM::checkArgCount(ls, funcName, 0);
1165 ls.push(RingMainURL);
1166 return 1;
1169 // ***************************************************************************
1170 int CLuaIHMRyzom::getCharSlot(CLuaState &ls)
1172 //H_AUTO(Lua_CLuaIHM_getCharSlot)
1173 const char *funcName = "getCharSlot";
1174 CLuaIHM::checkArgCount(ls, funcName, 0);
1175 ls.push(PlayerSelectedSlot);
1176 return 1;
1179 int CLuaIHMRyzom::getServerSeason(CLuaState &ls)
1181 //H_AUTO(Lua_CLuaIHM_getServerSeason)
1182 const char *funcName = "getServerSeason";
1183 CLuaIHM::checkArgCount(ls, funcName, 0);
1184 extern uint8 ServerSeasonValue;
1185 ls.push(ServerSeasonValue);
1186 return 1;
1189 int CLuaIHMRyzom::computeCurrSeason(CLuaState &ls)
1191 //H_AUTO(Lua_CLuaIHM_computeCurrSeason)
1192 const char *funcName = "computeCurrSeason";
1193 CLuaIHM::checkArgCount(ls, funcName, 0);
1194 ls.push((sint)(::computeCurrSeason() + 1));
1195 return 1;
1198 int CLuaIHMRyzom::getAutoSeason(CLuaState &ls)
1200 //H_AUTO(Lua_CLuaIHM_getAutoSeason)
1201 const char *funcName = "getAutoSeason";
1202 CLuaIHM::checkArgCount(ls, funcName, 0);
1203 ls.push((sint)(StartupSeason + 1));
1204 return 1;
1207 int CLuaIHMRyzom::enableModalWindow(CLuaState &ls)
1209 //H_AUTO(Lua_CLuaIHM_enableModalWindow)
1210 const char *funcName = "enableModalWindow";
1211 CLuaIHM::checkArgCount(ls, funcName, 2);
1213 CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "enableModalWindow() requires a UI object in param 1");
1214 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
1216 CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
1217 std::string modalId = ls.toString(2);
1219 // convert to id
1220 if (pIE)
1222 CCtrlBase *ctrl = dynamic_cast<CCtrlBase*>(pIE);
1224 if (ctrl)
1226 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1227 CInterfaceGroup *group = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(modalId));
1229 if (group)
1231 UserControls.stopFreeLook();
1233 // enable the modal
1234 CWidgetManager::getInstance()->enableModalWindow(ctrl, group);
1236 else
1238 nlwarning("<CLuaIHMRyzom::enableModalWindow> Couldn't find group %s", modalId.c_str());
1243 return 0;
1246 int CLuaIHMRyzom::getMousePos(CLuaState &ls)
1248 sint32 x, y;
1249 CTool::getMousePos(x, y);
1250 ls.push(x);
1251 ls.push(y);
1253 return 2;
1256 int CLuaIHMRyzom::getMouseDown(CLuaState &ls)
1258 sint32 x, y;
1259 bool down;
1260 CTool::getMouseDown(down, x, y);
1261 ls.push(down);
1262 ls.push(x);
1263 ls.push(y);
1265 return 3;
1268 int CLuaIHMRyzom::getMouseMiddleDown(CLuaState &ls)
1270 sint32 x, y;
1271 bool down;
1272 CTool::getMouseMiddleDown(down, x, y);
1274 ls.push(down);
1275 ls.push(x);
1276 ls.push(y);
1278 return 3;
1281 int CLuaIHMRyzom::getMouseRightDown(CLuaState &ls)
1283 sint32 x, y;
1284 bool down;
1285 CTool::getMouseRightDown(down, x, y);
1287 ls.push(down);
1288 ls.push(x);
1289 ls.push(y);
1291 return 3;
1295 int CLuaIHMRyzom::getShapeIdAt(CLuaState &ls)
1297 const char* funcName = "getShapeIdAt";
1298 CLuaIHM::checkArgCount(ls, funcName, 2);
1299 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
1300 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TNUMBER);
1302 uint32 x = (uint32)ls.toInteger(1);
1303 uint32 y = (uint32)ls.toInteger(2);
1305 uint32 w, h;
1306 CViewRenderer &viewRender = *CViewRenderer::getInstance();
1307 viewRender.getScreenSize(w, h);
1308 if(x >= w || y >= h) {
1309 ls.push(-1);
1310 return 1;
1313 float cursX = (float)x/(float)w;
1314 float cursY = (float)y/(float)h;
1316 sint32 instance_idx;
1317 EntitiesMngr.getShapeInstanceUnderPos(cursX, cursY, instance_idx);
1318 ls.push(instance_idx);
1320 return 1;
1323 int CLuaIHMRyzom::getGroundAtMouse(CLuaState &ls)
1325 sint32 x, y;
1326 CTool::getMousePos(x, y);
1328 if (CTool::isInScreen(x, y))
1330 float cursX, cursY;
1331 cursX = x / (float) CTool::getScreenWidth();
1332 cursY = y / (float) CTool::getScreenHeight();
1333 CMatrix camMatrix = MainCam.getMatrix();
1334 NL3D::CFrustum camFrust = MainCam.getFrustum();
1335 NL3D::CViewport viewport = Driver->getViewport();
1336 // Get the Ray made by the mouse.
1337 CTool::CWorldViewRay worldViewRay;
1338 worldViewRay.OnMiniMap = false;
1339 worldViewRay.Valid = true;
1340 viewport.getRayWithPoint(cursX, cursY, worldViewRay.Origin, worldViewRay.Dir, camMatrix, camFrust);
1341 worldViewRay.Dir.normalize();
1342 worldViewRay.Right = camMatrix.getI().normed();
1343 worldViewRay.Up = camMatrix.getK().normed();
1344 CVector sceneInter;
1345 CTool::TRayIntersectionType rayInterType = CTool::computeLandscapeRayIntersection(worldViewRay, sceneInter);
1347 ls.push(sceneInter.x);
1348 ls.push(sceneInter.y);
1349 ls.push(sceneInter.z);
1351 else
1353 ls.push(0);
1354 ls.push(0);
1355 ls.push(0);
1358 return 3;
1361 // ***************************************************************************
1362 int CLuaIHMRyzom::getPlayerPos(CLuaState &ls)
1364 //H_AUTO(Lua_CLuaIHM_getPlayerPos)
1365 CLuaIHM::checkArgCount(ls, "getPlayerPos", 0);
1366 ls.push(UserEntity->pos().x);
1367 ls.push(UserEntity->pos().y);
1368 ls.push(UserEntity->pos().z);
1369 return 3;
1372 // ***************************************************************************
1373 int CLuaIHMRyzom::getPlayerFront(CLuaState &ls)
1375 CLuaIHM::checkArgCount(ls, "getPlayerFront", 0);
1376 ls.push(atan2(UserEntity->front().y, UserEntity->front().x));
1377 return 1;
1380 // ***************************************************************************
1381 int CLuaIHMRyzom::getPlayerDirection(CLuaState &ls)
1383 CLuaIHM::checkArgCount(ls, "getPlayerDirection", 0);
1384 ls.push(atan2(UserEntity->dir().y, UserEntity->dir().x));
1385 return 1;
1388 // ***************************************************************************
1389 int CLuaIHMRyzom::getPlayerGender(CLuaState &ls)
1391 CLuaIHM::checkArgCount(ls, "getPlayerGender", 0);
1392 ls.push((uint8)UserEntity->getGender());
1393 return 1;
1396 // ***************************************************************************
1397 int CLuaIHMRyzom::getPlayerName(CLuaState &ls)
1399 CLuaIHM::checkArgCount(ls, "getPlayerName", 0);
1400 ls.push(UserEntity->getEntityName());
1401 return 1;
1404 // ***************************************************************************
1405 int CLuaIHMRyzom::getPlayerTitleRaw(CLuaState &ls)
1407 CLuaIHM::checkArgCount(ls, "getPlayerTitleRaw", 0);
1408 ls.push(UserEntity->getTitleRaw());
1409 return 1;
1412 // ***************************************************************************
1413 int CLuaIHMRyzom::getPlayerTitle(CLuaState &ls)
1415 CLuaIHM::checkArgCount(ls, "getPlayerTitle", 0);
1416 ls.push(UserEntity->getTitle());
1417 return 1;
1420 // ***************************************************************************
1421 int CLuaIHMRyzom::getTargetPos(CLuaState &ls)
1423 CLuaIHM::checkArgCount(ls, "getTargetPos", 0);
1424 CEntityCL *target = getTargetEntity();
1426 if (!target) return 0;
1428 ls.push(target->pos().x);
1429 ls.push(target->pos().y);
1430 ls.push(target->pos().z);
1431 return 3;
1434 // ***************************************************************************
1435 int CLuaIHMRyzom::getTargetFront(CLuaState &ls)
1437 CLuaIHM::checkArgCount(ls, "getTargetFront", 0);
1438 CEntityCL *target = getTargetEntity();
1440 if (!target) return 0;
1442 ls.push(atan2(target->front().y, target->front().x));
1443 return 1;
1446 // ***************************************************************************
1447 int CLuaIHMRyzom::getTargetDirection(CLuaState &ls)
1449 CLuaIHM::checkArgCount(ls, "getTargetDirection", 0);
1450 CEntityCL *target = getTargetEntity();
1452 if (!target) return 0;
1454 ls.push(atan2(target->dir().y, target->dir().x));
1455 return 1;
1458 // ***************************************************************************
1459 int CLuaIHMRyzom::getTargetGender(CLuaState &ls)
1461 CLuaIHM::checkArgCount(ls, "getTargetGender", 0);
1462 CCharacterCL* target = (CCharacterCL*)getTargetEntity();
1464 if (!target) return (int)GSGENDER::unknown;
1466 ls.push((uint8)target->getGender());
1467 return 1;
1470 // ***************************************************************************
1471 int CLuaIHMRyzom::getTargetName(CLuaState &ls)
1473 CLuaIHM::checkArgCount(ls, "getTargetName", 0);
1474 CEntityCL *target = getTargetEntity();
1476 if (!target) return 0;
1478 ls.push(target->getEntityName());
1479 return 1;
1482 // ***************************************************************************
1483 int CLuaIHMRyzom::getTargetTitleRaw(CLuaState &ls)
1485 CLuaIHM::checkArgCount(ls, "getTargetTitleRaw", 0);
1486 CEntityCL *target = getTargetEntity();
1488 if (!target) return 0;
1490 ls.push(target->getTitleRaw());
1491 return 1;
1494 // ***************************************************************************
1495 int CLuaIHMRyzom::getTargetTitle(CLuaState &ls)
1497 CLuaIHM::checkArgCount(ls, "getTargetTitle", 0);
1498 CEntityCL *target = getTargetEntity();
1500 if (!target) return 0;
1502 ls.push(target->getTitle());
1503 return 1;
1506 // ***************************************************************************
1507 int CLuaIHMRyzom::addSearchPathUser(CLuaState &ls)
1509 //H_AUTO(Lua_CLuaIHM_addSearchPathUser)
1510 bool memoryCompressed = CPath::isMemoryCompressed();
1512 if (memoryCompressed)
1514 CPath::memoryUncompress();
1517 CPath::addSearchPath("user/", true, false, NULL);
1519 if (memoryCompressed)
1521 CPath::memoryCompress();
1524 return 0;
1527 // ***************************************************************************
1528 int CLuaIHMRyzom::isPlayerFreeTrial(CLuaState &ls)
1530 CLuaIHM::checkArgCount(ls, "isPlayerFreeTrial", 0);
1531 ls.push(FreeTrial);
1532 return 1;
1537 // ***************************************************************************
1538 int CLuaIHMRyzom::disableContextHelp(CLuaState &ls)
1540 //H_AUTO(Lua_CLuaIHM_disableContextHelp)
1541 CLuaStackChecker lsc(&ls, 0);
1542 CLuaIHM::checkArgCount(ls, "disableContextHelp", 0);
1543 CWidgetManager::getInstance()->disableContextHelp();
1544 return 0;
1547 // ***************************************************************************
1548 int CLuaIHMRyzom::disableContextHelpForControl(CLuaState &ls)
1550 //H_AUTO(Lua_CLuaIHM_disableContextHelpForControl)
1551 CLuaStackChecker lsc(&ls, 0);
1553 // params: CCtrlBase*
1554 // return: none
1555 CLuaIHM::checkArgCount(ls, "disableContextHelpForControl", 1);
1556 CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "disableContextHelpForControl() requires a UI object in param 1");
1558 // retrieve args
1559 CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
1561 // go
1562 CWidgetManager::getInstance()->disableContextHelpForControl(dynamic_cast<CCtrlBase*>(pIE));
1564 return 0;
1568 // ***************************************************************************
1569 int CLuaIHMRyzom::isPlayerNewbie(CLuaState &ls)
1571 CLuaIHM::checkArgCount(ls, "isPlayerNewbie", 0);
1572 CInterfaceManager *im = CInterfaceManager::getInstance();
1573 ls.push(NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:IS_NEWBIE")->getValueBool());
1574 return 1;
1578 // ***************************************************************************
1579 int CLuaIHMRyzom::isInRingMode(CLuaState &ls)
1581 CLuaIHM::checkArgCount(ls, "isInRingMode", 0);
1582 extern bool IsInRingMode();
1583 ls.push(IsInRingMode());
1584 return 1;
1587 // ***************************************************************************
1588 int CLuaIHMRyzom::getUserRace(CLuaState &ls)
1590 CLuaIHM::checkArgCount(ls, "getUserRace", 0);
1592 if (!UserEntity || !UserEntity->playerSheet())
1594 ls.push("Unknwown");
1596 else
1598 ls.push(EGSPD::CPeople::toString(UserEntity->playerSheet()->People));
1601 return 1;
1604 // ***************************************************************************
1605 int CLuaIHMRyzom::getSheet2idx(CLuaState &ls)
1607 CLuaIHM::checkArgCount(ls, "getSheet2idx", 2);
1608 CLuaIHM::checkArgType(ls, "getSheet2idx", 1, LUA_TSTRING);
1609 CLuaIHM::checkArgType(ls, "getSheet2idx", 2, LUA_TNUMBER);
1611 const std::string &sheedtName = ls.toString(1);
1612 uint32 slotId = (uint32)ls.toInteger(2);
1614 NLMISC::CSheetId sheetId;
1616 if (sheetId.buildSheetId(sheedtName))
1618 uint32 idx = CVisualSlotManager::getInstance()->sheet2Index(sheetId, (SLOTTYPE::EVisualSlot)slotId);
1619 ls.push(idx);
1621 else
1622 return 0;
1624 return 1;
1627 // ***************************************************************************
1628 int CLuaIHMRyzom::getTargetSlot(CLuaState &ls)
1630 uint32 slot = (uint32)getTargetSlotNr();
1631 ls.push(slot);
1632 return 1;
1635 // ***************************************************************************
1636 int CLuaIHMRyzom::setTargetAsInterlocutor(CLuaState &ls)
1638 uint32 slot = (uint32)getTargetSlotNr();
1639 UserEntity->interlocutor(slot);
1640 return 0;
1643 // ***************************************************************************
1644 int CLuaIHMRyzom::unsetTargetAsInterlocutor(CLuaState &ls)
1646 uint32 slot = (uint32)getTargetSlotNr();
1647 UserEntity->interlocutor(CLFECOMMON::INVALID_SLOT);
1648 return 0;
1651 // ***************************************************************************
1652 int CLuaIHMRyzom::getSlotDataSetId(CLuaState &ls)
1654 CLuaIHM::checkArgCount(ls, "getSlotDataSetId", 1);
1655 CLuaIHM::checkArgType(ls, "getSlotDataSetId", 1, LUA_TNUMBER);
1657 uint32 slot = (uint32)ls.toInteger(1);
1658 CEntityCL *e = getSlotEntity(slot);
1659 string id = toString(e->dataSetId());
1660 ls.push(id);
1661 return 1;
1664 int CLuaIHMRyzom::getClientCfgVar(CLuaState &ls)
1666 //H_AUTO(Lua_CLuaIHM_getClientCfgVar)
1667 const char *funcName = "getClientCfgVar";
1668 CLuaIHM::checkArgCount(ls, funcName, 1);
1669 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
1670 std::string varName = ls.toString(1);
1672 CConfigFile::CVar *v = ClientCfg.ConfigFile.getVarPtr(varName);
1674 if (!v) return 0;
1676 if (v->size() == 1)
1678 switch (v->Type)
1680 case CConfigFile::CVar::T_REAL:
1681 ls.push(v->asDouble());
1682 return 1;
1683 break;
1685 case CConfigFile::CVar::T_STRING:
1686 ls.push(v->asString());
1687 return 1;
1688 break;
1690 default: // handle both T_INT && T_BOOL
1691 case CConfigFile::CVar::T_INT:
1692 ls.push(v->asInt());
1693 return 1;
1694 break;
1697 else
1699 ls.newTable();
1700 CLuaObject result(ls);
1701 uint count = 0;
1703 for (uint i = 0; i < v->StrValues.size(); i++)
1705 result.setValue(toString(count).c_str(), v->StrValues[i]);
1706 count++;
1709 for (uint i = 0; i < v->IntValues.size(); i++)
1711 result.setValue(toString(count).c_str(), (sint32)v->IntValues[i]);
1712 count++;
1715 for (uint i = 0; i < v->RealValues.size(); i++)
1717 result.setValue(toString(count).c_str(), (double)v->RealValues[i]);
1718 count++;
1721 result.push();
1722 return 1;
1725 return 0;
1728 int CLuaIHMRyzom::displaySystemInfo(CLuaState &ls)
1730 //H_AUTO(Lua_CLuaIHM_displaySystemInfo)
1731 const char *funcName = "displaySystemInfo";
1732 CLuaIHM::checkArgCount(ls, funcName, 2);
1733 #ifdef RYZOM_LUA_UCSTRING
1734 CLuaIHM::checkArgTypeUCString(ls, funcName, 1);
1735 #else
1736 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
1737 #endif
1738 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
1739 #ifdef RYZOM_LUA_UCSTRING
1740 ucstring msg;
1741 nlverify(CLuaIHM::getUCStringOnStack(ls, 1, msg));
1742 #endif
1743 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1744 #ifdef RYZOM_LUA_UCSTRING
1745 pIM->displaySystemInfo(msg.toUtf8(), ls.toString(2));
1746 #else
1747 pIM->displaySystemInfo(ls.toString(1), ls.toString(2));
1748 #endif
1749 return 0;
1752 int CLuaIHMRyzom::setWeatherValue(CLuaState &ls)
1754 //H_AUTO(Lua_CLuaIHM_setWeatherValue)
1755 const char *funcName = "setWeatherValue";
1756 CLuaIHM::checkArgMin(ls, funcName, 1);
1757 CLuaIHM::checkArgMax(ls, funcName, 2);
1758 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TBOOLEAN);
1759 // bool autoWeather = ls.toBoolean(1);
1760 ClientCfg.ManualWeatherSetup = !ls.toBoolean(1);
1762 if (ls.getTop() == 2)
1764 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TNUMBER);
1765 ManualWeatherValue = (float) ls.toNumber(2);
1768 return 0;
1771 int CLuaIHMRyzom::getWeatherValue(CLuaState &ls)
1773 //H_AUTO(Lua_CLuaIHM_getWeatherValue)
1774 const char *funcName = "getWeatherValue";
1775 CLuaIHM::checkArgCount(ls, funcName, 0);
1776 uint64 currDay = RT.getRyzomDay();
1777 float currHour = (float) RT.getRyzomTime();
1778 float weather = 0.f;
1779 if (ContinentMngr.cur())
1781 weather = ::getBlendedWeather(currDay, currHour, *WeatherFunctionParams, ContinentMngr.cur()->WeatherFunction);
1784 ls.push(weather);
1785 return 1;
1788 int CLuaIHMRyzom::getUICaller(CLuaState &ls)
1790 //H_AUTO(Lua_CLuaIHM_getUICaller)
1791 CLuaStackChecker lsc(&ls, 1);
1793 // params: none.
1794 // return: CInterfaceElement* (nil if error)
1795 CInterfaceElement *pIE = CHandlerLUA::getUICaller();
1797 if (!pIE)
1799 ls.pushNil();
1800 debugInfo(toString("getUICaller(): No UICaller found. return Nil"));
1802 else
1804 CLuaIHM::pushUIOnStack(ls, pIE);
1807 return 1;
1810 // ***************************************************************************
1811 int CLuaIHMRyzom::getIndexInDB(CLuaState &ls)
1813 //H_AUTO(Lua_CLuaIHM_getIndexInDB)
1814 CLuaStackChecker lsc(&ls, 1);
1816 // params: CDBCtrlSheet*
1817 // return: index in DB of a dbctrlsheet (empty if error)
1818 CLuaIHM::checkArgCount(ls, "getIndexInDB", 1);
1819 CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "getIndexInDB() requires a UI object in param 1");
1821 // retrieve args
1822 CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
1823 CDBCtrlSheet *pCS = dynamic_cast<CDBCtrlSheet*>(pIE);
1825 // get the index in db
1826 if (pCS)
1827 ls.push(pCS->getIndexInDB());
1828 else
1829 ls.push((sint)0);
1831 return 1;
1834 // ***************************************************************************
1835 int CLuaIHMRyzom::createGroupInstance(CLuaState &ls)
1837 //H_AUTO(Lua_CLuaIHM_createGroupInstance)
1838 const char *funcName = "createGroupInstance";
1839 CLuaIHM::checkArgCount(ls, funcName, 3);
1840 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
1841 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
1842 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TTABLE);
1843 std::vector<std::pair<std::string, std::string> > templateParams;
1844 CLuaObject params;
1845 params.pop(ls);
1846 ENUM_LUA_TABLE(params, it)
1848 if (!it.nextKey().isString())
1850 nlwarning("%s : bad key encountered with type %s, string expected.", funcName, it.nextKey().getTypename());
1851 continue;
1854 if (!it.nextValue().isString())
1856 nlwarning("%s : bad value encountered with type %s for key %s, string expected.", funcName, it.nextValue().getTypename(), it.nextKey().toString().c_str());
1857 continue;
1860 templateParams.push_back(std::pair<std::string, std::string>(it.nextKey().toString(), it.nextValue().toString())); // strange compilation bug here when I use std::make_pair ... :(
1862 CInterfaceManager *im = CInterfaceManager::getInstance();
1863 CInterfaceGroup *result = CWidgetManager::getInstance()->getParser()->createGroupInstance(ls.toString(1), ls.toString(2), templateParams);
1865 if (!result)
1867 ls.pushNil();
1869 else
1871 CLuaIHM::pushUIOnStack(ls, result);
1874 return 1;
1877 // ***************************************************************************
1878 int CLuaIHMRyzom::createRootGroupInstance(CLuaState &ls)
1880 //H_AUTO(Lua_CLuaIHM_createGroupInstance)
1881 const char *funcName = "createRootGroupInstance";
1882 CLuaIHM::checkArgCount(ls, funcName, 3);
1883 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
1884 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
1885 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TTABLE);
1886 std::vector<std::pair<std::string, std::string> > templateParams;
1887 CLuaObject params;
1888 params.pop(ls);
1889 ENUM_LUA_TABLE(params, it)
1891 if (!it.nextKey().isString())
1893 nlwarning("%s : bad key encountered with type %s, string expected.", funcName, it.nextKey().getTypename());
1894 continue;
1897 if (!it.nextValue().isString())
1899 nlwarning("%s : bad value encountered with type %s for key %s, string expected.", funcName, it.nextValue().getTypename(), it.nextKey().toString().c_str());
1900 continue;
1903 templateParams.push_back(std::pair<std::string, std::string>(it.nextKey().toString(), it.nextValue().toString())); // strange compilation bug here when I use std::make_pair ... :(
1905 CInterfaceManager *im = CInterfaceManager::getInstance();
1906 CInterfaceGroup *result = CWidgetManager::getInstance()->getParser()->createGroupInstance(ls.toString(1), "ui:interface:" + string(ls.toString(2)), templateParams);
1908 if (!result)
1910 ls.pushNil();
1912 else
1914 result->setId("ui:interface:" + string(ls.toString(2)));
1915 result->updateCoords();
1916 CWidgetManager::getInstance()->addWindowToMasterGroup("ui:interface", result);
1917 CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
1918 result->setParent(pRoot);
1920 if (pRoot)
1921 pRoot->addGroup(result);
1923 result->setActive(true);
1924 CLuaIHM::pushUIOnStack(ls, result);
1927 return 1;
1930 // ***************************************************************************
1931 int CLuaIHMRyzom::createUIElement(CLuaState &ls)
1933 //H_AUTO(Lua_CLuaIHM_createUIElement)
1934 const char *funcName = "addUIElement";
1935 CLuaIHM::checkArgCount(ls, funcName, 3);
1936 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
1937 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
1938 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TTABLE);
1939 std::vector<std::pair<std::string, std::string> > templateParams;
1940 CLuaObject params;
1941 params.pop(ls);
1942 ENUM_LUA_TABLE(params, it)
1944 if (!it.nextKey().isString())
1946 nlwarning("%s : bad key encountered with type %s, string expected.", funcName, it.nextKey().getTypename());
1947 continue;
1950 if (!it.nextValue().isString())
1952 nlwarning("%s : bad value encountered with type %s for key %s, string expected.", funcName, it.nextValue().getTypename(), it.nextKey().toString().c_str());
1953 continue;
1956 templateParams.push_back(std::pair<std::string, std::string>(it.nextKey().toString(), it.nextValue().toString())); // strange compilation bug here when I use std::make_pair ... :(
1958 CInterfaceManager *im = CInterfaceManager::getInstance();
1959 CInterfaceElement *result = CWidgetManager::getInstance()->getParser()->createUIElement(ls.toString(1), ls.toString(2), templateParams);
1961 if (!result)
1963 ls.pushNil();
1965 else
1967 CLuaIHM::pushUIOnStack(ls, result);
1970 return 1;
1974 // ***************************************************************************
1975 int CLuaIHMRyzom::displayBubble(CLuaState &ls)
1977 //H_AUTO(Lua_CLuaIHM_createUIElement)
1978 const char *funcName = "displayBubble";
1979 CLuaIHM::checkArgCount(ls, funcName, 3);
1980 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
1981 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
1982 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TTABLE);
1983 std::vector<std::string> strs;
1984 std::vector<std::string> links;
1985 CLuaObject params;
1986 params.pop(ls);
1987 ENUM_LUA_TABLE(params, it)
1989 if (!it.nextKey().isString())
1991 nlwarning("%s : bad key encountered with type %s, string expected.", funcName, it.nextKey().getTypename());
1992 continue;
1995 if (!it.nextValue().isString())
1997 nlwarning("%s : bad value encountered with type %s for key %s, string expected.", funcName, it.nextValue().getTypename(), it.nextKey().toString().c_str());
1998 continue;
2001 links.push_back(it.nextValue().toString());
2002 strs.push_back(it.nextKey().toString());
2005 InSceneBubbleManager.webIgChatOpen((uint32)ls.toInteger(1), ls.toString(2), strs, links);
2007 return 1;
2010 int CLuaIHMRyzom::launchContextMenuInGame(CLuaState &ls)
2012 //H_AUTO(Lua_CLuaIHM_launchContextMenuInGame)
2013 CLuaStackChecker lsc(&ls);
2014 CLuaIHM::checkArgCount(ls, "launchContextMenuInGame", 1);
2015 CLuaIHM::check(ls, ls.isString(1), "launchContextMenuInGame() requires a string in param 1");
2016 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2017 pIM->launchContextMenuInGame(ls.toString(1));
2018 return 0;
2021 // ***************************************************************************
2022 int CLuaIHMRyzom::parseInterfaceFromString(CLuaState &ls)
2024 //H_AUTO(Lua_CLuaIHM_parseInterfaceFromString)
2025 CLuaStackChecker lsc(&ls, 1);
2026 CLuaIHM::checkArgCount(ls, "parseInterfaceFromString", 1);
2027 CLuaIHM::check(ls, ls.isString(1), "parseInterfaceFromString() requires a string in param 1");
2028 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2029 std::vector<std::string> script(1);
2030 script[0] = ls.toString(1);
2031 ls.push(pIM->parseInterface(script, true, false));
2032 return 1;
2035 // ***************************************************************************
2036 int CLuaIHMRyzom::updateAllLocalisedElements(CLuaState &ls)
2038 //H_AUTO(Lua_CLuaIHM_updateAllLocalisedElements)
2039 TTime startTime = CTime::getLocalTime();
2041 CLuaStackChecker lsc(&ls);
2042 CLuaIHM::checkArgCount(ls, "updateAllLocalisedElements", 0);
2043 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2044 CWidgetManager::getInstance()->updateAllLocalisedElements();
2046 TTime endTime = CTime::getLocalTime();
2048 if (ClientCfg.R2EDVerboseParseTime)
2050 nlinfo("%.2f seconds for 'updateAllLocalisedElements'", (endTime - startTime) / 1000.f);
2053 return 0;
2056 // ***************************************************************************
2057 int CLuaIHMRyzom::getCompleteIslands(CLuaState &ls)
2059 //H_AUTO(Lua_CLuaIHM_getCompleteIslands)
2060 const char *funcName = "getCompleteIslands";
2061 CLuaIHM::checkArgCount(ls, funcName, 0);
2063 ls.newTable();
2064 CLuaObject result(ls);
2066 // load entryPoints
2067 CScenarioEntryPoints scenarioEntryPoints = CScenarioEntryPoints::getInstance();
2068 const CScenarioEntryPoints::TCompleteIslands &islands = scenarioEntryPoints.getCompleteIslands();
2070 CScenarioEntryPoints::TCompleteIslands::const_iterator island(islands.begin()), lastIsland(islands.end());
2072 for (; island != lastIsland ; ++island)
2074 ls.newTable();
2075 CLuaObject islandTable(ls);
2076 islandTable.setValue("continent", island->Continent);
2077 islandTable.setValue("xmin", island->XMin);
2078 islandTable.setValue("ymin", island->YMin);
2079 islandTable.setValue("xmax", island->XMax);
2080 islandTable.setValue("ymax", island->YMax);
2082 ls.newTable();
2083 CLuaObject entrypointsTable(ls);
2085 for (uint e = 0; e < island->EntryPoints.size(); e++)
2087 const CScenarioEntryPoints::CShortEntryPoint &entryPoint = island->EntryPoints[e];
2088 ls.newTable();
2089 CLuaObject entrypointTable(ls);
2090 entrypointTable.setValue("x", entryPoint.X);
2091 entrypointTable.setValue("y", entryPoint.Y);
2093 entrypointsTable.setValue(entryPoint.Location, entrypointTable);
2096 islandTable.setValue("entrypoints", entrypointsTable);
2098 result.setValue(island->Island, islandTable);
2101 result.push();
2103 return 1;
2106 // ***************************************************************************
2107 int CLuaIHMRyzom::getIslandId(CLuaState &ls)
2109 //H_AUTO(Lua_CLuaIHM_getIslandId)
2110 const char *funcName = "getIslandId";
2111 CLuaIHM::checkArgCount(ls, funcName, 1);
2112 CLuaIHM::check(ls, ls.isString(1), "getIslandId() requires a string in param 1");
2114 CScenarioEntryPoints scenarioEntryPoints = CScenarioEntryPoints::getInstance();
2115 uint32 id = scenarioEntryPoints.getIslandId(ls.toString(1));
2116 ls.push(id);
2117 return 1;
2120 // ***************************************************************************
2122 // addShape("shape", .x, .y, .z, "angle", .scale, collision?, "context", "url", highlight?, transparency?, "texture", "skeleton", "inIgZone?")
2124 //********
2125 int CLuaIHMRyzom::addShape(CLuaState &ls)
2127 const char* funcName = "addShape";
2128 CLuaIHM::checkArgMin(ls, funcName, 1);
2129 CLuaIHM::checkArgMax(ls, funcName, 14);
2130 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
2132 sint32 idx = -1;
2134 if (!Scene)
2136 nlwarning("No scene available");
2137 ls.pushNil();
2138 return 1;
2141 string shape = ls.toString(1);
2143 float x = 0.0f, y = 0.0f, z = 0.0f;
2144 float scale = 1.0f;
2145 string context, url, skeleton, texture;
2146 bool highlight = false;
2147 bool transparency = false;
2148 bool collision = true;
2149 bool inIgZone = false;
2151 if (ls.getTop() >= 2)
2153 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TNUMBER);
2154 x = (float) ls.toNumber(2);
2157 if (ls.getTop() >= 3)
2159 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TNUMBER);
2160 y = (float) ls.toNumber(3);
2163 if (ls.getTop() >= 4)
2165 CLuaIHM::checkArgType(ls, funcName, 4, LUA_TNUMBER);
2166 z = (float) ls.toNumber(4);
2170 if (x == 0.f && y == 0.f)
2172 x = UserEntity->pos().x;
2173 y = UserEntity->pos().y;
2174 z = UserEntity->pos().z;
2177 CVector userDir = UserEntity->dir();
2179 if (ls.getTop() >= 5)
2181 CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING);
2182 string angle = ls.toString(5);
2184 if (angle != "user")
2186 float a;
2187 fromString(angle, a);
2188 userDir = CVector(sin(a), cos(a), 0.f);
2192 if (ls.getTop() >= 6)
2194 CLuaIHM::checkArgType(ls, funcName, 6, LUA_TNUMBER);
2195 scale = (float) ls.toNumber(6);
2198 if (ls.getTop() >= 7)
2200 CLuaIHM::checkArgType(ls, funcName, 7, LUA_TBOOLEAN);
2201 collision = ls.toBoolean(7);
2204 if (ls.getTop() >= 8)
2206 CLuaIHM::checkArgType(ls, funcName, 8, LUA_TSTRING);
2207 context = ls.toString(8);
2210 if (ls.getTop() >= 9)
2212 CLuaIHM::checkArgType(ls, funcName, 9, LUA_TSTRING);
2213 url = ls.toString(9);
2216 if (ls.getTop() >= 10)
2218 CLuaIHM::checkArgType(ls, funcName, 10, LUA_TBOOLEAN);
2219 highlight = ls.toBoolean(10);
2222 if (ls.getTop() >= 11)
2224 CLuaIHM::checkArgType(ls, funcName, 11, LUA_TBOOLEAN);
2225 transparency = ls.toBoolean(11);
2228 if (ls.getTop() >= 12)
2230 CLuaIHM::checkArgType(ls, funcName, 12, LUA_TSTRING);
2231 texture = ls.toString(12);
2234 if (ls.getTop() >= 13)
2236 CLuaIHM::checkArgType(ls, funcName, 13, LUA_TSTRING);
2237 skeleton = ls.toString(13);
2240 if (ls.getTop() >= 14)
2242 CLuaIHM::checkArgType(ls, funcName, 14, LUA_TBOOLEAN);
2243 inIgZone = ls.toBoolean(14);
2246 CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector(x, y, z), context, url, collision, inIgZone, idx);
2247 UInstance instance = instref.Instance;
2249 if(!instance.empty())
2251 for(uint j=0;j<instance.getNumMaterials();j++)
2253 if (!highlight)
2255 instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
2256 instance.getMaterial(j).setEmissive(CRGBA(255,255,255,255));
2257 instance.getMaterial(j).setShininess(10.0f);
2259 else
2261 instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
2262 instance.getMaterial(j).setEmissive(CRGBA(255,0,0,255));
2263 instance.getMaterial(j).setShininess(1000.0f);
2266 if (!texture.empty())
2268 sint numStages = instance.getMaterial(j).getLastTextureStage() + 1;
2269 for(sint l = 0; l < numStages; l++)
2271 if (instance.getMaterial(j).isTextureFile((uint) l))
2273 instance.getMaterial(j).setTextureFileName(texture, (uint) l);
2279 if (!transparency)
2280 makeInstanceTransparent(instance, 255, false);
2281 else
2282 makeInstanceTransparent(instance, 100, true);
2284 instance.setClusterSystem(UserEntity->getClusterSystem()); // for simplicity, assume it is in the same
2285 // cluster system than the user
2286 // Compute the direction Matrix
2287 CMatrix dir;
2288 dir.identity();
2289 CVector vi = userDir^CVector(0.f, 0.f, 1.f);
2290 CVector vk = vi^userDir;
2291 dir.setRot(vi, userDir, vk, true);
2292 // Set Orientation : User Direction should be normalized.
2293 if (!skeleton.empty())
2295 USkeleton skel = Scene->createSkeleton(skeleton);
2296 if (!skel.empty())
2298 skel.bindSkin(instance);
2299 skel.setClusterSystem(UserEntity->getClusterSystem());
2300 skel.setScale(skel.getScale()*scale);
2301 skel.setPos(CVector(x, y, z));
2302 skel.setRotQuat(dir.getRot());
2305 else
2307 instance.setScale(instance.getScale()*scale);
2308 instance.setPos(CVector(x, y, z));
2309 instance.setRotQuat(dir.getRot());
2312 instance.setTransformMode(UTransformable::RotEuler);
2314 // if the shape is a particle system, additionnal parameters are user params
2315 UParticleSystemInstance psi;
2316 psi.cast (instance);
2317 /*if (!psi.empty())
2319 // set each user param that is present
2320 for(uint k = 0; k < 4; ++k)
2322 if (args.size() >= (k + 2))
2324 float uparam;
2325 if (fromString(args[k + 1], uparam))
2327 psi.setUserParam(k, uparam);
2329 else
2331 nlwarning("Cant read param %d", k);
2337 UMovePrimitive *primitive = instref.Primitive;
2338 if (primitive)
2340 NLMISC::CAABBox bbox;
2341 instance.getShapeAABBox(bbox);
2343 primitive->setReactionType(UMovePrimitive::Slide);
2344 primitive->setTriggerType(UMovePrimitive::NotATrigger);
2345 primitive->setAbsorbtion(0);
2347 primitive->setPrimitiveType(UMovePrimitive::_2DOrientedBox);
2348 primitive->setSize((bbox.getMax().x - bbox.getMin().x)*scale, (bbox.getMax().y - bbox.getMin().y)*scale);
2349 primitive->setHeight((bbox.getMax().z - bbox.getMin().z)*scale);
2351 primitive->setCollisionMask(MaskColPlayer | MaskColNpc | MaskColDoor);
2352 primitive->setOcclusionMask(MaskColPlayer | MaskColNpc | MaskColDoor);
2353 primitive->setObstacle(true);
2356 primitive->setGlobalPosition(instance.getPos(), dynamicWI);
2358 primitive->insertInWorldImage(dynamicWI);
2362 ls.push(idx);
2363 return 1;
2366 int CLuaIHMRyzom::setupShape(CLuaState &ls)
2368 const char* funcName = "setupShape";
2369 CLuaIHM::checkArgCount(ls, funcName, 2);
2370 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2371 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TTABLE);
2373 uint32 idx = (uint32)ls.toInteger(1);
2375 std::vector<string> keys;
2376 std::vector<string> values;
2377 CLuaObject params;
2378 params.pop(ls);
2380 ENUM_LUA_TABLE(params, it)
2382 if (!it.nextKey().isString())
2384 nlwarning("%s : bad key encountered with type %s, string expected.", funcName, it.nextKey().getTypename());
2385 continue;
2388 if (!it.nextValue().isString())
2390 nlwarning("%s : bad value encountered with type %s for key %s, string expected.", funcName, it.nextValue().getTypename(), it.nextKey().toString().c_str());
2391 continue;
2394 values.push_back(it.nextValue().toString());
2395 keys.push_back(it.nextKey().toString());
2398 if (EntitiesMngr.setupInstance(idx, keys, values))
2399 ls.push(1);
2400 else
2401 ls.pushNil();
2403 return 1;
2406 int CLuaIHMRyzom::moveShape(CLuaState &ls)
2408 const char* funcName = "moveShape";
2409 CLuaIHM::checkArgCount(ls, funcName, 4);
2410 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2411 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
2412 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING);
2413 CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING);
2415 uint32 idx = (uint32)ls.toInteger(1);
2417 CVector pos = EntitiesMngr.getInstancePos(idx);
2419 string x = ls.toString(2);
2420 string y = ls.toString(3);
2421 string z = ls.toString(4);
2423 float move_x = 0;
2424 float move_y = 0;
2425 float move_z = 0;
2427 if (!x.empty())
2429 if (x[0] == '+')
2431 fromString(x.substr(1), move_x);
2432 pos.x += move_x;
2434 else
2436 fromString(x, move_x);
2437 pos.x = move_x;
2441 if (!y.empty())
2443 if (y[0] == '+')
2445 fromString(y.substr(1), move_y);
2446 pos.y += move_y;
2448 else
2450 fromString(y, move_y);
2451 pos.y = move_y;
2455 if (!z.empty())
2457 if (z[0] == '+')
2459 fromString(z.substr(1), move_z);
2460 pos.z += move_z;
2462 else
2464 fromString(z, move_z);
2465 pos.z = move_z;
2469 if (EntitiesMngr.setInstancePos(idx, pos))
2470 ls.push(1);
2471 else
2472 ls.pushNil();
2474 return 1;
2477 int CLuaIHMRyzom::rotateShape(CLuaState &ls)
2479 const char* funcName = "rotateShape";
2480 CLuaIHM::checkArgCount(ls, funcName, 4);
2481 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2482 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
2483 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING);
2484 CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING);
2486 uint32 idx = (uint32)ls.toInteger(1);
2488 CVector rot = EntitiesMngr.getInstanceRot(idx);
2490 string x = ls.toString(2);
2491 string y = ls.toString(3);
2492 string z = ls.toString(4);
2494 float rot_x = 0;
2495 float rot_y = 0;
2496 float rot_z = 0;
2498 if (!x.empty())
2500 if (x[0] == '+')
2502 fromString(x.substr(1), rot_x);
2503 rot.x += rot_x;
2505 else
2507 fromString(x, rot_x);
2508 rot.x = rot_x;
2512 if (!y.empty())
2514 if (y[0] == '+')
2516 fromString(y.substr(1), rot_y);
2517 rot.y += rot_y;
2519 else
2521 fromString(y, rot_y);
2522 rot.y = rot_y;
2526 if (!z.empty())
2528 if (z[0] == '+')
2530 fromString(z.substr(1), rot_z);
2531 rot.z += rot_z;
2533 else
2535 fromString(z, rot_z);
2536 rot.z = rot_z;
2540 if (EntitiesMngr.setInstanceRot(idx, rot))
2541 ls.push(1);
2542 else
2543 ls.pushNil();
2545 return 1;
2548 int CLuaIHMRyzom::deleteShape(CLuaState &ls)
2550 const char* funcName = "deleteShape";
2551 CLuaIHM::checkArgCount(ls, funcName, 1);
2552 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2554 if (EntitiesMngr.deleteInstance((uint32)ls.toInteger(1)))
2555 ls.push(1);
2556 else
2557 ls.pushNil();
2559 return 1;
2562 int CLuaIHMRyzom::getShapePos(CLuaState &ls)
2564 const char* funcName = "getShapePos";
2565 CLuaIHM::checkArgCount(ls, funcName, 1);
2566 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2568 uint32 idx = (uint32)ls.toInteger(1);
2570 CVector pos = EntitiesMngr.getInstancePos(idx);
2572 ls.push(pos.x);
2573 ls.push(pos.y);
2574 ls.push(pos.z);
2575 return 3;
2578 int CLuaIHMRyzom::getShapeRot(CLuaState &ls)
2580 const char* funcName = "getShapeRot";
2581 CLuaIHM::checkArgCount(ls, funcName, 1);
2582 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2584 uint32 idx = (uint32)ls.toInteger(1);
2586 CVector rot = EntitiesMngr.getInstanceRot(idx);
2588 ls.push(rot.x);
2589 ls.push(rot.y);
2590 ls.push(rot.z);
2591 return 3;
2594 int CLuaIHMRyzom::getShapeScale(CLuaState &ls)
2596 const char* funcName = "getShapeScale";
2597 CLuaIHM::checkArgCount(ls, funcName, 1);
2598 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2600 uint32 idx = (uint32)ls.toInteger(1);
2602 CVector scale = EntitiesMngr.getInstanceScale(idx);
2604 ls.push(scale.x);
2605 ls.push(scale.y);
2606 ls.push(scale.z);
2607 return 3;
2610 int CLuaIHMRyzom::getShapeColPos(CLuaState &ls)
2612 const char* funcName = "getShapeColPos";
2613 CLuaIHM::checkArgCount(ls, funcName, 1);
2614 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2616 uint32 idx = (uint32)ls.toInteger(1);
2618 CVector pos = EntitiesMngr.getInstanceColPos(idx);
2620 ls.push(pos.x);
2621 ls.push(pos.y);
2622 ls.push(pos.z);
2623 return 3;
2626 int CLuaIHMRyzom::getShapeColScale(CLuaState &ls)
2628 const char* funcName = "getShapeColScale";
2629 CLuaIHM::checkArgCount(ls, funcName, 1);
2630 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2632 uint32 idx = (uint32)ls.toInteger(1);
2634 CVector scale = EntitiesMngr.getInstanceColScale(idx);
2636 ls.push(scale.x);
2637 ls.push(scale.y);
2638 ls.push(scale.z);
2639 return 3;
2642 int CLuaIHMRyzom::getShapeColOrient(CLuaState &ls)
2644 const char* funcName = "getShapeColOrient";
2645 CLuaIHM::checkArgCount(ls, funcName, 1);
2646 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
2648 uint32 idx = (uint32)ls.toInteger(1);
2650 double orient = EntitiesMngr.getInstanceColOrient(idx);
2652 ls.push(orient);
2653 return 1;
2657 ////////////////////////////////////////// Standard Lua stuff ends here //////////////////////////////////////
2659 // ***************************************************************************
2660 sint32 CLuaIHMRyzom::getDbProp(const std::string &dbProp)
2662 //H_AUTO(Lua_CLuaIHM_getDbProp)
2663 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2664 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, false);
2666 if (node)
2667 return node->getValue32();
2668 else
2670 debugInfo(toString("getDbProp(): '%s' dbProp Not found", dbProp.c_str()));
2671 return 0;
2675 sint64 CLuaIHMRyzom::getDbProp64(const std::string &dbProp)
2677 //H_AUTO(Lua_CLuaIHM_getDbProp)
2678 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2679 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, false);
2681 if (node)
2683 sint64 prop = node->getValue64();
2684 return prop;
2686 else
2688 debugInfo(toString("getDbProp64(): '%s' dbProp Not found", dbProp.c_str()));
2689 return 0;
2694 void CLuaIHMRyzom::setDbProp(const std::string &dbProp, sint32 value)
2696 //H_AUTO(Lua_CLuaIHM_setDbProp)
2697 // Do not allow Write on SERVER: or LOCAL:
2698 static const std::string dbServer = "SERVER:";
2699 static const std::string dbLocal = "LOCAL:";
2700 static const std::string dbLocalR2 = "LOCAL:R2";
2702 if ((dbProp.compare(0, dbServer.size(), dbServer) == 0) ||
2703 (dbProp.compare(0, dbLocal.size(), dbLocal) == 0)
2706 if (dbProp.compare(0, dbLocalR2.size(), dbLocalR2) != 0)
2708 nlstop;
2709 throw ELuaIHMException("setDbProp(): You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database");
2713 // Write to the DB if found
2714 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2715 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, false);
2717 if (node)
2718 node->setValue32(value);
2719 else
2720 debugInfo(toString("setDbProp(): '%s' dbProp Not found", dbProp.c_str()));
2723 void CLuaIHMRyzom::setDbProp64(const std::string &dbProp, sint64 value)
2725 //H_AUTO(Lua_CLuaIHM_setDbProp)
2726 // Do not allow Write on SERVER: or LOCAL:
2727 static const std::string dbServer = "SERVER:";
2728 static const std::string dbLocal = "LOCAL:";
2729 static const std::string dbLocalR2 = "LOCAL:R2";
2731 if ((dbProp.compare(0, dbServer.size(), dbServer) == 0) ||
2732 (dbProp.compare(0, dbLocal.size(), dbLocal) == 0)
2735 if (dbProp.compare(0, dbLocalR2.size(), dbLocalR2) != 0)
2737 nlstop;
2738 throw ELuaIHMException("setDbProp(): You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database");
2742 // Write to the DB if found
2743 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2744 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, false);
2746 if (node)
2747 node->setValue64(value);
2748 else
2749 debugInfo(toString("setDbProp(): '%s' dbProp Not found", dbProp.c_str()));
2753 void CLuaIHMRyzom::delDbProp(const string &dbProp)
2755 //H_AUTO(Lua_CLuaIHM_setDbProp)
2756 // Do not allow Write on SERVER: or LOCAL:
2757 static const string dbServer = "SERVER:";
2758 static const string dbLocal = "LOCAL:";
2759 static const string dbLocalR2 = "LOCAL:R2";
2761 if ((dbProp.compare(0, dbServer.size(), dbServer) == 0) ||
2762 (dbProp.compare(0, dbLocal.size(), dbLocal) == 0)
2765 if (dbProp.compare(0, dbLocalR2.size(), dbLocalR2) != 0)
2767 nlstop;
2768 throw ELuaIHMException("setDbProp(): You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database");
2772 // Write to the DB if found
2773 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2774 NLGUI::CDBManager::getInstance()->delDbProp(dbProp);
2777 void CLuaIHMRyzom::addDbProp(const std::string &dbProp, sint32 value)
2779 //H_AUTO(Lua_CLuaIHM_setDbProp)
2780 // Do not allow Write on SERVER: or LOCAL:
2781 static const std::string dbServer = "SERVER:";
2782 static const std::string dbLocal = "LOCAL:";
2783 static const std::string dbLocalR2 = "LOCAL:R2";
2785 if ((dbProp.compare(0, dbServer.size(), dbServer) == 0) ||
2786 (dbProp.compare(0, dbLocal.size(), dbLocal) == 0)
2789 if (dbProp.compare(0, dbLocalR2.size(), dbLocalR2) != 0)
2791 nlstop;
2792 throw ELuaIHMException("setDbProp(): You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database");
2796 // Write to the DB if found
2797 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2798 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, true);
2800 if (node)
2801 node->setValue32(value);
2804 // ***************************************************************************
2805 void CLuaIHMRyzom::debugInfo(const std::string &cstDbg)
2807 //H_AUTO(Lua_CLuaIHM_debugInfo)
2808 if (ClientCfg.DisplayLuaDebugInfo)
2810 std::string dbg = cstDbg;
2812 if (ClientCfg.LuaDebugInfoGotoButtonEnabled)
2814 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2815 lua_State *ls = CLuaManager::getInstance().getLuaState()->getStatePointer();
2816 lua_Debug luaDbg;
2818 if (lua_getstack(ls, 1, &luaDbg))
2820 if (lua_getinfo(ls, "lS", &luaDbg))
2822 // add a command button to jump to the wanted file
2823 dbg = createGotoFileButtonTag(luaDbg.short_src, luaDbg.currentline) + dbg;
2828 rawDebugInfo(dbg);
2832 // ***************************************************************************
2833 void CLuaIHMRyzom::rawDebugInfo(const std::string &dbg)
2835 //H_AUTO(Lua_CLuaIHM_rawDebugInfo)
2836 if (ClientCfg.DisplayLuaDebugInfo)
2838 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2840 if (!dbg.empty() && dbg[0] == '@')
2842 // if color is already given use the message as it
2843 NLMISC::InfoLog->displayRawNL(dbg.c_str());
2845 else
2847 NLMISC::InfoLog->displayRawNL(LuaHelperStuff::formatLuaErrorSysInfo(dbg).c_str());
2850 #ifdef LUA_NEVRAX_VERSION
2852 if (LuaDebuggerIDE)
2854 LuaDebuggerIDE->debugInfo(dbg.c_str());
2857 #endif
2858 pIM->displaySystemInfo(LuaHelperStuff::formatLuaErrorSysInfo(dbg));
2863 void CLuaIHMRyzom::dumpCallStack(int startStackLevel)
2865 //H_AUTO(Lua_CLuaIHM_dumpCallStack)
2866 if (ClientCfg.DisplayLuaDebugInfo)
2868 lua_Debug dbg;
2869 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2870 lua_State *ls = CLuaManager::getInstance().getLuaState()->getStatePointer();
2871 int stackLevel = startStackLevel;
2872 rawDebugInfo("Call stack : ");
2873 rawDebugInfo("-------------");
2875 while (lua_getstack(ls, stackLevel, &dbg))
2877 if (lua_getinfo(ls, "lS", &dbg))
2879 std::string result = createGotoFileButtonTag(dbg.short_src, dbg.currentline) + NLMISC::toString("%s:%d:", dbg.short_src, dbg.currentline);
2880 rawDebugInfo(result);
2883 ++ stackLevel;
2888 // ***************************************************************************
2889 void CLuaIHMRyzom::getCallStackAsString(int startStackLevel /*=0*/, std::string &result)
2891 //H_AUTO(Lua_CLuaIHM_getCallStackAsString)
2892 result.clear();
2893 lua_Debug dbg;
2894 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2895 lua_State *ls = CLuaManager::getInstance().getLuaState()->getStatePointer();
2896 int stackLevel = startStackLevel;
2897 result += "Call stack : \n";
2898 result += "-------------";
2900 while (lua_getstack(ls, stackLevel, &dbg))
2902 if (lua_getinfo(ls, "lS", &dbg))
2904 result += NLMISC::toString("%s:%d:", dbg.short_src, dbg.currentline);
2907 ++ stackLevel;
2911 // ***************************************************************************
2912 std::string CLuaIHMRyzom::getDefine(const std::string &def)
2914 //H_AUTO(Lua_CLuaIHM_getDefine)
2915 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2917 if (ClientCfg.DisplayLuaDebugInfo && !CWidgetManager::getInstance()->getParser()->isDefineExist(def))
2918 debugInfo(toString("getDefine(): '%s' not found", def.c_str()));
2920 return CWidgetManager::getInstance()->getParser()->getDefine(def);
2923 #ifdef RYZOM_LUA_UCSTRING
2924 // ***************************************************************************
2925 void CLuaIHMRyzom::setContextHelpText(const ucstring &text)
2927 CWidgetManager::getInstance()->setContextHelpText(text.toUtf8());
2929 #else
2930 // ***************************************************************************
2931 void CLuaIHMRyzom::setContextHelpText(const std::string &text)
2933 CWidgetManager::getInstance()->setContextHelpText(text);
2935 #endif
2937 #ifdef RYZOM_LUA_UCSTRING
2938 // ***************************************************************************
2939 void CLuaIHMRyzom::messageBox(const ucstring &text)
2941 //H_AUTO(Lua_CLuaIHM_messageBox)
2942 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2943 pIM->messageBox(text.toUtf8());
2946 // ***************************************************************************
2947 void CLuaIHMRyzom::messageBox(const ucstring &text, const std::string &masterGroup)
2949 //H_AUTO(Lua_CLuaIHM_messageBox)
2950 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2951 pIM->messageBox(text.toUtf8(), masterGroup);
2954 // ***************************************************************************
2955 void CLuaIHMRyzom::messageBox(const ucstring &text, const std::string &masterGroup, int caseMode)
2957 if (caseMode < 0 || caseMode >= CaseCount)
2959 throw ELuaIHMException("messageBox: case mode value is invalid.");
2962 //H_AUTO(Lua_CLuaIHM_messageBox)
2963 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2964 pIM->messageBox(text.toUtf8(), masterGroup, (TCaseMode) caseMode);
2966 #endif
2968 // ***************************************************************************
2969 void CLuaIHMRyzom::messageBox(const std::string &text)
2971 //H_AUTO(Lua_CLuaIHM_messageBox)
2972 static volatile bool dumpCallStack = false;
2974 if (dumpCallStack)
2976 CLuaIHMRyzom::dumpCallStack(0);
2979 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2980 pIM->messageBox(text);
2983 // ***************************************************************************
2984 void CLuaIHMRyzom::messageBox(const std::string &text, const std::string &masterGroup)
2986 //H_AUTO(Lua_CLuaIHM_messageBox)
2987 CInterfaceManager *pIM = CInterfaceManager::getInstance();
2988 pIM->messageBox(text, masterGroup);
2991 // ***************************************************************************
2992 void CLuaIHMRyzom::messageBox(const std::string &text, const std::string &masterGroup, int caseMode)
2994 if (caseMode < 0 || caseMode >= CaseCount)
2996 throw ELuaIHMException("messageBox: case mode value is invalid.");
2999 //H_AUTO(Lua_CLuaIHM_messageBox)
3000 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3001 pIM->messageBox(text, masterGroup, (TCaseMode) caseMode);
3004 #ifdef RYZOM_LUA_UCSTRING
3005 // ***************************************************************************
3006 void CLuaIHMRyzom::messageBoxWithHelp(const ucstring &text) // TODO: Lua UTF-8
3008 //H_AUTO(Lua_CLuaIHM_messageBox)
3009 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3010 pIM->messageBoxWithHelp(text.toUtf8());
3013 // ***************************************************************************
3014 void CLuaIHMRyzom::messageBoxWithHelp(const ucstring &text, const std::string &masterGroup) // TODO: Lua UTF-8
3016 //H_AUTO(Lua_CLuaIHM_messageBox)
3017 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3018 pIM->messageBoxWithHelp(text.toUtf8(), masterGroup);
3021 // ***************************************************************************
3022 void CLuaIHMRyzom::messageBoxWithHelp(const ucstring &text, const std::string &masterGroup, int caseMode) // TODO: Lua UTF-8
3024 if (caseMode < 0 || caseMode >= CaseCount)
3026 throw ELuaIHMException("messageBoxWithHelp: case mode value is invalid.");
3029 //H_AUTO(Lua_CLuaIHM_messageBox)
3030 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3031 pIM->messageBoxWithHelp(text.toUtf8(), masterGroup, "" , "", (TCaseMode) caseMode);
3033 #endif
3035 // ***************************************************************************
3036 void CLuaIHMRyzom::messageBoxWithHelp(const std::string &text)
3038 //H_AUTO(Lua_CLuaIHM_messageBox)
3039 static volatile bool dumpCallStack = false;
3041 if (dumpCallStack)
3043 CLuaIHMRyzom::dumpCallStack(0);
3046 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3047 pIM->messageBoxWithHelp(text);
3050 // ***************************************************************************
3051 void CLuaIHMRyzom::messageBoxWithHelp(const std::string &text, const std::string &masterGroup)
3053 //H_AUTO(Lua_CLuaIHM_messageBox)
3054 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3055 pIM->messageBoxWithHelp(text, masterGroup);
3058 // ***************************************************************************
3059 void CLuaIHMRyzom::messageBoxWithHelp(const std::string &text, const std::string &masterGroup, int caseMode)
3061 if (caseMode < 0 || caseMode >= CaseCount)
3063 throw ELuaIHMException("messageBoxWithHelp: case mode value is invalid.");
3066 //H_AUTO(Lua_CLuaIHM_messageBox)
3067 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3068 pIM->messageBoxWithHelp(text, masterGroup, "" , "", (TCaseMode) caseMode);
3071 // ***************************************************************************
3072 bool CLuaIHMRyzom::executeFunctionOnStack(CLuaState &ls, int numArgs, int numRet)
3074 //H_AUTO(Lua_CLuaIHM_executeFunctionOnStack)
3075 static volatile bool dumpFunction = false;
3077 if (dumpFunction)
3079 CLuaStackRestorer lsr(&ls, ls.getTop());
3080 lua_Debug ar;
3081 ls.pushValue(-1 - numArgs);
3082 lua_getinfo(ls.getStatePointer(), ">lS", &ar);
3083 nlwarning((std::string(ar.what) + ", at line " + toString(ar.linedefined) + " in " + std::string(ar.source)).c_str());
3086 int result = ls.pcall(numArgs, numRet);
3088 switch (result)
3090 case LUA_ERRRUN:
3091 case LUA_ERRMEM:
3092 case LUA_ERRERR:
3094 debugInfo(ls.toString(-1));
3095 ls.pop();
3096 return false;
3098 break;
3100 case 0:
3101 return true;
3102 break;
3104 default:
3105 nlassert(0);
3106 break;
3109 return false;
3112 // ***************************************************************************
3113 #ifdef RYZOM_LUA_UCSTRING
3114 ucstring CLuaIHMRyzom::replacePvpEffectParam(const ucstring &str, sint32 parameter)
3115 #else
3116 std::string CLuaIHMRyzom::replacePvpEffectParam(const std::string &str, sint32 parameter)
3117 #endif
3119 //H_AUTO(Lua_CLuaIHM_replacePvpEffectParam)
3120 #ifdef RYZOM_LUA_UCSTRING
3121 ucstring result = str;
3122 CSString s = str.toString();
3123 #else
3124 std::string result = str;
3125 CSString s = str;
3126 #endif
3127 std::string p, paramString;
3129 // Locate parameter and store it
3130 p = s.splitTo('%', true);
3132 while (!p.empty() && !s.empty())
3134 if (s[0] == 'p' || s[0] == 'n' || s[0] == 'r')
3136 paramString = "%";
3137 paramString += s[0];
3138 break;
3141 p = s.splitTo('%', true);
3144 // Return original string if param isn't found
3145 if (paramString.size() < 2)
3146 return str;
3148 // Replace parameter based on its type
3149 switch (paramString[1])
3151 case 'p':
3152 p = toString("%.1f %%", parameter / 100.0);
3153 break;
3155 case 'n':
3156 p = toString(parameter);
3157 break;
3159 case 'r':
3160 p = toString("%.1f", parameter / 100.0);
3161 break;
3163 default:
3164 #ifdef RYZOM_LUA_UCSTRING
3165 debugInfo("Bad arguments in " + str.toString() + " : " + paramString);
3166 #else
3167 debugInfo("Bad arguments in " + str + " : " + paramString);
3168 #endif
3171 strFindReplace(result, paramString.c_str(), p);
3173 return result;
3176 // ***************************************************************************
3177 sint32 CLuaIHMRyzom::secondsSince1970ToHour(sint32 seconds)
3179 //H_AUTO(Lua_CLuaIHM_secondsSince1970ToHour)
3180 // convert to readable form
3181 struct tm *tstruct;
3182 time_t tval = seconds;
3183 tstruct = gmtime(&tval);
3185 if (!tstruct)
3187 debugInfo(toString("Bad Date Received: %d", seconds));
3188 return 0;
3191 return tstruct->tm_hour; // 0-23
3194 #ifdef RYZOM_BG_DOWNLOADER
3195 // ***************************************************************************
3196 void CLuaIHMRyzom::pauseBGDownloader()
3198 ::pauseBGDownloader();
3201 // ***************************************************************************
3202 void CLuaIHMRyzom::unpauseBGDownloader()
3204 ::unpauseBGDownloader();
3207 // ***************************************************************************
3208 void CLuaIHMRyzom::requestBGDownloaderPriority(uint priority)
3210 if (priority >= BGDownloader::ThreadPriority_Count)
3212 throw NLMISC::Exception("requestBGDownloaderPriority() : invalid priority");
3215 CBGDownloaderAccess::getInstance().requestDownloadThreadPriority((BGDownloader::TThreadPriority) priority, false);
3218 // ***************************************************************************
3219 sint CLuaIHMRyzom::getBGDownloaderPriority()
3221 return CBGDownloaderAccess::getInstance().getDownloadThreadPriority();
3223 #endif
3225 // ***************************************************************************
3226 void CLuaIHMRyzom::loadBackground(const std::string &bg)
3228 LoadingBackground = CustomBackground;
3229 LoadingBackgroundBG = bg;
3233 // ***************************************************************************
3234 #ifdef RYZOM_LUA_UCSTRING
3235 ucstring CLuaIHMRyzom::getPatchLastErrorMessage()
3236 #else
3237 std::string CLuaIHMRyzom::getPatchLastErrorMessage()
3238 #endif
3240 #ifdef RYZOM_BG_DOWNLOADER
3241 if (isBGDownloadEnabled())
3243 return CBGDownloaderAccess::getInstance().getLastErrorMessage();
3245 else
3246 #endif
3248 CPatchManager *pPM = CPatchManager::getInstance();
3249 return pPM->getLastErrorMessage();
3253 // ***************************************************************************
3254 bool CLuaIHMRyzom::isInGame()
3256 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3257 return pIM->isInGame();
3260 // ***************************************************************************
3261 uint32 CLuaIHMRyzom::getPlayerSelectedSlot()
3263 return (uint32) PlayerSelectedSlot;
3266 // ***************************************************************************
3267 bool CLuaIHMRyzom::isPlayerSlotNewbieLand(uint32 slot)
3269 if (slot > CharacterSummaries.size())
3271 throw ELuaIHMException("isPlayerSlotNewbieLand(): Invalid slot %d", (int) slot);
3274 return CharacterSummaries[slot].InNewbieland;
3277 // ***************************************************************************
3278 ucstring CLuaIHMRyzom::getSheetLocalizedName(const std::string &sheet)
3280 return ucstring(STRING_MANAGER::CStringManagerClient::getItemLocalizedName(CSheetId(sheet)));
3283 // ***************************************************************************
3284 ucstring CLuaIHMRyzom::getSheetLocalizedDesc(const std::string &sheet)
3286 return ucstring(STRING_MANAGER::CStringManagerClient::getItemLocalizedDescription(CSheetId(sheet)));
3291 // ***************************************************************************
3292 sint32 CLuaIHMRyzom::getSkillIdFromName(const std::string &def)
3294 //H_AUTO(Lua_CLuaIHM_getSkillIdFromName)
3295 SKILLS::ESkills e = SKILLS::toSkill(def);
3297 // Avoid any bug, return SF if not found
3298 if (e >= SKILLS::unknown)
3299 e = SKILLS::SF;
3301 return e;
3304 // ***************************************************************************
3305 #ifdef RYZOM_LUA_UCSTRING
3306 ucstring CLuaIHMRyzom::getSkillLocalizedName(sint32 skillId)
3308 //H_AUTO(Lua_CLuaIHM_getSkillLocalizedName)
3309 return ucstring(STRING_MANAGER::CStringManagerClient::getSkillLocalizedName((SKILLS::ESkills)skillId));
3311 #else
3312 std::string CLuaIHMRyzom::getSkillLocalizedName(sint32 skillId)
3314 //H_AUTO(Lua_CLuaIHM_getSkillLocalizedName)
3315 return STRING_MANAGER::CStringManagerClient::getSkillLocalizedName((SKILLS::ESkills)skillId);
3317 #endif
3319 // ***************************************************************************
3320 sint32 CLuaIHMRyzom::getMaxSkillValue(sint32 skillId)
3322 //H_AUTO(Lua_CLuaIHM_getMaxSkillValue)
3323 CSkillManager *pSM = CSkillManager::getInstance();
3324 return pSM->getMaxSkillValue((SKILLS::ESkills)skillId);
3327 // ***************************************************************************
3328 sint32 CLuaIHMRyzom::getBaseSkillValueMaxChildren(sint32 skillId)
3330 //H_AUTO(Lua_CLuaIHM_getBaseSkillValueMaxChildren)
3331 CSkillManager *pSM = CSkillManager::getInstance();
3332 return pSM->getBaseSkillValueMaxChildren((SKILLS::ESkills)skillId);
3335 // ***************************************************************************
3336 sint32 CLuaIHMRyzom::getMagicResistChance(bool elementalSpell, sint32 casterSpellLvl, sint32 victimResistLvl)
3338 //H_AUTO(Lua_CLuaIHM_getMagicResistChance)
3339 CSPhraseManager *pPM = CSPhraseManager::getInstance();
3340 casterSpellLvl = std::max(casterSpellLvl, sint32(0));
3341 victimResistLvl = std::max(victimResistLvl, sint32(0));
3342 /* The success rate in the table is actually the "Casting Success Chance".
3343 Thus, the relativeLevel is casterSpellLvl - victimResistLvl
3344 Moreover, must take the "PartialSuccessMaxDraw" line because the spell is not resisted if success>0
3346 sint32 chanceToHit = pPM->getSuccessRate(elementalSpell ? CSPhraseManager::STResistMagic : CSPhraseManager::STResistMagicLink,
3347 casterSpellLvl - victimResistLvl, true);
3348 clamp(chanceToHit, 0, 100);
3350 // Thus, the resist chance is 100 - hit chance.
3351 return 100 - chanceToHit;
3354 // ***************************************************************************
3355 sint32 CLuaIHMRyzom::getDodgeParryChance(sint32 attLvl, sint32 defLvl)
3357 //H_AUTO(Lua_CLuaIHM_getDodgeParryChance)
3358 CSPhraseManager *pPM = CSPhraseManager::getInstance();
3359 attLvl = std::max(attLvl, sint32(0));
3360 defLvl = std::max(defLvl, sint32(0));
3362 sint32 chance = pPM->getSuccessRate(CSPhraseManager::STDodgeParry, defLvl - attLvl, false);
3363 clamp(chance, 0, 100);
3365 return chance;
3368 // ***************************************************************************
3369 void CLuaIHMRyzom::browseNpcWebPage(const std::string &htmlId, const std::string &urlIn, bool addParameters, double timeout)
3371 //H_AUTO(Lua_CLuaIHM_browseNpcWebPage)
3372 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3373 CGroupHTML *groupHtml = dynamic_cast<CGroupHTML*>(CWidgetManager::getInstance()->getElementFromId(htmlId));
3375 if (groupHtml)
3377 // if true, it means that we want to display a web page that use webig auth
3378 bool webig = urlIn.find("http://") == 0 || urlIn.find("https://") == 0;
3380 string url;
3382 // append the WebServer to the url
3383 if (urlIn.find("ring_access_point=1") != std::string::npos)
3385 url = RingMainURL + "?" + urlIn;
3387 else if (webig)
3389 url = urlIn;
3391 else
3393 url = WebServer + urlIn;
3396 if (addParameters && !webig)
3398 // append shardid, playername and language code
3399 string userName;
3400 string guildName;
3402 if (UserEntity)
3404 userName = UserEntity->getDisplayName();
3405 STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance();
3406 pSMC->getString(UserEntity->getGuildNameID(), guildName);
3408 while (guildName.find(' ') != string::npos)
3410 guildName[guildName.find(' ')] = '_';
3414 url += ((url.find('?') != string::npos) ? "&" : "?") +
3415 string("shard=") + toString(ShardId) +
3416 string("&user_login=") + userName +
3417 string("&lang=") + ClientCfg.getHtmlLanguageCode() +
3418 string("&guild_name=") + guildName;
3421 /* Already added by GroupHtml
3422 if(webig)
3424 // append special webig auth params
3425 addWebIGParams(url);
3428 // set the wanted timeout
3429 groupHtml->setTimeout((float)std::max(0.0, timeout));
3431 // Browse the url
3432 groupHtml->browse(url.c_str());
3433 // Set top of the page
3434 CCtrlScroll *pScroll = groupHtml->getScrollBar();
3436 if (pScroll != NULL)
3437 pScroll->moveTrackY(10000);
3442 // ***************************************************************************
3443 void CLuaIHMRyzom::clearHtmlUndoRedo(const std::string &htmlId)
3445 //H_AUTO(Lua_CLuaIHM_clearHtmlUndoRedo)
3446 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3447 CGroupHTML *groupHtml = dynamic_cast<CGroupHTML*>(CWidgetManager::getInstance()->getElementFromId(htmlId));
3449 if (groupHtml)
3450 groupHtml->clearUndoRedo();
3453 // ***************************************************************************
3454 #ifdef RYZOM_LUA_UCSTRING
3455 ucstring CLuaIHMRyzom::getDynString(sint32 dynStringId)
3457 //H_AUTO(Lua_CLuaIHM_getDynString)
3458 string result;
3459 STRING_MANAGER::CStringManagerClient::instance()->getDynString(dynStringId, result);
3460 return ucstring::makeFromUtf8(result); // Compatibility
3462 #else
3463 std::string CLuaIHMRyzom::getDynString(sint32 dynStringId)
3465 //H_AUTO(Lua_CLuaIHM_getDynString)
3466 string result;
3467 STRING_MANAGER::CStringManagerClient::instance()->getDynString(dynStringId, result);
3468 return result;
3470 #endif
3472 // ***************************************************************************
3473 bool CLuaIHMRyzom::isDynStringAvailable(sint32 dynStringId)
3475 //H_AUTO(Lua_CLuaIHM_isDynStringAvailable)
3476 string result;
3477 bool res = STRING_MANAGER::CStringManagerClient::instance()->getDynString(dynStringId, result);
3478 return res;
3481 // ***************************************************************************
3482 bool CLuaIHMRyzom::isFullyPatched()
3484 return AvailablePatchs == 0;
3487 // ***************************************************************************
3488 std::string CLuaIHMRyzom::getSheetType(const std::string &sheet)
3490 //H_AUTO(Lua_CLuaIHM_getSheetType)
3491 const CEntitySheet *sheetPtr = SheetMngr.get(CSheetId(sheet));
3493 if (!sheetPtr) return "";
3495 return CEntitySheet::typeToString(sheetPtr->Type);
3499 // ***************************************************************************
3500 std::string CLuaIHMRyzom::getSheetFamily(const std::string &sheet)
3502 CEntitySheet *pES = SheetMngr.get ( CSheetId(sheet) );
3503 if ((pES != NULL) && (pES->type() == CEntitySheet::ITEM))
3505 CItemSheet *pIS = (CItemSheet*)pES;
3507 if (pIS)
3508 return ITEMFAMILY::toString(pIS->Family);
3511 return "";
3514 // ***************************************************************************
3515 std::string CLuaIHMRyzom::getSheetName(uint32 sheetId)
3517 return CSheetId(sheetId).toString();
3520 // ***************************************************************************
3521 sint32 CLuaIHMRyzom::getFameIndex(const std::string &factionName)
3523 //H_AUTO(Lua_CLuaIHM_getFameIndex)
3524 return CStaticFames::getInstance().getFactionIndex(factionName);
3527 // ***************************************************************************
3528 std::string CLuaIHMRyzom::getFameName(sint32 fameIndex)
3530 //H_AUTO(Lua_CLuaIHM_getFameName)
3531 return CStaticFames::getInstance().getFactionName(fameIndex);
3534 // ***************************************************************************
3535 sint32 CLuaIHMRyzom::getFameDBIndex(sint32 fameIndex)
3537 //H_AUTO(Lua_CLuaIHM_getFameDBIndex)
3538 // Yoyo: avoid crash if fames not initialized
3539 if (CStaticFames::getInstance().getNbFame() == 0)
3540 return 0;
3541 else
3542 return CStaticFames::getInstance().getDatabaseIndex(fameIndex);
3545 // ***************************************************************************
3546 sint32 CLuaIHMRyzom::getFirstTribeFameIndex()
3548 //H_AUTO(Lua_CLuaIHM_getFirstTribeFameIndex)
3549 return CStaticFames::getInstance().getFirstTribeFameIndex();
3552 // ***************************************************************************
3553 sint32 CLuaIHMRyzom::getNbTribeFameIndex()
3555 //H_AUTO(Lua_CLuaIHM_getNbTribeFameIndex)
3556 // Yoyo: avoid crash if fames not initialized. at leasst one tribe
3557 return std::max(1U, CStaticFames::getInstance().getNbTribeFameIndex());
3560 // ***************************************************************************
3561 string CLuaIHMRyzom::getClientCfg(const string &varName)
3563 //H_AUTO(Lua_CLuaIHM_getClientCfg)
3564 return ClientCfg.readString(varName);
3567 // ***************************************************************************
3568 void CLuaIHMRyzom::sendMsgToServer(const std::string &sMsg)
3570 //H_AUTO(Lua_CLuaIHM_sendMsgToServer)
3571 ::sendMsgToServer(sMsg);
3574 // ***************************************************************************
3575 void CLuaIHMRyzom::sendMsgToServerPvpTag(bool pvpTag)
3577 //H_AUTO(Lua_CLuaIHM_sendMsgToServerPvpTag)
3578 uint8 tag = (uint8)pvpTag;
3579 ::sendMsgToServer("PVP:PVP_TAG", tag);
3582 // ***************************************************************************
3583 void CLuaIHMRyzom::sendMsgToServerAutoPact(bool bval)
3585 //H_AUTO(Lua_CLuaIHM_sendMsgToServerAutoPact)
3586 uint8 dopact = (uint8)bval;
3587 ::sendMsgToServer("COMMAND:AUTOPACT", dopact);
3590 // ***************************************************************************
3591 void CLuaIHMRyzom::sendMsgToServerUseItem(sint32 slot)
3593 //H_AUTO(Lua_CLuaIHM_sendMsgToServerUseItem)
3594 uint8 u8n1 = (uint8)((uint16)slot >> 8);
3595 uint8 u8n2 = (uint8)((uint16)slot & 0x00FF);
3597 ::sendMsgToServer("ITEM:USE_ITEM", u8n1, u8n2);
3600 // ***************************************************************************
3601 bool CLuaIHMRyzom::isGuildQuitAvailable()
3603 //H_AUTO(Lua_CLuaIHM_isGuildQuitAvailable)
3604 return CGuildManager::getInstance()->getGuild().QuitGuildAvailable;
3607 // ***************************************************************************
3608 void CLuaIHMRyzom::sortGuildMembers()
3610 //H_AUTO(Lua_CLuaIHM_sortGuildMembers)
3611 CGuildManager::getInstance()->sortGuildMembers();
3614 // ***************************************************************************
3615 sint32 CLuaIHMRyzom::getNbGuildMembers()
3617 //H_AUTO(Lua_CLuaIHM_getNbGuildMembers)
3618 return (sint32)CGuildManager::getInstance()->getGuildMembers().size();
3621 // ***************************************************************************
3622 string CLuaIHMRyzom::getGuildMemberName(sint32 nMemberId)
3624 //H_AUTO(Lua_CLuaIHM_getGuildMemberName)
3625 if ((nMemberId < 0) || (nMemberId >= getNbGuildMembers()))
3626 return "";
3628 return CGuildManager::getInstance()->getGuildMembers()[nMemberId].Name;
3631 // ***************************************************************************
3632 string CLuaIHMRyzom::getGuildMemberGrade(sint32 nMemberId)
3634 //H_AUTO(Lua_CLuaIHM_getGuildMemberGrade)
3635 if ((nMemberId < 0) || (nMemberId >= getNbGuildMembers()))
3636 return "";
3638 return EGSPD::CGuildGrade::toString(CGuildManager::getInstance()->getGuildMembers()[nMemberId].Grade);
3641 // ***************************************************************************
3642 bool CLuaIHMRyzom::isR2Player(const std::string &sheet)
3644 //H_AUTO(Lua_CLuaIHM_isR2Player)
3645 const CEntitySheet *entitySheet = SheetMngr.get(CSheetId(sheet));
3647 if (!entitySheet) return false;
3649 const CCharacterSheet *chSheet = dynamic_cast<const CCharacterSheet*>(entitySheet);
3651 if (!chSheet) return false;
3653 return chSheet->R2Npc;
3656 // ***************************************************************************
3657 std::string CLuaIHMRyzom::getR2PlayerRace(const std::string &sheet)
3659 //H_AUTO(Lua_CLuaIHM_getR2PlayerRace)
3660 const CEntitySheet *entitySheet = SheetMngr.get(CSheetId(sheet));
3662 if (!entitySheet) return "";
3664 const CCharacterSheet *chSheet = dynamic_cast<const CCharacterSheet*>(entitySheet);
3666 if (!chSheet) return "";
3668 return EGSPD::CPeople::toString(chSheet->Race);
3671 // ***************************************************************************
3672 bool CLuaIHMRyzom::isR2PlayerMale(const std::string &sheet)
3674 //H_AUTO(Lua_CLuaIHM_isR2PlayerMale)
3675 const CEntitySheet *entitySheet = SheetMngr.get(CSheetId(sheet));
3677 if (!entitySheet) return true;
3679 const CCharacterSheet *chSheet = dynamic_cast<const CCharacterSheet*>(entitySheet);
3681 if (!chSheet) return true;
3683 return (chSheet->Gender == GSGENDER::male);
3686 // ***************************************************************************
3687 std::string CLuaIHMRyzom::getCharacterSheetSkel(const std::string &sheet, bool isMale)
3689 //H_AUTO(Lua_CLuaIHM_getCharacterSheetSkel)
3690 const CEntitySheet *sheetPtr = SheetMngr.get(CSheetId(sheet));
3691 const CCharacterSheet *charSheet = dynamic_cast<const CCharacterSheet*>(sheetPtr);
3693 if (charSheet) return charSheet->getSkelFilename();
3695 const CRaceStatsSheet *raceStatSheet = dynamic_cast<const CRaceStatsSheet*>(sheetPtr);
3697 if (raceStatSheet) return raceStatSheet->GenderInfos[isMale ? 0 : 1].Skelfilename;
3699 return "";
3702 // ***************************************************************************
3703 sint32 CLuaIHMRyzom::getSheetId(const std::string &itemName)
3705 //H_AUTO(Lua_CLuaIHM_getSheetId)
3706 return (sint32)CSheetId(itemName).asInt();
3709 // ***************************************************************************
3710 sint CLuaIHMRyzom::getCharacterSheetRegionForce(const std::string &sheet)
3712 //H_AUTO(Lua_CLuaIHM_getCharacterSheetRegionForce)
3713 const CCharacterSheet *charSheet = dynamic_cast<const CCharacterSheet*>(SheetMngr.get(CSheetId(sheet)));
3715 if (!charSheet) return 0;
3717 return charSheet->RegionForce;
3720 // ***************************************************************************
3721 sint CLuaIHMRyzom::getCharacterSheetRegionLevel(const std::string &sheet)
3723 //H_AUTO(Lua_CLuaIHM_getCharacterSheetRegionLevel)
3724 const CCharacterSheet *charSheet = dynamic_cast<const CCharacterSheet*>(SheetMngr.get(CSheetId(sheet)));
3726 if (!charSheet) return 0;
3728 return charSheet->RegionForce;
3731 // ***************************************************************************
3732 string CLuaIHMRyzom::getRegionByAlias(uint32 alias)
3734 //H_AUTO(Lua_CLuaIHM_getRegionByAlias)
3735 return ContinentMngr.getRegionNameByAlias(alias);
3738 float CLuaIHMRyzom::getGroundZ(float x, float y)
3740 CVector vect = UserEntity->pos();
3741 vect.x = x;
3742 vect.y = y;
3744 UserEntity->getCollisionEntity()->snapToGround(vect);
3746 return vect.z;
3749 void setMouseCursor(const std::string &texture)
3751 if (texture.empty())
3752 CTool::setMouseCursor("curs_default.tga");
3753 else
3754 CTool::setMouseCursor(texture);
3757 // ***************************************************************************
3758 #ifdef RYZOM_LUA_UCSTRING
3759 void CLuaIHMRyzom::tell(const ucstring &player, const ucstring &msg)
3760 #else
3761 void CLuaIHMRyzom::tell(const std::string &player, const std::string &msg)
3762 #endif
3764 //H_AUTO(Lua_CLuaIHM_tell)
3765 // display a /tell command in the main chat
3766 if (!player.empty())
3768 if (!msg.empty())
3770 // Parse any tokens in the message.
3771 #ifdef RYZOM_LUA_UCSTRING
3772 string msg_modified = msg.toUtf8();
3773 #else
3774 string msg_modified = msg;
3775 #endif
3777 // Parse any tokens in the text
3778 if (! CInterfaceManager::parseTokens(msg_modified))
3780 return;
3783 #ifdef RYZOM_LUA_UCSTRING
3784 ChatMngr.tell(player.toUtf8(), msg_modified);
3785 #else
3786 ChatMngr.tell(player, msg_modified);
3787 #endif
3789 else
3791 CChatWindow *w = PeopleInterraction.ChatGroup.Window;
3793 if (w)
3795 CInterfaceManager *im = CInterfaceManager::getInstance();
3796 w->setKeyboardFocus();
3797 w->enableBlink(1);
3798 #ifdef RYZOM_LUA_UCSTRING
3799 w->setCommand("tell " + CEntityCL::removeTitleFromName(player.toUtf8()) + " ", false);
3800 #else
3801 w->setCommand("tell " + CEntityCL::removeTitleFromName(player) + " ", false);
3802 #endif
3803 CGroupEditBox *eb = w->getEditBox();
3805 if (eb != NULL)
3807 eb->bypassNextKey();
3810 if (w->getContainer())
3812 w->getContainer()->setActive(true);
3813 CWidgetManager::getInstance()->setTopWindow(w->getContainer());
3820 // ***************************************************************************
3821 bool CLuaIHMRyzom::isRingAccessPointInReach()
3823 //H_AUTO(Lua_CLuaIHM_isRingAccessPointInReach)
3824 if (BotChatPageAll->RingSessions->RingAccessPointPos == CVector::Null) return false;
3826 const CVectorD &vect1 = BotChatPageAll->RingSessions->RingAccessPointPos;
3827 CVectorD vect2 = UserEntity->pos();
3828 double distanceSquare = pow(vect1.x - vect2.x, 2) + pow(vect1.y - vect2.y, 2);
3829 return distanceSquare <= MaxTalkingDistSquare;
3832 // ***************************************************************************
3833 void CLuaIHMRyzom::updateTooltipCoords()
3835 CWidgetManager::getInstance()->updateTooltipCoords();
3838 // ***************************************************************************
3839 bool CLuaIHMRyzom::isCtrlKeyDown()
3841 //H_AUTO(Lua_CLuaIHM_isCtrlKeyDown)
3842 bool ctrlDown = Driver->AsyncListener.isKeyDown(KeyLCONTROL) ||
3843 Driver->AsyncListener.isKeyDown(KeyRCONTROL);
3845 if (ctrlDown) nlwarning("ctrl down");
3846 else nlwarning("ctrl up");
3848 return ctrlDown;
3851 // ***************************************************************************
3852 #ifdef RYZOM_LUA_UCSTRING
3853 std::string CLuaIHMRyzom::encodeURLUnicodeParam(const ucstring &text)
3855 //H_AUTO(Lua_CLuaIHM_encodeURLUnicodeParam)
3856 return convertToHTML(text.toUtf8());
3858 #else
3859 std::string CLuaIHMRyzom::encodeURLUnicodeParam(const std::string &text)
3861 //H_AUTO(Lua_CLuaIHM_encodeURLUnicodeParam)
3862 return convertToHTML(text);
3864 #endif
3866 // ***************************************************************************
3867 sint32 CLuaIHMRyzom::getPlayerLevel()
3869 if (!UserEntity) return -1;
3871 CSkillManager *pSM = CSkillManager::getInstance();
3872 uint32 maxskill = pSM->getBestSkillValue(SKILLS::SC);
3873 maxskill = std::max(maxskill, pSM->getBestSkillValue(SKILLS::SF));
3874 maxskill = std::max(maxskill, pSM->getBestSkillValue(SKILLS::SH));
3875 maxskill = std::max(maxskill, pSM->getBestSkillValue(SKILLS::SM));
3876 return sint32(maxskill);
3879 // ***************************************************************************
3880 sint64 CLuaIHMRyzom::getPlayerVpa()
3882 sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P" + toString("%d", CLFECOMMON::PROPERTY_VPA))->getValue64();
3883 return prop;
3886 // ***************************************************************************
3887 sint64 CLuaIHMRyzom::getPlayerVpb()
3889 sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P" + toString("%d", CLFECOMMON::PROPERTY_VPB))->getValue64();
3890 return prop;
3893 // ***************************************************************************
3894 sint64 CLuaIHMRyzom::getPlayerVpc()
3896 sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P" + toString("%d", CLFECOMMON::PROPERTY_VPB))->getValue64();
3897 return prop;
3900 // ***************************************************************************
3901 sint32 CLuaIHMRyzom::getTargetLevel()
3903 CEntityCL *target = getTargetEntity();
3905 if (!target) return -1;
3907 if (target->isPlayer())
3909 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3910 CCDBNodeLeaf *pDbPlayerLevel = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("target_player_level"));
3911 return pDbPlayerLevel ? pDbPlayerLevel->getValue32() : -1;
3913 else
3915 CCharacterSheet *pCS = dynamic_cast<CCharacterSheet*>(SheetMngr.get(target->sheetId()));
3917 if (!pCS) return -1;
3919 // only display the consider if the target is attackable #523
3920 if (!pCS->Attackable) return -1;
3922 if (!target->properties().attackable()) return -1;
3924 return sint32(pCS->Level);
3927 return -1;
3930 // ***************************************************************************
3931 #ifdef RYZOM_LUA_UCSTRING
3932 ucstring CLuaIHMRyzom::getTargetSheet()
3934 CEntityCL *target = getTargetEntity();
3935 if (!target) return ucstring();
3937 return target->sheetId().toString();
3939 #else
3940 std::string CLuaIHMRyzom::getTargetSheet()
3942 CEntityCL *target = getTargetEntity();
3943 if (!target) return std::string();
3945 return target->sheetId().toString();
3947 #endif
3949 // ***************************************************************************
3950 sint64 CLuaIHMRyzom::getTargetVpa()
3952 CEntityCL *target = getTargetEntity();
3953 if (!target) return 0;
3955 sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E" + toString("%d", getTargetSlotNr()) + ":P" + toString("%d", CLFECOMMON::PROPERTY_VPA))->getValue64();
3957 return prop;
3960 // ***************************************************************************
3961 sint64 CLuaIHMRyzom::getTargetVpb()
3963 CEntityCL *target = getTargetEntity();
3964 if (!target) return 0;
3966 sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E" + toString("%d", getTargetSlotNr()) + ":P" + toString("%d", CLFECOMMON::PROPERTY_VPB))->getValue64();
3968 return prop;
3971 // ***************************************************************************
3972 sint64 CLuaIHMRyzom::getTargetVpc()
3974 CEntityCL *target = getTargetEntity();
3975 if (!target) return 0;
3977 sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E" + toString("%d", getTargetSlotNr()) + ":P" + toString("%d", CLFECOMMON::PROPERTY_VPB))->getValue64();
3979 return prop;
3982 // ***************************************************************************
3983 sint32 CLuaIHMRyzom::getTargetForceRegion()
3985 CEntityCL *target = getTargetEntity();
3987 if (!target) return -1;
3989 if (target->isPlayer())
3991 CInterfaceManager *pIM = CInterfaceManager::getInstance();
3992 CCDBNodeLeaf *pDbPlayerLevel = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("target_player_level"));
3994 if (!pDbPlayerLevel) return -1;
3996 sint nLevel = pDbPlayerLevel->getValue32();
3998 if (nLevel < 250)
4000 return (sint32)((nLevel < 20) ? 1 : (nLevel / 50) + 2);
4002 else
4004 return 8;
4007 else
4009 CCharacterSheet *pCS = dynamic_cast<CCharacterSheet*>(SheetMngr.get(target->sheetId()));
4010 return pCS ? (sint32) pCS->RegionForce : -1;
4013 return 0;
4016 // ***************************************************************************
4017 sint32 CLuaIHMRyzom::getTargetLevelForce()
4019 CEntityCL *target = getTargetEntity();
4021 if (!target) return -1;
4023 if (target->isPlayer())
4025 CInterfaceManager *pIM = CInterfaceManager::getInstance();
4026 CCDBNodeLeaf *pDbPlayerLevel = NLGUI::CDBManager::getInstance()->getDbProp(CWidgetManager::getInstance()->getParser()->getDefine("target_player_level"));
4028 if (!pDbPlayerLevel) return -1;
4030 sint nLevel = pDbPlayerLevel->getValue32();
4032 if (nLevel < 250)
4034 return (sint32)(((nLevel % 50) * 5 / 50) + 1);
4036 else
4038 return 6;
4041 else
4043 CCharacterSheet *pCS = dynamic_cast<CCharacterSheet*>(SheetMngr.get(target->sheetId()));
4044 return pCS ? (sint32) pCS->ForceLevel : -1;
4047 return 0;
4050 // ***************************************************************************
4051 bool CLuaIHMRyzom::isTargetNPC()
4053 CEntityCL *target = getTargetEntity();
4055 if (!target) return false;
4057 return target->isNPC();
4060 // ***************************************************************************
4061 bool CLuaIHMRyzom::isTargetPlayer()
4063 CEntityCL *target = getTargetEntity();
4065 if (!target) return false;
4067 return target->isPlayer();
4071 // ***************************************************************************
4072 bool CLuaIHMRyzom::isTargetUser()
4074 CEntityCL *target = getTargetEntity();
4076 if (!target) return false;
4078 return target->isUser();
4081 // ***************************************************************************
4082 bool CLuaIHMRyzom::isPlayerInPVPMode()
4084 if (!UserEntity) return false;
4086 return (UserEntity->getPvpMode() & PVP_MODE::PvpFaction || UserEntity->getPvpMode() & PVP_MODE::PvpFactionFlagged || UserEntity->getPvpMode() & PVP_MODE::PvpZoneFaction) != 0;
4089 // ***************************************************************************
4090 bool CLuaIHMRyzom::isTargetInPVPMode()
4092 CEntityCL *target = getTargetEntity();
4094 if (!target) return false;
4096 return (target->getPvpMode() & PVP_MODE::PvpFaction || target->getPvpMode() & PVP_MODE::PvpFactionFlagged || target->getPvpMode() & PVP_MODE::PvpZoneFaction) != 0;
4100 // ***************************************************************************
4101 int CLuaIHMRyzom::removeLandMarks(CLuaState &ls)
4103 CGroupMap *pMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map"));
4104 if (pMap != NULL)
4105 pMap->removeUserLandMarks();
4106 return 0;
4109 // ***************************************************************************
4110 // addLandMark(10000, -4000, "Hello Atys!", "ico_over_homin.tga","","","","")
4111 int CLuaIHMRyzom::addLandMark(CLuaState &ls)
4113 const char* funcName = "addLandMark";
4114 CLuaIHM::checkArgMin(ls, funcName, 4);
4115 CLuaIHM::checkArgMax(ls, funcName, 9);
4116 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); // x
4117 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TNUMBER); // y
4118 CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING); // title
4119 CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING); // texture
4120 CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING); // left click action
4121 CLuaIHM::checkArgType(ls, funcName, 6, LUA_TSTRING); // left click param
4122 CLuaIHM::checkArgType(ls, funcName, 7, LUA_TSTRING); // right click action
4123 CLuaIHM::checkArgType(ls, funcName, 8, LUA_TSTRING); // right click params
4125 CArkPoint point;
4126 point.x = (sint32)(ls.toNumber(1)*1000.f);
4127 point.y = (sint32)(ls.toNumber(2)*1000.f);
4128 point.Title = ls.toString(3);
4129 point.Texture = ls.toString(4);
4130 point.LeftClickAction = ls.toString(5);
4131 point.LeftClickParam = ls.toString(6);
4132 point.RightClickAction = ls.toString(7);
4133 point.RightClickParam = ls.toString(8);
4135 point.Color = CRGBA(255,255,255,255);
4137 if (ls.getTop() >= 9)
4138 CLuaIHM::pop(ls, point.Color);
4140 CGroupMap *pMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map"));
4141 if (pMap != NULL)
4142 pMap->addArkPoint(point);
4143 return 0;
4146 // ***************************************************************************
4147 int CLuaIHMRyzom::delArkPoints(CLuaState &ls)
4149 CGroupMap *pMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map"));
4150 if (pMap != NULL)
4151 pMap->delArkPoints();
4152 return 0;
4155 // ***************************************************************************
4156 int CLuaIHMRyzom::addRespawnPoint(CLuaState &ls)
4158 const char* funcName = "addRespawnPoint";
4159 CLuaIHM::checkArgMin(ls, funcName, 2);
4160 float x = (float) ls.toNumber(1);
4161 float y = (float) ls.toNumber(2);
4162 CVector2f pos(x, y);
4164 CGroupMap *pMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map"));
4165 if (pMap != NULL)
4166 pMap->addUserRespawnPoint(pos);
4167 return 0;
4170 // ***************************************************************************
4171 int CLuaIHMRyzom::updateUserLandMarks(CLuaState &ls)
4173 CGroupMap *pMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map"));
4174 if (pMap != NULL)
4175 pMap->updateUserLandMarks();
4176 return 0;
4179 // ***************************************************************************
4180 int CLuaIHMRyzom::setArkPowoOptions(CLuaState &ls)
4182 const char* funcName = "setArkPowoOptions";
4183 CLuaIHM::checkArgMin(ls, funcName, 2);
4184 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
4185 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
4186 CGroupMap *pMap = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map"));
4187 if (pMap != NULL) {
4188 pMap->setArkPowoMode(ls.toString(1));
4189 pMap->setArkPowoMapMenu(ls.toString(2));
4191 return 0;
4194 // ***************************************************************************
4195 int CLuaIHMRyzom::readUserChannels(CLuaState &ls)
4197 const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
4200 CIFile fd;
4201 if (fd.open(CPath::lookup(filename)))
4203 CIXml stream;
4204 stream.init(fd);
4206 xmlKeepBlanksDefault(0);
4207 xmlNodePtr root = stream.getRootNode();
4209 if (!root) return 0;
4211 CXMLAutoPtr prop;
4213 ls.newTable();
4214 CLuaObject output(ls);
4216 std::vector< string > tags;
4218 // allowed tags
4219 tags.push_back("id");
4220 tags.push_back("name");
4221 tags.push_back("rgba");
4222 tags.push_back("passwd");
4224 xmlNodePtr node = root->children;
4225 uint nb = 0;
4226 while (node)
4228 ls.newTable();
4229 CLuaObject nodeTable(ls);
4231 for (uint i = 0; i < tags.size(); i++)
4233 prop = xmlGetProp(node, (xmlChar*)tags[i].c_str());
4234 if (!prop) return 0;
4236 nodeTable.setValue(tags[i].c_str(), (const char *)prop);
4238 output.setValue(toString("%i", nb).c_str(), nodeTable);
4239 node = node->next;
4240 nb++;
4242 output.push();
4243 // no exception
4244 fd.close();
4246 nlinfo("parse %s", filename.c_str());
4248 catch (const Exception &e)
4250 nlwarning("Error while parsing xml file %s : %s", filename.c_str(), e.what());
4251 return 0;
4253 return 1;
4256 // ***************************************************************************
4257 int CLuaIHMRyzom::saveUserChannels(CLuaState &ls)
4259 const char *funcName = "saveUserChannels";
4261 CLuaIHM::check(ls, ls.getTop()==1 || ls.getTop()==2, funcName);
4262 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TTABLE);
4264 bool verbose = false;
4265 if (ls.getTop() > 1)
4267 CLuaIHM::checkArgType(ls, funcName, 2, LUA_TBOOLEAN);
4268 verbose = ls.toBoolean(2);
4269 ls.pop();
4271 CLuaObject params;
4272 params.pop(ls);
4274 const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
4277 COFile fd;
4278 if (fd.open(filename, false, false, true))
4280 COXml stream;
4281 stream.init(&fd);
4283 xmlDocPtr doc = stream.getDocument();
4284 xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)"interface_config", NULL);
4285 xmlDocSetRootElement(doc, node);
4287 std::string key, value;
4288 ENUM_LUA_TABLE(params, it)
4290 if (it.nextKey().type() == LUA_TSTRING)
4292 xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"channels", NULL);
4294 if (it.nextValue().type() == LUA_TTABLE)
4296 xmlSetProp(newNode, (const xmlChar*)"id", (const xmlChar*)it.nextKey().toString().c_str());
4298 ENUM_LUA_TABLE(it.nextValue(), itt)
4300 if (!itt.nextKey().isString())
4301 continue;
4302 if (!itt.nextValue().isString())
4303 continue;
4305 key = itt.nextKey().toString();
4306 value = itt.nextValue().toString();
4308 xmlSetProp(newNode, (const xmlChar*)key.c_str(), (const xmlChar*)value.c_str());
4313 stream.flush();
4314 fd.close();
4316 nlinfo("save %s", filename.c_str());
4317 if (verbose)
4318 CInterfaceManager::getInstance()->displaySystemInfo("Save " + filename);
4320 catch (const Exception &e)
4322 nlwarning("Error while writing the file %s : %s", filename.c_str(), e.what());
4323 return 0;
4325 return 1;
4328 // ***************************************************************************
4329 int CLuaIHMRyzom::getMaxDynChan(CLuaState &ls)
4331 ls.push((sint32)CChatGroup::MaxDynChanPerPlayer);
4332 return 1;
4335 // ***************************************************************************
4336 std::string CLuaIHMRyzom::createGotoFileButtonTag(const char *fileName, uint line)
4338 //H_AUTO(Lua_CLuaIHM_createGotoFileButtonTag)
4339 if (ClientCfg.LuaDebugInfoGotoButtonEnabled)
4341 // TODO nico : put this in the interface
4342 // add a command button to jump to the wanted file
4343 return toString("/$$%s|%s|lua|%s('%s', %d)$$/",
4344 ClientCfg.LuaDebugInfoGotoButtonTemplate.c_str(),
4345 ClientCfg.LuaDebugInfoGotoButtonCaption.c_str(),
4346 ClientCfg.LuaDebugInfoGotoButtonFunction.c_str(),
4347 fileName,
4348 line
4352 return "";
4355 // ***************************************************************************
4356 void CLuaIHMRyzom::setDbRGBA(const std::string &dbProp, const NLMISC::CRGBA &color)
4358 //H_AUTO(Lua_CLuaIHM_setDbRGBA)
4359 static const std::string dbServer = "SERVER:";
4360 static const std::string dbLocal = "LOCAL:";
4361 static const std::string dbLocalR2 = "LOCAL:R2";
4363 // do not allow write on SERVER: or LOCAL:
4364 if ((dbProp.compare(0, dbServer.size(), dbServer) == 0) || (dbProp.compare(0, dbLocal.size(), dbLocal) == 0))
4366 if (dbProp.compare(0, dbLocalR2.size(), dbLocalR2) != 0)
4368 nlstop;
4369 throw ELuaIHMException("setDbRGBA(): You are not allowed to write on 'SERVER:...' or 'LOCAL:...' database");
4372 // write to the db
4373 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, true);
4374 if (node)
4375 node->setValue64(color.R+(color.G<<8)+(color.B<<16)+(color.A<<24));
4376 return;
4379 // ***************************************************************************
4380 std::string CLuaIHMRyzom::getDbRGBA(const std::string &dbProp)
4382 //H_AUTO(Lua_CLuaIHM_getDbRGBA)
4383 CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp(dbProp, false);
4384 if (node)
4386 CRGBA color = CRGBA::White;
4387 sint64 rgba = (sint64)node->getValue64();
4389 color.R = (sint8)(rgba & 0xff);
4390 color.G = (sint8)((rgba >> 8) & 0xff);
4391 color.B = (sint8)((rgba >> 16) & 0xff);
4392 color.A = (sint8)((rgba >> 24) & 0xff);
4394 return toString("%i %i %i %i", color.R, color.G, color.B, color.A);
4396 return "";
4399 // ***************************************************************************
4400 int CLuaIHMRyzom::displayChatMessage(CLuaState &ls)
4402 //H_AUTO(Lua_CLuaIHM_displayChatMessage)
4403 const char *funcName = "displayChatMessage";
4404 CLuaIHM::checkArgMin(ls, funcName, 2);
4405 CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
4407 CInterfaceProperty prop;
4408 CChatStdInput &ci = PeopleInterraction.ChatInput;
4410 std::string msg = ls.toString(1);
4411 const std::string dbPath = "UI:SAVE:CHAT:COLORS";
4413 if (ls.type(2) == LUA_TSTRING)
4415 std::string input = toLowerAscii(ls.toString(2));
4416 if (input == "around")
4418 prop.readRGBA(std::string(dbPath + ":SAY").c_str(), " ");
4419 ci.AroundMe.displayMessage(msg, prop.getRGBA());
4421 else if (input == "region")
4423 prop.readRGBA(std::string(dbPath + ":REGION").c_str(), " ");
4424 ci.Region.displayMessage(msg, prop.getRGBA());
4426 else if (input == "universe")
4428 prop.readRGBA(std::string(dbPath + ":UNIVERSE_NEW").c_str(), " ");
4429 ci.Universe.displayMessage(msg, prop.getRGBA());
4431 else if (input == "guild")
4433 prop.readRGBA(std::string(dbPath + ":CLADE").c_str(), " ");
4434 ci.Guild.displayMessage(msg, prop.getRGBA());
4436 else if (input == "team")
4438 prop.readRGBA(std::string(dbPath + ":GROUP").c_str(), " ");
4439 ci.Team.displayMessage(msg, prop.getRGBA());
4442 if (ls.type(2) == LUA_TNUMBER)
4444 sint64 id = ls.toInteger(2);
4445 prop.readRGBA(toString("%s:DYN:%i", dbPath.c_str(), id).c_str(), " ");
4446 if (id >= 0 && id < CChatGroup::MaxDynChanPerPlayer)
4447 ci.DynamicChat[id].displayMessage(msg, prop.getRGBA());
4449 return 1;
4452 // ***************************************************************************
4453 int CLuaIHMRyzom::scrollElement(CLuaState &ls)
4455 const char *funcName = "scrollElement";
4457 // scrollElement(object, vertical, direction, offset_multiplier)
4459 CLuaIHM::checkArgMin(ls, funcName, 3);
4460 CLuaIHM::check(ls, ls.getTop() > 2, funcName);
4462 CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), toString("%s requires a UI object in param 1", funcName));
4463 CLuaIHM::check(ls, ls.type(2)==LUA_TBOOLEAN, toString("%s requires a boolean in param 2", funcName));
4464 CLuaIHM::check(ls, ls.isInteger(3), toString("%s requires a number in param 3", funcName));
4466 if (ls.getTop() > 3)
4467 CLuaIHM::check(ls, ls.isInteger(4), toString("%s requires a number in param 4", funcName));
4469 CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
4470 if (pIE)
4472 // must be a scroll element
4473 CCtrlScroll *pCS = dynamic_cast<CCtrlScroll*>(pIE);
4474 if (pCS)
4476 sint32 direction = 0;
4477 sint32 multiplier = 16;
4479 direction = (ls.toInteger(3) > 0) ? 1 : -1;
4480 if (ls.getTop() > 3)
4481 multiplier = (ls.toInteger(4) > 0) ? ls.toInteger(4) : 1;
4483 const bool vertical = ls.toBoolean(2);
4484 if (vertical)
4485 pCS->moveTrackY(-(direction * multiplier));
4486 else
4487 pCS->moveTrackX(-(direction * multiplier));
4489 return 0;
4492 ls.pushNil();
4493 return 1;