Added: game:onLoadMap lua event to allow override map texture as needed

--HG--
branch : develop
feature/pipeline-tools
Nimetu 6 years ago
parent 8c51bbc808
commit 4e515eedf0

@ -0,0 +1,42 @@
--
-- custom maps
--
if (game==nil) then
game= {};
end
-- alternative textures for maps
game.mapTextures = {}
-- game.mapTextures["zorai_map.tga"] = "tryker_map.tga"
-- register alternative texture for map
function game:setAltMap(mapName, altMap)
self.mapTextures[mapName] = altMap
end
-- remove alternative map texture
function game:removeAltMap(mapName)
self.mapTextures[mapName] = nil
end
-- map = getUI("ui:interface:map:content:map_content:actual_map")
function game:onLoadMap(map)
-- debugInfo("onLoadMap(id=".. map.id ..", texture=".. map.texture ..")");
-- if alt view not enabled
if getDbProp("UI:VARIABLES:SHOW_ALT_MAP") == 0 or map:isIsland() then
return
end
local texture = map.texture
if self.mapTextures[texture] ~= nil then
-- debugInfo("-- using ".. self.mapTextures[texture] .." for " .. texture)
return self.mapTextures[texture]
end
end
-- register map overrride
-- game:setAltMap("fyros_map.tga", "fyros_map_sp.tga")

@ -2,6 +2,10 @@
<root id="interface" x="0" y="0" w="800" h="600" active="true" />
<lua file="map.lua" />
<!-- flag for game:onLoadMap() handler to override map texture or not -->
<variable entry="UI:VARIABLES:SHOW_ALT_MAP" type="bool" value="0" />
<!-- base menu of landmark -->
<group type="menu" id="land_mark_menu" extends="base_menu">

@ -38,6 +38,7 @@
#include "../sheet_manager.h" // for MaxNumPeopleInTeam
#include "../global.h"
#include "nel/gui/ctrl_quad.h"
#include "nel/gui/lua_ihm.h"
//
#include "nel/misc/xml_auto_ptr.h"
#include "game_share/mission_desc.h"
@ -403,6 +404,7 @@ CGroupMap::CGroupMap(const TCtorParam &param)
_MaxH = 2000;
//_MinW = 50;
_MapTF = NULL;
_MapTexture.clear();
_PlayerPosMaterial = NULL;
_PlayerPosTF = NULL;
_MapTexW = 0;
@ -462,6 +464,8 @@ CGroupMap::CGroupMap(const TCtorParam &param)
_PanStartDateInMs = 0;
_DeltaTimeBeforePanInMs = 0;
_DeltaPosBeforePan = 0;
//
_LuaLoadMapEntered = false;
}
//============================================================================================================
@ -2070,16 +2074,62 @@ void CGroupMap::loadPlayerPos()
_PlayerPosMaterial.setTexture(_PlayerPosTF);
}
//============================================================================================================
void CGroupMap::reload()
{
if (!_CurMap || !getActive()) return;
SMap* current = _CurMap;
_CurMap = NULL;
setMap(current);
}
//============================================================================================================
void CGroupMap::loadMap()
{
_MapLoadFailure = true;
if (!_CurMap) return;
const std::string &mapName = _CurMap->BitmapName;
std::string fullName = NLMISC::CPath::lookup(mapName, false, false);
_MapTexture = _CurMap->BitmapName;
// call lua game:onLoadMap() function if present
// avoid deadlock if called recursively
if (!_LuaLoadMapEntered)
{
_LuaLoadMapEntered = true;
CLuaState *ls = CLuaManager::getInstance().getLuaState();
CLuaStackRestorer lsr(ls, ls->getTop());
ls->pushGlobalTable();
CLuaObject game(*ls);
game = game["game"];
if (!game["onLoadMap"].isNil())
{
uint numArg = 1;
uint numResult = 1;
CLuaIHM::pushReflectableOnStack(*ls, this);
if (game.callMethodByNameNoThrow("onLoadMap", numArg, numResult))
{
if (ls->isString(1))
{
if (!NLMISC::CPath::lookup(ls->toString(1), false, false).empty())
_MapTexture = ls->toString(1);
else
nlwarning("Custom map texture not found '%s' for map '%s'", ls->toString(1), _MapTexture.c_str());
}
}
}
_LuaLoadMapEntered = false;
}
std::string fullName = NLMISC::CPath::lookup(_MapTexture, false, false);
if (fullName.empty())
{
nlwarning("Can't find map %s", mapName.c_str());
nlwarning("Can't find map %s", _MapTexture.c_str());
return;
}
uint32 w, h;
@ -2098,7 +2148,7 @@ void CGroupMap::loadMap()
}
else
{
nlwarning("Can't open map %s", mapName.c_str());
nlwarning("Can't open map %s", _MapTexture.c_str());
return;
}
_MapTF = Driver->createTextureFile(fullName);
@ -3322,6 +3372,36 @@ SMap *CGroupMap::getParentMap(SMap *map)
return NULL;
}
//=========================================================================================================
std::string CGroupMap::getContinentName() const
{
if (_CurMap == NULL) return "";
return toLower(_CurMap->ContinentName);
}
//=========================================================================================================
std::string CGroupMap::getMapTexture() const
{
return toLower(_MapTexture);
}
//=========================================================================================================
int CGroupMap::luaReload(CLuaState &ls)
{
CLuaIHM::checkArgCount(ls, "reload", 0);
reload();
return 0;
}
//=========================================================================================================
int CGroupMap::luaIsIsland(CLuaState &ls)
{
CLuaIHM::checkArgCount(ls, "isIsland", 0);
ls.push(_IsIsland);
return 1;
}
/////////////////////
// ACTION HANDLERS //

@ -114,6 +114,17 @@ public:
*/
virtual void onUpdate(CGroupMap &/* owner */) {}
};
REFLECT_EXPORT_START(CGroupMap, CInterfaceGroup)
REFLECT_STRING("continent", getContinentName, dummySet);
REFLECT_STRING("texture", getMapTexture, dummySet);
REFLECT_LUA_METHOD("isIsland", luaIsIsland);
REFLECT_LUA_METHOD("reload", luaReload);
REFLECT_EXPORT_END
int luaReload(CLuaState &ls);
int luaIsIsland(CLuaState &ls);
public:
CGroupMap(const TCtorParam &param);
virtual ~CGroupMap();
@ -134,6 +145,14 @@ public:
void setMap(const std::string &mapName);
void setMap(SMap *map);
// return current continent
std::string getContinentName() const;
// return currently displayed map texture
std::string getMapTexture() const;
// reload current map texture
void reload();
// pan the map of the given number of pixels
void pan(sint32 dx, sint32 dy);
@ -323,6 +342,7 @@ private:
CContinent *_CurContinent; // the last continent for which the map was displayed (can be NULL if world)
NLMISC::CVector2f _MapMinCorner; // In world coordinates
NLMISC::CVector2f _MapMaxCorner;
std::string _MapTexture; // currently displayed map texture
bool _IsIsland; // true if current map is an island (island bitmap need not to be raised to the next
// power of 2
@ -499,6 +519,8 @@ private:
// r2 islands
std::vector<SMap> _Islands;
// guard against recursive calls
bool _LuaLoadMapEntered;
private:
void loadPlayerPos();

@ -34,6 +34,7 @@ void registerInterfaceElements()
CViewPointerRyzom::forceLinking();
REGISTER_REFLECTABLE_CLASS(CViewRadar, CViewBase);
REGISTER_REFLECTABLE_CLASS(CGroupMap, CInterfaceGroup);
REGISTER_REFLECTABLE_CLASS(CDBCtrlSheet, CCtrlDraggable);
REGISTER_REFLECTABLE_CLASS(IListSheetBase, CInterfaceGroup);
REGISTER_REFLECTABLE_CLASS(CInterface3DScene, CInterfaceGroup);

Loading…
Cancel
Save