Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/styles/10-effect.otui
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Effect < UIEffect
1 change: 1 addition & 0 deletions data/styles/10-missile.otui
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Missile < UIMissile
4 changes: 4 additions & 0 deletions src/client/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ using ProtocolLoginPtr = std::shared_ptr<ProtocolLogin>;

// ui
class UIItem;
class UIEffect;
class UIMissile;
class UICreature;
class UIGraph;
class UIMap;
Expand All @@ -118,6 +120,8 @@ class UIPositionAnchor;
class UISprite;

using UIItemPtr = std::shared_ptr<UIItem>;
using UIEffectPtr = std::shared_ptr<UIEffect>;
using UIMissilePtr = std::shared_ptr<UIMissile>;
using UICreaturePtr = std::shared_ptr<UICreature>;
using UIGraphPtr = std::shared_ptr<UIGraph>;
using UISpritePtr = std::shared_ptr<UISprite>;
Expand Down
29 changes: 29 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include "towns.h"
#include "uicreature.h"
#include "uiitem.h"
#include "uieffect.h"
#include "uimissile.h"

#include "uimap.h"
#include "uimapanchorlayout.h"
#include "uiminimap.h"
Expand Down Expand Up @@ -926,6 +929,32 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIItem>("isVirtual", &UIItem::isVirtual);
g_lua.bindClassMemberFunction<UIItem>("isItemVisible", &UIItem::isItemVisible);

g_lua.registerClass<UIEffect, UIWidget>();
g_lua.bindClassStaticFunction<UIEffect>("create", [] { return std::make_shared<UIEffect>(); });
g_lua.bindClassMemberFunction<UIEffect>("setEffectId", &UIEffect::setEffectId);
g_lua.bindClassMemberFunction<UIEffect>("setEffectVisible", &UIEffect::setEffectVisible);
g_lua.bindClassMemberFunction<UIEffect>("setEffect", &UIEffect::setEffect);
g_lua.bindClassMemberFunction<UIEffect>("setVirtual", &UIEffect::setVirtual);
g_lua.bindClassMemberFunction<UIEffect>("clearEffect", &UIEffect::clearEffect);
g_lua.bindClassMemberFunction<UIEffect>("getEffectId", &UIEffect::getEffectId);
g_lua.bindClassMemberFunction<UIEffect>("getEffect", &UIEffect::getEffect);
g_lua.bindClassMemberFunction<UIEffect>("isVirtual", &UIEffect::isVirtual);
g_lua.bindClassMemberFunction<UIEffect>("isEffectVisible", &UIEffect::isEffectVisible);

g_lua.registerClass<UIMissile, UIWidget>();
g_lua.bindClassStaticFunction<UIMissile>("create", [] { return std::make_shared<UIMissile>(); });
g_lua.bindClassMemberFunction<UIMissile>("setMissileId", &UIMissile::setMissileId);
g_lua.bindClassMemberFunction<UIMissile>("setMissileVisible", &UIMissile::setMissileVisible);
g_lua.bindClassMemberFunction<UIMissile>("setMissile", &UIMissile::setMissile);
g_lua.bindClassMemberFunction<UIMissile>("setVirtual", &UIMissile::setVirtual);
g_lua.bindClassMemberFunction<UIMissile>("clearMissile", &UIMissile::clearMissile);
g_lua.bindClassMemberFunction<UIMissile>("getMissileId", &UIMissile::getMissileId);
g_lua.bindClassMemberFunction<UIMissile>("getMissile", &UIMissile::getMissile);
g_lua.bindClassMemberFunction<UIMissile>("isVirtual", &UIMissile::isVirtual);
g_lua.bindClassMemberFunction<UIMissile>("isMissileVisible", &UIMissile::isMissileVisible);
g_lua.bindClassMemberFunction<UIMissile>("setDirection", &UIMissile::setDirection);
g_lua.bindClassMemberFunction<UIMissile>("getDirection", &UIMissile::getDirection);

g_lua.registerClass<UISprite, UIWidget>();
g_lua.bindClassStaticFunction<UISprite>("create", [] { return std::make_shared<UISprite>(); });
g_lua.bindClassMemberFunction<UISprite>("setSpriteId", &UISprite::setSpriteId);
Expand Down
65 changes: 35 additions & 30 deletions src/client/missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Missile::draw(const Point& dest, bool drawThings, const LightViewPtr& light
if (!canDraw() || isHided())
return;

const float fraction = m_animationTimer.ticksElapsed() / m_duration;
const float fraction = m_duration > 0 ? m_animationTimer.ticksElapsed() / m_duration : 1;

if (g_drawPool.getCurrentType() == DrawPoolType::MAP) {
if (drawThings && g_client.getMissileAlpha() < 1.f)
Expand All @@ -55,48 +55,53 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
return;
}

m_direction = fromPosition.getDirectionFromPosition(toPosition);
setDirection(fromPosition.getDirectionFromPosition(toPosition));

m_duration = (g_gameConfig.getMissileTicksPerFrame() * 2) * std::sqrt(deltaLength);
m_delta *= g_gameConfig.getSpriteSize();
m_animationTimer.restart();
m_distance = fromPosition.distance(toPosition);

{ // Update Pattern
if (m_direction == Otc::NorthWest) {
m_numPatternX = 0;
m_numPatternY = 0;
} else if (m_direction == Otc::North) {
m_numPatternX = 1;
m_numPatternY = 0;
} else if (m_direction == Otc::NorthEast) {
m_numPatternX = 2;
m_numPatternY = 0;
} else if (m_direction == Otc::East) {
m_numPatternX = 2;
m_numPatternY = 1;
} else if (m_direction == Otc::SouthEast) {
m_numPatternX = 2;
m_numPatternY = 2;
} else if (m_direction == Otc::South) {
m_numPatternX = 1;
m_numPatternY = 2;
} else if (m_direction == Otc::SouthWest) {
m_numPatternX = 0;
m_numPatternY = 2;
} else if (m_direction == Otc::West) {
m_numPatternX = 0;
m_numPatternY = 1;
} else {
m_numPatternX = 1;
m_numPatternY = 1;
}
}

// schedule removal
g_dispatcher.scheduleEvent([self = asMissile()] { g_map.removeThing(self); }, m_duration);
}

void Missile::setDirection(Otc::Direction dir) {
m_direction = dir;

if (m_direction == Otc::NorthWest) {
m_numPatternX = 0;
m_numPatternY = 0;
} else if (m_direction == Otc::North) {
m_numPatternX = 1;
m_numPatternY = 0;
} else if (m_direction == Otc::NorthEast) {
m_numPatternX = 2;
m_numPatternY = 0;
} else if (m_direction == Otc::East) {
m_numPatternX = 2;
m_numPatternY = 1;
} else if (m_direction == Otc::SouthEast) {
m_numPatternX = 2;
m_numPatternY = 2;
} else if (m_direction == Otc::South) {
m_numPatternX = 1;
m_numPatternY = 2;
} else if (m_direction == Otc::SouthWest) {
m_numPatternX = 0;
m_numPatternY = 2;
} else if (m_direction == Otc::West) {
m_numPatternX = 0;
m_numPatternY = 1;
} else {
m_numPatternX = 1;
m_numPatternY = 1;
}
}

void Missile::setId(uint32_t id)
{
if (!g_things.isValidDatId(id, ThingCategoryMissile))
Expand Down
3 changes: 3 additions & 0 deletions src/client/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Missile : public Thing

MissilePtr asMissile() { return static_self_cast<Missile>(); }

void setDirection(Otc::Direction dir);
auto getDirection() { return m_direction; }

protected:
ThingType* getThingType() const override;

Expand Down
84 changes: 84 additions & 0 deletions src/client/uieffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2010-2022 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "uieffect.h"

UIEffect::UIEffect() { setProp(PropDraggable, true, false); }

void UIEffect::drawSelf(DrawPoolType drawPane)
{
if (drawPane != DrawPoolType::FOREGROUND)
return;

// draw style components in order
if (m_backgroundColor.aF() > Fw::MIN_ALPHA) {
Rect backgroundDestRect = m_rect;
backgroundDestRect.expand(-m_borderWidth.top, -m_borderWidth.right, -m_borderWidth.bottom, -m_borderWidth.left);
drawBackground(m_rect);
}

drawImage(m_rect);

if (m_effectVisible && m_effect) {
const int exactSize = std::max<int>(g_gameConfig.getSpriteSize(), m_effect->getExactSize());

g_drawPool.bindFrameBuffer(exactSize);
m_effect->draw(Point(exactSize - g_gameConfig.getSpriteSize()) + m_effect->getDisplacement());
g_drawPool.releaseFrameBuffer(getPaddingRect());
}

drawBorder(m_rect);
drawIcon(m_rect);
drawText(m_rect);
}

void UIEffect::setEffectId(int id)
{
if (id == 0)
m_effect = nullptr;
else {
if (!m_effect)
m_effect = std::make_shared<Effect>();
m_effect->setId(id);
}
}

void UIEffect::setEffect(const EffectPtr& e)
{
m_effect = e;
}

void UIEffect::onStyleApply(const std::string_view styleName, const OTMLNodePtr& styleNode)
{
UIWidget::onStyleApply(styleName, styleNode);

for (const auto& node : styleNode->children()) {
if (node->tag() == "effect-id")
setEffectId(node->value<int>());
else if (node->tag() == "effect-visible")
setEffectVisible(node->value<bool>());
else if (node->tag() == "virtual")
setVirtual(node->value<bool>());
else if (node->tag() == "show-id")
m_showId = node->value<bool>();
}
}
53 changes: 53 additions & 0 deletions src/client/uieffect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2010-2022 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

#include <framework/ui/uiwidget.h>
#include "declarations.h"
#include "effect.h"

class UIEffect : public UIWidget
{
public:
UIEffect();
void drawSelf(DrawPoolType drawPane) override;

void setEffectId(int id);
void setEffectVisible(bool visible) { m_effectVisible = visible; }
void setEffect(const EffectPtr& effect);
void setVirtual(bool virt) { m_virtual = virt; }
void clearEffect() { setEffectId(0); }

int getEffectId() { return m_effect ? m_effect->getId() : 0; }
auto getEffect() { return m_effect; }
bool isVirtual() { return m_virtual; }
bool isEffectVisible() { return m_effectVisible; }

protected:
void onStyleApply(const std::string_view styleName, const OTMLNodePtr& styleNode) override;

EffectPtr m_effect;
bool m_virtual{ false };
bool m_showId{ false };
bool m_effectVisible{ true };
};
87 changes: 87 additions & 0 deletions src/client/uimissile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2010-2022 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "UIMissile.h"

UIMissile::UIMissile() { setProp(PropDraggable, true, false); }

void UIMissile::drawSelf(DrawPoolType drawPane)
{
if (drawPane != DrawPoolType::FOREGROUND)
return;

// draw style components in order
if (m_backgroundColor.aF() > Fw::MIN_ALPHA) {
Rect backgroundDestRect = m_rect;
backgroundDestRect.expand(-m_borderWidth.top, -m_borderWidth.right, -m_borderWidth.bottom, -m_borderWidth.left);
drawBackground(m_rect);
}

drawImage(m_rect);

if (m_missileVisible && m_missile) {
const int exactSize = std::max<int>(g_gameConfig.getSpriteSize(), m_missile->getExactSize());

g_drawPool.bindFrameBuffer(exactSize);
m_missile->draw(Point(exactSize - g_gameConfig.getSpriteSize()) + m_missile->getDisplacement());
g_drawPool.releaseFrameBuffer(getPaddingRect());
}

drawBorder(m_rect);
drawIcon(m_rect);
drawText(m_rect);
}

void UIMissile::setMissileId(int id)
{
if (id == 0)
m_missile = nullptr;
else {
if (!m_missile)
m_missile = std::make_shared<Missile>();
m_missile->setId(id);
m_missile->setDirection(Otc::South);
}
}

void UIMissile::setMissile(const MissilePtr& e)
{
m_missile = e;
}

void UIMissile::onStyleApply(const std::string_view styleName, const OTMLNodePtr& styleNode)
{
UIWidget::onStyleApply(styleName, styleNode);

for (const auto& node : styleNode->children()) {
if (node->tag() == "missile-id")
setMissileId(node->value<int>());
else if (node->tag() == "missile-visible")
setMissileVisible(node->value<bool>());
else if (node->tag() == "virtual")
setVirtual(node->value<bool>());
else if (node->tag() == "show-id")
m_showId = node->value<bool>();
else if (node->tag() == "direction")
setDirection(static_cast<Otc::Direction>(node->value<int>()));
}
}
Loading