Added: Export usefull cursor and shape functions in lua:

getGroundAtMouse
getMousePos
getMouseDown
getMouseMiddleDown
getMouseRightDown
setMouseCursor
setupShape
getShapeIdAt
addShape
moveShape
rotateShape
getShapePos
getShapeScale
getShapeRot
getShapeColPos
getShapeColScale
getShapeColOrient
deleteShape
This commit is contained in:
ulukyn 2016-12-10 22:04:33 +01:00
parent 18b024f0c7
commit 512d300741
15 changed files with 1910 additions and 528 deletions

View file

@ -38,14 +38,17 @@ namespace NLGUI
void resetPointerPos (); void resetPointerPos ();
void setPointerDown (bool pd); void setPointerDown (bool pd);
void setPointerMiddleDown (bool pd);
void setPointerRightDown (bool pd);
void setPointerDownString (const std::string &s); void setPointerDownString (const std::string &s);
void getPointerPos (sint32 &x, sint32 &y); void getPointerPos (sint32 &x, sint32 &y);
void getPointerDispPos (sint32 &x, sint32 &y); void getPointerDispPos (sint32 &x, sint32 &y);
void getPointerOldPos (sint32 &x, sint32 &y); void getPointerOldPos (sint32 &x, sint32 &y);
void getPointerDownPos (sint32 &x, sint32 &y); bool getPointerDown (sint32 &x, sint32 &y);
bool getPointerDown (); bool getPointerMiddleDown (sint32 &x, sint32 &y);
bool getPointerRightDown (sint32 &x, sint32 &y);
std::string getPointerDownString (); std::string getPointerDownString ();
bool getPointerDrag (); bool getPointerDrag ();
@ -70,6 +73,12 @@ namespace NLGUI
bool _PointerDown; // Is the pointer down ? bool _PointerDown; // Is the pointer down ?
sint32 _PointerDownX; // Pointer down position sint32 _PointerDownX; // Pointer down position
sint32 _PointerDownY; sint32 _PointerDownY;
bool _PointerMiddleDown; // Is the middle pointer down ?
sint32 _PointerMiddleDownX; // Pointer middle down position
sint32 _PointerMiddleDownY;
bool _PointerRightDown; // Is the right pointer down ?
sint32 _PointerRightDownX; // Pointer right down position
sint32 _PointerRightDownY;
std::string _PointerDownString; // What is under the pointer at the down position std::string _PointerDownString; // What is under the pointer at the down position
bool _PointerDrag; // Is the pointer down and we have moved ? bool _PointerDrag; // Is the pointer down and we have moved ?
bool _PointerVisible; // Is the pointer visible or hidden ? bool _PointerVisible; // Is the pointer visible or hidden ?

View file

@ -76,16 +76,39 @@ namespace NLGUI
{ {
_PointerDown = pd; _PointerDown = pd;
if (_PointerDown == true) if (_PointerDown)
{ {
_PointerDownX = _PointerX; _PointerDownX = _PointerX;
_PointerDownY = _PointerY; _PointerDownY = _PointerY;
} }
else
if (_PointerDown == false)
_PointerDrag = false; _PointerDrag = false;
} }
// --------------------------------------------------------------------------------------------------------------------
void CViewPointerBase::setPointerMiddleDown (bool pd)
{
_PointerMiddleDown = pd;
if (_PointerMiddleDown)
{
_PointerMiddleDownX = _PointerX;
_PointerMiddleDownY = _PointerY;
}
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointerBase::setPointerRightDown (bool pd)
{
_PointerRightDown = pd;
if (_PointerRightDown)
{
_PointerRightDownX = _PointerX;
_PointerRightDownY = _PointerY;
}
}
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
void CViewPointerBase::setPointerDownString (const std::string &s) void CViewPointerBase::setPointerDownString (const std::string &s)
{ {
@ -116,16 +139,30 @@ namespace NLGUI
} }
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
void CViewPointerBase::getPointerDownPos (sint32 &x, sint32 &y) bool CViewPointerBase::getPointerDown (sint32 &x, sint32 &y)
{ {
x = _PointerDownX; x = _PointerDownX;
y = _PointerDownY; y = _PointerDownY;
return _PointerDown;
} }
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------
bool CViewPointerBase::getPointerDown () bool CViewPointerBase::getPointerMiddleDown (sint32 &x, sint32 &y)
{ {
return _PointerDown; x = _PointerMiddleDownX;
y = _PointerMiddleDownY;
return _PointerMiddleDown;
}
// --------------------------------------------------------------------------------------------------------------------
bool CViewPointerBase::getPointerRightDown (sint32 &x, sint32 &y)
{
x = _PointerRightDownX;
y = _PointerRightDownY;
return _PointerRightDown;
} }
// -------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------

View file

@ -55,6 +55,7 @@ CContextualCursor ContextCur;
CLFECOMMON::TCLEntityId SlotUnderCursor; CLFECOMMON::TCLEntityId SlotUnderCursor;
uint32 MissionId = 0; uint32 MissionId = 0;
uint32 MissionRingId = 0; uint32 MissionRingId = 0;
sint32 InstanceId = 0;
UInstance selectedInstance; UInstance selectedInstance;
const UInstance noSelectedInstance; const UInstance noSelectedInstance;
string selectedInstanceURL; string selectedInstanceURL;
@ -85,6 +86,7 @@ void contextExtractRM (bool rightClick, bool dblClick);
void contextMission (bool rightClick, bool dblClick); void contextMission (bool rightClick, bool dblClick);
void contextWebPage (bool rightClick, bool dblClick); void contextWebPage (bool rightClick, bool dblClick);
void contextWebIG (bool rightClick, bool dblClick); void contextWebIG (bool rightClick, bool dblClick);
void contextARKitect (bool rightClick, bool dblClick);
void contextRingMission (bool rightClick, bool dblClick); void contextRingMission (bool rightClick, bool dblClick);
void contextOutpost (bool rightClick, bool dblClick); void contextOutpost (bool rightClick, bool dblClick);
void contextBuildTotem (bool rightClick, bool dblClick); void contextBuildTotem (bool rightClick, bool dblClick);
@ -123,6 +125,7 @@ void initContextualCursor()
ContextCur.add(true, "MISSION", string(""), 0.0f, checkUnderCursor, contextMission); ContextCur.add(true, "MISSION", string(""), 0.0f, checkUnderCursor, contextMission);
ContextCur.add(true, "WEB PAGE", string(""), 0.0f, checkUnderCursor, contextWebPage); ContextCur.add(true, "WEB PAGE", string(""), 0.0f, checkUnderCursor, contextWebPage);
ContextCur.add(true, "WEBIG", string(""), 0.0f, checkUnderCursor, contextWebIG); ContextCur.add(true, "WEBIG", string(""), 0.0f, checkUnderCursor, contextWebIG);
ContextCur.add(false, "ARKITECT", string("curs_pick.tga"), 0.0f, checkUnderCursor, contextARKitect);
ContextCur.add(true, "OUTPOST", string(""), 0.0f, checkUnderCursor, contextOutpost); ContextCur.add(true, "OUTPOST", string(""), 0.0f, checkUnderCursor, contextOutpost);
ContextCur.add(true, "RING MISSION", string(""), 0.0f, checkUnderCursor, contextRingMission); ContextCur.add(true, "RING MISSION", string(""), 0.0f, checkUnderCursor, contextRingMission);
ContextCur.add(true, "BUILD_TOTEM", string("uimGcmChooseBuilding"), 0.0f, checkUnderCursor, contextBuildTotem); ContextCur.add(true, "BUILD_TOTEM", string("uimGcmChooseBuilding"), 0.0f, checkUnderCursor, contextBuildTotem);
@ -526,10 +529,10 @@ void checkUnderCursor()
} }
else else
{ {
CShapeInstanceReference instref = EntitiesMngr.getShapeInstanceUnderPos(cursX, cursY); sint32 instance_idx;
CShapeInstanceReference instref = EntitiesMngr.getShapeInstanceUnderPos(cursX, cursY, instance_idx);
bool cleanSelectedInstance = EntitiesMngr.instancesRemoved(); if (EntitiesMngr.instancesRemoved())
if (cleanSelectedInstance)
selectedInstance = noSelectedInstance; selectedInstance = noSelectedInstance;
UInstance instance = instref.Instance; UInstance instance = instref.Instance;
@ -552,9 +555,16 @@ void checkUnderCursor()
selectedInstance.getMaterial(j).setShininess( 1000.0f ); selectedInstance.getMaterial(j).setShininess( 1000.0f );
} }
} }
if (!instref.ContextText.empty())
selectedInstanceURL = instref.ContextURL;
if (instref.ContextText.empty())
{
InstanceId = instance_idx;
if(ContextCur.context("ARKITECT", 0.f, ucstring()))
return;
}
else
{ {
selectedInstanceURL = instref.ContextURL;
ucstring contextText; ucstring contextText;
contextText.fromUtf8(instref.ContextText); contextText.fromUtf8(instref.ContextText);
if(ContextCur.context("WEBIG", 0.f, contextText)) if(ContextCur.context("WEBIG", 0.f, contextText))
@ -875,6 +885,8 @@ void contextWebPage(bool rightClick, bool dblClick)
//----------------------------------------------- //-----------------------------------------------
void contextWebIG(bool rightClick, bool dblClick) void contextWebIG(bool rightClick, bool dblClick)
{ {
if(rightClick)
return;
CInterfaceManager *IM = CInterfaceManager::getInstance(); CInterfaceManager *IM = CInterfaceManager::getInstance();
CInterfaceElement *pGC = CWidgetManager::getInstance()->getElementFromId("ui:interface:bot_chat_object"); CInterfaceElement *pGC = CWidgetManager::getInstance()->getElementFromId("ui:interface:bot_chat_object");
CInterface3DShape *el= dynamic_cast<CInterface3DShape*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:bot_chat_object:scene3d:object_1")); CInterface3DShape *el= dynamic_cast<CInterface3DShape*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:bot_chat_object:scene3d:object_1"));
@ -896,6 +908,24 @@ void contextWebIG(bool rightClick, bool dblClick)
} }
}// contextWebIG // }// contextWebIG //
//-----------------------------------------------
// contextARKitect :
//-----------------------------------------------
void contextARKitect(bool rightClick, bool dblClick)
{
string header;
if (rightClick)
{
header = toString("rightClick = true\nSelectedInstanceId = %u\n", InstanceId);
} else {
header = toString("rightClick = false\nSelectedInstanceId = %u\n", InstanceId);
}
CLuaManager::getInstance().executeLuaScript(string(header)+selectedInstanceURL, true);
}// contextARKitect //
//----------------------------------------------- //-----------------------------------------------
// contextOutpost // contextOutpost
//----------------------------------------------- //-----------------------------------------------

View file

@ -43,6 +43,7 @@
#include "interface_v3/people_interraction.h" #include "interface_v3/people_interraction.h"
#include "interface_v3/bar_manager.h" #include "interface_v3/bar_manager.h"
#include "interface_v3/group_compas.h" #include "interface_v3/group_compas.h"
#include "misc.h"
// 3D // 3D
#include "nel/3d/quad_tree.h" #include "nel/3d/quad_tree.h"
// Interface 3D // Interface 3D
@ -65,11 +66,13 @@
#include "player_r2_cl.h" #include "player_r2_cl.h"
#include "r2/editor.h" #include "r2/editor.h"
/////////// ///////////
// USING // // USING //
/////////// ///////////
using namespace NLMISC; using namespace NLMISC;
using namespace NL3D; using namespace NL3D;
using namespace NLPACS;
using namespace std; using namespace std;
@ -400,6 +403,7 @@ CEntityManager::CEntityManager()
_NbPlayer = 0; _NbPlayer = 0;
_NbChar = 0; _NbChar = 0;
_LastEntityUnderPos= NULL; _LastEntityUnderPos= NULL;
_LastRemovedInstance = -1;
}// CEntityManager // }// CEntityManager //
//----------------------------------------------- //-----------------------------------------------
@ -522,22 +526,179 @@ void CEntityManager::reinit()
initialize(_NbMaxEntity); initialize(_NbMaxEntity);
} }
CShapeInstanceReference CEntityManager::createInstance(const string& shape, const CVector &pos, const string& text, const string& url, bool bbox_active) CShapeInstanceReference CEntityManager::createInstance(const string& shape, const CVector &pos, const string& text, const string& url, bool haveCollisions, sint32& idx)
{ {
idx = -1;
CShapeInstanceReference nullinstref(UInstance(), string(""), string("")); CShapeInstanceReference nullinstref(UInstance(), string(""), string(""));
if (!Scene) return nullinstref; if (!Scene) return nullinstref;
UInstance instance = Scene->createInstance(shape); UInstance instance = Scene->createInstance(shape);
if (text.empty())
bbox_active = false;
CShapeInstanceReference instref = CShapeInstanceReference(instance, text, url, bbox_active);
if(!instance.empty()) if(!instance.empty())
{ {
_ShapeInstances.push_back(instref); UMovePrimitive *primitive = NULL;
if (PACS && haveCollisions)
{
primitive = PACS->addCollisionablePrimitive(dynamicWI, 1);
primitive->setDontSnapToGround(false);
}
// Put instance in last deleted position if found
if (_LastRemovedInstance != -1)
{
idx = _LastRemovedInstance;
nlinfo("OK adding to index : %d", idx);
_ShapeInstances[idx].Instance = instance;
_ShapeInstances[idx].Primitive = primitive;
_ShapeInstances[idx].ContextText = text;
_ShapeInstances[idx].ContextURL = url;
_ShapeInstances[idx].BboxActive = !text.empty() || !url.empty();
_ShapeInstances[idx].Deleted = false;
_LastRemovedInstance = _ShapeInstances[idx].LastDeleted;
_ShapeInstances[idx].LastDeleted = -1;
return _ShapeInstances[idx];
}
else
{
nlinfo("OK url, text = %s, %s", url.c_str(), text.c_str());
CShapeInstanceReference instref = CShapeInstanceReference(instance, text, url, !text.empty() || !url.empty());
instref.Primitive = primitive;
idx = _ShapeInstances.size();
_ShapeInstances.push_back(instref);
return instref;
}
} }
return instref; return nullinstref;
} }
bool CEntityManager::deleteInstance(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size())
return false;
if (!_ShapeInstances[idx].Instance.empty())
Scene->deleteInstance(_ShapeInstances[idx].Instance);
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
if (primitive)
{
PACS->removePrimitive(primitive);
}
_ShapeInstances[idx].Primitive = NULL;
_ShapeInstances[idx].Deleted = true;
_ShapeInstances[idx].LastDeleted = _LastRemovedInstance;
_LastRemovedInstance = idx;
return true;
}
CVector CEntityManager::getInstancePos(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return CVector(0,0,0);
return instance.getPos();
}
bool CEntityManager::setInstancePos(uint32 idx, CVector pos)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return false;
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return false;
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
if (primitive)
{
primitive->setGlobalPosition(_ShapeInstances[idx].PrimRelativePos + pos, dynamicWI);
}
instance.setPos(pos);
return true;
}
CVector CEntityManager::getInstanceRot(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return CVector(0,0,0);
return instance.getRotEuler();
}
bool CEntityManager::setInstanceRot(uint32 idx, CVector rot)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return false;
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return false;
instance.setRotEuler(rot);
return true;
}
CVector CEntityManager::getInstanceScale(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return CVector(0,0,0);
return instance.getScale();
}
CVector CEntityManager::getInstanceColPos(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
return _ShapeInstances[idx].PrimRelativePos;
}
CVector CEntityManager::getInstanceColScale(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
if (!primitive)
return CVector(0,0,0);
float width, depth;
primitive->getSize(width, depth);
float height = primitive->getHeight();
return CVector(width, depth, height);
}
double CEntityManager::getInstanceColOrient(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return 0.f;
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
if (!primitive)
return 0.f;
return primitive->getOrientation(dynamicWI);
}
bool CEntityManager::removeInstances() bool CEntityManager::removeInstances()
{ {
if (!Scene) return false; if (!Scene) return false;
@ -546,9 +707,16 @@ bool CEntityManager::removeInstances()
{ {
if (!_ShapeInstances[i].Instance.empty()) if (!_ShapeInstances[i].Instance.empty())
Scene->deleteInstance(_ShapeInstances[i].Instance); Scene->deleteInstance(_ShapeInstances[i].Instance);
UMovePrimitive *primitive = _ShapeInstances[i].Primitive;
if (primitive)
{
PACS->removePrimitive(primitive);
}
} }
_ShapeInstances.clear(); _ShapeInstances.clear();
_InstancesRemoved = true; _InstancesRemoved = true;
_LastRemovedInstance = -1;
return true; return true;
} }
@ -559,11 +727,166 @@ bool CEntityManager::instancesRemoved()
return instRemoved; return instRemoved;
} }
CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float y)
bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const vector<string> &values) {
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return false;
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return false;
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
for (uint32 i=0; i < keys.size(); i++)
{
nlinfo("Setup [%s] with [%s]", keys[i].c_str(), values[i].c_str());
string param = keys[i];
if (param == "transparency")
{
uint t;
if( fromString( values[i], t ) ) {
t = max(0, min((int)t, 255));
makeInstanceTransparent(instance, t, t == 255);
}
}
else if (param == "colorize")
{
CRGBA c;
if( fromString( values[i], c ) )
{
for(uint j=0;j<instance.getNumMaterials();j++)
{
instance.getMaterial(j).setShininess( 1000.0f );
instance.getMaterial(j).setEmissive(c);
instance.getMaterial(j).setDiffuse(c);
}
}
}
else if (param == "texture")
{
if (!values[i].empty())
{
for(uint j=0;j<instance.getNumMaterials();j++)
{
sint numStages = instance.getMaterial(j).getLastTextureStage() + 1;
for(sint l = 0; l < numStages; l++)
{
if (instance.getMaterial(j).isTextureFile((uint) l))
instance.getMaterial(j).setTextureFileName(values[i], (uint) l);
}
}
}
}
else if (param == "scale x" || param == "scale y" || param == "scale z")
{
float v;
CVector scale = instance.getScale();
if( getRelativeFloatFromString( values[i], v ) ) {
updateVector(param, scale, v, true);
} else {
updateVector(param, scale, v, false);
}
instance.setScale(scale);
}
// Primitive colissions setups
if (!primitive) continue;
if (param == "col size x" || param == "col size y" || param == "col size z")
{
float width, depth;
primitive->getSize(width, depth);
float height = primitive->getHeight();
CVector size = CVector(width, depth, height);
float v;
if( getRelativeFloatFromString( values[i], v ) ) {
updateVector(param, size, v, true);
} else {
updateVector(param, size, v, false);
}
primitive->setSize(size.x, size.y);
primitive->setHeight(size.z);
}
else if (param == "col pos x" || param == "col pos y" || param == "col pos z")
{
CVector pos = instance.getPos();
float v;
if( getRelativeFloatFromString( values[i], v ) ) {
updateVector(param, _ShapeInstances[idx].PrimRelativePos, v, false);
} else {
if (param == "col pos x")
_ShapeInstances[idx].PrimRelativePos.x = v - pos.x;
if (param == "col pos y")
_ShapeInstances[idx].PrimRelativePos.y = v - pos.y;
if (param == "col pos z")
_ShapeInstances[idx].PrimRelativePos.z = v - pos.z;
}
primitive->setGlobalPosition(pos + _ShapeInstances[idx].PrimRelativePos, dynamicWI);
}
else if (param == "col orientation")
{
double orient = primitive->getOrientation(dynamicWI);
double v = 0.f;
if (values[i].empty())
continue;
if (values[i][0] == '+')
{
fromString(values[i].substr(1), v);
orient += v;
}
else
{
fromString(values[i], v);
orient = v;
}
primitive->setOrientation(orient, dynamicWI);
}
else if (param == "col mask player")
{
bool active;
fromString(values[i], active);
UMovePrimitive::TCollisionMask mask=primitive->getCollisionMask();
if (active)
primitive->setCollisionMask(mask|MaskColPlayer);
else
primitive->setCollisionMask(mask&~MaskColPlayer);
}
else if (param == "col mask door")
{
bool active;
fromString(values[i], active);
UMovePrimitive::TCollisionMask mask=primitive->getCollisionMask();
if (active)
primitive->setCollisionMask(mask|MaskColDoor);
else
primitive->setCollisionMask(mask&~MaskColDoor);
}
else if (param == "col obstacle")
{
bool active;
fromString(values[i], active);
primitive->setObstacle(active);
}
}
}
CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float y, sint32 &idx)
{ {
CShapeInstanceReference selectedInstance(UInstance(), string(""), string("")); CShapeInstanceReference selectedInstance(UInstance(), string(""), string(""));
_LastInstanceUnderPos= NULL; _LastInstanceUnderPos= NULL;
idx = -1;
// If not initialised, return // If not initialised, return
if (_ShapeInstances.empty()) if (_ShapeInstances.empty())
return selectedInstance; return selectedInstance;
@ -583,29 +906,32 @@ CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float
float bestDist = 255; float bestDist = 255;
for(uint i=0; i<_ShapeInstances.size(); i++) for(uint i=0; i<_ShapeInstances.size(); i++)
{ {
if (_ShapeInstances[i].BboxActive) if (!_ShapeInstances[i].Deleted && _ShapeInstances[i].BboxActive)
{ {
H_AUTO(RZ_Client_GEUP_box_intersect) H_AUTO(RZ_Client_GEUP_box_intersect)
// if intersect the bbox // if intersect the bbox
NLMISC::CAABBox bbox; NLMISC::CAABBox bbox;
//= _ShapeInstances[i].SelectionBox; //= _ShapeInstances[i].SelectionBox;
_ShapeInstances[i].Instance.getShapeAABBox(bbox); if(!_ShapeInstances[i].Instance.empty()) {
if (bbox.getCenter() == CVector::Null) _ShapeInstances[i].Instance.getShapeAABBox(bbox);
{ if (bbox.getCenter() == CVector::Null)
bbox.setMinMax(CVector(-0.3f, -0.3f, -0.3f)+_ShapeInstances[i].Instance.getPos(), CVector(0.3f, 0.3f, 0.3f)+_ShapeInstances[i].Instance.getPos());
}
else
{
bbox.setMinMax((bbox.getMin()*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos(), (bbox.getMax()*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos());
}
if(bbox.intersect(pos, pos+dir*15.0f))
{
float dist = (bbox.getCenter()-pos).norm();
if (dist < bestDist)
{ {
selectedInstance = _ShapeInstances[i]; bbox.setMinMax(CVector(-0.3f, -0.3f, -0.3f)+_ShapeInstances[i].Instance.getPos(), CVector(0.3f, 0.3f, 0.3f)+_ShapeInstances[i].Instance.getPos());
bestDist = dist; }
else
{
bbox.setMinMax((bbox.getMin()*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos(), (bbox.getMax()*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos());
}
if(bbox.intersect(pos, pos+dir*50.0f))
{
float dist = (bbox.getCenter()-pos).norm();
if (dist < bestDist)
{
selectedInstance = _ShapeInstances[i];
bestDist = dist;
idx = (sint32)i;
}
} }
} }
} }

View file

@ -101,12 +101,24 @@ public:
ContextText = text; ContextText = text;
ContextURL = url; ContextURL = url;
BboxActive = bbox_active; BboxActive = bbox_active;
Deleted = false;
LastDeleted = -1;
Primitive = NULL;
PrimSize = CVector(1.f, 1.f, 1.f);
PrimHeight = 1.f;
PrimRelativePos = CVector(0.f, 0.f, 0.f);
} }
NL3D::UInstance Instance; NL3D::UInstance Instance;
NLPACS::UMovePrimitive *Primitive;
CVector PrimSize;
float PrimHeight;
CVector PrimRelativePos;
string ContextText; string ContextText;
string ContextURL; string ContextURL;
bool BboxActive; bool BboxActive;
bool Deleted;
sint32 LastDeleted;
}; };
/** /**
@ -132,6 +144,7 @@ private:
/// Shapes Instances caches /// Shapes Instances caches
std::vector<CShapeInstanceReference> _ShapeInstances; std::vector<CShapeInstanceReference> _ShapeInstances;
sint32 _LastRemovedInstance;
bool _InstancesRemoved; bool _InstancesRemoved;
typedef struct typedef struct
@ -213,10 +226,20 @@ public:
void reinit(); void reinit();
CShapeInstanceReference createInstance(const string& shape, const CVector &pos, const string &text, const string &url, bool active=true); CShapeInstanceReference createInstance(const string& shape, const CVector &pos, const string &text, const string &url, bool haveCollisions, sint32 &idx);
bool deleteInstance(uint32 idx);
bool removeInstances(); bool removeInstances();
CVector getInstancePos(uint32 idx);
bool setInstancePos(uint32 idx, CVector pos);
CVector getInstanceRot(uint32 idx);
CVector getInstanceScale(uint32 idx);
CVector getInstanceColPos(uint32 idx);
CVector getInstanceColScale(uint32 idx);
double getInstanceColOrient(uint32 idx);
bool setInstanceRot(uint32 idx, CVector pos);
bool instancesRemoved(); bool instancesRemoved();
CShapeInstanceReference getShapeInstanceUnderPos(float x, float y); bool setupInstance(uint32 idx, const std::vector<std::string> &keys, const std::vector<std::string> &values);
CShapeInstanceReference getShapeInstanceUnderPos(float x, float y, sint32 &idx);
/** /**
* Create an entity according to the slot and the form. * Create an entity according to the slot and the form.

View file

@ -271,6 +271,15 @@ void HandleSystemCursorCapture(const CEvent &event)
{ {
CEventMouseDown &em = (CEventMouseDown &) event; CEventMouseDown &em = (CEventMouseDown &) event;
DownMouseButtons |= em.Button & (leftButton | middleButton | rightButton); DownMouseButtons |= em.Button & (leftButton | middleButton | rightButton);
CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
if (cursor)
{
cursor->setPointerDown(em.Button == leftButton);
cursor->setPointerMiddleDown(em.Button == middleButton);
cursor->setPointerRightDown(em.Button == rightButton);
}
Driver->setCapture(true); Driver->setCapture(true);
} }
@ -281,6 +290,13 @@ void HandleSystemCursorCapture(const CEvent &event)
DownMouseButtons &= ~(em.Button & (leftButton | middleButton | rightButton)); DownMouseButtons &= ~(em.Button & (leftButton | middleButton | rightButton));
if (DownMouseButtons == 0) if (DownMouseButtons == 0)
{ {
CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
if (cursor)
{
cursor->setPointerDown(false);
cursor->setPointerMiddleDown(false);
cursor->setPointerRightDown(false);
}
Driver->setCapture(false); Driver->setCapture(false);
} }
} }

View file

@ -2520,7 +2520,6 @@ class CAHAddShape : public IActionHandler
} }
bool have_shapes = true; bool have_shapes = true;
bool first_shape = true;
while(have_shapes) while(have_shapes)
{ {
string shape; string shape;
@ -2537,8 +2536,8 @@ class CAHAddShape : public IActionHandler
have_shapes = false; have_shapes = false;
} }
sint32 idx;
CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector((float)x, (float)y, (float)z), c, u, first_shape); CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector((float)x, (float)y, (float)z), c, u, false, idx);
UInstance instance = instref.Instance; UInstance instance = instref.Instance;
if(!instance.empty()) if(!instance.empty())
@ -2558,7 +2557,7 @@ class CAHAddShape : public IActionHandler
instance.getMaterial(j).setShininess( 1000.0f ); instance.getMaterial(j).setShininess( 1000.0f );
} }
if (!texture_name.empty() && first_shape) if (!texture_name.empty())
{ {
sint numStages = instance.getMaterial(j).getLastTextureStage() + 1; sint numStages = instance.getMaterial(j).getLastTextureStage() + 1;
for(sint l = 0; l < numStages; l++) for(sint l = 0; l < numStages; l++)
@ -2570,9 +2569,7 @@ class CAHAddShape : public IActionHandler
} }
} }
} }
first_shape = false;
if (transparency.empty()) if (transparency.empty())
::makeInstanceTransparent(instance, 255, false); ::makeInstanceTransparent(instance, 255, false);
else else
@ -2605,6 +2602,9 @@ class CAHAddShape : public IActionHandler
instance.setPos(CVector((float)x, (float)y, (float)z)); instance.setPos(CVector((float)x, (float)y, (float)z));
instance.setRotQuat(dir.getRot()); instance.setRotQuat(dir.getRot());
} }
instance.setTransformMode(UTransformable::RotEuler);
// if the shape is a particle system, additionnal parameters are user params // if the shape is a particle system, additionnal parameters are user params
UParticleSystemInstance psi; UParticleSystemInstance psi;
psi.cast (instance); psi.cast (instance);
@ -2637,6 +2637,7 @@ class CAHAddShape : public IActionHandler
}; };
REGISTER_ACTION_HANDLER (CAHAddShape, "add_shape"); REGISTER_ACTION_HANDLER (CAHAddShape, "add_shape");
class CAHRemoveShapes : public IActionHandler class CAHRemoveShapes : public IActionHandler
{ {
virtual void execute (CCtrlBase * /* pCaller */, const string &Params) virtual void execute (CCtrlBase * /* pCaller */, const string &Params)

File diff suppressed because it is too large Load diff

View file

@ -106,6 +106,16 @@ private:
static int getCompleteIslands(CLuaState &ls); static int getCompleteIslands(CLuaState &ls);
static int getIslandId(CLuaState &ls);//TEMP static int getIslandId(CLuaState &ls);//TEMP
static int addShape(CLuaState &ls);
static int moveShape(CLuaState &ls);
static int rotateShape(CLuaState &ls);
static int getShapePos(CLuaState &ls);
static int getShapeScale(CLuaState &ls);
static int getShapeRot(CLuaState &ls);
static int getShapeColPos(CLuaState &ls);
static int getShapeColScale(CLuaState &ls);
static int getShapeColOrient(CLuaState &ls);
static int deleteShape(CLuaState &ls);
///////////////////////////// Standard Lua stuff ends here ////////////////////////////////////////////// ///////////////////////////// Standard Lua stuff ends here //////////////////////////////////////////////
@ -202,6 +212,14 @@ private:
static sint getCharacterSheetRegionLevel(const std::string &sheet); static sint getCharacterSheetRegionLevel(const std::string &sheet);
static std::string getRegionByAlias(uint32 alias); static std::string getRegionByAlias(uint32 alias);
static sint getGroundZ(uint32 x, sint32 y); static sint getGroundZ(uint32 x, sint32 y);
static int getGroundAtMouse(CLuaState &ls);
static int getMousePos(CLuaState &ls);
static int getMouseDown(CLuaState &ls);
static int getMouseMiddleDown(CLuaState &ls);
static int getMouseRightDown(CLuaState &ls);
static int getShapeIdAt(CLuaState &ls);
static int setupShape(CLuaState &ls);
static void setMouseCursor(const std::string texture);
// open the window to do a tell to 'player', if 'msg' is not empty, then the message will be sent immediatly // open the window to do a tell to 'player', if 'msg' is not empty, then the message will be sent immediatly
// else, current command of the chat window will be replaced with tell 'player' // else, current command of the chat window will be replaced with tell 'player'
static void tell(const ucstring &player, const ucstring &msg); static void tell(const ucstring &player, const ucstring &msg);

View file

@ -2502,6 +2502,8 @@ bool mainLoop()
// R2ED enabled ? // R2ED enabled ?
R2::getEditor().autoConfigInit(IsInRingSession); R2::getEditor().autoConfigInit(IsInRingSession);
if (!IsInRingSession)
R2::getEditor().registerLuaFunc();
CurrSeason = computeCurrSeason(); CurrSeason = computeCurrSeason();

View file

@ -1507,3 +1507,44 @@ bool getRyzomModes(std::vector<NL3D::UDriver::CMode> &videoModes, std::vector<st
return nFoundStringMode > -1; return nFoundStringMode > -1;
} }
// Get float value from string. Return true if the value is relatif ( src = "+15.5" for example )
bool getRelativeFloatFromString(const std::string src, float &dst)
{
dst = 0;
if (src.empty())
return false;
if (src[0] == '+')
return fromString(src.substr(1), dst);
else
fromString(src, dst);
return false;
}
bool updateVector(const string part, CVector &dst, float value, bool add /* = false */)
{
string p = part;
if (part.size() > 1)
p = part.substr(part.size()-1, 1);
if (add)
{
if (p == "x")
dst.x += value;
else if (p == "y")
dst.y += value;
else if (p == "z")
dst.z += value;
}
else
{
if (p == "x")
dst.x = value;
else if (p == "y")
dst.y = value;
else if (p == "z")
dst.z = value;
}
}

View file

@ -168,6 +168,9 @@ std::string getStringCategory(const ucstring &src, ucstring &dest, bool alwaysAd
// Get the category from the string (src="&SYS&Who are you?" and dest="Who are you?" and return "SYS"), if no category, return "" // Get the category from the string (src="&SYS&Who are you?" and dest="Who are you?" and return "SYS"), if no category, return ""
std::string getStringCategoryIfAny(const ucstring &src, ucstring &dest); std::string getStringCategoryIfAny(const ucstring &src, ucstring &dest);
bool getRelativeFloatFromString(const std::string src, float &dst);
bool updateVector(const std::string part, NLMISC::CVector &dst, float value, bool add = false);
// Number of shortcut // Number of shortcut
#define RYZOM_MAX_SHORTCUT 20 #define RYZOM_MAX_SHORTCUT 20

View file

@ -893,6 +893,7 @@ public:
static NLMISC::CCDBNodeLeaf *getPlotItemSheetDBLeaf(uint index); static NLMISC::CCDBNodeLeaf *getPlotItemSheetDBLeaf(uint index);
static bool getIsStartingScenario() { return _IsStartingScenario; } static bool getIsStartingScenario() { return _IsStartingScenario; }
bool isClearingContent() const { return _ClearingContent; } bool isClearingContent() const { return _ClearingContent; }
void registerLuaFunc();
private: private:
void initPlotItems(); void initPlotItems();
@ -925,7 +926,7 @@ private:
void initObjectProjectionMetatable(); void initObjectProjectionMetatable();
void registerDisplayers(); void registerDisplayers();
void registerTools(); void registerTools();
void registerLuaFunc();
// add a C++ method in the environement // add a C++ method in the environement
void registerEnvMethod(const char *name, TLuaWrappedFunction func); void registerEnvMethod(const char *name, TLuaWrappedFunction func);
void registerEnvFunction(const char *name, TLuaWrappedFunction func); void registerEnvFunction(const char *name, TLuaWrappedFunction func);

View file

@ -165,6 +165,47 @@ void CTool::getMousePos(sint32 &x, sint32 &y)
cursor->getPointerPos(x, y); cursor->getPointerPos(x, y);
} }
// ***************************************************************
void CTool::getMouseDown(bool &down, sint32 &x, sint32 &y)
{
down = false;
//H_AUTO(R2_CTool_getMousePos)
CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
if(cursor == NULL)
{
x = y = -1;
return;
}
down = cursor->getPointerDown(x, y);
}
// ***************************************************************
void CTool::getMouseMiddleDown(bool &down, sint32 &x, sint32 &y)
{
//H_AUTO(R2_CTool_getMousePos)
CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
if(cursor == NULL)
{
x = y = -1;
return;
}
down = cursor->getPointerMiddleDown(x, y);
}
// ***************************************************************
void CTool::getMouseRightDown(bool &down, sint32 &x, sint32 &y)
{
//H_AUTO(R2_CTool_getMousePos)
CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
if(cursor == NULL)
{
x = y = -1;
return;
}
down = cursor->getPointerMiddleDown(x, y);
}
// *************************************************************** // ***************************************************************
sint32 CTool::getMouseX() sint32 CTool::getMouseX()
{ {
@ -331,6 +372,7 @@ bool CTool::raytrace(const NLMISC::CVector &segmentStart, const NLMISC::CVector
{ {
if (Landscape) if (Landscape)
{ {
nlinfo("landscape=%d,%d", segmentStart.x, segmentStart.y);
// use a shortest distance for collision manager (for speed) // use a shortest distance for collision manager (for speed)
CVector segmentEnd = segmentStart + 100.f * dir; CVector segmentEnd = segmentStart + 100.f * dir;
float dist = Landscape->getRayCollision(segmentStart, segmentEnd); float dist = Landscape->getRayCollision(segmentStart, segmentEnd);
@ -443,16 +485,27 @@ bool CTool::computeNearestValidSurfaceFromHeightMap(float x, float y, NLMISC::CV
const CScenarioEntryPoints::CCompleteIsland *islandDesc = getEditor().getIslandCollision().getCurrIslandDesc(); const CScenarioEntryPoints::CCompleteIsland *islandDesc = getEditor().getIslandCollision().getCurrIslandDesc();
if (!islandDesc) return false; if (!islandDesc) return false;
nlinfo("have island");
sint mapX = (sint) (x - islandDesc->XMin); sint mapX = (sint) (x - islandDesc->XMin);
sint mapY = (sint) (y - islandDesc->YMin); sint mapY = (sint) (y - islandDesc->YMin);
nlinfo("mapX,mapY=%d,%d island=%d,%d-%d,%d", mapX, mapY, islandDesc->XMin, islandDesc->YMin, islandDesc->XMax, islandDesc->YMax);
if (mapX < 0 || mapY < 0 || mapX >= (islandDesc->XMax - islandDesc->XMin) || mapY >= (islandDesc->YMax - islandDesc->YMin)) return false; if (mapX < 0 || mapY < 0 || mapX >= (islandDesc->XMax - islandDesc->XMin) || mapY >= (islandDesc->YMax - islandDesc->YMin)) return false;
sint hmZ = heightMap(mapX, mapY); sint hmZ = heightMap(mapX, mapY);
nlinfo("HeightMap = %d", hmZ);
if (hmZ >= 0x7ffe) return false; // not an accessible pos if (hmZ >= 0x7ffe) return false; // not an accessible pos
nlinfo("accessible pos");
if (!isIslandValidPos(heightMap, *islandDesc, x + 0.5f, y) || if (!isIslandValidPos(heightMap, *islandDesc, x + 0.5f, y) ||
!isIslandValidPos(heightMap, *islandDesc, x - 0.5f, y) || !isIslandValidPos(heightMap, *islandDesc, x - 0.5f, y) ||
!isIslandValidPos(heightMap, *islandDesc, x, y + 0.5f) || !isIslandValidPos(heightMap, *islandDesc, x, y + 0.5f) ||
!isIslandValidPos(heightMap, *islandDesc, x, y - 0.5f)) return false; !isIslandValidPos(heightMap, *islandDesc, x, y - 0.5f)) return false;
nlinfo("valid pos");
float z = 1.f + 2.f * hmZ; float z = 1.f + 2.f * hmZ;
// this is a possibly valid position // this is a possibly valid position
// compute nearest surface from here, and see if not far from the intersection // compute nearest surface from here, and see if not far from the intersection
@ -471,6 +524,9 @@ bool CTool::computeNearestValidSurfaceFromHeightMap(float x, float y, NLMISC::CV
inter1Found = inter1Found && normal1.z >= minAngleSin; inter1Found = inter1Found && normal1.z >= minAngleSin;
inter2Found = inter2Found && normal2.z >= minAngleSin; inter2Found = inter2Found && normal2.z >= minAngleSin;
if (!inter1Found && !inter2Found) return false; if (!inter1Found && !inter2Found) return false;
nlinfo("inter foud");
if (inter1Found && inter2Found) if (inter1Found && inter2Found)
{ {
// because z in heightmap in usually a 'ceil' of real height, tends to favor surface below // because z in heightmap in usually a 'ceil' of real height, tends to favor surface below
@ -487,6 +543,7 @@ bool CTool::computeNearestValidSurfaceFromHeightMap(float x, float y, NLMISC::CV
{ {
inter = inter2; inter = inter2;
} }
nlinfo("inter = %d,%d", inter.x, inter.y);
return true; return true;
} }
@ -516,6 +573,7 @@ CTool::TRayIntersectionType CTool::computeLandscapeRayIntersection(const CWorldV
{ {
CVector delta = bias * (cardinals[k].x * worldViewRay.Right + cardinals[k].y * worldViewRay.Up); CVector delta = bias * (cardinals[k].x * worldViewRay.Right + cardinals[k].y * worldViewRay.Up);
found = raytrace(worldViewRay.Origin + delta, worldViewRay.Dir, inter); found = raytrace(worldViewRay.Origin + delta, worldViewRay.Dir, inter);
nlinfo("found");
} }
if (!found) if (!found)
{ {
@ -527,10 +585,12 @@ CTool::TRayIntersectionType CTool::computeLandscapeRayIntersection(const CWorldV
const CArray2D<sint16> &heightMap = getEditor().getIslandCollision().getHeightMap(); const CArray2D<sint16> &heightMap = getEditor().getIslandCollision().getHeightMap();
if (!heightMap.empty()) if (!heightMap.empty())
{ {
nlinfo("okidoi : %d, %d", inter.x, inter.y);
// if heightmap is present, use it because it gives us more reliable information // if heightmap is present, use it because it gives us more reliable information
CVector surfPos; CVector surfPos;
if (!computeNearestValidSurfaceFromHeightMap(inter.x, inter.y, surfPos)) return InvalidPacsPos; if (!computeNearestValidSurfaceFromHeightMap(inter.x, inter.y, surfPos)) return InvalidPacsPos;
static volatile float threshold = 2.f; static volatile float threshold = 2.f;
nlinfo("found");
return (inter - surfPos).norm() < threshold ? ValidPacsPos : InvalidPacsPos; return (inter - surfPos).norm() < threshold ? ValidPacsPos : InvalidPacsPos;
} }
@ -541,6 +601,7 @@ CTool::TRayIntersectionType CTool::computeLandscapeRayIntersection(const CWorldV
} }
else else
{ {
nlinfo("GR");
// see if pacs collisions are ok at that pos // see if pacs collisions are ok at that pos
NLPACS::UGlobalPosition dummyPos; NLPACS::UGlobalPosition dummyPos;
return getPacsType(inter, 2.f, dummyPos); return getPacsType(inter, 2.f, dummyPos);
@ -901,5 +962,4 @@ NLMISC::CRGBA CTool::getInvalidPosColor()
} }
} // R2 } // R2

View file

@ -213,6 +213,12 @@ public:
static CInterfaceManager &getUI(); static CInterfaceManager &getUI();
// Get mouse position // Get mouse position
static void getMousePos(sint32 &x, sint32 &y) ; static void getMousePos(sint32 &x, sint32 &y) ;
// Get if mouse are clicked down and position of last down click
static void getMouseDown(bool &down, sint32 &x, sint32 &y);
// Get if mouse are middle clicked down and position of last down click
static void getMouseMiddleDown(bool &down, sint32 &x, sint32 &y);
// Get if mouse are right clicked down and position of last down click
static void getMouseRightDown(bool &down, sint32 &x, sint32 &y);
// Get mouse x position // Get mouse x position
static sint32 getMouseX(); static sint32 getMouseX();
// Get mouse y position // Get mouse y position