Skip to content

Commit

Permalink
Merge pull request #29 from MaxFleur/dev_staging
Browse files Browse the repository at this point in the history
Merge 2.2.1 changes
  • Loading branch information
MaxFleur authored Oct 19, 2024
2 parents 129416c + 67e547f commit e277cf2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![License badge](https://img.shields.io/badge/License-GPLv3-blue.svg)
![C++ badge](https://img.shields.io/badge/C++-17-blue.svg)
![CI badge](https://github.com/MaxFleur/LightCombatManager/actions/workflows/run.yml/badge.svg)
![Tag badge](https://img.shields.io/badge/Release-v2.2.0-blue.svg)
![Tag badge](https://img.shields.io/badge/Release-v2.2.1-blue.svg)

</div>

Expand Down Expand Up @@ -84,6 +84,9 @@ The following description is focused on building the application with `cmake`, M
```
The dll files can be found under the Qt installation path under `/bin` and `/plugins`.

# License
Until Version 2.1.0, LCM used the [MIT license](https://www.mit.edu/~amini/LICENSE.md). Since Version 2.2.0, LCM uses [GPL-3.0](https://www.gnu.org/licenses/gpl-3.0.txt).

# Contribution

## More features
Expand Down
4 changes: 2 additions & 2 deletions src/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ MainWindow::saveTable()
fileName = m_dirSettings.openDir;
}
// Save the table
if (m_combatWidget->saveTableData(fileName)) {
if (m_combatWidget->writeTableToFile(fileName)) {
m_isTableSavedInFile = true;
m_dirSettings.write(fileName, true);
m_fileName = Utils::General::getLCMName(fileName);
Expand Down Expand Up @@ -229,7 +229,7 @@ MainWindow::about()
QMessageBox::about(this, tr("About Light Combat Manager"),
tr("<p>Light Combat Manager. A small, lightweight Combat Manager for d20-based role playing games.<br>"
"<a href='https://github.com/MaxFleur/LightCombatManager'>Code available on Github.</a></p>"
"<p>Version 2.2.0.<br>"
"<p>Version 2.2.1.<br>"
"<a href='https://github.com/MaxFleur/LightCombatManager/releases'>Changelog</a></p>"));
}

Expand Down
5 changes: 2 additions & 3 deletions src/ui/WelcomeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ WelcomeWidget::WelcomeWidget(QWidget *parent)
"or open an already existing Combat ('File' -> 'Open...')."));
welcomeLabel->setAlignment(Qt::AlignCenter);

auto* const versionLabel = new QLabel("v2.2.0");
versionLabel->setToolTip(tr("New settings, insert Tables into an existing Combat,\n"
"change HP for multiple Characters at once and more!"));
auto* const versionLabel = new QLabel("v2.2.1");
versionLabel->setToolTip(tr("Minor bugfixes and refactoring."));
versionLabel->setAlignment(Qt::AlignRight);

auto *const layout = new QVBoxLayout(this);
Expand Down
50 changes: 25 additions & 25 deletions src/ui/table/CombatWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ CombatWidget::generateTableFromTableData()

// Load the data from file
const auto& loadedFileData = m_tableFileHandler->getData();
writeStoredCharacters(loadedFileData);
loadCharactersFromTable(loadedFileData);
m_rowEntered = loadedFileData.value("row_entered").toInt();
m_roundCounter = loadedFileData.value("round_counter").toInt();

Expand All @@ -218,20 +218,20 @@ CombatWidget::generateTableFromTableData()

// Then create the table in the ui
pushOnUndoStack();
// We do not need a save step directly after table creation, so reset the stack
// We do not need a save step directly after table creation
m_undoStack->clear();
}


bool
CombatWidget::saveTableData(const QString& fileName)
CombatWidget::writeTableToFile(const QString& fileName)
{
return m_tableFileHandler->writeToFile(m_tableWidget->tableDataFromWidget(), fileName, m_rowEntered,
m_roundCounter, m_ruleSettings.ruleset, m_ruleSettings.rollAutomatical);
}


// Save the old table state before a change occurs, which is important for the undo command
// Save the old table state before a table change occurs (later used for the undo stack)
void
CombatWidget::saveOldState()
{
Expand Down Expand Up @@ -376,7 +376,7 @@ CombatWidget::insertTable()
{
saveOldState();
const auto oldSize = m_characterHandler->getCharacters().size();
writeStoredCharacters(m_tableFileHandler->getData());
loadCharactersFromTable(m_tableFileHandler->getData());

for (auto i = oldSize; i < m_characterHandler->getCharacters().size(); i++) {
m_removedOrAddedRowIndices.push_back(i);
Expand Down Expand Up @@ -412,6 +412,7 @@ CombatWidget::openStatusEffectDialog()
if (const auto& effects = dialog->getEffects(); effects.empty()) {
return;
}

saveOldState();
m_tableWidget->resynchronizeCharacters();
auto& characters = m_characterHandler->getCharacters();
Expand All @@ -422,13 +423,13 @@ CombatWidget::openStatusEffectDialog()
auto& statusEffects = characters[i.row()].additionalInfoData.statusEffects;

for (const auto& dialogEffect : dialog->getEffects()) {
// Store normally for DnD 5E, for the others only if it's new or the duration is bigger
// Store normally for DnD 5E
if (m_ruleSettings.ruleset == RuleSettings::Ruleset::DND_5E) {
statusEffects.push_back(dialogEffect);
needsUndo = true;
continue;
}

// For the others only if it's new or the duration is bigger
auto it = std::find_if(statusEffects.begin(), statusEffects.end(), [dialogEffect] (const auto& statusEffect) {
return statusEffect.name == dialogEffect.name;
});
Expand Down Expand Up @@ -463,7 +464,7 @@ CombatWidget::addCharacter(CharacterHandler::Character character, int instanceCo
m_tableWidget->resynchronizeCharacters();

const auto trimmedName = character.name.trimmed();
for (int i = 0; i < instanceCount; i++) {
for (auto i = 0; i < instanceCount; i++) {
m_characterHandler->storeCharacter(instanceCount > 1 && m_additionalSettings.indicatorMultipleChars ? trimmedName + " #" + QString::number(i + 1)
: trimmedName,
instanceCount > 1 && m_additionalSettings.rollIniMultipleChars ? Utils::General::rollDice() + character.modifier
Expand Down Expand Up @@ -507,7 +508,7 @@ CombatWidget::rerollIni()
void
CombatWidget::changeHPForMultipleChars()
{
if (m_tableWidget->selectionModel()->selectedRows().size() <= 1) {
if (m_tableWidget->selectionModel()->selectedRows().size() < 2) {
return;
}

Expand Down Expand Up @@ -597,7 +598,10 @@ CombatWidget::duplicateRow()
void
CombatWidget::handleTableWidgetItemPressed(QTableWidgetItem *item)
{
if (item->column() == Utils::Table::COL_ENEMY) {
if (item->column() == Utils::Table::COL_NAME) {
const auto nameWidth = Utils::General::getStringWidth(item->text());
resetNameAndInfoWidth(nameWidth, m_tableWidget->columnWidth(Utils::Table::COL_ADDITIONAL));
} else if (item->column() == Utils::Table::COL_ENEMY) {
m_tableWidget->blockSignals(true);
// We need to store the old checkbox state, so we will reset the state for a short time
// Then, after saving, reset to the new value and set the correct undo command
Expand Down Expand Up @@ -669,26 +673,22 @@ CombatWidget::switchCharacterPosition(bool goDown)


void
CombatWidget::enteredRowChanged(bool goDown)
CombatWidget::enteredRowChanged(bool isGoingDown)
{
if (m_tableWidget->rowCount() == 0 || (!goDown && m_rowEntered == 0 && m_roundCounter == 1)) {
if (m_tableWidget->rowCount() == 0 || (!isGoingDown && m_rowEntered == 0 && m_roundCounter == 1)) {
return;
}

saveOldState();
const auto rowEnteredModifier = isGoingDown ? 1 : -1;
const auto boundaryIndex = isGoingDown ? m_tableWidget->rowCount() - 1 : 0;

const auto setForBound = [this, goDown] {
m_rowEntered = goDown ? 0 : m_tableWidget->rowCount() - 1;
m_roundCounter += goDown ? 1 : -1;
m_tableWidget->adjustStatusEffectRoundCounter(goDown);
if ((int) m_rowEntered == boundaryIndex) {
m_rowEntered = isGoingDown ? 0 : m_tableWidget->rowCount() - 1;
m_roundCounter += isGoingDown ? 1 : -1;
m_tableWidget->adjustStatusEffectRoundCounter(isGoingDown);

emit roundCounterSet();
};

const auto rowEnteredModifier = goDown ? 1 : -1;
const auto tableWidgetBoundIndex = goDown ? m_tableWidget->rowCount() - 1 : 0;
if ((int) m_rowEntered == tableWidgetBoundIndex) {
setForBound();
} else {
m_rowEntered += rowEnteredModifier;
}
Expand Down Expand Up @@ -723,9 +723,9 @@ CombatWidget::setTableOption(bool option, int valueType)
}


// Write characters stored in a file to the table
// Load characters stored in a file to the table
void
CombatWidget::writeStoredCharacters(const QJsonObject& jsonObject)
CombatWidget::loadCharactersFromTable(const QJsonObject& jsonObject)
{
auto& characters = m_characterHandler->getCharacters();
const auto& charactersObject = jsonObject.value("characters").toObject();
Expand Down Expand Up @@ -775,13 +775,13 @@ void
CombatWidget::contextMenuEvent(QContextMenuEvent *event)
{
auto *const menu = new QMenu(this);
const auto currentRow = m_tableWidget->indexAt(m_tableWidget->viewport()->mapFrom(this, event->pos())).row();

menu->addAction(m_addCharacterAction);
if (m_tableWidget->rowCount() > 0) {
menu->addAction(m_insertTableAction);
}

const auto currentRow = m_tableWidget->indexAt(m_tableWidget->viewport()->mapFrom(this, event->pos())).row();
// Map from MainWindow coordinates to Table Widget coordinates
if (currentRow >= 0) {
menu->addAction(m_removeAction);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/table/CombatWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CombatWidget : public QWidget {
}

[[nodiscard]] bool
saveTableData(const QString& fileName);
writeTableToFile(const QString& fileName);

void
saveOldState();
Expand Down Expand Up @@ -138,7 +138,7 @@ private slots:
int valueType);

void
writeStoredCharacters(const QJsonObject& jsonObject);
loadCharactersFromTable(const QJsonObject& jsonObject);

[[nodiscard]] QAction*
createAction(const QString& text,
Expand Down
1 change: 1 addition & 0 deletions src/ui/table/additional/AdditionalInfoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ AdditionalInfoWidget::triggerAdditionalInfoEdited()

const auto mainInfoText = getMainInfoText();
if (m_mainInfoTextCache != mainInfoText) {
m_additionalInfoData.mainInfoText = mainInfoText;
emit additionalInfoEdited();
}
}
Expand Down

0 comments on commit e277cf2

Please sign in to comment.