1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-05 06:40:09 +00:00

Use settings values for Map settings

This commit is contained in:
elsid 2023-07-27 22:52:51 +02:00
parent bdb4808588
commit 9acb93ab29
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625
7 changed files with 56 additions and 62 deletions

View File

@ -88,7 +88,7 @@ namespace MWGui
HUD::HUD(CustomMarkerCollection& customMarkers, DragAndDrop* dragAndDrop, MWRender::LocalMap* localMapRender)
: WindowBase("openmw_hud.layout")
, LocalMapBase(customMarkers, localMapRender, Settings::Manager::getBool("local map hud fog of war", "Map"))
, LocalMapBase(customMarkers, localMapRender)
, mHealth(nullptr)
, mMagicka(nullptr)
, mStamina(nullptr)

View File

@ -87,14 +87,13 @@ namespace
int getLocalViewingDistance()
{
if (!Settings::Manager::getBool("allow zooming", "Map"))
if (!Settings::map().mAllowZooming)
return Constants::CellGridRadius;
if (!Settings::Manager::getBool("distant terrain", "Terrain"))
return Constants::CellGridRadius;
const int maxLocalViewingDistance
= std::max(Settings::Manager::getInt("max local viewing distance", "Map"), Constants::CellGridRadius);
const int viewingDistanceInCells = Settings::camera().mViewingDistance / Constants::CellSizeInUnits;
return std::clamp(viewingDistanceInCells, Constants::CellGridRadius, maxLocalViewingDistance);
return std::clamp(
viewingDistanceInCells, Constants::CellGridRadius, Settings::map().mMaxLocalViewingDistance.get());
}
}
@ -168,8 +167,7 @@ namespace MWGui
// ------------------------------------------------------
LocalMapBase::LocalMapBase(
CustomMarkerCollection& markers, MWRender::LocalMap* localMapRender, bool fogOfWarEnabled)
LocalMapBase::LocalMapBase(CustomMarkerCollection& markers, MWRender::LocalMap* localMapRender)
: mLocalMapRender(localMapRender)
, mCurX(0)
, mCurY(0)
@ -178,8 +176,6 @@ namespace MWGui
, mCompass(nullptr)
, mChanged(true)
, mFogOfWarToggled(true)
, mFogOfWarEnabled(fogOfWarEnabled)
, mMapWidgetSize(0)
, mNumCells(1)
, mCellDistance(0)
, mCustomMarkers(markers)
@ -200,11 +196,12 @@ namespace MWGui
{
mLocalMap = widget;
mCompass = compass;
mMapWidgetSize = std::max(1, Settings::Manager::getInt("local map widget size", "Map"));
mCellDistance = cellDistance;
mNumCells = mCellDistance * 2 + 1;
mLocalMap->setCanvasSize(mMapWidgetSize * mNumCells, mMapWidgetSize * mNumCells);
const int mapWidgetSize = Settings::map().mLocalMapWidgetSize;
mLocalMap->setCanvasSize(mapWidgetSize * mNumCells, mapWidgetSize * mNumCells);
mCompass->setDepth(Local_CompassLayer);
mCompass->setNeedMouseFocus(false);
@ -214,12 +211,12 @@ namespace MWGui
for (int my = 0; my < mNumCells; ++my)
{
MyGUI::ImageBox* map = mLocalMap->createWidget<MyGUI::ImageBox>("ImageBox",
MyGUI::IntCoord(mx * mMapWidgetSize, my * mMapWidgetSize, mMapWidgetSize, mMapWidgetSize),
MyGUI::IntCoord(mx * mapWidgetSize, my * mapWidgetSize, mapWidgetSize, mapWidgetSize),
MyGUI::Align::Top | MyGUI::Align::Left);
map->setDepth(Local_MapLayer);
MyGUI::ImageBox* fog = mLocalMap->createWidget<MyGUI::ImageBox>("ImageBox",
MyGUI::IntCoord(mx * mMapWidgetSize, my * mMapWidgetSize, mMapWidgetSize, mMapWidgetSize),
MyGUI::IntCoord(mx * mapWidgetSize, my * mapWidgetSize, mapWidgetSize, mapWidgetSize),
MyGUI::Align::Top | MyGUI::Align::Left);
fog->setDepth(Local_FogLayer);
fog->setColour(MyGUI::Colour(0, 0, 0));
@ -247,7 +244,7 @@ namespace MWGui
void LocalMapBase::applyFogOfWar()
{
if (!mFogOfWarToggled || !mFogOfWarEnabled)
if (!mFogOfWarToggled || !Settings::map().mLocalMapHudFogOfWar)
{
for (auto& entry : mMaps)
{
@ -464,7 +461,7 @@ namespace MWGui
float LocalMapBase::getWidgetSize() const
{
return mLocalMapZoom * mMapWidgetSize;
return mLocalMapZoom * Settings::map().mLocalMapWidgetSize;
}
void LocalMapBase::setPlayerPos(int cellX, int cellY, const float nx, const float ny)
@ -598,7 +595,7 @@ namespace MWGui
else
entry.mMapTexture = std::make_unique<osgMyGUI::OSGTexture>(std::string(), nullptr);
}
if (!entry.mFogTexture && mFogOfWarToggled && mFogOfWarEnabled)
if (!entry.mFogTexture && mFogOfWarToggled && Settings::map().mLocalMapHudFogOfWar)
{
osg::ref_ptr<osg::Texture2D> tex = mLocalMapRender->getFogOfWarTexture(entry.mCellX, entry.mCellY);
if (tex)
@ -760,12 +757,10 @@ namespace MWGui
, mGlobalMap(nullptr)
, mGlobalMapImage(nullptr)
, mGlobalMapOverlay(nullptr)
, mGlobal(Settings::Manager::getBool("global", "Map"))
, mEventBoxGlobal(nullptr)
, mEventBoxLocal(nullptr)
, mGlobalMapRender(std::make_unique<MWRender::GlobalMap>(localMapRender->getRoot(), workQueue))
, mEditNoteDialog()
, mAllowZooming(Settings::Manager::getBool("allow zooming", "Map"))
{
static bool registered = false;
if (!registered)
@ -799,12 +794,18 @@ namespace MWGui
getWidget(mButton, "WorldButton");
mButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MapWindow::onWorldButtonClicked);
mButton->setCaptionWithReplacing(mGlobal ? "#{sLocal}" : "#{sWorld}");
const bool global = Settings::map().mGlobal;
mButton->setCaptionWithReplacing(global ? "#{sLocal}" : "#{sWorld}");
getWidget(mEventBoxGlobal, "EventBoxGlobal");
mEventBoxGlobal->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
mEventBoxGlobal->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
if (mAllowZooming)
const bool allowZooming = Settings::map().mAllowZooming;
if (allowZooming)
mEventBoxGlobal->eventMouseWheel += MyGUI::newDelegate(this, &MapWindow::onMapZoomed);
mEventBoxGlobal->setDepth(Global_ExploreOverlayLayer);
@ -812,13 +813,13 @@ namespace MWGui
mEventBoxLocal->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
mEventBoxLocal->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
mEventBoxLocal->eventMouseButtonDoubleClick += MyGUI::newDelegate(this, &MapWindow::onMapDoubleClicked);
if (mAllowZooming)
if (allowZooming)
mEventBoxLocal->eventMouseWheel += MyGUI::newDelegate(this, &MapWindow::onMapZoomed);
LocalMapBase::init(mLocalMap, mPlayerArrowLocal, getLocalViewingDistance());
mGlobalMap->setVisible(mGlobal);
mLocalMap->setVisible(!mGlobal);
mGlobalMap->setVisible(global);
mLocalMap->setVisible(!global);
}
void MapWindow::onNoteEditOk()
@ -895,8 +896,7 @@ namespace MWGui
void MapWindow::onMapZoomed(MyGUI::Widget* sender, int rel)
{
const static int localWidgetSize = Settings::Manager::getInt("local map widget size", "Map");
const int localWidgetSize = Settings::map().mLocalMapWidgetSize;
const bool zoomOut = rel < 0;
const bool zoomIn = !zoomOut;
const double speedDiff = zoomOut ? 1.0 / speed : speed;
@ -906,7 +906,7 @@ namespace MWGui
/ float(localWidgetSize),
float(mLocalMap->getWidth()) / localMapSizeInUnits, float(mLocalMap->getHeight()) / localMapSizeInUnits });
if (mGlobal)
if (Settings::map().mGlobal)
{
const float currentGlobalZoom = mGlobalMapZoom;
const float currentMinGlobalMapZoom
@ -961,11 +961,11 @@ namespace MWGui
void MapWindow::zoomOnCursor(float speedDiff)
{
auto map = mGlobal ? mGlobalMap : mLocalMap;
auto map = Settings::map().mGlobal ? mGlobalMap : mLocalMap;
auto cursor = MyGUI::InputManager::getInstance().getMousePosition() - map->getAbsolutePosition();
auto centerView = map->getViewOffset() - cursor;
mGlobal ? updateGlobalMap() : updateLocalMap();
Settings::map().mGlobal ? updateGlobalMap() : updateLocalMap();
map->setViewOffset(MyGUI::IntPoint(std::round(centerView.left * speedDiff) + cursor.left,
std::round(centerView.top * speedDiff) + cursor.top));
@ -1053,7 +1053,7 @@ namespace MWGui
MyGUI::Colour::parse(MyGUI::LanguageManager::getInstance().replaceTags("#{fontcolour=normal}")));
markerWidget->setDepth(Global_MarkerLayer);
markerWidget->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
if (mAllowZooming)
if (Settings::map().mAllowZooming)
markerWidget->eventMouseWheel += MyGUI::newDelegate(this, &MapWindow::onMapZoomed);
markerWidget->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
@ -1177,7 +1177,7 @@ namespace MWGui
MyGUI::IntPoint diff = MyGUI::IntPoint(_left, _top) - mLastDragPos;
if (!mGlobal)
if (!Settings::map().mGlobal)
{
mNeedDoorMarkersUpdate = true;
mLocalMap->setViewOffset(mLocalMap->getViewOffset() + diff);
@ -1190,13 +1190,14 @@ namespace MWGui
void MapWindow::onWorldButtonClicked(MyGUI::Widget* _sender)
{
mGlobal = !mGlobal;
mGlobalMap->setVisible(mGlobal);
mLocalMap->setVisible(!mGlobal);
const bool global = !Settings::map().mGlobal;
Settings::Manager::setBool("global", "Map", mGlobal);
Settings::map().mGlobal.set(global);
mButton->setCaptionWithReplacing(mGlobal ? "#{sLocal}" : "#{sWorld}");
mGlobalMap->setVisible(global);
mLocalMap->setVisible(!global);
mButton->setCaptionWithReplacing(global ? "#{sLocal}" : "#{sWorld}");
}
void MapWindow::onPinToggled()
@ -1340,7 +1341,7 @@ namespace MWGui
marker->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
marker->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
marker->eventMouseButtonDoubleClick += MyGUI::newDelegate(this, &MapWindow::onCustomMarkerDoubleClicked);
if (mAllowZooming)
if (Settings::map().mAllowZooming)
marker->eventMouseWheel += MyGUI::newDelegate(this, &MapWindow::onMapZoomed);
}
@ -1348,7 +1349,7 @@ namespace MWGui
{
marker->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
marker->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
if (mAllowZooming)
if (Settings::map().mAllowZooming)
marker->eventMouseWheel += MyGUI::newDelegate(this, &MapWindow::onMapZoomed);
}

View File

@ -73,7 +73,7 @@ namespace MWGui
class LocalMapBase
{
public:
LocalMapBase(CustomMarkerCollection& markers, MWRender::LocalMap* localMapRender, bool fogOfWarEnabled = true);
LocalMapBase(CustomMarkerCollection& markers, MWRender::LocalMap* localMapRender);
virtual ~LocalMapBase();
void init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, int cellDistance = Constants::CellGridRadius);
@ -125,9 +125,6 @@ namespace MWGui
std::string mPrefix;
bool mChanged;
bool mFogOfWarToggled;
bool mFogOfWarEnabled;
int mMapWidgetSize;
int mNumCells; // for convenience, mCellDistance * 2 + 1
int mCellDistance;
@ -301,7 +298,6 @@ namespace MWGui
MyGUI::ImageBox* mPlayerArrowGlobal;
MyGUI::Button* mButton;
MyGUI::IntPoint mLastDragPos;
bool mGlobal;
MyGUI::IntCoord mLastScrollWindowCoordinates;
@ -328,7 +324,6 @@ namespace MWGui
EditNoteDialog mEditNoteDialog;
ESM::CustomMarker mEditingMarker;
bool mAllowZooming;
void onPinToggled() override;
void onTitleDoubleClicked() override;

View File

@ -263,8 +263,7 @@ namespace MWRender
};
GlobalMap::GlobalMap(osg::Group* root, SceneUtil::WorkQueue* workQueue)
: mCellSize(Settings::map().mGlobalMapCellSize)
, mRoot(root)
: mRoot(root)
, mWorkQueue(workQueue)
, mWidth(0)
, mHeight(0)
@ -304,11 +303,13 @@ namespace MWRender
mMaxY = it->getGridY();
}
mWidth = mCellSize * (mMaxX - mMinX + 1);
mHeight = mCellSize * (mMaxY - mMinY + 1);
const int cellSize = Settings::map().mGlobalMapCellSize;
mWidth = cellSize * (mMaxX - mMinX + 1);
mHeight = cellSize * (mMaxY - mMinY + 1);
mWorkItem
= new CreateMapWorkItem(mWidth, mHeight, mMinX, mMinY, mMaxX, mMaxY, mCellSize, esmStore.get<ESM::Land>());
= new CreateMapWorkItem(mWidth, mHeight, mMinX, mMinY, mMaxX, mMaxY, cellSize, esmStore.get<ESM::Land>());
mWorkQueue->addWorkItem(mWorkItem);
}
@ -412,14 +413,15 @@ namespace MWRender
if (!localMapTexture)
return;
int originX = (cellX - mMinX) * mCellSize;
int originY = (cellY - mMinY + 1)
* mCellSize; // +1 because we want the top left corner of the cell, not the bottom left
const int cellSize = Settings::map().mGlobalMapCellSize;
const int originX = (cellX - mMinX) * cellSize;
// +1 because we want the top left corner of the cell, not the bottom left
const int originY = (cellY - mMinY + 1) * cellSize;
if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
return;
requestOverlayTextureUpdate(originX, mHeight - originY, mCellSize, mCellSize, localMapTexture, false, true);
requestOverlayTextureUpdate(originX, mHeight - originY, cellSize, cellSize, localMapTexture, false, true);
}
void GlobalMap::clear()
@ -520,7 +522,7 @@ namespace MWRender
// If cell bounds of the currently loaded content and the loaded savegame do not match,
// we need to resize source/dest boxes to accommodate
// This means nonexisting cells will be dropped silently
int cellImageSizeDst = mCellSize;
const int cellImageSizeDst = Settings::map().mGlobalMapCellSize;
// Completely off-screen? -> no need to blit anything
if (bounds.mMaxX < mMinX || bounds.mMaxY < mMinY || bounds.mMinX > mMaxX || bounds.mMinY > mMaxY)

View File

@ -86,8 +86,6 @@ namespace MWRender
bool clear, bool cpuCopy, float srcLeft = 0.f, float srcTop = 0.f, float srcRight = 1.f,
float srcBottom = 1.f);
int mCellSize;
osg::ref_ptr<osg::Group> mRoot;
typedef std::vector<osg::ref_ptr<osg::Camera>> CameraVector;

View File

@ -22,7 +22,7 @@
#include <components/sceneutil/rtt.hpp>
#include <components/sceneutil/shadow.hpp>
#include <components/sceneutil/visitor.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#include <components/stereo/multiview.hpp>
#include "../mwbase/environment.hpp"
@ -75,16 +75,13 @@ namespace MWRender
LocalMap::LocalMap(osg::Group* root)
: mRoot(root)
, mMapResolution(Settings::Manager::getInt("local map resolution", "Map"))
, mMapResolution(
Settings::map().mLocalMapResolution * MWBase::Environment::get().getWindowManager()->getScalingFactor())
, mMapWorldSize(Constants::CellSizeInUnits)
, mCellDistance(Constants::CellGridRadius)
, mAngle(0.f)
, mInterior(false)
{
// Increase map resolution, if use UI scaling
float uiScale = MWBase::Environment::get().getWindowManager()->getScalingFactor();
mMapResolution *= uiScale;
SceneUtil::FindByNameVisitor find("Scene Root");
mRoot->accept(find);
mSceneRoot = find.mFoundNode;

View File

@ -1,6 +1,7 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_CATEGORIES_MAP_H
#define OPENMW_COMPONENTS_SETTINGS_CATEGORIES_MAP_H
#include "components/misc/constants.hpp"
#include "components/settings/sanitizerimpl.hpp"
#include "components/settings/settingvalue.hpp"
@ -25,7 +26,7 @@ namespace Settings
SettingValue<bool> mGlobal{ mIndex, "Map", "global" };
SettingValue<bool> mAllowZooming{ mIndex, "Map", "allow zooming" };
SettingValue<int> mMaxLocalViewingDistance{ mIndex, "Map", "max local viewing distance",
makeMaxSanitizerInt(1) };
makeMaxSanitizerInt(Constants::CellGridRadius) };
};
}