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
6 changes: 3 additions & 3 deletions src/client/animatedtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

#include "animatedtext.h"
#include <framework/core/eventdispatcher.h>
#include <framework/core/graphicalapplication.h>
#include "game.h"
#include "map.h"
#include "gameconfig.h"
#include "map.h"
#include <framework/core/eventdispatcher.h>
#include <framework/core/graphicalapplication.h>

AnimatedText::AnimatedText()
{
Expand Down
6 changes: 3 additions & 3 deletions src/client/animatedtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#include <framework/luaengine/luaobject.h>

// @bindclass
class AnimatedText : public LuaObject
class AnimatedText final : public LuaObject
{
public:
AnimatedText();
AnimatedText(const std::string_view text, int color) : AnimatedText() {
AnimatedText(const std::string_view text, const int color) : AnimatedText() {
setText(text);
setColor(color);
}
Expand All @@ -42,7 +42,7 @@ class AnimatedText : public LuaObject

void onAppear();

void setColor(int color) { m_color = Color::from8bit(color); }
void setColor(const int color) { m_color = Color::from8bit(color); }
void setText(const std::string_view text) { m_cachedText.setText(text); }
void setOffset(const Point& offset) { m_offset = offset; }

Expand Down
8 changes: 4 additions & 4 deletions src/client/animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Animator::unserializeAppearance(const appearances::SpriteAnimation& animati
assert(m_startPhase >= -1 && m_startPhase < m_animationPhases);
}

void Animator::unserialize(int animationPhases, const FileStreamPtr& fin)
void Animator::unserialize(const int animationPhases, const FileStreamPtr& fin)
{
m_animationPhases = animationPhases;
m_async = fin->getU8() == 0;
Expand Down Expand Up @@ -77,7 +77,7 @@ void Animator::serialize(const FileStreamPtr& fin) const
}
}

void Animator::setPhase(int phase)
void Animator::setPhase(const int phase)
{
if (m_phase == phase)
return;
Expand Down Expand Up @@ -133,7 +133,7 @@ int Animator::getPhase()
return m_phase;
}

int Animator::getPhaseAt(Timer& timer, float durationFactor) const
int Animator::getPhaseAt(Timer& timer, const float durationFactor) const
{
const ticks_t time = timer.ticksElapsed();

Expand Down Expand Up @@ -195,7 +195,7 @@ int Animator::getLoopPhase()
return m_phase;
}

int Animator::getPhaseDuration(int phase) const
int Animator::getPhaseDuration(const int phase) const
{
assert(phase < static_cast<int>(m_phaseDurations.size()));

Expand Down
36 changes: 19 additions & 17 deletions src/client/attachableobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
*/

#include "attachableobject.h"
#include <framework/graphics/particlemanager.h>
#include <framework/graphics/particleeffect.h>
#include <framework/graphics/particlemanager.h>

#include <framework/core/eventdispatcher.h>
#include <framework/ui/uiwidget.h>
#include <framework/core/eventdispatcher.h>
#include <framework/ui/uimanager.h>
#include <framework/ui/uiwidget.h>

#include <algorithm>

#include "client.h"
#include "game.h"
Expand Down Expand Up @@ -55,7 +57,7 @@ void AttachableObject::attachEffect(const AttachedEffectPtr& obj)
++m_ownerHidden;

if (obj->getDuration() > 0) {
g_dispatcher.scheduleEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect = obj]() {
g_dispatcher.scheduleEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect = obj] {
self->detachEffect(effect);
}, obj->getDuration());
}
Expand Down Expand Up @@ -95,7 +97,7 @@ bool AttachableObject::detachEffectById(uint16_t id)
return true;
}

void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect, bool callEvent)
void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect, const bool callEvent)
{
if (effect->isHidedOwner())
--m_ownerHidden;
Expand All @@ -106,7 +108,7 @@ void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect, bool call
effect->callLuaField("onDetach", attachedObjectToLuaObject());
}

void AttachableObject::clearAttachedEffects(bool ignoreLuaEvent)
void AttachableObject::clearAttachedEffects(const bool ignoreLuaEvent)
{
if (!hasAttachedEffects()) return;
for (const auto& e : m_data->attachedEffects)
Expand All @@ -117,27 +119,27 @@ void AttachableObject::clearAttachedEffects(bool ignoreLuaEvent)
void AttachableObject::clearTemporaryAttachedEffects()
{
if (!hasAttachedEffects()) return;
m_data->attachedEffects.erase(std::remove_if(m_data->attachedEffects.begin(), m_data->attachedEffects.end(),
[this](const AttachedEffectPtr& obj) {
std::erase_if(m_data->attachedEffects,
[this](const AttachedEffectPtr& obj) {
if (!obj->isPermanent()) {
onDetachEffect(obj);
return true;
}
return false;
}), m_data->attachedEffects.end());
});
}

void AttachableObject::clearPermanentAttachedEffects()
{
if (!hasAttachedEffects()) return;
m_data->attachedEffects.erase(std::remove_if(m_data->attachedEffects.begin(), m_data->attachedEffects.end(),
[this](const AttachedEffectPtr& obj) {
std::erase_if(m_data->attachedEffects,
[this](const AttachedEffectPtr& obj) {
if (obj->isPermanent()) {
onDetachEffect(obj);
return true;
}
return false;
}), m_data->attachedEffects.end());
});
}

AttachedEffectPtr AttachableObject::getAttachedEffectById(uint16_t id)
Expand All @@ -152,13 +154,13 @@ AttachedEffectPtr AttachableObject::getAttachedEffectById(uint16_t id)
return *it;
}

void AttachableObject::drawAttachedEffect(const Point& dest, const LightViewPtr& lightView, bool isOnTop)
void AttachableObject::drawAttachedEffect(const Point& dest, const LightViewPtr& lightView, const bool isOnTop)
{
if (!hasAttachedEffects()) return;
for (const auto& effect : m_data->attachedEffects) {
effect->draw(dest, isOnTop, lightView);
if (effect->getLoop() == 0) {
g_dispatcher.addEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect]() {
g_dispatcher.addEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect] {
self->detachEffect(effect);
});
}
Expand Down Expand Up @@ -228,7 +230,7 @@ void AttachableObject::updateAndAttachParticlesEffects(std::vector<std::string>&
toRemove.reserve(m_data->attachedParticles.size());

for (const auto& effect : m_data->attachedParticles) {
auto findPos = std::find(newElements.begin(), newElements.end(), effect->getEffectType()->getName());
auto findPos = std::ranges::find(newElements, effect->getEffectType()->getName());
if (findPos == newElements.end())
toRemove.emplace_back(effect->getEffectType()->getName());
else
Expand Down Expand Up @@ -262,7 +264,7 @@ void AttachableObject::attachWidget(const UIWidgetPtr& widget) {
getData()->attachedWidgets.emplace_back(widget);
g_map.addAttachedWidgetToObject(widget, std::static_pointer_cast<AttachableObject>(shared_from_this()));
widget->callLuaField("onAttached", asLuaObject());
widget->addOnDestroyCallback("attached-widget-destroy", [this, widget]() {
widget->addOnDestroyCallback("attached-widget-destroy", [this, widget] {
detachWidget(widget);
});
}
Expand Down Expand Up @@ -301,12 +303,12 @@ bool AttachableObject::detachWidget(const UIWidgetPtr widget)
return true;
}

void AttachableObject::clearAttachedWidgets(bool callEvent)
void AttachableObject::clearAttachedWidgets(const bool callEvent)
{
if (!hasAttachedWidgets()) return;

// keep the same behavior as detachWidget
auto oldList = std::move(m_data->attachedWidgets);
const auto oldList = std::move(m_data->attachedWidgets);
m_data->attachedWidgets.clear();

for (const auto& widget : oldList) {
Expand Down
12 changes: 6 additions & 6 deletions src/client/attachableobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AttachableObject : public LuaObject
{
public:
AttachableObject() = default;
virtual ~AttachableObject();
~AttachableObject() override;

virtual LuaObjectPtr attachedObjectToLuaObject() = 0;
virtual bool isTile() { return false; }
Expand All @@ -45,9 +45,9 @@ class AttachableObject : public LuaObject
bool detachEffect(const AttachedEffectPtr& obj);
AttachedEffectPtr getAttachedEffectById(uint16_t id);

virtual void onStartAttachEffect(const AttachedEffectPtr& /*effect*/) { };
virtual void onDispatcherAttachEffect(const AttachedEffectPtr& /*effect*/) { };
virtual void onStartDetachEffect(const AttachedEffectPtr& /*effect*/) { };
virtual void onStartAttachEffect(const AttachedEffectPtr& /*effect*/) {};
virtual void onDispatcherAttachEffect(const AttachedEffectPtr& /*effect*/) {};
virtual void onStartDetachEffect(const AttachedEffectPtr& /*effect*/) {};

bool isOwnerHidden() { return m_ownerHidden > 0; }

Expand All @@ -67,7 +67,7 @@ class AttachableObject : public LuaObject
void attachWidget(const UIWidgetPtr& widget);
void clearAttachedWidgets(bool callEvent = true);
bool detachWidgetById(const std::string& id);
bool detachWidget(const UIWidgetPtr widget);
bool detachWidget(UIWidgetPtr widget);
UIWidgetPtr getAttachedWidgetById(const std::string& id);

protected:
Expand All @@ -84,7 +84,7 @@ class AttachableObject : public LuaObject
void onDetachEffect(const AttachedEffectPtr& effect, bool callEvent = true);
void drawAttachedParticlesEffect(const Point& dest);

inline auto getData() {
auto getData() {
if (!m_data)
m_data = std::make_shared<Data>();
return m_data;
Expand Down
6 changes: 3 additions & 3 deletions src/client/attachedeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include "lightview.h"

#include <framework/core/clock.h>
#include <framework/graphics/texturemanager.h>
#include <framework/graphics/animatedtexture.h>
#include <framework/graphics/shadermanager.h>
#include <framework/graphics/texturemanager.h>

AttachedEffectPtr AttachedEffect::create(uint16_t thingId, ThingCategory category) {
AttachedEffectPtr AttachedEffect::create(const uint16_t thingId, const ThingCategory category) {
if (!g_things.isValidDatId(thingId, category)) {
g_logger.error(stdext::format("AttachedEffectManager::getInstance(%d, %d): invalid thing with id or category.", thingId, static_cast<uint8_t>(category)));
return nullptr;
Expand Down Expand Up @@ -71,7 +71,7 @@ int getBounce(const AttachedEffect::Bounce bounce, const ticks_t ticks) {
return minHeight + (height - std::abs(height - static_cast<int>(ticks / (bounce.speed / 100.f)) % static_cast<int>(height * 2)));
}

void AttachedEffect::draw(const Point& dest, bool isOnTop, const LightViewPtr& lightView, const bool drawThing) {
void AttachedEffect::draw(const Point& dest, const bool isOnTop, const LightViewPtr& lightView, const bool drawThing) {
if (m_transform)
return;

Expand Down
66 changes: 43 additions & 23 deletions src/client/attachedeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,73 +22,93 @@

#pragma once

#include "thingtype.h"
#include "outfit.h"
#include "thingtype.h"

class AttachedEffect : public LuaObject
class AttachedEffect final : public LuaObject
{
public:
static AttachedEffectPtr create(uint16_t thingId, ThingCategory category);

void draw(const Point& /*dest*/, bool /*isOnTop*/, const LightViewPtr & = nullptr, const bool drawThing = true);
void draw(const Point& /*dest*/, bool /*isOnTop*/, const LightViewPtr & = nullptr, bool drawThing = true);
void drawLight(const Point& /*dest*/, const LightViewPtr&);

uint16_t getId() { return m_id; }

AttachedEffectPtr clone();

float getSpeed() { return m_speed / 100.f; }
void setSpeed(float speed) { m_speed = speed * 100u; }
void setSpeed(const float speed) { m_speed = speed * 100u; }

float getOpacity() { return m_opacity / 100.f; }
void setOpacity(float opacity) { m_opacity = opacity * 100u; }
void setOpacity(const float opacity) { m_opacity = opacity * 100u; }

Size getSize() { return m_size; }
void setSize(const Size& s) { m_size = s; }

bool isHidedOwner() { return m_hideOwner; }
void setHideOwner(bool v) { m_hideOwner = v; }
void setHideOwner(const bool v) { m_hideOwner = v; }

bool isTransform() { return m_transform; }
void setTransform(bool v) { m_transform = v; }
void setTransform(const bool v) { m_transform = v; }

bool isDisabledWalkAnimation() { return m_disableWalkAnimation; }
void setDisableWalkAnimation(bool v) { m_disableWalkAnimation = v; }
void setDisableWalkAnimation(const bool v) { m_disableWalkAnimation = v; }

bool isPermanent() { return m_permanent; }
void setPermanent(bool permanent) { m_permanent = permanent; }
void setPermanent(const bool permanent) { m_permanent = permanent; }

uint16_t getDuration() { return m_duration; }
void setDuration(uint16_t v) { m_duration = v; }
void setDuration(const uint16_t v) { m_duration = v; }

int8_t getLoop() { return m_loop; }
void setLoop(int8_t v) { m_loop = v; }
void setLoop(const int8_t v) { m_loop = v; }

void setName(std::string_view n) { m_name = { n.data() }; }
std::string getName() { return m_name; }

Otc::Direction getDirection() { return m_direction; }
void setDirection(const Otc::Direction dir) { m_direction = std::min<Otc::Direction>(dir, Otc::NorthWest); }

void setBounce(uint8_t minHeight, uint8_t height, uint16_t speed) { m_bounce = { minHeight, height , speed }; }
void setPulse(uint8_t minHeight, uint8_t height, uint16_t speed) { m_pulse = { minHeight, height , speed }; }
void setFade(uint8_t start, uint8_t end, uint16_t speed) { m_fade = { start, end , speed }; }

void setOnTop(bool onTop) { for (auto& control : m_offsetDirections) control.onTop = onTop; }
void setBounce(const uint8_t minHeight, const uint8_t height, const uint16_t speed) {
m_bounce = { .minHeight =
minHeight,
.height = height, .speed = speed
};
}
void setPulse(const uint8_t minHeight, const uint8_t height, const uint16_t speed) {
m_pulse = { .minHeight =
minHeight,
.height = height, .speed = speed
};
}
void setFade(const uint8_t start, const uint8_t end, const uint16_t speed) {
m_fade = { .minHeight = start, .height =
end,
.speed = speed
};
}

void setOnTop(const bool onTop) { for (auto& control : m_offsetDirections) control.onTop = onTop; }
void setOffset(int16_t x, int16_t y) { for (auto& control : m_offsetDirections) control.offset = { x, y }; }
void setOnTopByDir(Otc::Direction direction, bool onTop) { m_offsetDirections[direction].onTop = onTop; }

void setDirOffset(Otc::Direction direction, int8_t x, int8_t y, bool onTop = false) { m_offsetDirections[direction] = { onTop, {x, y} }; }
void setShader(const std::string_view name);
void setCanDrawOnUI(bool canDraw) { m_canDrawOnUI = canDraw; }
void setOnTopByDir(const Otc::Direction direction, const bool onTop) { m_offsetDirections[direction].onTop = onTop; }

void setDirOffset(const Otc::Direction direction, int8_t x, int8_t y, const bool onTop = false) {
m_offsetDirections[direction] = { .onTop =
onTop,
.offset = {x, y}
};
}
void setShader(std::string_view name);
void setCanDrawOnUI(const bool canDraw) { m_canDrawOnUI = canDraw; }
bool canDrawOnUI() { return m_canDrawOnUI; }

void move(const Position& fromPosition, const Position& toPosition);

void attachEffect(const AttachedEffectPtr& e) { m_effects.emplace_back(e); }

DrawOrder getDrawOrder() { return m_drawOrder; }
void setDrawOrder(DrawOrder drawOrder) { m_drawOrder = drawOrder; }
void setDrawOrder(const DrawOrder drawOrder) { m_drawOrder = drawOrder; }
const Light& getLight() const { return m_light; }
void setLight(const Light& light) { m_light = light; }

Expand Down Expand Up @@ -116,7 +136,7 @@ class AttachedEffect : public LuaObject
uint8_t m_speed{ 100 };
uint8_t m_opacity{ 100 };
uint8_t m_lastAnimation{ 0 };
DrawOrder m_drawOrder{ DrawOrder::FIRST };
DrawOrder m_drawOrder{ FIRST };

uint16_t m_id{ 0 };
uint16_t m_duration{ 0 };
Expand Down
Loading