[pushbutton] removed name, added text/text_color and made is resizeble
Dieser Commit ist enthalten in:
Ursprung
f96485e3c3
Commit
60437cdce8
@ -175,6 +175,8 @@ void BoardAreaWidget::tileObjectAdded(int16_t x, int16_t y, const ObjectPtr& obj
|
||||
|
||||
case TileId::PushButton:
|
||||
tryConnect("color");
|
||||
tryConnect("text");
|
||||
tryConnect("text_color");
|
||||
break;
|
||||
|
||||
case TileId::RailNXButton:
|
||||
@ -462,8 +464,7 @@ QString BoardAreaWidget::getTileToolTip(const TileLocation& l) const
|
||||
return text;
|
||||
}
|
||||
}
|
||||
else if(tileId == TileId::PushButton ||
|
||||
tileId == TileId::RailNXButton)
|
||||
else if(tileId == TileId::RailNXButton)
|
||||
{
|
||||
if(auto tile = m_board->getTileObject(l))
|
||||
{
|
||||
@ -740,7 +741,17 @@ void BoardAreaWidget::paintEvent(QPaintEvent* event)
|
||||
break;
|
||||
|
||||
case TileId::PushButton:
|
||||
tilePainter.drawPushButton(r, getColor(it.first));
|
||||
if(auto button = m_board->getTileObject(it.first)) [[likely]]
|
||||
{
|
||||
tilePainter.drawPushButton(r,
|
||||
button->getPropertyValueEnum<Color>("color", Color::Yellow),
|
||||
button->getPropertyValueEnum<Color>("text_color", Color::Black),
|
||||
button->getPropertyValueString("text"));
|
||||
}
|
||||
else
|
||||
{
|
||||
tilePainter.drawPushButton(r);
|
||||
}
|
||||
break;
|
||||
|
||||
case TileId::RailDecoupler:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2020-2024 Reinder Feenstra
|
||||
* Copyright (C) 2020-2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -438,12 +438,28 @@ void TilePainter::drawBlock(TileId id, const QRectF& r, TileRotate rotate, bool
|
||||
}
|
||||
}
|
||||
|
||||
void TilePainter::drawPushButton(const QRectF& r, Color color)
|
||||
void TilePainter::drawPushButton(const QRectF& r, Color color, Color textColor, const QString& text)
|
||||
{
|
||||
m_painter.setPen(QPen(Qt::gray, r.width() / 10));
|
||||
const auto size = std::min(r.height(), r.width());
|
||||
m_painter.setPen(QPen(Qt::gray, size / 10));
|
||||
m_painter.setBrush(toQColor(color));
|
||||
const qreal radius = r.width() * 0.4;
|
||||
m_painter.drawEllipse(r.center(), radius, radius);
|
||||
const qreal radius = size * 0.4;
|
||||
if(r.height() == r.width())
|
||||
{
|
||||
m_painter.drawEllipse(r.center(), radius, radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto margin = size * 0.1;
|
||||
m_painter.drawRoundedRect(r.adjusted(margin, margin, -margin, -margin), radius, radius);
|
||||
}
|
||||
|
||||
if(!text.isEmpty())
|
||||
{
|
||||
const auto margin = size * 0.2;
|
||||
m_painter.setPen(toQColor(textColor));
|
||||
m_painter.drawText(r.adjusted(margin, margin, -margin, -margin), text, QTextOption(Qt::AlignCenter));
|
||||
}
|
||||
}
|
||||
|
||||
void TilePainter::drawSwitch(const QRectF& r, bool value, Color colorOn, Color colorOff)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2020-2024 Reinder Feenstra
|
||||
* Copyright (C) 2020-2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -107,7 +107,7 @@ class TilePainter
|
||||
void drawSignal(TileId id, const QRectF& r, TileRotate rotate, bool isReserved = false, SignalAspect aspect = SignalAspect::Unknown);
|
||||
void drawBlock(TileId id, const QRectF& r, TileRotate rotate, bool isReservedA = false, bool isReservedB = false, const ObjectPtr& blockTile = {});
|
||||
|
||||
void drawPushButton(const QRectF& r, Color color = Color::Yellow);
|
||||
void drawPushButton(const QRectF& r, Color color = Color::Yellow, Color textColor = Color::Black, const QString& text = {});
|
||||
void drawSwitch(const QRectF& r, bool value = false, Color colorOn = Color::Yellow, Color colorOff = Color::Gray);
|
||||
|
||||
void drawRailDecoupler(const QRectF& r, TileRotate rotate, bool isReserved = false, DecouplerState active = DecouplerState::Deactivated);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": {},
|
||||
"color": {},
|
||||
"text": {},
|
||||
"text_color": {},
|
||||
"on_pressed": {
|
||||
"parameters": [
|
||||
{
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022,2024 Reinder Feenstra
|
||||
* Copyright (C) 2022-2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -30,8 +30,9 @@ CREATE_IMPL(PushButtonTile)
|
||||
|
||||
PushButtonTile::PushButtonTile(World& world, std::string_view _id)
|
||||
: Tile(world, _id, TileId::PushButton)
|
||||
, name{this, "name", id, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadOnly}
|
||||
, color{this, "color", Color::Yellow, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadOnly}
|
||||
, color{this, "color", Color::Yellow, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadWrite}
|
||||
, text{this, "text", "", PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadWrite}
|
||||
, textColor{this, "text_color", Color::Black, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadWrite}
|
||||
, pressed{*this, "pressed",
|
||||
[this]()
|
||||
{
|
||||
@ -39,28 +40,19 @@ PushButtonTile::PushButtonTile(World& world, std::string_view _id)
|
||||
}}
|
||||
, onPressed{*this, "on_pressed", EventFlags::Scriptable}
|
||||
{
|
||||
const bool editable = contains(m_world.state.value(), WorldState::Edit);
|
||||
Attributes::setMax<uint8_t>(height, 16);
|
||||
Attributes::setMax<uint8_t>(width, 16);
|
||||
|
||||
Attributes::addDisplayName(name, DisplayName::Object::name);
|
||||
Attributes::addEnabled(name, editable);
|
||||
m_interfaceItems.add(name);
|
||||
|
||||
Attributes::addEnabled(color, editable);
|
||||
Attributes::addValues(color, colorValuesWithoutNone);
|
||||
m_interfaceItems.add(color);
|
||||
|
||||
m_interfaceItems.add(text);
|
||||
|
||||
Attributes::addValues(textColor, colorValuesWithoutNone);
|
||||
m_interfaceItems.add(textColor);
|
||||
|
||||
Attributes::addObjectEditor(pressed, false);
|
||||
m_interfaceItems.add(pressed);
|
||||
|
||||
m_interfaceItems.add(onPressed);
|
||||
}
|
||||
|
||||
void PushButtonTile::worldEvent(WorldState worldState, WorldEvent worldEvent)
|
||||
{
|
||||
Tile::worldEvent(worldState, worldEvent);
|
||||
|
||||
const bool editable = contains(worldState, WorldState::Edit);
|
||||
|
||||
Attributes::setEnabled(name, editable);
|
||||
Attributes::setEnabled(color, editable);
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022,2024 Reinder Feenstra
|
||||
* Copyright (C) 2022-2025 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -34,12 +34,10 @@ class PushButtonTile : public Tile
|
||||
DEFAULT_ID("push_button")
|
||||
CREATE_DEF(PushButtonTile)
|
||||
|
||||
protected:
|
||||
void worldEvent(WorldState worldState, WorldEvent worldEvent) final;
|
||||
|
||||
public:
|
||||
Property<std::string> name;
|
||||
Property<Color> color;
|
||||
Property<std::string> text;
|
||||
Property<Color> textColor;
|
||||
Method<void()> pressed;
|
||||
Event<std::shared_ptr<PushButtonTile>> onPressed;
|
||||
|
||||
|
||||
@ -83,6 +83,14 @@
|
||||
"term": "board_tile.misc.push_button:color",
|
||||
"definition": "Color"
|
||||
},
|
||||
{
|
||||
"term": "board_tile.misc.push_button:text",
|
||||
"definition": "Text"
|
||||
},
|
||||
{
|
||||
"term": "board_tile.misc.push_button:text_color",
|
||||
"definition": "Text color"
|
||||
},
|
||||
{
|
||||
"term": "board_tile.misc.switch:color_off",
|
||||
"definition": "Color when off"
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren