Improve: remember 2D mapper zoom amounts between sessions#6615
Conversation
This is intended to close Mudlet#2388. This enables the 2D (only) map zoom amounts for each map area to be save independently and restored when switching between areas in the mapper. It also saves the data between session. It extends the existing `setMapZoom(...)` API to take an optional second argument to specify the map area ID to set the zoom (which is a floating point number) for any existing area, not just the current one. It also adds a `getMapZoom(...)` function that, without any arguments, returns the currently used 2D map zoom value for the area currently being shown in the 2D mapper. If an area ID is provided it instead returns the value that was last used for that area - or the default value that is used initially on starting the profile or for an area that has not been viewed before. Importantly when switching between the areas in the 2D mapper the values are retained and applied so that one area can be zoomed in and another zoomed out and switching from the first to the second and back to the first means that the zoom level used in the first is reused when it is returned to. Deleting an area will forget the stored zoom level so if it is reused it starts from scratch. Code to save the zoom level for each area has also been implemented within the C++ core. It saves it in the Area User Data for current map formats (but removes it on loading so the user never sees it there) under a `system.fallback_map2DZoom` key but will save it directly in the binary data (which is more efficient) in the next format version whenever it is enabled. A new Mudlet event, which has been called `mapAreaViewedChangeEvent` has been added with two additional arguments being the area ID changed to followed by the one that it was changed from. I originally thought I would need it to handle saving the zoom level for each area via the Lua system but I found that that was not practicable. I'll leave it in for now but it could be removed if peer-review finds it not to be of use. Also, in refactoring `T2DMap::paintEvent(...)` I: Removed/combined some locals: * `(TArea*) playerArea` and `(TArea*) pPlayerArea` ==> `pArea` * `(TRoom*) playerRoom` ==> `pPlayerRoom` Remove unneeded (refactored out): * `(qreal) ox` * `(qreal) oy` Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
There was a problem hiding this comment.
This does what it says on the tin.
Ideas for further improvement:
- Also remember the previous position on map, because right now, switching back and to a map will indeed show the same zoom level, but a different position, if you moved in the intermediate area meanwhile.
- Prevent mapper zoom / pan combinations which actually show no rooms at all in the resulting view part
- Smartly calculate a "good" default zoom level for each first visit in an area, so it shows the whole map, unless it gets "too big", whatever that means exactly
|
If I request |
|
In that case it should be a Lua error since it'll never be possible to have a zoom level less than 3. What does zoom value 3.0 actually look like though? |
The second argument is optional, but by explicitly providing a Remember someone did a lot of refactoring to create and use all those |
|
For backwards compatibility that would make sense. It shouldn't return |
What you describe seems like a worthwhile addition (in a new PR). |
Well, given that it has been extended - and there are a number of ways that it can fail and return a |
…l zoom Also revise the error message for it and the corresponding getter `getZoom(...)`, when the versions with an area id provided has an id that doesn't exist, to the same text as some other cases in the Lua API. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
src/TLuaInterpreter.cpp
Outdated
| } | ||
|
|
||
| if (zoom < T2DMap::csmMinXYZoom) { | ||
| return warnArgumentValue(L, __func__, qsl("%1 is less than the minimum value allowed for zoom which is %2").arg(QString::number(zoom), QString::number(T2DMap::csmMinXYZoom))); |
There was a problem hiding this comment.
Align language to other warnings in this file.
| return warnArgumentValue(L, __func__, qsl("%1 is less than the minimum value allowed for zoom which is %2").arg(QString::number(zoom), QString::number(T2DMap::csmMinXYZoom))); | |
| return warnArgumentValue(L, __func__, qsl("zoom %1 is invalid, it must be greater than %2").arg(QString::number(zoom), QString::number(T2DMap::csmMinXYZoom))); |
There was a problem hiding this comment.
Technically it should be "greater than or equal to" or "not less than" - the second is shorter in English, not sure if that negative form is the clearest to use though.
There was a problem hiding this comment.
Fair enough.
| return warnArgumentValue(L, __func__, qsl("%1 is less than the minimum value allowed for zoom which is %2").arg(QString::number(zoom), QString::number(T2DMap::csmMinXYZoom))); | |
| return warnArgumentValue(L, __func__, qsl("zoom %1 is invalid, it must be at least %2").arg(QString::number(zoom), QString::number(T2DMap::csmMinXYZoom))); |
You're welcome.
src/TLuaInterpreter.cpp
Outdated
| if (!result) { | ||
| // Whilst it will also return false should there not be a map or mapper | ||
| // we should have already ruled those cases out: | ||
| return warnArgumentValue(L, __func__, qsl("number %1 is not a valid area id").arg(QString::number(areaID.value()))); |
There was a problem hiding this comment.
as discussed in #2605
| return warnArgumentValue(L, __func__, qsl("number %1 is not a valid area id").arg(QString::number(areaID.value()))); | |
| return warnArgumentValue(L, __func__, qsl("number %1 is not a valid areaID").arg(QString::number(areaID.value()))); |
There was a problem hiding this comment.
There are multiple instances of both texts in the file IIRC and I didn't do a count of each to find which one was precisely the most common... as it is that issue has not, um, been actioned/resolved yet! However I will take on board that you have pointed it out in regard to these texts in the PR.
src/TLuaInterpreter.cpp
Outdated
|
|
||
| if (areaID.has_value()) { | ||
| if (!host.mpMap->mpRoomDB->getArea(areaID.value())) { | ||
| return warnArgumentValue(L, __func__, qsl("number %1 is not a valid area id").arg(QString::number(areaID.value()))); |
There was a problem hiding this comment.
| return warnArgumentValue(L, __func__, qsl("number %1 is not a valid area id").arg(QString::number(areaID.value()))); | |
| return warnArgumentValue(L, __func__, qsl("number %1 is not a valid areaID").arg(QString::number(areaID.value()))); |
|
The default zoom value seems not very enticing, and short of implementing any smart calculation, I implore you to reconsider this:
|
Those values are the ones that are already in place, the mapper was starting off the session at 20.0 and 3.0 was the existing limit - therefore they are the least surprising values to use going forward. This PR currently means that if you go to a newly created area (or to one for the first time since you use Mudlet with this PR in place) you will get the default 20.0 zoom - because each area is now handled separately. Whilst I suppose it might be possible to copy over the zoom from the last area previous viewed I think that that will required extra code and make this PR larger. Would it be reasonable to defer that to a separate PR? |
There is no maximum limit (well other than an inherent Let me check that - I thought it did repaint the map in the new zoom, but maybe I left out an |
|
Not redrawing map after using single argument Strange thing is that the Lua I need to dig deeper. |
|
Please convert to draft until new tests are possible |
Also revise some error/warning texts. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Not really necessary - I think it is fixed-up now. Both the messages and the single argument setting case. |
…enSessions_simplified
|
📚 Documentation pending in Area 51:
|
#### Brief overview of PR changes/additions In particular try and use ID in a uniform manner when referring to an integer number that uniquely identifies an instance of something like a room or an area in the map. #### Motivation for adding to Mudlet It became clear that there are a significant number of duplicate strings involving ID and it was possible to reduce the number of duplicate `qsl(`...`)` - which are our wrapper of `QStringLiteral` - by replacing each with a QString constant initialised at compile time. This is a good thing as it is bad to have multiple copies of the same string as one of these as each one is stored separately in the (Read-Only) data part of the executable. #### Other info (issues closed, discussion etc) This should close #2605. This was prompted by @Kebap 's comments here: #6615 (comment) Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
📚 Documentation reordered/improved. |
…enSessions_simplified
Work has been done and approval given by project leader.



This is intended to close #2388.
This enables the 2D (only) map zoom amounts for each map area to be save independently and restored when switching between areas in the mapper. It also saves the data between session.
It extends the existing
setMapZoom(...)API to take an optional second argument to specify the map area ID to set the zoom (which is a floating point number) for any existing area, not just the current one.It also adds a
getMapZoom(...)function that, without any arguments, returns the currently used 2D map zoom value for the area currently being shown in the 2D mapper. If an area ID is provided it instead returns the value that was last used for that area - or the default value that is used initially on starting the profile or for an area that has not been viewed before.Importantly when switching between the areas in the 2D mapper the values are retained and applied so that one area can be zoomed in and another zoomed out and switching from the first to the second and back to the first means that the zoom level used in the first is reused when it is returned to. Deleting an area will forget the stored zoom level so if it is reused it starts from scratch.
Code to save the zoom level for each area has also been implemented within the C++ core. It saves it in the Area User Data for current map formats (but removes it on loading so the user never sees it there) under a
system.fallback_map2DZoomkey but will save it directly in the binary data (which is more efficient) in the next format version whenever it is enabled.A new Mudlet event, which has been called
mapAreaViewedChangeEventhas been added with two additional arguments being the area ID changed to followed by the one that it was changed from. I originally thought I would need it to handle saving the zoom level for each area via the Lua system but I found that that was not practicable. I'll leave it in for now but it could be removed if peer-review finds it not to be of use.Also, in refactoring
T2DMap::paintEvent(...)I:Removed/combined some locals:
(TArea*) playerAreaand(TArea*) pPlayerArea==>pArea(TRoom*) playerRoom==>pPlayerRoomRemove unneeded (refactored out):
(qreal) ox(qreal) oySigned-off by: Stephen Lyons slysven@virginmedia.com