Skip to content

Add way to color room characters#4573

Merged
vadi2 merged 15 commits intoMudlet:developmentfrom
Delwing:room-symbol-color-selection
Jan 5, 2021
Merged

Add way to color room characters#4573
vadi2 merged 15 commits intoMudlet:developmentfrom
Delwing:room-symbol-color-selection

Conversation

@Delwing
Copy link
Copy Markdown
Contributor

@Delwing Delwing commented Jan 2, 2021

Brief overview of PR changes/additions

Add way to change color of room symbol through map context menu and Lua API
image
Map symbol picking is no longer modal as well.

Motivation for adding to Mudlet

More customization for maps of course!

Other info (issues closed, discussion etc)

closes #3988

@Delwing Delwing requested a review from a team as a code owner January 2, 2021 22:50
@Delwing Delwing requested review from a team January 2, 2021 22:50
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Jan 2, 2021

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to build this before I can give a more fuller review...

}
int r = lua_tonumber(L, 2);
if (r < 0 || r > 255) {
lua_pushfstring(L, "setRoomCharColor: bad argument #2 type (red component value %d out of range (0 to 255)", r);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are a nil + errormessage type case (value out of range rather than being the wrong type). It shouldn't throw a lua_error(...) IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equally invalid as putting string actually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's an error to misuse the API. There's no case where this would ever be valid, so it can't be nil+error

src/TMap.cpp Outdated
}
ofs << oldCharacterCode;
}
if(mSaveVersion >= 21) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like wot CodeFactor sez...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nutin.. :) Corrected.

src/TMap.cpp Outdated
}
}
switch (env) {
case 1:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it were me I'd collapse these all down to single line cases - with the elements all padded out to 4-space columns (like the tab key will do in QT Creator if it is set to use only 4 spaces for indentation) like this:

        switch (env) {
        case 1:     color = mpHost->mRed_2;             break;
        case 2:     color = mpHost->mGreen_2;           break;
        case 3:     color = mpHost->mYellow_2;          break;
        case 4:     color = mpHost->mBlue_2;            break;
        case 5:     color = mpHost->mMagenta_2;         break;
        case 6:     color = mpHost->mCyan_2;            break;
        case 7:     color = mpHost->mWhite_2;           break;
        case 8:     color = mpHost->mBlack_2;           break;
        case 9:     color = mpHost->mLightRed_2;        break;
        case 10:    color = mpHost->mLightGreen_2;      break;
        case 11:    color = mpHost->mLightYellow_2;     break;
        case 12:    color = mpHost->mLightBlue_2;       break;
        case 13:    color = mpHost->mLightMagenta_2;    break;
        case 14:    color = mpHost->mLightCyan_2;       break;
        case 15:    color = mpHost->mLightWhite_2;      break;
        case 16:    color = mpHost->mLightBlack_2;      break;
        default: //user defined room color
            if (!customEnvColors.contains(env)) {
                if (16 < env && env < 232) {
                    quint8 base = env - 16;
                    quint8 r = base / 36;
                    quint8 g = (base - (r * 36)) / 6;
                    quint8 b = (base - (r * 36)) - (g * 6);
    
                    r = r * 51;
                    g = g * 51;
                    b = b * 51;
                    color = QColor(r, g, b, 255);
                } else if (231 < env && env < 256) {
                    quint8 k = ((env - 232) * 10) + 8;
                    color = QColor(k, k, k, 255);
                }
                break;
            }
            color = customEnvColors[env];
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

{
if (mpSymbols.size() <= 1) {
return lineEdit_roomSymbol->text();
} else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ There is no need for the else { ... } as the return on the line before will mean that the formerly else code can be unindented one level - this is the coding anti-pattern that several linters call else-after-return... https://clang.llvm.org/extra/clang-tidy/checks/readability-else-after-return.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one slipped. Corrected.

<property name="windowTitle">
<string>Room symbol</string>
</property>
<layout class="QGridLayout" name="gridLayout">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have some redundancy here - this QGridLayout only has one member..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover after playing around with layout. Removed.

Piotr Wilczynski and others added 2 commits January 3, 2021 01:20
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Jan 3, 2021

I added Delwing#6 which improves on the design of the dialog:

image
image

…layout

Improve room symbol dialog design
Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big piece of work, good job, you can be proud :)

<item>
<widget class="QLineEdit" name="lineEdit_roomSymbol">
<property name="inputMethodHints">
<set>Qt::ImhUrlCharactersOnly</set>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for enabling this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some miscclick I guess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a little arrow button you can use to unset a property, instead of having it set to none

src/T2DMap.cpp Outdated
}
}
}
QString inputSymbol = QString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QString inputSymbol = QString();
QString inputSymbol;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually remove whole line. Not needed.

src/TRoom.h Outdated
qreal max_x;
qreal max_y;
QString mSymbol;
QColor mSymbolColor = nullptr;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just QColor mSymbolColor; is enough

src/T2DMap.cpp Outdated
auto symbolDialog = new dlgRoomSymbol(mpHost, this);
symbolDialog->init(usedSymbols, roomPtrsSet);
symbolDialog->show();
symbolDialog->raise();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also want to set the Qt::WA_DeleteOnClose property so it gets deleted when closed to free the memory.

src/T2DMap.cpp Outdated
}
}
QString inputSymbol = QString();
auto symbolDialog = new dlgRoomSymbol(mpHost, this);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new design allows spawning multiple dialogs at once, even on the same room, maybe not the best idea?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure out how custom lines dialog is done. It blocks map interactions, but does not block main window... This could be applied.
In theory it has exec call which make this window modal... but when I do set modality on symbol dialog it blocks main window as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember the fix for multiple About buttons - same here, store a pointer and if the dialog is open, don't show another one.

#include <QPainter>
#include "post_guard.h"

dlgRoomSymbol::dlgRoomSymbol(Host* pHost, QWidget* pF) : QDialog(pF), mpHost(pHost)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote, we ought to give pF a much better name everywhere in the project.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a new issue for future reference, so it does not get buried with this PR merged: #6375

label_preview->setFont(font);
}

void dlgRoomSymbol::init(QHash<QString, unsigned int>& pSymbols, QSet<TRoom*>& pRooms)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote, I know this came from existing code, but unsigned here is an anti-pattern according to modern C++ guidelines: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-nonnegative

We should avoid it in the future and remove its use here. The more you know!

See also Expects: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i6-prefer-expects-for-expressing-preconditions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a new issue for future reference, so it does not get buried with this PR merged: #6376


void dlgRoomSymbol::initInstructionLabel()
{
if (mpSymbols.size() == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (mpSymbols.size() == 0) {
if (mpSymbols.empty()) {

#define MUDLET_DLGROOMSYMBOL_H

/***************************************************************************
* Copyright (C) 2020 by Piotr Wilczynski - delwing@gmail.com *
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2021 probably, and in the other file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the development period concerned it should probably be 2020-2021...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really the case, or does only the merge time matter?

@vadi2 vadi2 changed the title add way to color room characters Add way to color room characters Jan 3, 2021
Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great 👍

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 3, 2021

When there is multiple rooms selected with different symbols there is a count missing (it is stuck at 0) for how many rooms are in the selection:
image

When there are multiple rooms with the SAME symbol the text does not seem to be constructed so that it reports that one is working with more than one room - I don't know if that is a defect from my original coding...!
image

BTW If I set the colour of the rooms for those three death-trap rooms differently then the colour used in the sample is of only one of them:

It isn't obvious on first use that one has to click on the button (?) to change the colour - and the tool tip has a typo (it also needs to be fed the selection size - an %n - but I haven't checked the code yet, only the run-time behaviour) - it might be better for it to have some contrasting text on it saying "Change color...":
image

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 3, 2021

You might want to consider how you handle the case where only the specified font is to be used and one or more of the symbol glyphs cannot be shown in that font. The two selected before the symbol dialogue was opened are ones that would have the warning triangle in the symbol usage dialogue - but they are not in the map symbol font so if you use it for your sample you won't get anything useful - in the map painting code and the symbol usage code I arranged for that to be handled by inserting the replacement character instead...
image

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 3, 2021

👍 This is an interesting development and it shows potential...

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Jan 3, 2021

I think that both of us forgot about it shows that this font symbol fallback system is too complicated...

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 3, 2021

It is NOT a fallback system - it is a requirement for a MUD that provides a specific font for its maps - so that the user can stay within that font when they are editing it...

... the fall-back as you describe it is to use all the fonts on the system (which IS the default) but if as a map maker you are using odd glyphs from a particular font (or even a custom one - and I have done stuff in that area myself!) that you are shipping as part of a Mud specific UI you will be trying to see that everyone gets the same map symbols from the same font.

@Delwing
Copy link
Copy Markdown
Contributor Author

Delwing commented Jan 4, 2021

Used parts of logic for creating pixmaps of symbols.
Corrected room counts issues (+ text labels selection)
Fixed default color behavior (after some fixes initial default was always black)

@vadi2 vadi2 merged commit 42f6c8c into Mudlet:development Jan 5, 2021
SlySven added a commit to SlySven/Mudlet that referenced this pull request Jan 25, 2021
It seems like PR Mudlet#4573 introduced a bogus use of pointer access to a
`QColor` whereas the correct methodology is `QColor::isValid()` - a default
constructed `QColor` is itself equivalent to an RGBA specified colour of
`QColor(0,0,0,0)` and that will fail in that test. This PR fixes things so
that (instead of a `nullptr` test) is used.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
SlySven added a commit that referenced this pull request Jan 25, 2021
…4679)

It seems like PR #4573 introduced a bogus use of pointer access to a
`QColor` whereas the correct methodology is `QColor::isValid()` - a default
constructed `QColor` is itself equivalent to an RGBA specified colour of
`QColor(0,0,0,0)` and that will fail in that test. This PR fixes things so
that (instead of a `nullptr` test) is used.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
SlySven added a commit to SlySven/Mudlet that referenced this pull request Jan 26, 2021
…gain

A test for this pointer being a `nullptr` is what enables a new dialogue to
be made in the 2D mapper - by not initialising it in Mudlet#4573 a random
non-null value is found so the dialogue and thus the functionality can be
virtually impossible to use.

As it is a pointer I have taken the liberty to introduce a `p` into the
initial part of the name - after the `m` to indicate it is a class member.

As the defect is a regression that causes loss of functionality I am rating
this as a **high** priority bug(fix) even though it does not induce any
fatal termination of the application.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
SlySven added a commit that referenced this pull request Jan 26, 2021
…gain (#4687)

A test for this pointer being a `nullptr` is what enables a new dialogue to
be made in the 2D mapper - by not initialising it in #4573 a random
non-null value is found so the dialogue and thus the functionality can be
virtually impossible to use.

As it is a pointer I have taken the liberty to introduce a `p` into the
initial part of the name - after the `m` to indicate it is a class member.

As the defect is a regression that causes loss of functionality I am rating
this as a **high** priority bug(fix) even though it does not induce any
fatal termination of the application.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
SlySven added a commit to SlySven/Mudlet that referenced this pull request Jan 26, 2021
…gain (Mudlet#4687)

A test for this pointer being a `nullptr` is what enables a new dialogue to
be made in the 2D mapper - by not initialising it in Mudlet#4573 a random
non-null value is found so the dialogue and thus the functionality can be
virtually impossible to use.

As it is a pointer I have taken the liberty to introduce a `p` into the
initial part of the name - after the `m` to indicate it is a class member.

As the defect is a regression that causes loss of functionality I am rating
this as a **high** priority bug(fix) even though it does not induce any
fatal termination of the application.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@vadi2 vadi2 added the needs documentation This pull request changes things the players would use/see and thus needs an update in the manual label Aug 5, 2021
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Aug 5, 2021

This never made it into the docs 😮

@Delwing Delwing removed the needs documentation This pull request changes things the players would use/see and thus needs an update in the manual label Sep 12, 2021
Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
* add way to color room characters

* accept new translations

* fix qmake build

* addSymbolToPixmapCache improve

* cr corrections

* Modernize design

* remove accidental hints

* remove not needed variable

* minor fixes

* room not exists will not throw error in room char color functions

* remove properties with auto suggestion

* remove not neede assignment

* prevent spawning multiple symbol char dialogs at once

* fix room symbol selection issues

Co-authored-by: Piotr Wilczynski <piotr.wilczynski@bisnode.com>
Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
…udlet#4679)

It seems like PR Mudlet#4573 introduced a bogus use of pointer access to a
`QColor` whereas the correct methodology is `QColor::isValid()` - a default
constructed `QColor` is itself equivalent to an RGBA specified colour of
`QColor(0,0,0,0)` and that will fail in that test. This PR fixes things so
that (instead of a `nullptr` test) is used.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
…gain (Mudlet#4687)

A test for this pointer being a `nullptr` is what enables a new dialogue to
be made in the 2D mapper - by not initialising it in Mudlet#4573 a random
non-null value is found so the dialogue and thus the functionality can be
virtually impossible to use.

As it is a pointer I have taken the liberty to introduce a `p` into the
initial part of the name - after the `m` to indicate it is a class member.

As the defect is a regression that causes loss of functionality I am rating
this as a **high** priority bug(fix) even though it does not induce any
fatal termination of the application.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow choosing of map symbol colors

4 participants