Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance: improve code for room custom exit lines in 2D map (Mudlet#2106)
Changes the TRoom class to store the detail about the style of line as the Qt::PenStyle enum that is used when it is actually drawn (saves a few bytes per custom exit line)! Concurrently change the 2D map UI that adjusts this setting on both new custom exit lines being drawn and existing lines selected by the UI to separate the text used to describe the style from this value so that the text can be translated for other GUI languages without breaking the code. Enhance the control (a `QComboBox`) used for this so that it has icons with a visual representation of each style! Revise the Lua function `addCustomLine` to bring the error reporting up to current UI style - including detection some error conditions that were not previously reported (included whether there was the exit that the custom line was to be added to show). Also the target room who's location was used as the end-point for a single segment line was not being checked to confirm that it existed and was in the same area as the room that the exit line was being drawn from. Alternatively, when a table of tables of coordinate triplets {x, y, z} was provided there was previously no proper validation that they all existed and were numbers to be used as coordinates... I also discovered that TLuaInterpreter::dirToString was not producing the right `QString`s necessary for numeric arguments for the normal exit direction to work in the two lua functions that used it (`addCustomLine` and `setExitWeight`) I have corrected it and updated the callers of it to now return the right normal exit strings needed for each of them. To validate whether there is actually an exit in the direction that the lua addCustomLine function is told is a little complicated so I have added a `(bool) TRoom::hasExitOrSpecialExit(const QString&, const bool) const` method that does this so that addCustomLine can return a run-time error (nil + error message) if the given exit does not already exist. In some places in the TLuaInterpreter custom line functions and the `T2DMap::paintEvent()` method non-const method were being used to access the details of the custom exit lines - as this takes longer and runs the risk of changing the data when it should not be being changed I have switched to using the read only or constant `at(...)`/`value(...)` methods rather than the read/write or non-constant `operator[...]` method where practical. I have also made each custom exit line be drawn as a polyline rather than a series of single segments - this is more effiecent I think and it means that the dotted/dashed pattern effect "goes around" each corner rather than restarting on each segment which looks better IMHO - draw a multi-segment line and move one of the vertexes towards the end and you will see the differences. 8-) This should close Mudlet#2095 ! Revised to make addCustomLine & setExitWeight not case sensitive for exit dir In fact have converted the TRoom custom exit line data members use a lower case key for "Normal" exit directions and go through all the places where those keys were used. Also make the change in the binary map data format 20 (and above). As it was convenient to do so, I have also changed it so that the custom line colour is stored as a `QColor` instead of a `QList<int>` of RGB components. The addCustomLine and setExitWeight lua functions now treat a wider range of strings as being for "Normal" exit directions in a case insensitive manner - there is a small possibility that this may clash with strings used for "Special" exits if they use a full English word for the exit direction (with or without hyphens for diagonal exits)... In testing the lua addCustomLine command I found that adding a new line to a room that did not previously have one produced a weirdly visible line that only showed up at some zoom levels and was very thin. It turned out that this is because there was not a call to TRoom::calcRoomDimensions() after adding the line and the TRoom::{min|max}_{x|y} members (which are updated by that) are used during the T2DMap::paintEvent(). Whilst I was working in this area of code I decided I could also provide the missing lua function `removeCustomLine`... Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
- Loading branch information