Add way to color room characters#4573
Conversation
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
SlySven
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is equally invalid as putting string actually.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Nutin.. :) Corrected.
src/TMap.cpp
Outdated
| } | ||
| } | ||
| switch (env) { | ||
| case 1: |
There was a problem hiding this comment.
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];
}| { | ||
| if (mpSymbols.size() <= 1) { | ||
| return lineEdit_roomSymbol->text(); | ||
| } else { |
There was a problem hiding this comment.
ℹ️ 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
There was a problem hiding this comment.
This one slipped. Corrected.
| <property name="windowTitle"> | ||
| <string>Room symbol</string> | ||
| </property> | ||
| <layout class="QGridLayout" name="gridLayout"> |
There was a problem hiding this comment.
I think you have some redundancy here - this QGridLayout only has one member..
There was a problem hiding this comment.
Leftover after playing around with layout. Removed.
|
I added Delwing#6 which improves on the design of the dialog: |
…layout Improve room symbol dialog design
vadi2
left a comment
There was a problem hiding this comment.
This is a big piece of work, good job, you can be proud :)
src/ui/room_symbol.ui
Outdated
| <item> | ||
| <widget class="QLineEdit" name="lineEdit_roomSymbol"> | ||
| <property name="inputMethodHints"> | ||
| <set>Qt::ImhUrlCharactersOnly</set> |
There was a problem hiding this comment.
What's the reason for enabling this?
There was a problem hiding this comment.
Some miscclick I guess.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
| QString inputSymbol = QString(); | |
| QString inputSymbol; |
There was a problem hiding this comment.
Actually remove whole line. Not needed.
src/TRoom.h
Outdated
| qreal max_x; | ||
| qreal max_y; | ||
| QString mSymbol; | ||
| QColor mSymbolColor = nullptr; |
There was a problem hiding this comment.
Just QColor mSymbolColor; is enough
src/T2DMap.cpp
Outdated
| auto symbolDialog = new dlgRoomSymbol(mpHost, this); | ||
| symbolDialog->init(usedSymbols, roomPtrsSet); | ||
| symbolDialog->show(); | ||
| symbolDialog->raise(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
The new design allows spawning multiple dialogs at once, even on the same room, maybe not the best idea?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Remember the fix for multiple About buttons - same here, store a pointer and if the dialog is open, don't show another one.
src/dlgRoomSymbol.cpp
Outdated
| #include <QPainter> | ||
| #include "post_guard.h" | ||
|
|
||
| dlgRoomSymbol::dlgRoomSymbol(Host* pHost, QWidget* pF) : QDialog(pF), mpHost(pHost) |
There was a problem hiding this comment.
Sidenote, we ought to give pF a much better name everywhere in the project.
There was a problem hiding this comment.
Put a new issue for future reference, so it does not get buried with this PR merged: #6375
src/dlgRoomSymbol.cpp
Outdated
| label_preview->setFont(font); | ||
| } | ||
|
|
||
| void dlgRoomSymbol::init(QHash<QString, unsigned int>& pSymbols, QSet<TRoom*>& pRooms) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Put a new issue for future reference, so it does not get buried with this PR merged: #6376
src/dlgRoomSymbol.cpp
Outdated
|
|
||
| void dlgRoomSymbol::initInstructionLabel() | ||
| { | ||
| if (mpSymbols.size() == 0) { |
There was a problem hiding this comment.
| if (mpSymbols.size() == 0) { | |
| if (mpSymbols.empty()) { |
src/dlgRoomSymbol.h
Outdated
| #define MUDLET_DLGROOMSYMBOL_H | ||
|
|
||
| /*************************************************************************** | ||
| * Copyright (C) 2020 by Piotr Wilczynski - delwing@gmail.com * |
There was a problem hiding this comment.
2021 probably, and in the other file?
There was a problem hiding this comment.
Given the development period concerned it should probably be 2020-2021...
There was a problem hiding this comment.
Is that really the case, or does only the merge time matter?
|
👍 This is an interesting development and it shows potential... |
|
I think that both of us forgot about it shows that this font symbol fallback system is too complicated... |
|
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. |
|
Used parts of logic for creating pixmaps of symbols. |
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>
…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>
…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>
…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>
…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>
|
This never made it into the docs 😮 |
* 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>
…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>
…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>






Brief overview of PR changes/additions
Add way to change color of room symbol through map context menu and Lua API

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