Skip to content

Commit

Permalink
Events: Set event command indent values automatically
Browse files Browse the repository at this point in the history
The indent values of event commands are now automatically set.
  • Loading branch information
rueter37 committed Nov 24, 2021
1 parent 400d82c commit 1c950ae
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/ui/event/event_commands_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void EventCommandsWidget::editRawEvent(QTreeWidgetItem *item, int column, bool s
dialog.reset(wrapper);

dialog->exec();
currentItem()->setData(column, Qt::DisplayRole, Stringizer::stringize(cmd));
refreshList();
}

void EventCommandsWidget::deleteEvent(QTreeWidgetItem *item) {
Expand Down Expand Up @@ -332,17 +332,45 @@ void EventCommandsWidget::showContextMenu(const QPoint& pos) {
}

void EventCommandsWidget::refreshList() {
using Cmd = lcf::rpg::EventCommand::Code;

clear();

// Populate event command list
int32_t prev_indent = -1;
std::vector<QTreeWidgetItem*> parent_stack;
parent_stack.reserve(10);
int32_t indent = 0;

for (size_t i = 0; i < m_commands->size(); ++i) {
auto& cmd = (*m_commands)[i];

auto indent = cmd.indent;
if (i > 0) {
auto& last_cmd = (*m_commands)[i - 1];
switch (static_cast<Cmd>(last_cmd.code)) {
case Cmd::ConditionalBranch:
case Cmd::ElseBranch:
case Cmd::ConditionalBranch_B:
case Cmd::ElseBranch_B:
case Cmd::Loop:
case Cmd::ShowChoiceOption:
case Cmd::VictoryHandler:
case Cmd::EscapeHandler:
case Cmd::DefeatHandler:
case Cmd::Transaction:
case Cmd::NoTransaction:
case Cmd::Stay:
case Cmd::NoStay:
indent++;
break;
case Cmd::END:
indent--;
break;
default:
break;
}
}
cmd.indent = indent;

auto* item = new QTreeWidgetItem({Stringizer::stringize(cmd), QString::number(i)});
item->setToolTip(0, tr("Line") + ": " + QString::number(i + 1));
Expand Down

0 comments on commit 1c950ae

Please sign in to comment.