Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Fix tutorial texts do not appear
Browse files Browse the repository at this point in the history
Fixes #115
  • Loading branch information
scemino committed Mar 22, 2020
1 parent ffcfb38 commit 345add1
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 89 deletions.
2 changes: 1 addition & 1 deletion include/Entities/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Entity : public ScriptObject, public sf::Drawable
virtual void stopObjectMotors();

protected:
sf::Transform getTransform() const;
sf::Transformable getTransform() const;
sf::Transformable _transform;

private:
Expand Down
1 change: 1 addition & 0 deletions include/Entities/Objects/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Object : public Entity
void setOwner(Actor* pActor);

void setScreenSpace(ScreenSpace screenSpace);
ScreenSpace getScreenSpace() const;

void stopObjectMotors() override;

Expand Down
23 changes: 10 additions & 13 deletions src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct Engine::Impl
std::array<VerbUiColors, 6> _verbUiColors;
bool _inputHUD{true};
bool _inputActive{false};
bool _showCursor{false};
bool _showCursor{true};
bool _inputVerbsActive{false};
SpriteSheet _verbSheet, _gameSheet, _saveLoadSheet;
Actor *_pFollowActor{nullptr};
Expand Down Expand Up @@ -478,7 +478,7 @@ sf::Vector2f Engine::findScreenPosition(int verbId) const
auto pVerb = getVerb(verbId);
auto s = _pImpl->getVerbName(*pVerb);
auto r = _pImpl->_verbSheet.getSpriteSourceSize(s);
return sf::Vector2f(r.left + r.width / 2.f, r.top + r.height / 2.f);
return sf::Vector2f(r.left + r.width / 2.f, Screen::Height - (r.top + r.height / 2.f));
}

Preferences &Engine::getPreferences() { return _pImpl->_preferences; }
Expand Down Expand Up @@ -739,9 +739,7 @@ SQInteger Engine::enterRoomFromDoor(Object *pDoor)
actor->setRoom(pRoom);
auto pos = pDoor->getRealPosition();
auto usePos = pDoor->getUsePosition();
auto roomHeight = pDoor->getRoom()->getRoomSize().y;
pos.x += usePos.x;
pos.y += usePos.y - roomHeight;
pos += usePos;
actor->setPosition(pos);
_pImpl->_camera.at(pos);
}
Expand Down Expand Up @@ -1135,7 +1133,8 @@ void Engine::update(const sf::Time &el)
_pImpl->_cursorDirection = CursorDirection::None;
_pImpl->updateMouseCursor();

_pImpl->_mousePosInRoom = _pImpl->_mousePos + _pImpl->_camera.getAt();
auto mousePos = sf::Vector2f(_pImpl->_mousePos.x, _pImpl->_pWindow->getView().getSize().y - _pImpl->_mousePos.y);
_pImpl->_mousePosInRoom = mousePos + _pImpl->_camera.getAt();

_pImpl->_inventory.setMousePosition(_pImpl->_mousePos);
_pImpl->_dialogManager.update(elapsed);
Expand Down Expand Up @@ -1575,11 +1574,10 @@ void Engine::Impl::drawCursorText(sf::RenderTarget &target) const
text.setString(s);

// do display cursor position:
// auto mousePosInRoom = _mousePos + _camera.getAt();
// std::wstringstream ss;
// std::wstring txt = text.getText();
// ss << txt << L" (" << std::fixed << std::setprecision(0) << mousePosInRoom.x << L"," << mousePosInRoom.y << L")";
// text.setText(ss.str());
std::wstringstream ss;
std::wstring txt = text.getString();
ss << txt << L" (" << std::fixed << std::setprecision(0) << _mousePosInRoom.x << L"," << _mousePosInRoom.y << L")";
text.setString(ss.str());

auto screenSize = _pRoom->getScreenSize();
auto pos = toDefaultView((sf::Vector2i)_mousePos, screenSize);
Expand Down Expand Up @@ -1865,8 +1863,7 @@ void Engine::sayLineAt(sf::Vector2i pos, sf::Color color, sf::Time duration, con
{
_pImpl->_talkingState.setTalkColor(color);
auto size = getRoom()->getRoomSize();
sf::Vector2i p(pos.x, size.y - pos.y);
_pImpl->_talkingState.setPosition(toDefaultView(p, size));
_pImpl->_talkingState.setPosition(toDefaultView(pos, size));
_pImpl->_talkingState.setText(getText(text));
_pImpl->_talkingState.setDuration(duration);
}
Expand Down
28 changes: 14 additions & 14 deletions src/Entities/Actor/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ bool Actor::contains(const sf::Vector2f &pos) const
if (!pAnim)
return false;

auto size = pImpl->_pRoom->getRoomSize();
auto scale = pImpl->_pRoom->getRoomScaling().getScaling(size.y - getRealPosition().y);
auto transform = getTransform();
auto scale = pImpl->_pRoom->getRoomScaling().getScaling(getRealPosition().y);
auto transform = getTransform().getTransform();
transform.scale(scale, scale);
transform.translate((sf::Vector2f)-getRenderOffset() * scale);
auto t = transform.getInverse();
Expand Down Expand Up @@ -257,7 +256,7 @@ Facing Actor::Impl::WalkingState::getFacing()
auto dy = _path[0].y - pos.y;
if (fabs(dx) > fabs(dy))
return (dx > 0) ? Facing::FACE_RIGHT : Facing::FACE_LEFT;
return (dy > 0) ? Facing::FACE_FRONT : Facing::FACE_BACK;
return (dy < 0) ? Facing::FACE_FRONT : Facing::FACE_BACK;
}

void Actor::Impl::WalkingState::update(const sf::Time &elapsed)
Expand Down Expand Up @@ -316,7 +315,7 @@ Actor::~Actor() = default;

const Room *Actor::getRoom() const { return pImpl->_pRoom; }

int Actor::getZOrder() const { return static_cast<int>(getRoom()->getRoomSize().y - getRealPosition().y); }
int Actor::getZOrder() const { return static_cast<int>(getRealPosition().y); }

void Actor::setRoom(Room *pRoom)
{
Expand All @@ -341,8 +340,7 @@ void Actor::setCostume(const std::string &name, const std::string &sheet)

float Actor::getScale() const
{
auto size = pImpl->_pRoom->getRoomSize();
return pImpl->_pRoom->getRoomScaling().getScaling(size.y - getRealPosition().y);
return pImpl->_pRoom->getRoomScaling().getScaling(getRealPosition().y);
}

void Actor::draw(sf::RenderTarget &target, sf::RenderStates states) const
Expand All @@ -351,17 +349,19 @@ void Actor::draw(sf::RenderTarget &target, sf::RenderStates states) const

if (isVisible()) {
auto scale = getScale();
auto transform = getTransform();
transform.scale(scale, scale);
transform.translate(getRenderOffset().x, -getRenderOffset().y);
states.transform *= transform;
auto transformable = getTransform();
transformable.scale(scale, scale);
transformable.move(getRenderOffset().x, getRenderOffset().y);
transformable.setPosition(transformable.getPosition().x, target.getView().getSize().y - transformable.getPosition().y);
states.transform *= transformable.getTransform();
target.draw(pImpl->_costume, states);
}

auto scale = getScale();
auto transform = getTransform();
transform.scale(scale, scale);
statesHotSpot.transform *= transform;
auto transformable = getTransform();
transformable.scale(scale, scale);
transformable.setPosition(transformable.getPosition().x, target.getView().getSize().y - transformable.getPosition().y);
statesHotSpot.transform *= transformable.getTransform();
pImpl->drawHotspot(target, statesHotSpot);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ float Entity::getScale() const
return _transform.getScale().x;
}

sf::Transform Entity::getTransform() const
sf::Transformable Entity::getTransform() const
{
auto transform = _transform;
transform.move(_offset.x, _offset.y);
return transform.getTransform();
return transform;
}

sf::Vector2f Entity::getUsePosition() const
Expand Down
22 changes: 13 additions & 9 deletions src/Entities/Objects/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool Object::isTouchable() const
sf::IntRect Object::getRealHotspot() const
{
auto rect = getHotspot();
auto transform = getTransform();
auto transform = getTransform().getTransform();
return (sf::IntRect)transform.transformRect((sf::FloatRect)rect);
}

Expand Down Expand Up @@ -208,6 +208,8 @@ bool Object::isHotspotVisible() const { return pImpl->_hotspotVisible; }

void Object::setScreenSpace(ScreenSpace screenSpace) { pImpl->_screenSpace = screenSpace; }

ScreenSpace Object::getScreenSpace() const { return pImpl->_screenSpace; }

void Object::drawHotspot(sf::RenderTarget &target, sf::RenderStates states) const
{
if (!pImpl->_hotspotVisible)
Expand Down Expand Up @@ -240,12 +242,12 @@ void Object::drawHotspot(sf::RenderTarget &target, sf::RenderStates states) cons
target.draw(s, states);

sf::RectangleShape vl(sf::Vector2f(1, 7));
vl.setPosition(pImpl->_usePos.x, -pImpl->_usePos.y - 3);
vl.setPosition(pImpl->_usePos.x, pImpl->_usePos.y - 3);
vl.setFillColor(color);
target.draw(vl, states);

sf::RectangleShape hl(sf::Vector2f(7, 1));
hl.setPosition(pImpl->_usePos.x - 3, -pImpl->_usePos.y);
hl.setPosition(pImpl->_usePos.x - 3, pImpl->_usePos.y);
hl.setFillColor(color);
target.draw(hl, states);

Expand All @@ -254,15 +256,15 @@ void Object::drawHotspot(sf::RenderTarget &target, sf::RenderStates states) cons
case UseDirection::Front:
{
sf::RectangleShape dirShape(sf::Vector2f(3, 1));
dirShape.setPosition(pImpl->_usePos.x - 1, -pImpl->_usePos.y + 2);
dirShape.setPosition(pImpl->_usePos.x - 1, pImpl->_usePos.y + 2);
dirShape.setFillColor(color);
target.draw(dirShape, states);
}
break;
case UseDirection::Back:
{
sf::RectangleShape dirShape(sf::Vector2f(3, 1));
dirShape.setPosition(pImpl->_usePos.x - 1, -pImpl->_usePos.y - 2);
dirShape.setPosition(pImpl->_usePos.x - 1, pImpl->_usePos.y - 2);
dirShape.setFillColor(color);
target.draw(dirShape, states);
}
Expand Down Expand Up @@ -295,8 +297,9 @@ void Object::drawForeground(sf::RenderTarget &target, sf::RenderStates) const
target.setView(sf::View(sf::FloatRect(0, 0, Screen::Width, Screen::Height)));

sf::RenderStates s;
auto transform = _transform;
s.transform = transform.getTransform();
auto transformable = getTransform();
transformable.setPosition(transformable.getPosition().x, target.getView().getSize().y - transformable.getPosition().y);
s.transform *= transformable.getTransform();

if (pImpl->_pAnim)
{
Expand All @@ -316,8 +319,9 @@ void Object::draw(sf::RenderTarget &target, sf::RenderStates states) const
if (pImpl->_screenSpace == ScreenSpace::Object)
return;

auto transform = getTransform();
states.transform *= transform;
auto transformable = getTransform();
transformable.setPosition(transformable.getPosition().x, target.getView().getSize().y - transformable.getPosition().y);
states.transform *= transformable.getTransform();

if (pImpl->_pAnim)
{
Expand Down
31 changes: 24 additions & 7 deletions src/Entities/Objects/TextObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void TextObject::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
if(!isVisible())
return;

const auto view = target.getView();
if (getScreenSpace() == ScreenSpace::Object) {
target.setView(sf::View(sf::FloatRect(0, 0, Screen::Width, Screen::Height)));
}

Text txt;
txt.setFont(_font);
txt.setFillColor(getColor());
Expand All @@ -43,27 +49,38 @@ void TextObject::draw(sf::RenderTarget &target, sf::RenderStates states) const
sf::Vector2f offset;
if (_alignment & TextAlignment::Center)
{
offset.x = -bounds.width / 2;
offset.x = getScale() * -bounds.width / 2;
}
else if (_alignment & TextAlignment::Right)
{
offset.x = bounds.width / 2;
offset.x = getScale() * bounds.width / 2;
}
if (_alignment & TextAlignment::Top)
{
offset.y = 0;
}
else if (_alignment & TextAlignment::Bottom)
{
offset.y = -bounds.height;
offset.y = getScale() * bounds.height;
}
else
{
offset.y = -bounds.height / 2;
offset.y = getScale() * bounds.height / 2;
}
auto height = target.getView().getSize().y;
auto transformable = getTransform();
transformable.move(offset.x, offset.y);
transformable.setPosition(transformable.getPosition().x, height - transformable.getPosition().y);

if (getScreenSpace() == ScreenSpace::Object) {
sf::RenderStates s;
s.transform *= transformable.getTransform();
target.draw(txt, s);
target.setView(view);
} else {
states.transform *= transformable.getTransform();
target.draw(txt, states);
}
txt.move(offset);
states.transform *= _transform.getTransform();
target.draw(txt, states);
}

} // namespace ng
5 changes: 3 additions & 2 deletions src/Math/PathFinding/_WalkboxDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ _WalkboxDrawable::_WalkboxDrawable(const Walkbox &walkbox) : _walkbox(walkbox) {
}

void _WalkboxDrawable::draw(sf::RenderTarget &target, sf::RenderStates states) const {
auto height = target.getView().getSize().y;
auto color = _walkbox.isEnabled() ? sf::Color::Green : sf::Color::Red;
sf::VertexArray triangle(sf::LinesStrip, _walkbox.getVertices().size() + 1);
for (size_t i = 0; i < _walkbox.getVertices().size(); ++i) {
auto &vertex = _walkbox.getVertex(i);
triangle[i].position = sf::Vector2f(vertex.x, vertex.y);
triangle[i].position = sf::Vector2f(vertex.x, height - vertex.y);
triangle[i].color = color;
}
{
auto &vertex = _walkbox.getVertex(0);
triangle[_walkbox.getVertices().size()].position = sf::Vector2f(vertex.x, vertex.y);
triangle[_walkbox.getVertices().size()].position = sf::Vector2f(vertex.x, height - vertex.y);
triangle[_walkbox.getVertices().size()].color = color;
}
target.draw(triangle, states);
Expand Down
10 changes: 5 additions & 5 deletions src/Room/Room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct Room::Impl
object->setUseDirection(useDir);
// hotspot
auto hotspot = _parseRect(jObject["hotspot"].string_value);
object->setHotspot(sf::IntRect(hotspot.left, -hotspot.top-hotspot.height, hotspot.width, hotspot.height));
object->setHotspot(sf::IntRect(hotspot.left, hotspot.top, hotspot.width, hotspot.height));
// prop
bool isProp = jObject["prop"].isInteger() && jObject["prop"].int_value == 1;
if(isProp) object->setType(ObjectType::Prop);
Expand All @@ -235,8 +235,8 @@ struct Room::Impl
bool isTrigger = jObject["trigger"].isInteger() && jObject["trigger"].int_value == 1;
if(isTrigger) object->setType(ObjectType::Trigger);

object->setPosition(sf::Vector2f(pos.x, _roomSize.y - pos.y));
object->setUsePosition(sf::Vector2f(usePos.x, _roomSize.y - usePos.y));
object->setPosition(pos);
object->setUsePosition(usePos);

// animations
if (jObject["animations"].isArray())
Expand Down Expand Up @@ -382,7 +382,7 @@ struct Room::Impl
{
std::vector<sf::Vector2i> vertices;
auto polygon = jWalkbox["polygon"].string_value;
_parsePolygon(polygon, vertices, _roomSize.y);
_parsePolygon(polygon, vertices);
Walkbox walkbox(vertices);
if (jWalkbox["name"].isString())
{
Expand Down Expand Up @@ -698,7 +698,7 @@ void Room::draw(sf::RenderWindow &window, const sf::Vector2f &cameraPos) const
}

auto screen = window.getView().getSize();
auto h = pImpl->_roomSize.y - screen.y;
auto h = screen.y;

for (const auto &layer : pImpl->_layers)
{
Expand Down
Loading

0 comments on commit 345add1

Please sign in to comment.