Skip to content

Commit

Permalink
Enhance: allow modification of the player room indication on 2D map (M…
Browse files Browse the repository at this point in the history
…udlet#2621)

This is a squash-and-merge of a number of commits with the following
edited summary:

This PR reorganises the 2D Painter code to draw the player room
indicator AFTER all the rooms have been drawn so that it does not get
overdrawn by rooms painted after the player's room - which it could be
if the rooms are at maximum size or the area is in "gridMode".

It also offers some alternative marker options in the form of an oversized
ring around the room which reduces the obstruction of the details of the
room when the marker is drawn on it. The alternatives are:
* a fixed red colour ring
* a fixed blue/yellow colour ring - two contrasting colours mean that it
can not be lost if drawn over a room that already has one of them as its
colour (environment) setting.
* a customizable two colour ring where the user can set the outer and inner
colours as they like - even to the same colour.

The ancient `(bool) Host::mMapStrongHighlight` option is still respected,
I note that it was introduced in 3cb1719
from 2011/01/20 (after Mudlet 1.0.5) and the code to control it was lost
in 8b0e8bb from 2012/12/31 "NEW Vadim
Peretokin: mapper remembers settings" just before the release of Mudlet
2.0...!

Refactor: ensure player room is drawn last

This is done by extracting the relevant room drawing code to a separate
inline function that is used whilst iterating through the area rooms to
paint them, skipping but noting if the player room is found and then that
function is used to paint the player's room afterwards.

Revise: made code acceptable to all compilers

The clang compiler does not like `auto` being used as a type in function
prototypes as it is not formally part of the C++14 standard but a GCC
extension - it got put in by the Qt Creator function extraction code
option on the refactor menu.

Revise: allow player room marking customisation to be saved and restored

They are saved with the profile's data rather than the map.

Revise: show transparency effects in custom player room marker colours

It is not possible to just colour the background of the `QPushButton`s that
set the custom colours to use for the *custom* player room marker as the
transparency effects do not show. Instead this commit arranges for an icon
with a black-and-white checker board pattern is over-painted with a brush
in the relevant colour so that when the opacity is less than 100% the
pattern is shown to an extent which is proportional to the degree of
transparency of the colour chosen.

Refactor: extract code to start 2D map speed-walk & simplify drawRoom code

Suggested in peer review comment:
Mudlet#2621

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven authored Dec 1, 2019
1 parent b71694a commit 56c363d
Show file tree
Hide file tree
Showing 15 changed files with 1,175 additions and 591 deletions.
33 changes: 33 additions & 0 deletions src/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ Host::Host(int port, const QString& hostname, const QString& login, const QStrin
// DISABLED: - Prevent "None" option for user dictionary - changed to true and not changed anywhere else
, mEnableUserDictionary(true)
, mUseSharedDictionary(false)
, mPlayerRoomStyle(0)
, mPlayerRoomOuterColor(Qt::red)
, mPlayerRoomInnerColor(Qt::white)
, mPlayerRoomOuterDiameterPercentage(120)
, mPlayerRoomInnerDiameterPercentage(70)
{
// mLogStatus = mudlet::self()->mAutolog;
mLuaInterface.reset(new LuaInterface(this));
Expand Down Expand Up @@ -2360,3 +2365,31 @@ void Host::updateAnsi16ColorsInTable()
{
mLuaInterpreter.updateAnsi16ColorsInTable();
}

void Host::setPlayerRoomStyleDetails(const quint8 styleCode, const quint8 outerDiameter, const quint8 innerDiameter, const QColor& outerColor, const QColor& innerColor)
{
QMutexLocker locker(& mLock);
// Now we have the exclusive lock on this class's protected members

mPlayerRoomStyle = styleCode;
mPlayerRoomOuterDiameterPercentage = outerDiameter;
mPlayerRoomInnerDiameterPercentage = innerDiameter;
mPlayerRoomOuterColor = outerColor;
mPlayerRoomInnerColor = innerColor;
// We have made the change to the protected aspects of this class so can unlock the mutex locker and proceed:
locker.unlock();
}

void Host::getPlayerRoomStyleDetails(quint8& styleCode, quint8& outerDiameter, quint8& innerDiameter, QColor& primaryColor, QColor& secondaryColor)
{
QMutexLocker locker(& mLock);
// Now we have the exclusive lock on this class's protected members

styleCode = mPlayerRoomStyle;
outerDiameter = mPlayerRoomOuterDiameterPercentage;
innerDiameter = mPlayerRoomInnerDiameterPercentage;
primaryColor = mPlayerRoomOuterColor;
secondaryColor = mPlayerRoomInnerColor;
// We have accessed the protected aspects of this class so can unlock the mutex locker and proceed:
locker.unlock();
}
25 changes: 25 additions & 0 deletions src/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ class Host : public QObject
void updateProxySettings(QNetworkAccessManager* manager);
std::unique_ptr<QNetworkProxy>& getConnectionProxy();
void updateAnsi16ColorsInTable();
// Store/retrieve all the settings in one call:
void setPlayerRoomStyleDetails(const quint8 styleCode, const quint8 outerDiameter = 120, const quint8 innerDiameter = 70, const QColor& outerColor = QColor(), const QColor& innerColor = QColor());
void getPlayerRoomStyleDetails(quint8& styleCode, quint8& outerDiameter, quint8& innerDiameter, QColor& outerColor, QColor& innerColor);

cTelnet mTelnet;
QPointer<TConsole> mpConsole;
Expand Down Expand Up @@ -647,6 +650,28 @@ private slots:
// looked up directly by that class:
bool mEnableUserDictionary;
bool mUseSharedDictionary;

// These hold values that are needed in the TMap clas which are saved with
// the profile - but which cannot be kept there as that class is not
// necessarily instantiated when the profile is read.
// Base color(s) for the player room in the mappers:
// Mode selected:
// 0 is closest to original style with adjustable outer diameter
// 1 is Fixed red color ring with adjustable outer/inner diameter
// 2 is fixed blue/yellow colors ring with adjustable outer/inner diameter
// 3 is adjustable outer(primary)/inner(secondary) colors ring with adjustable outer/inner diameter
quint8 mPlayerRoomStyle;
QColor mPlayerRoomOuterColor;
QColor mPlayerRoomInnerColor;
// Percentage of the room size (actually width) for the outer diameter of
// the circular marking, integer percentage clamped in the preferences
// between 200 and 50 - default 120:
quint8 mPlayerRoomOuterDiameterPercentage;
// Percentage of the outer size for the inner diameter of the circular
// marking, integer percentage clamped in the preferences between 83 and 0,
// with a default of 70. NOT USED FOR "Original" style marking (the 0'th
// one):
quint8 mPlayerRoomInnerDiameterPercentage;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Host::DiscordOptionFlags)
Expand Down
Loading

0 comments on commit 56c363d

Please sign in to comment.