Skip to content

Commit

Permalink
Combat tracker and dice improvements: min/max for crits is now the de…
Browse files Browse the repository at this point in the history
…fault, the last dice result is remembered, dice panel in combat tracker is open by default, exact result calculation is now also shown in combat tracker
  • Loading branch information
PhilInTheGaps committed Nov 8, 2023
1 parent 1eeab6d commit c3862fc
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 326 deletions.
2 changes: 1 addition & 1 deletion app/ui/tools/CombatTracker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Page {
id: root

readonly property bool inPortrait: width < height || width < 1200
property bool diceEnabled: false
property bool diceEnabled: true

Component.onCompleted: CombatTrackerTool.loadData()

Expand Down
44 changes: 19 additions & 25 deletions app/ui/tools/Dice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ Page {
id: dice_page

property bool combat_tracker_mode: false
property var diceSides: [4, 6, 8, 10, 12, 20]
readonly property var diceSides: [4, 6, 8, 10, 12, 20]
property alias diceTypeSpinBox: dice_type_spin_box
readonly property int minimalHeight: main_column.height

Connections {
target: DiceTool

function onCalculationStringChanged() {
calculation_text_edit.text = DiceTool.calculationString
}

function onMixedCriticalResult() {
roll_result.color = "orange"
roll_result_help.visible = true
Expand Down Expand Up @@ -82,7 +78,7 @@ Page {
anchors.margins: 5

sides: modelData
isCurrentType: dice_type_spin_box.value == sides
isCurrentType: dice_type_spin_box.value === sides
onClicked: dice_type_spin_box.value = sides
}
}
Expand All @@ -108,6 +104,7 @@ Page {
spacing: 10
padding: 10
topPadding: 0
anchors.top: parent.top
anchors.left: parent.left
anchors.right: dice_page.combat_tracker_mode ? parent.right : undefined
width: dice_page.combat_tracker_mode ? 0 : 620
Expand Down Expand Up @@ -165,6 +162,7 @@ Page {
width: (parent.width - parent.spacing * 2) / 3
value: 1
from: 1
to: 9999
onValueChanged: DiceTool.setAmount(value)
editable: true
font.pixelSize: value_row.width / 25
Expand All @@ -173,19 +171,19 @@ Page {
SpinBox {
id: dice_type_spin_box
value: 20
to: 1000
to: 9999
width: (parent.width - parent.spacing * 2) / 3
editable: true
onValueChanged: DiceTool.setSides(value)
onValueChanged: DiceTool.sides = value
font.pixelSize: value_row.width / 25
}

SpinBox {
id: modifier_spin_box
width: (parent.width - parent.spacing * 2) / 3
value: 0
from: -99
to: 99
from: -9999
to: 9999
onValueChanged: DiceTool.setModifier(value)
editable: true
font.pixelSize: value_row.width / 25
Expand Down Expand Up @@ -216,7 +214,7 @@ Page {
hoverEnabled: true

onClicked: {
roll_result.text = DiceTool.roll
DiceTool.roll()
}
}

Expand All @@ -230,7 +228,7 @@ Page {
Label {
id: roll_result
font.pixelSize: value_row.width / 20
text: "-"
text: DiceTool.result.length > 0 ? DiceTool.result : "-"
anchors.verticalCenter: parent.verticalCenter
font.bold: true
}
Expand All @@ -243,24 +241,20 @@ Page {
}
}

ScrollView {
CustomTextEdit {
id: textedit

anchors.top: main_column.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom

clip: true
padding: 10
contentHeight: calculation_text_edit.implicitHeight
color: palette.base
border.width: 0
font.pointSize: 12

TextEdit {
id: calculation_text_edit
readOnly: true
color: palette.text
selectedTextColor: palette.highlightedText
selectionColor: palette.highlight
area.readOnly: true

font.pixelSize: value_row.width / 30
}
text: DiceTool.calculation
}
}
13 changes: 7 additions & 6 deletions app/ui/tools/DiceAlt.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Item {
id: count_spinbox
value: 1
from: 1
to: 9999
onValueChanged: DiceTool.setAmount(value)
editable: true
font.pixelSize: parent.height * 0.4
Expand All @@ -73,9 +74,9 @@ Item {
SpinBox {
id: dice_type_spin_box
value: 20
to: 1000
to: 9999
editable: true
onValueChanged: DiceTool.setSides(value)
onValueChanged: DiceTool.sides = value
font.pixelSize: parent.height * 0.4
}

Expand All @@ -89,8 +90,8 @@ Item {
// Modifier
SpinBox {
value: 0
from: -99
to: 99
from: -9999
to: 9999
onValueChanged: DiceTool.setModifier(value)
editable: true
font.pixelSize: parent.height * 0.4
Expand All @@ -114,7 +115,7 @@ Item {
hoverEnabled: true

onClicked: {
roll_result.text = DiceTool.roll
DiceTool.roll()
}
}

Expand All @@ -129,7 +130,7 @@ Item {
// Result
Label {
id: roll_result
text: "-"
text: DiceTool.result.length > 0 ? DiceTool.result : "-"
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
font.pixelSize: parent.height * 0.5
Expand Down
2 changes: 1 addition & 1 deletion app/ui/tools/combat_tracker/CharacterListHeader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Rectangle {
"text": qsTr("Priority"),
"divisor": 6,
"alignment": "center",
"helpText": qsTr("Characters with the same initiative value will be ordered by their priority.")
"helpText": qsTr("Characters with the same initiative value will be ordered by their priority (highest first).")
}, {
"text": qsTr("Notes"),
"divisor": 6,
Expand Down
5 changes: 3 additions & 2 deletions app/ui/tools/dice/DiceCombatTracker.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma ComponentBehavior: Bound

import QtQuick
import ".."
import "../.."
Expand Down Expand Up @@ -32,7 +33,7 @@ Item {
anchors.left: dice_col.left
anchors.right: dice_col.right

isCurrentType: dice.diceTypeSpinBox.value == sides
isCurrentType: dice.diceTypeSpinBox.value === sides
onClicked: dice.diceTypeSpinBox.value = sides
}
}
Expand All @@ -41,10 +42,10 @@ Item {

Dice {
id: dice
height: minimalHeight
combat_tracker_mode: true
anchors.left: parent.left
anchors.right: sidebar.left
anchors.top: parent.top
anchors.bottom: parent.bottom
}
}
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ set(SRC_GENERATORS
set_source_files_properties(${SRC_GENERATORS} PROPERTIES UNITY_GROUP "generators")

set(SRC_COMBAT
tools/combat_tracker/effect.h
tools/combat_tracker/effect.cpp
tools/combat_tracker/effecttool.h
tools/combat_tracker/effecttool.cpp
tools/combat_tracker/combattracker.h
tools/combat_tracker/combattracker.cpp
tools/combat_tracker/combattrackerstate.h
Expand Down
9 changes: 2 additions & 7 deletions src/tools/combat_tracker/combattracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@ using namespace Qt::Literals::StringLiterals;

Q_LOGGING_CATEGORY(gmCombatTracker, "gm.combat.tracker")

CombatTracker::CombatTracker(const QQmlEngine *qmlEngine, QObject *parent) : AbstractTool(parent), m_effectTool(this)
CombatTracker::CombatTracker(QObject *parent) : AbstractTool(parent)
{
if (qmlEngine)
{
qmlEngine->rootContext()->setContextProperty(u"combat_tracker_effects"_s, &m_effectTool);
}

connect(&m_state, &CombatTrackerState::currentIndexChanged, this, &CombatTracker::currentIndexChanged);
connect(&m_state, &CombatTrackerState::currentRoundChanged, this, &CombatTracker::currentRoundChanged);
}

auto CombatTracker::create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) -> CombatTracker *
{
Q_UNUSED(jsEngine)
return new CombatTracker(qmlEngine, qmlEngine);
return new CombatTracker(qmlEngine);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/tools/combat_tracker/combattracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "abstracttool.h"
#include "combatant.h"
#include "combattrackerstate.h"
#include "effecttool.h"
#include <QFile>
#include <QList>
#include <QObject>
Expand All @@ -20,7 +19,7 @@ class CombatTracker : public AbstractTool

public:
CombatTracker() = delete;
explicit CombatTracker(const QQmlEngine *qmlEngine, QObject *parent = nullptr);
explicit CombatTracker(QObject *parent = nullptr);
static auto create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) -> CombatTracker *;

Q_PROPERTY(int currentRound READ currentRound NOTIFY currentRoundChanged)
Expand Down Expand Up @@ -80,8 +79,6 @@ public slots:
static auto getCacheFile() -> QFile;

private:
EffectTool m_effectTool;

CombatTrackerState m_state;
};

Expand Down
20 changes: 0 additions & 20 deletions src/tools/combat_tracker/effect.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions src/tools/combat_tracker/effect.h

This file was deleted.

Loading

0 comments on commit c3862fc

Please sign in to comment.