diff --git a/Sources/libewol/ewol/game/GameElement.h b/Sources/libewol/ewol/game/GameElement.h index 6110b6ce..ec3844e7 100644 --- a/Sources/libewol/ewol/game/GameElement.h +++ b/Sources/libewol/ewol/game/GameElement.h @@ -148,7 +148,7 @@ namespace ewol { virtual bool HaveImpact(int32_t group, int32_t type, Vector2D position, float size); virtual bool Explosion(int32_t group, int32_t type, Vector2D position, float pxAtenuation, float power) { return false; } ; - virtual void Message(etk::UString control, etk::UString message) { } ; + virtual etk::UString Message(etk::UString control, etk::UString message) { return ""; } ; virtual void StatusUpdate(void) { }; }; diff --git a/Sources/libewol/ewol/game/GameElementLua.cpp b/Sources/libewol/ewol/game/GameElementLua.cpp index aac088f1..6f3e9f97 100644 --- a/Sources/libewol/ewol/game/GameElementLua.cpp +++ b/Sources/libewol/ewol/game/GameElementLua.cpp @@ -890,7 +890,7 @@ bool ewol::GameElementLua::Explosion(int32_t group, int32_t type, Vector2D position, float size); virtual bool Explosion(int32_t group, int32_t type, Vector2D position, float pxAtenuation, float power); - virtual void Message(etk::UString control, etk::UString message); + virtual etk::UString Message(etk::UString control, etk::UString message); }; void RegisterLuaElementInFolder(ewol::SceneElement & sceneElement, etk::UString folder); void RegisterLuaElementSpecify(ewol::SceneElement & sceneElement, etk::UString folder, etk::UString name); diff --git a/Sources/libewol/ewol/game/SceneElement.cpp b/Sources/libewol/ewol/game/SceneElement.cpp index 7742d451..a7f11e66 100644 --- a/Sources/libewol/ewol/game/SceneElement.cpp +++ b/Sources/libewol/ewol/game/SceneElement.cpp @@ -104,7 +104,7 @@ void ewol::SceneElement::RegisterElementType(etk::UString name, creatorElement_t } -void ewol::SceneElement::RmElement(int32_t group, int32_t idElement) +void ewol::SceneElement::RmElement(int16_t group, int16_t idElement) { if (group < 0 || group >= MAX_GROUP_NUMBER) { EWOL_ERROR("group is wrong " << group << "!=[0," << MAX_GROUP_NUMBER << "]==> not rm at the system ..."); @@ -117,6 +117,9 @@ void ewol::SceneElement::RmElement(int32_t group, int32_t idElement) if (NULL == listAnimatedElements[group][idElement]) { return; } + // inform remove system : + SendEventRemove(createUniqueId(listAnimatedElements[group][idElement]->GetUniqueId(), idElement) ); + // try to find an empty slot : for (int32_t iii=0; iii> 16 ) & 0x0000FFFF); + uint16_t posInList = (uint16_t)(idElement & 0x0000FFFF); + for (int32_t iii=0; iiiGetUniqueId()) { + RmElement(iii, posInList); + return; + } + } +} + uint32_t ewol::SceneElement::AddElement(int32_t group, ewol::GameElement* newElement) { if (NULL == newElement) { @@ -235,10 +255,7 @@ uint32_t ewol::SceneElement::GetNearestEnemy(Vector2D position, int32_t g Vector2D tmpPos = listAnimatedElements[gId][iii]->PositionGet(); float distance = quadDist(position, tmpPos); if( distance <= lastQuadDistance - && ( ( maxRange>0 - && maxRange >= lastQuadDistance) - || maxRange==0) - ) { + && maxRange >= distance ) { lastQuadDistance = distance; result = createUniqueId(listAnimatedElements[gId][iii]->GetUniqueId(), iii); } @@ -456,3 +473,41 @@ void ewol::SceneElement::UnLoadSprite(int32_t spriteId) } } +void ewol::SceneElement::AddEarrerDestroy(uint32_t uId) +{ + //EWOL_DEBUG("ADD eraer : " << uId); + if (uId==0) { + return; + } + eventDestroy.PushBack(uId); +} + +void ewol::SceneElement::RmEarrerDestroy(uint32_t uId) +{ + //EWOL_DEBUG("RM eraer : " << uId); + if (uId==0) { + return; + } + for (int32_t iii=0; iiiMessage("Destroy", uId); + } + } + } +} diff --git a/Sources/libewol/ewol/game/SceneElement.h b/Sources/libewol/ewol/game/SceneElement.h index 04397573..6e427db1 100644 --- a/Sources/libewol/ewol/game/SceneElement.h +++ b/Sources/libewol/ewol/game/SceneElement.h @@ -51,6 +51,7 @@ namespace ewol { public: SceneElement(void); ~SceneElement(void); + etk::Vector eventDestroy; //!< element uid when element is destroy int32_t numberOfGroup; //!< curent scene number of group etk::UString groupDescription[MAX_GROUP_NUMBER]; //!< name of all the groups int32_t groupEnemy[MAX_GROUP_NUMBER][MAX_GROUP_NUMBER]; //!< list of the ennemy @@ -60,11 +61,12 @@ namespace ewol { etk::Vector listCreatorElement; //!< list of all creatable elements int16_t GetUniqueId(void) { int16_t iddd = m_id; m_id++; return iddd; }; void RegisterElementType(etk::UString name, creatorElement_tf * loadElement, etk::UString userString); - void RmElement(int32_t group, int32_t idElement); + void RmElement(int16_t group, int16_t posInList); + void RmElement(int32_t elementID); uint32_t AddElement(int32_t group, ewol::GameElement* newElement); uint32_t AddElementNamed(int32_t group, etk::UString &elementName); ewol::GameElement* GetElement(uint32_t idElement); - uint32_t GetNearestEnemy(Vector2D position, int32_t groupId, float maxRange=0); + uint32_t GetNearestEnemy(Vector2D position, int32_t groupId, float maxRange=9999999999999999.0); void GetNearestEnemy(Vector2D position, int32_t groupId, float maxRange, etk::Vector& list); uint32_t GetNearestFriend(Vector2D position, int32_t groupId, uint32_t us); void GetNearestFriend(Vector2D position, int32_t groupId, float maxRange, etk::Vector& list, uint32_t us); @@ -88,6 +90,9 @@ namespace ewol { * @return --- */ void UnLoadSprite(int32_t spriteId); + void AddEarrerDestroy(uint32_t uId); + void RmEarrerDestroy(uint32_t uId); + void SendEventRemove(uint32_t uId); }; }; diff --git a/Sources/libewol/ewol/widget/Scene.cpp b/Sources/libewol/ewol/widget/Scene.cpp index a38edfb9..8c324459 100644 --- a/Sources/libewol/ewol/widget/Scene.cpp +++ b/Sources/libewol/ewol/widget/Scene.cpp @@ -166,7 +166,7 @@ void ewol::Scene::GenDraw(DrawProperty displayProp) #ifdef __VIDEO__OPENGL_ES_2 etk::Matrix tmpProjection; - if (ratio >= 0.0) { + if (ratio >= 1.0) { tmpProjection = etk::matrix::Perspective(-ratio, ratio, -1, 1, -1, 1); } else { ratio = 1.0/ratio; @@ -179,7 +179,7 @@ void ewol::Scene::GenDraw(DrawProperty displayProp) #else glMatrixMode(GL_PROJECTION); glLoadIdentity(); - if (ratio >= 0.0) { + if (ratio >= 1.0) { glOrthoEwol(-ratio, ratio, -1, 1, -1, 1); } else { ratio = 1.0/ratio; @@ -210,12 +210,30 @@ void ewol::Scene::GenDraw(DrawProperty displayProp) */ Vector2D ewol::Scene::RelativePosition(Vector2D pos) { + // Remove origin of the widget pos.x -= m_origin.x; pos.y -= m_origin.y; + // move the position at the center (openGl system pos.x -= m_size.x/2; pos.y -= m_size.y/2; - pos.x *= m_zoom; - pos.y *= m_zoom; + // scale the position with the ratio display of the screen + float ratio = m_size.x / m_size.y; + if (ratio >= 1.0) { + pos.x /= m_size.x; + pos.x *= ratio; + pos.y /= m_size.y; + } else { + ratio = 1.0/ratio; + pos.x /= m_size.x; + pos.y /= m_size.y; + pos.y *= ratio; + } + // integrate zoom + pos.x /= m_zoom; + pos.y /= m_zoom; + // all the position are half the size due to the fact -1 --> 1 + pos.x *= 2; + pos.y *= 2; return pos; };