mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 09:04:53 -07:00
Use the new mana symbols. (#5687)
* Use the new mana symbols. * Fixup some thangs. * Lint. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
85a50ce9d5
commit
8fc1b22889
13 changed files with 330 additions and 337 deletions
|
|
@ -82,6 +82,9 @@ set(cockatrice_SOURCES
|
||||||
src/utility/logger.cpp
|
src/utility/logger.cpp
|
||||||
src/client/ui/widgets/cards/card_info_picture_enlarged_widget.cpp
|
src/client/ui/widgets/cards/card_info_picture_enlarged_widget.cpp
|
||||||
src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.cpp
|
src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.cpp
|
||||||
|
src/client/ui/widgets/cards/additional_info/color_identity_widget.cpp
|
||||||
|
src/client/ui/widgets/cards/additional_info/mana_cost_widget.cpp
|
||||||
|
src/client/ui/widgets/cards/additional_info/mana_symbol_widget.cpp
|
||||||
src/client/ui/widgets/general/display/banner_widget.cpp
|
src/client/ui/widgets/general/display/banner_widget.cpp
|
||||||
src/client/ui/widgets/general/display/labeled_input.cpp
|
src/client/ui/widgets/general/display/labeled_input.cpp
|
||||||
src/client/ui/widgets/general/display/dynamic_font_size_label.cpp
|
src/client/ui/widgets/general/display/dynamic_font_size_label.cpp
|
||||||
|
|
@ -182,7 +185,6 @@ set(cockatrice_SOURCES
|
||||||
src/client/menus/deck_editor/deck_editor_menu.cpp
|
src/client/menus/deck_editor/deck_editor_menu.cpp
|
||||||
src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp
|
src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp
|
||||||
src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp
|
src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp
|
||||||
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_color_identity_widget.cpp
|
|
||||||
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_color_identity_filter_widget.cpp
|
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_color_identity_filter_widget.cpp
|
||||||
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_tag_addition_widget.cpp
|
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_tag_addition_widget.cpp
|
||||||
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_tag_display_widget.cpp
|
src/client/ui/widgets/visual_deck_storage/deck_preview/deck_preview_tag_display_widget.cpp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
#include "color_identity_widget.h"
|
||||||
|
|
||||||
|
#include "mana_symbol_widget.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
#include <QSize>
|
||||||
|
|
||||||
|
ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, CardInfoPtr _card) : QWidget(parent), card(_card)
|
||||||
|
{
|
||||||
|
layout = new QHBoxLayout(this);
|
||||||
|
layout->setSpacing(5); // Small spacing between icons
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
if (card) {
|
||||||
|
QString manaCost = card->getColors(); // Get mana cost string
|
||||||
|
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
|
||||||
|
|
||||||
|
for (const QString &symbol : symbols) {
|
||||||
|
ManaSymbolWidget *manaSymbol = new ManaSymbolWidget(this, symbol, true);
|
||||||
|
layout->addWidget(manaSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, QString manaCost) : QWidget(parent), card(nullptr)
|
||||||
|
{
|
||||||
|
layout = new QHBoxLayout(this);
|
||||||
|
layout->setSpacing(5); // Small spacing between icons
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
|
||||||
|
|
||||||
|
for (const QString &symbol : symbols) {
|
||||||
|
ManaSymbolWidget *manaSymbol = new ManaSymbolWidget(this, symbol);
|
||||||
|
layout->addWidget(manaSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
QList<ManaSymbolWidget *> manaSymbols = findChildren<ManaSymbolWidget *>();
|
||||||
|
|
||||||
|
if (!manaSymbols.isEmpty()) {
|
||||||
|
int totalWidth = event->size().width();
|
||||||
|
int totalHeight = totalWidth / 6; // Set height to 1/4 of the width
|
||||||
|
setFixedHeight(totalHeight);
|
||||||
|
|
||||||
|
int spacing = layout->spacing();
|
||||||
|
int count = manaSymbols.size();
|
||||||
|
int availableWidth = totalWidth - (spacing * (count - 1));
|
||||||
|
int iconSize = qMin(availableWidth / count, totalHeight); // Ensure icons fit within the new height
|
||||||
|
|
||||||
|
for (ManaSymbolWidget *manaSymbol : manaSymbols) {
|
||||||
|
manaSymbol->setFixedSize(iconSize, iconSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList ColorIdentityWidget::parseColorIdentity(const QString &cmc)
|
||||||
|
{
|
||||||
|
QStringList symbols;
|
||||||
|
|
||||||
|
// Handle split costs (e.g., "3U // 4UU")
|
||||||
|
QStringList splitCosts = cmc.split(" // ");
|
||||||
|
for (const QString &part : splitCosts) {
|
||||||
|
QRegularExpression regex(R"(\{([^}]+)\}|(\d+)|([WUBRGCSPX]))");
|
||||||
|
QRegularExpressionMatchIterator matches = regex.globalMatch(part);
|
||||||
|
while (matches.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = matches.next();
|
||||||
|
if (match.captured(1).isEmpty()) { // If no `{}` group was captured, check other groups
|
||||||
|
if (!match.captured(2).isEmpty()) {
|
||||||
|
symbols.append(match.captured(2)); // Number match
|
||||||
|
} else {
|
||||||
|
symbols.append(match.captured(3)); // Single mana letter match
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
symbols.append(match.captured(1)); // `{}` enclosed match
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return symbols;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef COLOR_IDENTITY_WIDGET_H
|
||||||
|
#define COLOR_IDENTITY_WIDGET_H
|
||||||
|
|
||||||
|
#include "../../../../../game/cards/card_database.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ColorIdentityWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ColorIdentityWidget(QWidget *parent, CardInfoPtr card);
|
||||||
|
explicit ColorIdentityWidget(QWidget *parent, QString manaCost);
|
||||||
|
|
||||||
|
QStringList parseColorIdentity(const QString &manaString);
|
||||||
|
public slots:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CardInfoPtr card;
|
||||||
|
QHBoxLayout *layout;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COLOR_IDENTITY_WIDGET_H
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
#include "mana_cost_widget.h"
|
||||||
|
|
||||||
|
#include "mana_symbol_widget.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
#include <QSize>
|
||||||
|
#include <qregularexpression.h>
|
||||||
|
|
||||||
|
ManaCostWidget::ManaCostWidget(QWidget *parent, CardInfoPtr _card) : QWidget(parent), card(_card)
|
||||||
|
{
|
||||||
|
layout = new QHBoxLayout(this);
|
||||||
|
layout->setSpacing(5); // Small spacing between icons
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
setFixedHeight(50); // Fixed height
|
||||||
|
|
||||||
|
if (card) {
|
||||||
|
QString manaCost = card->getManaCost(); // Get mana cost string
|
||||||
|
QStringList symbols = parseManaCost(manaCost); // Parse mana cost string
|
||||||
|
|
||||||
|
for (const QString &symbol : symbols) {
|
||||||
|
ManaSymbolWidget *manaSymbol = new ManaSymbolWidget(this, symbol, true, false);
|
||||||
|
layout->addWidget(manaSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManaCostWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
QList<ManaSymbolWidget *> manaSymbols = findChildren<ManaSymbolWidget *>();
|
||||||
|
|
||||||
|
if (!manaSymbols.isEmpty()) {
|
||||||
|
int totalWidth = event->size().width();
|
||||||
|
int spacing = layout->spacing();
|
||||||
|
int count = manaSymbols.size();
|
||||||
|
|
||||||
|
// Available width minus total spacing
|
||||||
|
int availableWidth = totalWidth - (spacing * (count - 1));
|
||||||
|
int iconSize = qMin(50, availableWidth / count);
|
||||||
|
|
||||||
|
for (ManaSymbolWidget *manaSymbol : manaSymbols) {
|
||||||
|
manaSymbol->setFixedSize(iconSize, iconSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList ManaCostWidget::parseManaCost(const QString &cmc)
|
||||||
|
{
|
||||||
|
QStringList symbols;
|
||||||
|
|
||||||
|
// Handle split costs (e.g., "3U // 4UU")
|
||||||
|
QStringList splitCosts = cmc.split(" // ");
|
||||||
|
for (const QString &part : splitCosts) {
|
||||||
|
QRegularExpression regex(R"(\{([^}]+)\}|(\d+)|([WUBRGCSPX]))");
|
||||||
|
QRegularExpressionMatchIterator matches = regex.globalMatch(part);
|
||||||
|
while (matches.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = matches.next();
|
||||||
|
if (match.captured(1).isEmpty()) { // If no `{}` group was captured, check other groups
|
||||||
|
if (!match.captured(2).isEmpty()) {
|
||||||
|
symbols.append(match.captured(2)); // Number match
|
||||||
|
} else {
|
||||||
|
symbols.append(match.captured(3)); // Single mana letter match
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
symbols.append(match.captured(1)); // `{}` enclosed match
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return symbols;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef MANA_COST_WIDGET_H
|
||||||
|
#define MANA_COST_WIDGET_H
|
||||||
|
|
||||||
|
#include "../../../../../game/cards/card_database.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ManaCostWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ManaCostWidget(QWidget *parent, CardInfoPtr card);
|
||||||
|
|
||||||
|
QStringList parseManaCost(const QString &manaString);
|
||||||
|
public slots:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CardInfoPtr card;
|
||||||
|
QHBoxLayout *layout;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MANA_COST_WIDGET_H
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "mana_symbol_widget.h"
|
||||||
|
|
||||||
|
#include <QResizeEvent>
|
||||||
|
|
||||||
|
ManaSymbolWidget::ManaSymbolWidget(QWidget *parent, QString _symbol, bool _isActive, bool _mayBeToggled)
|
||||||
|
: QLabel(parent), symbol(_symbol), isActive(_isActive), mayBeToggled(_mayBeToggled)
|
||||||
|
{
|
||||||
|
loadManaIcon();
|
||||||
|
setPixmap(manaIcon.scaled(50, 50, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
setMaximumWidth(50);
|
||||||
|
|
||||||
|
// Initialize opacity effect
|
||||||
|
opacityEffect = new QGraphicsOpacityEffect(this);
|
||||||
|
setGraphicsEffect(opacityEffect);
|
||||||
|
updateOpacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManaSymbolWidget::setColorActive(bool active)
|
||||||
|
{
|
||||||
|
if (isActive != active) {
|
||||||
|
isActive = active;
|
||||||
|
updateOpacity();
|
||||||
|
emit colorToggled(getSymbolChar(), isActive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManaSymbolWidget::updateOpacity()
|
||||||
|
{
|
||||||
|
qreal opacity = isActive ? 1.0 : 0.5;
|
||||||
|
opacityEffect->setOpacity(opacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManaSymbolWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
if (mayBeToggled) {
|
||||||
|
isActive = !isActive;
|
||||||
|
updateOpacity();
|
||||||
|
emit colorToggled(getSymbolChar(), isActive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManaSymbolWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QLabel::resizeEvent(event);
|
||||||
|
setPixmap(manaIcon.scaled(event->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManaSymbolWidget::loadManaIcon()
|
||||||
|
{
|
||||||
|
QString filename = "theme:icons/mana/";
|
||||||
|
|
||||||
|
if (symbol == "W" || symbol == "U" || symbol == "B" || symbol == "R" || symbol == "G") {
|
||||||
|
filename += symbol + ".svg";
|
||||||
|
}
|
||||||
|
|
||||||
|
manaIcon = QPixmap(filename);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef MANA_SYMBOL_WIDGET_H
|
||||||
|
#define MANA_SYMBOL_WIDGET_H
|
||||||
|
|
||||||
|
#include <QGraphicsOpacityEffect>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
class ManaSymbolWidget : public QLabel
|
||||||
|
{
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ManaSymbolWidget(QWidget *parent, QString symbol, bool isActive = true, bool mayBeToggled = false);
|
||||||
|
void setColorActive(bool active);
|
||||||
|
void updateOpacity();
|
||||||
|
bool isColorActive() const;
|
||||||
|
QString getSymbol() const
|
||||||
|
{
|
||||||
|
return symbol;
|
||||||
|
};
|
||||||
|
QChar getSymbolChar() const
|
||||||
|
{
|
||||||
|
return symbol[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
void loadManaIcon();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void colorToggled(QChar symbol, bool isActive);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString symbol;
|
||||||
|
QPixmap manaIcon;
|
||||||
|
bool isActive;
|
||||||
|
bool mayBeToggled;
|
||||||
|
QGraphicsOpacityEffect *opacityEffect;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MANA_SYMBOL_WIDGET_H
|
||||||
|
|
@ -1,89 +1,11 @@
|
||||||
#include "deck_preview_color_identity_filter_widget.h"
|
#include "deck_preview_color_identity_filter_widget.h"
|
||||||
|
|
||||||
|
#include "../../cards/additional_info/mana_symbol_widget.h"
|
||||||
#include "deck_preview_widget.h"
|
#include "deck_preview_widget.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
DeckPreviewColorIdentityFilterCircleWidget::DeckPreviewColorIdentityFilterCircleWidget(QChar color, QWidget *parent)
|
|
||||||
: QWidget(parent), colorChar(color), isActive(false), circleDiameter(30)
|
|
||||||
{
|
|
||||||
setFixedSize(circleDiameter, circleDiameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorIdentityFilterCircleWidget::setColorActive(bool active)
|
|
||||||
{
|
|
||||||
if (isActive != active) {
|
|
||||||
isActive = active;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeckPreviewColorIdentityFilterCircleWidget::isColorActive() const
|
|
||||||
{
|
|
||||||
return isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
QChar DeckPreviewColorIdentityFilterCircleWidget::getColorChar() const
|
|
||||||
{
|
|
||||||
return colorChar;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorIdentityFilterCircleWidget::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
|
||||||
|
|
||||||
QColor circleColor;
|
|
||||||
switch (colorChar.unicode()) {
|
|
||||||
case 'W':
|
|
||||||
circleColor = Qt::white;
|
|
||||||
break;
|
|
||||||
case 'U':
|
|
||||||
circleColor = QColor(0, 115, 230);
|
|
||||||
break;
|
|
||||||
case 'B':
|
|
||||||
circleColor = QColor(50, 50, 50);
|
|
||||||
break;
|
|
||||||
case 'R':
|
|
||||||
circleColor = QColor(230, 30, 30);
|
|
||||||
break;
|
|
||||||
case 'G':
|
|
||||||
circleColor = QColor(30, 180, 30);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
circleColor = Qt::transparent;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isActive) {
|
|
||||||
circleColor.setAlpha(100); // Dim inactive circles
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.setBrush(circleColor);
|
|
||||||
painter.setPen(Qt::black);
|
|
||||||
painter.drawEllipse(rect());
|
|
||||||
|
|
||||||
if (isActive) {
|
|
||||||
QFont font = painter.font();
|
|
||||||
font.setBold(true);
|
|
||||||
font.setPointSize(circleDiameter / 3);
|
|
||||||
painter.setFont(font);
|
|
||||||
painter.setPen(colorChar.unicode() == 'B' ? Qt::white : Qt::black);
|
|
||||||
painter.drawText(rect(), Qt::AlignCenter, colorChar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorIdentityFilterCircleWidget::mousePressEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
isActive = !isActive;
|
|
||||||
emit colorToggled(colorChar, isActive);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeckPreviewColorIdentityFilterWidget::DeckPreviewColorIdentityFilterWidget(VisualDeckStorageWidget *parent)
|
DeckPreviewColorIdentityFilterWidget::DeckPreviewColorIdentityFilterWidget(VisualDeckStorageWidget *parent)
|
||||||
: QWidget(parent), layout(new QHBoxLayout(this))
|
: QWidget(parent), layout(new QHBoxLayout(this))
|
||||||
{
|
{
|
||||||
|
|
@ -93,15 +15,16 @@ DeckPreviewColorIdentityFilterWidget::DeckPreviewColorIdentityFilterWidget(Visua
|
||||||
|
|
||||||
QString fullColorIdentity = "WUBRG";
|
QString fullColorIdentity = "WUBRG";
|
||||||
for (const QChar &color : fullColorIdentity) {
|
for (const QChar &color : fullColorIdentity) {
|
||||||
auto *circle = new DeckPreviewColorIdentityFilterCircleWidget(color, this);
|
auto *manaSymbol = new ManaSymbolWidget(this, color, false, true);
|
||||||
|
manaSymbol->setMaximumWidth(25);
|
||||||
|
|
||||||
layout->addWidget(circle);
|
layout->addWidget(manaSymbol);
|
||||||
|
|
||||||
// Initialize the activeColors map
|
// Initialize the activeColors map
|
||||||
activeColors[color] = false;
|
activeColors[color] = false;
|
||||||
|
|
||||||
// Connect the color toggled signal
|
// Connect the color toggled signal
|
||||||
connect(circle, &DeckPreviewColorIdentityFilterCircleWidget::colorToggled, this,
|
connect(manaSymbol, &ManaSymbolWidget::colorToggled, this,
|
||||||
&DeckPreviewColorIdentityFilterWidget::handleColorToggled);
|
&DeckPreviewColorIdentityFilterWidget::handleColorToggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,29 +12,6 @@
|
||||||
class DeckPreviewWidget;
|
class DeckPreviewWidget;
|
||||||
class VisualDeckStorageWidget;
|
class VisualDeckStorageWidget;
|
||||||
|
|
||||||
class DeckPreviewColorIdentityFilterCircleWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit DeckPreviewColorIdentityFilterCircleWidget(QChar color, QWidget *parent = nullptr);
|
|
||||||
void setColorActive(bool active);
|
|
||||||
bool isColorActive() const;
|
|
||||||
QChar getColorChar() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void colorToggled(QChar color, bool active);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QChar colorChar;
|
|
||||||
bool isActive;
|
|
||||||
int circleDiameter;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DeckPreviewColorIdentityFilterWidget : public QWidget
|
class DeckPreviewColorIdentityFilterWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -1,176 +0,0 @@
|
||||||
#include "deck_preview_color_identity_widget.h"
|
|
||||||
|
|
||||||
#include "../../../../../settings/cache_settings.h"
|
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QResizeEvent>
|
|
||||||
|
|
||||||
DeckPreviewColorCircleWidget::DeckPreviewColorCircleWidget(QChar color, QWidget *parent)
|
|
||||||
: QWidget(parent), colorChar(color), circleDiameter(0), isActive(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorCircleWidget::resizeEvent(QResizeEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
|
|
||||||
// Get the parent of the DeckPreviewColorIdentityWidget
|
|
||||||
QWidget *identityParent = parentWidget() ? parentWidget()->parentWidget() : nullptr;
|
|
||||||
if (identityParent) {
|
|
||||||
// Calculate the circle diameter as 15% of the parent's height
|
|
||||||
int maxSize = identityParent->width() * 0.15;
|
|
||||||
circleDiameter = maxSize;
|
|
||||||
|
|
||||||
// Update the widget size based on the diameter
|
|
||||||
updateGeometry(); // Request a resize based on sizeHint()
|
|
||||||
}
|
|
||||||
|
|
||||||
update(); // Trigger a repaint
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize DeckPreviewColorCircleWidget::sizeHint() const
|
|
||||||
{
|
|
||||||
// Return the size we calculated based on the parent widget
|
|
||||||
return QSize(circleDiameter, circleDiameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize DeckPreviewColorCircleWidget::minimumSizeHint() const
|
|
||||||
{
|
|
||||||
// Return the same value as sizeHint() for minimum size
|
|
||||||
return QSize(circleDiameter, circleDiameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorCircleWidget::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
|
||||||
|
|
||||||
// Calculate the circle's bounding rectangle
|
|
||||||
int x = (width() - circleDiameter) / 2;
|
|
||||||
int y = (height() - circleDiameter) / 2;
|
|
||||||
QRect circleRect(x, y, circleDiameter, circleDiameter);
|
|
||||||
|
|
||||||
// Map color characters to their respective colors
|
|
||||||
QColor circleColor;
|
|
||||||
switch (colorChar.unicode()) {
|
|
||||||
case 'W':
|
|
||||||
circleColor = Qt::white;
|
|
||||||
break;
|
|
||||||
case 'U':
|
|
||||||
circleColor = QColor(0, 115, 230);
|
|
||||||
break; // Blue
|
|
||||||
case 'B':
|
|
||||||
circleColor = QColor(50, 50, 50);
|
|
||||||
break; // Black
|
|
||||||
case 'R':
|
|
||||||
circleColor = QColor(230, 30, 30);
|
|
||||||
break; // Red
|
|
||||||
case 'G':
|
|
||||||
circleColor = QColor(30, 180, 30);
|
|
||||||
break; // Green
|
|
||||||
default:
|
|
||||||
circleColor = Qt::transparent;
|
|
||||||
break; // Fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities() || isActive) {
|
|
||||||
// Make the circle faint if it is not active
|
|
||||||
if (!isActive) {
|
|
||||||
circleColor.setAlpha(SettingsCache::instance().getVisualDeckStorageUnusedColorIdentitiesOpacity() / 100.0 *
|
|
||||||
255.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the circle
|
|
||||||
painter.setBrush(circleColor);
|
|
||||||
painter.setPen(Qt::black);
|
|
||||||
painter.drawEllipse(circleRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the color character only if the circle is active
|
|
||||||
if (isActive) {
|
|
||||||
QFont font = painter.font();
|
|
||||||
font.setBold(true);
|
|
||||||
font.setPointSize(circleDiameter * 0.4); // Adjust font size relative to circle diameter
|
|
||||||
painter.setFont(font);
|
|
||||||
if (colorChar.unicode() == 'B') {
|
|
||||||
painter.setPen(Qt::white);
|
|
||||||
} else {
|
|
||||||
painter.setPen(Qt::black);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Center the text within the circle
|
|
||||||
painter.drawText(circleRect, Qt::AlignCenter, colorChar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorCircleWidget::setColorActive(bool active)
|
|
||||||
{
|
|
||||||
isActive = active;
|
|
||||||
update(); // Redraw the circle with the new active state
|
|
||||||
}
|
|
||||||
|
|
||||||
QChar DeckPreviewColorCircleWidget::getColorChar() const
|
|
||||||
{
|
|
||||||
return colorChar;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeckPreviewColorIdentityWidget::DeckPreviewColorIdentityWidget(QWidget *parent, const QString &colorIdentity)
|
|
||||||
: QWidget(parent)
|
|
||||||
{
|
|
||||||
layout = new QHBoxLayout(this);
|
|
||||||
layout->setSpacing(5);
|
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
layout->setAlignment(Qt::AlignHCenter);
|
|
||||||
setLayout(layout);
|
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
||||||
|
|
||||||
// Define the full WUBRG set (White, Blue, Black, Red, Green)
|
|
||||||
QString fullColorIdentity = "WUBRG";
|
|
||||||
|
|
||||||
// Create and add a DeckPreviewColorCircleWidget for each color in WUBRG
|
|
||||||
for (const QChar &color : fullColorIdentity) {
|
|
||||||
auto *circle = new DeckPreviewColorCircleWidget(color, this);
|
|
||||||
layout->addWidget(circle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set any active colors from the input colorIdentity
|
|
||||||
for (const QChar &color : colorIdentity) {
|
|
||||||
for (DeckPreviewColorCircleWidget *circle : findChildren<DeckPreviewColorCircleWidget *>()) {
|
|
||||||
if (circle->getColorChar() == color) {
|
|
||||||
circle->setColorActive(true); // Mark the color as active
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageDrawUnusedColorIdentitiesChanged, this,
|
|
||||||
&DeckPreviewColorIdentityWidget::toggleUnusedVisibility);
|
|
||||||
toggleUnusedVisibility(SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorIdentityWidget::toggleUnusedVisibility(bool _visible) const
|
|
||||||
{
|
|
||||||
if (_visible) {
|
|
||||||
for (DeckPreviewColorCircleWidget *circle : findChildren<DeckPreviewColorCircleWidget *>()) {
|
|
||||||
circle->setVisible(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (DeckPreviewColorCircleWidget *circle : findChildren<DeckPreviewColorCircleWidget *>()) {
|
|
||||||
if (!circle->getIsActive()) {
|
|
||||||
circle->setHidden(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckPreviewColorIdentityWidget::resizeEvent(QResizeEvent *event)
|
|
||||||
{
|
|
||||||
QWidget::resizeEvent(event);
|
|
||||||
|
|
||||||
// Notify child widgets to update their sizes based on the new parent size
|
|
||||||
for (auto *circle : findChildren<DeckPreviewColorCircleWidget *>()) {
|
|
||||||
circle->updateGeometry(); // Request each circle to resize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#ifndef DECK_PREVIEW_COLOR_IDENTITY_WIDGET_H
|
|
||||||
#define DECK_PREVIEW_COLOR_IDENTITY_WIDGET_H
|
|
||||||
|
|
||||||
#include <QChar>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QSize>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
class DeckPreviewColorCircleWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit DeckPreviewColorCircleWidget(QChar color, QWidget *parent);
|
|
||||||
|
|
||||||
void setColorActive(bool active);
|
|
||||||
QChar getColorChar() const;
|
|
||||||
bool getIsActive() const
|
|
||||||
{
|
|
||||||
return isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
QSize sizeHint() const override;
|
|
||||||
QSize minimumSizeHint() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QChar colorChar;
|
|
||||||
int circleDiameter;
|
|
||||||
bool isActive;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DeckPreviewColorIdentityWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit DeckPreviewColorIdentityWidget(QWidget *parent, const QString &colorIdentity);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void toggleUnusedVisibility(bool _visible) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QHBoxLayout *layout;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DECK_PREVIEW_COLOR_IDENTITY_WIDGET_H
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "../../../../../game/cards/card_database_manager.h"
|
#include "../../../../../game/cards/card_database_manager.h"
|
||||||
#include "../../../../../settings/cache_settings.h"
|
#include "../../../../../settings/cache_settings.h"
|
||||||
|
#include "../../cards/additional_info/color_identity_widget.h"
|
||||||
#include "../../cards/deck_preview_card_picture_widget.h"
|
#include "../../cards/deck_preview_card_picture_widget.h"
|
||||||
#include "deck_preview_deck_tags_display_widget.h"
|
#include "deck_preview_deck_tags_display_widget.h"
|
||||||
|
|
||||||
|
|
@ -77,7 +78,7 @@ void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
|
||||||
refreshBannerCardText();
|
refreshBannerCardText();
|
||||||
setFilePath(deckLoader->getLastFileName());
|
setFilePath(deckLoader->getLastFileName());
|
||||||
|
|
||||||
colorIdentityWidget = new DeckPreviewColorIdentityWidget(this, getColorIdentity());
|
colorIdentityWidget = new ColorIdentityWidget(this, getColorIdentity());
|
||||||
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
|
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
|
||||||
|
|
||||||
bannerCardLabel = new QLabel();
|
bannerCardLabel = new QLabel();
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
#define DECK_PREVIEW_WIDGET_H
|
#define DECK_PREVIEW_WIDGET_H
|
||||||
|
|
||||||
#include "../../../../../deck/deck_loader.h"
|
#include "../../../../../deck/deck_loader.h"
|
||||||
|
#include "../../cards/additional_info/color_identity_widget.h"
|
||||||
#include "../../cards/deck_preview_card_picture_widget.h"
|
#include "../../cards/deck_preview_card_picture_widget.h"
|
||||||
#include "../visual_deck_storage_widget.h"
|
#include "../visual_deck_storage_widget.h"
|
||||||
#include "deck_preview_color_identity_widget.h"
|
|
||||||
#include "deck_preview_deck_tags_display_widget.h"
|
#include "deck_preview_deck_tags_display_widget.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
@ -31,7 +31,7 @@ public:
|
||||||
QString filePath;
|
QString filePath;
|
||||||
DeckLoader *deckLoader;
|
DeckLoader *deckLoader;
|
||||||
DeckPreviewCardPictureWidget *bannerCardDisplayWidget = nullptr;
|
DeckPreviewCardPictureWidget *bannerCardDisplayWidget = nullptr;
|
||||||
DeckPreviewColorIdentityWidget *colorIdentityWidget = nullptr;
|
ColorIdentityWidget *colorIdentityWidget = nullptr;
|
||||||
DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget = nullptr;
|
DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget = nullptr;
|
||||||
QLabel *bannerCardLabel = nullptr;
|
QLabel *bannerCardLabel = nullptr;
|
||||||
QComboBox *bannerCardComboBox = nullptr;
|
QComboBox *bannerCardComboBox = nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue