summaryrefslogtreecommitdiff
path: root/src/gui/viewport.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-20 10:26:22 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-01-20 10:51:24 +0100
commitdb9b9f316d7bdcb9504092908bb18e82fc21de2f (patch)
tree3f7bb1577c5210a9523fd240556cf840665f3efb /src/gui/viewport.cpp
parent0d1024b64155a05f45f247ad57d0f444db01c1e2 (diff)
downloadmana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.tar.gz
mana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.tar.bz2
mana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.tar.xz
mana-db9b9f316d7bdcb9504092908bb18e82fc21de2f.zip
Made client config statically typed
This makes accessing the config values much faster, since it no longer needs to do a lookup nor string conversion, which means we could remove some needless copying of the values. Overall it makes it easier to find out where settings are used and it puts the defaults along with the declaration. Options with default values are no longer saved to the config file. This does not include unrecognized options, which are kept around to provide some compatibility with older clients. While most basic options have kept the same name, more complicated settings like window geometry, shortcuts, outfits, etc. now have their own XML elements. Older clients will ignore these and erase them when saving the configuration.
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r--src/gui/viewport.cpp41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 8fcca014..558ce0e6 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -49,11 +49,6 @@ Viewport::Viewport()
setOpaque(false);
addMouseListener(this);
- mScrollLaziness = config.getIntValue("ScrollLaziness");
- mScrollRadius = config.getIntValue("ScrollRadius");
- mScrollCenterOffsetX = config.getIntValue("ScrollCenterOffsetX");
- mScrollCenterOffsetY = config.getIntValue("ScrollCenterOffsetY");
-
mPopupMenu = new PopupMenu;
mBeingPopup = new BeingPopup;
@@ -95,8 +90,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
auto *graphics = static_cast<Graphics*>(gcnGraphics);
// Calculate viewpoint
- int midTileX = (graphics->getWidth() + mScrollCenterOffsetX) / 2;
- int midTileY = (graphics->getHeight() + mScrollCenterOffsetX) / 2;
+ int midTileX = (graphics->getWidth() + config.scrollCenterOffsetX) / 2;
+ int midTileY = (graphics->getHeight() + config.scrollCenterOffsetY) / 2;
const Vector &playerPos = local_player->getPosition();
const int player_x = (int) playerPos.x - midTileX;
@@ -105,34 +100,34 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
const float ticks = Time::deltaTimeMs() / static_cast<float>(MILLISECONDS_IN_A_TICK);
float scrollFraction = 1.0f;
- if (mScrollLaziness > 1)
+ if (config.scrollLaziness > 1)
{
- // mScrollLaziness defines the fraction of the desired camera movement
+ // settings.ScrollLaziness defines the fraction of the desired camera movement
// that is applied every 10ms. To make this work independently of the
// frame duration, we calculate the actual scroll fraction based on the
// time delta.
- scrollFraction = 1.0f - std::pow(1.0f - 1.0f / mScrollLaziness, ticks);
+ scrollFraction = 1.0f - std::pow(1.0f - 1.0f / config.scrollLaziness, ticks);
}
// Apply lazy scrolling
- if (player_x > mPixelViewX + mScrollRadius)
+ if (player_x > mPixelViewX + config.scrollRadius)
{
- mPixelViewX += (player_x - mPixelViewX - mScrollRadius) *
+ mPixelViewX += (player_x - mPixelViewX - config.scrollRadius) *
scrollFraction;
}
- if (player_x < mPixelViewX - mScrollRadius)
+ if (player_x < mPixelViewX - config.scrollRadius)
{
- mPixelViewX += (player_x - mPixelViewX + mScrollRadius) *
+ mPixelViewX += (player_x - mPixelViewX + config.scrollRadius) *
scrollFraction;
}
- if (player_y > mPixelViewY + mScrollRadius)
+ if (player_y > mPixelViewY + config.scrollRadius)
{
- mPixelViewY += (player_y - mPixelViewY - mScrollRadius) *
+ mPixelViewY += (player_y - mPixelViewY - config.scrollRadius) *
scrollFraction;
}
- if (player_y < mPixelViewY - mScrollRadius)
+ if (player_y < mPixelViewY - config.scrollRadius)
{
- mPixelViewY += (player_y - mPixelViewY + mScrollRadius) *
+ mPixelViewY += (player_y - mPixelViewY + config.scrollRadius) *
scrollFraction;
}
@@ -624,14 +619,4 @@ void Viewport::event(Event::Channel channel, const Event &event)
if (mHoverItem == actor)
mHoverItem = nullptr;
}
- else if (channel == Event::ConfigChannel &&
- event.getType() == Event::ConfigOptionChanged)
- {
- const std::string &option = event.getString("option");
- if (option == "ScrollLaziness" || option == "ScrollRadius")
- {
- mScrollLaziness = config.getIntValue("ScrollLaziness");
- mScrollRadius = config.getIntValue("ScrollRadius");
- }
- }
}