Skip to content

Commit

Permalink
Add move/insert to RepeatedProtoModel, add shader and timeline editors (
Browse files Browse the repository at this point in the history
  • Loading branch information
fundies authored and JoshDreamland committed Dec 21, 2019
1 parent a2bc5c2 commit 30340ac
Show file tree
Hide file tree
Showing 38 changed files with 1,164 additions and 657 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
AllowShortCaseLabelsOnASingleLine: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ set(RGM_SOURCES
main.cpp
MainWindow.cpp
Dialogs/PreferencesDialog.cpp
Dialogs/TimelineChangeMoment.cpp
Editors/BaseEditor.cpp
Editors/CodeEditor.cpp
Editors/BackgroundEditor.cpp
Editors/ObjectEditor.cpp
Editors/SoundEditor.cpp
Editors/ScriptEditor.cpp
Editors/ShaderEditor.cpp
Editors/FontEditor.cpp
Editors/PathEditor.cpp
Editors/TimelineEditor.cpp
Expand All @@ -55,6 +57,7 @@ set(RGM_SOURCES
Components/QMenuView.cpp
Widgets/BackgroundView.cpp
Widgets/CodeWidget.cpp
Widgets/StackedCodeWidget.cpp
Widgets/ColorPicker.cpp
Widgets/RoomView.cpp
Widgets/AssetView.cpp
Expand All @@ -71,12 +74,14 @@ set(RGM_HEADERS
MainWindow.h
Dialogs/PreferencesDialog.h
Dialogs/PreferencesKeys.h
Dialogs/TimelineChangeMoment.h
Editors/CodeEditor.h
Editors/BaseEditor.h
Editors/BackgroundEditor.h
Editors/ObjectEditor.h
Editors/SoundEditor.h
Editors/ScriptEditor.h
Editors/ShaderEditor.h
Editors/FontEditor.h
Editors/PathEditor.h
Editors/TimelineEditor.h
Expand All @@ -98,6 +103,7 @@ set(RGM_HEADERS
Components/Logger.h
Widgets/BackgroundView.h
Widgets/CodeWidget.h
Widgets/StackedCodeWidget.h
Widgets/ColorPicker.h
Widgets/RoomView.h
Widgets/AssetView.h
Expand All @@ -109,6 +115,7 @@ set(RGM_UI
MainWindow.ui
Dialogs/PreferencesDialog.ui
Dialogs/AddImageDialog.ui
Dialogs/TimelineChangeMoment.ui
Editors/CodeEditor.ui
Editors/BackgroundEditor.ui
Editors/ObjectEditor.ui
Expand Down Expand Up @@ -184,14 +191,14 @@ target_link_libraries(${EXE} PRIVATE yaml-cpp)

# Find libEGM
# Debug
find_library(LIB_EGM_D NAMES EGMd PATHS ${ENIGMA_DIR})
find_library(LIB_EGM_D NAMES EGMd EGM PATHS ${ENIGMA_DIR})
# Release
find_library(LIB_EGM NAMES EGM PATHS ${ENIGMA_DIR})
target_link_libraries(${EXE} PRIVATE "$<IF:$<CONFIG:Debug>,${LIB_EGM_D},${LIB_EGM}>")

# Find libProtocols
# Debug
find_library(LIB_PROTO_D NAMES Protocolsd PATHS ${ENIGMA_DIR})
find_library(LIB_PROTO_D NAMES Protocolsd Protocols PATHS ${ENIGMA_DIR})
# Release
find_library(LIB_PROTO NAMES Protocols PATHS ${ENIGMA_DIR})
target_link_libraries(${EXE} PRIVATE "$<IF:$<CONFIG:Debug>,${LIB_PROTO_D},${LIB_PROTO}>")
Expand Down
18 changes: 18 additions & 0 deletions Dialogs/TimelineChangeMoment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "TimelineChangeMoment.h"
#include "ui_TimelineChangeMoment.h"

TimelineChangeMoment::TimelineChangeMoment(QWidget *parent) :
QDialog(parent),
ui(new Ui::TimelineChangeMoment) {
ui->setupUi(this);
}

TimelineChangeMoment::~TimelineChangeMoment() { delete ui; }

int TimelineChangeMoment::GetSpinBoxValue() {
return ui->spinBox->value();
}

void TimelineChangeMoment::SetSpinBoxValue(int val) {
ui->spinBox->setValue(val);
}
24 changes: 24 additions & 0 deletions Dialogs/TimelineChangeMoment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef TIMELINECHANGEMOMENT_H
#define TIMELINECHANGEMOMENT_H

#include <QDialog>

namespace Ui {
class TimelineChangeMoment;
}

class TimelineChangeMoment : public QDialog
{
Q_OBJECT

public:
explicit TimelineChangeMoment(QWidget *parent = nullptr);
~TimelineChangeMoment();
int GetSpinBoxValue();
void SetSpinBoxValue(int val);

private:
Ui::TimelineChangeMoment *ui;
};

#endif // TIMELINECHANGEMOMENT_H
78 changes: 78 additions & 0 deletions Dialogs/TimelineChangeMoment.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TimelineChangeMoment</class>
<widget class="QDialog" name="TimelineChangeMoment">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>206</width>
<height>89</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>New Step Value</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>TimelineChangeMoment</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>TimelineChangeMoment</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
2 changes: 1 addition & 1 deletion Editors/BackgroundEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BackgroundEditor : public BaseEditor {

public:
explicit BackgroundEditor(ProtoModelPtr model, QWidget *parent);
~BackgroundEditor();
~BackgroundEditor() override;

private slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVariant &oldValue = QVariant(0),
Expand Down
13 changes: 11 additions & 2 deletions Editors/BaseEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include "BaseEditor.h"

#include <QCloseEvent>
#include <QMessageBox>
#include <QDebug>
#include <QMessageBox>

BaseEditor::BaseEditor(ProtoModelPtr treeNodeModel, QWidget* parent)
: QWidget(parent), nodeMapper(new ModelMapper(treeNodeModel, this)) {
: QWidget(parent), nodeMapper(new ModelMapper(treeNodeModel, this)), _model(treeNodeModel) {
buffers::TreeNode* n = static_cast<buffers::TreeNode*>(treeNodeModel->GetBuffer());
resMapper = new ModelMapper(treeNodeModel->GetSubModel(ResTypeFields[n->type_case()]), this);

// Backup should be deleted by Qt's garbage collector when this editor is closed
resMapper->GetModel()->BackupModel(this);

connect(_model, &QAbstractItemModel::modelReset, [this]() { this->RebindSubModels(); });
}

void BaseEditor::closeEvent(QCloseEvent* event) {
Expand Down Expand Up @@ -50,6 +53,12 @@ void BaseEditor::dataChanged(const QModelIndex& topLeft, const QModelIndex& /*bo
this->setWindowTitle(QString::fromStdString(n->name()));
emit ResourceRenamed(n->type_case(), oldValue.toString(), QString::fromStdString(n->name()));
}
resMapper->SetDirty(true);
}

void BaseEditor::RebindSubModels() {
resMapper->toFirst();
nodeMapper->toFirst();
}

void BaseEditor::OnSave() {
Expand Down
18 changes: 10 additions & 8 deletions Editors/BaseEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <QWidget>

static const QHash<int, int> ResTypeFields = {
{TypeCase::kFolder, TreeNode::kFolderFieldNumber}, {TypeCase::kSprite, TreeNode::kSpriteFieldNumber},
{TypeCase::kSound, TreeNode::kSoundFieldNumber}, {TypeCase::kBackground, TreeNode::kBackgroundFieldNumber},
{TypeCase::kPath, TreeNode::kPathFieldNumber}, {TypeCase::kFont, TreeNode::kFontFieldNumber},
{TypeCase::kScript, TreeNode::kScriptFieldNumber}, {TypeCase::kTimeline, TreeNode::kTimelineFieldNumber},
{TypeCase::kObject, TreeNode::kObjectFieldNumber}, {TypeCase::kRoom, TreeNode::kRoomFieldNumber},
{TypeCase::kSettings, TreeNode::kSettingsFieldNumber}};
{TypeCase::kFolder, TreeNode::kFolderFieldNumber}, {TypeCase::kSprite, TreeNode::kSpriteFieldNumber},
{TypeCase::kSound, TreeNode::kSoundFieldNumber}, {TypeCase::kBackground, TreeNode::kBackgroundFieldNumber},
{TypeCase::kPath, TreeNode::kPathFieldNumber}, {TypeCase::kFont, TreeNode::kFontFieldNumber},
{TypeCase::kScript, TreeNode::kScriptFieldNumber}, {TypeCase::kTimeline, TreeNode::kTimelineFieldNumber},
{TypeCase::kObject, TreeNode::kObjectFieldNumber}, {TypeCase::kRoom, TreeNode::kRoomFieldNumber},
{TypeCase::kSettings, TreeNode::kSettingsFieldNumber}, {TypeCase::kShader, TreeNode::kShaderFieldNumber}};

class BaseEditor : public QWidget {
Q_OBJECT
Expand All @@ -31,11 +31,13 @@ class BaseEditor : public QWidget {
public slots:
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVariant &oldValue = QVariant(0), const QVector<int> &roles = QVector<int>());
virtual void RebindSubModels();
void OnSave();

protected:
ModelMapper* nodeMapper;
ModelMapper* resMapper;
ModelMapper *nodeMapper;
ModelMapper *resMapper;
ProtoModelPtr _model;
};

#endif // BASEEDTIOR_H
65 changes: 55 additions & 10 deletions Editors/CodeEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
#include "CodeEditor.h"
#include "Widgets/StackedCodeWidget.h"
#include "ui_CodeEditor.h"

CodeEditor::CodeEditor(ProtoModelPtr model, QWidget *parent) : BaseEditor(model, parent), ui(new Ui::CodeEditor) {
CodeEditor::CodeEditor(QWidget* parent, bool removeSaveBtn) : ui(new Ui::CodeEditor) {
ui->setupUi(this);

connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);
if (removeSaveBtn) ui->mainToolBar->removeAction(ui->actionSave);

layout()->setAlignment(Qt::AlignTop);

connect(ui->actionCut, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::cut);
connect(ui->actionCopy, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::copy);
connect(ui->actionRedo, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::redo);
connect(ui->actionUndo, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::undo);
connect(ui->actionPaste, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::paste);
connect(ui->actionPrint, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::printSource);
connect(ui->actionGoToLine, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::gotoLineDialog);
connect(ui->actionNewSource, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::newSource);
connect(ui->actionLoadSource, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::loadSource);
connect(ui->actionSaveSource, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::saveSource);
//connect(ui->actionFindAndReplace, &QAction::triggered, ui->stackedWidget, &StackedCodeWidget::findAndReplace);

cursorPositionLabel = new QLabel(ui->statusBar);
lineCountLabel = new QLabel(ui->statusBar);

connect(ui->stackedWidget, &QStackedWidget::currentChanged, [this]() {
if (ui->stackedWidget->count() > 0) {
this->updateCursorPositionLabel();
this->updateLineCountLabel();
}
});

ui->statusBar->addWidget(cursorPositionLabel);
ui->statusBar->addWidget(lineCountLabel);
}

// make sure we set the status labels at least once
updateCursorPositionLabel();
updateLineCountLabel();
CodeEditor::~CodeEditor() { delete ui; }

connect(ui->codeWidget, &CodeWidget::cursorPositionChanged, this, &CodeEditor::setCursorPositionLabel);
connect(ui->codeWidget, &CodeWidget::lineCountChanged, this, &CodeEditor::setLineCountLabel);
void CodeEditor::SetDisabled(bool disabled) {
(disabled) ? ui->stackedWidget->hide() : ui->stackedWidget->show();
(disabled) ? ui->statusBar->hide() : ui->statusBar->show();
for (QAction* action : ui->mainToolBar->actions()) {
action->setDisabled(disabled);
}
}

CodeEditor::~CodeEditor() { delete ui; }
int CodeEditor::GetCurrentIndex() { return ui->stackedWidget->currentIndex(); }

void CodeEditor::SetCurrentIndex(int index) { ui->stackedWidget->setCurrentIndex(index); }

void CodeEditor::RemoveCodeWidget(int index) { ui->stackedWidget->removeWidget(ui->stackedWidget->widget(index)); }

void CodeEditor::ClearCodeWidgets() {
for (int i = 0; i < ui->stackedWidget->count(); ++i) {
ui->stackedWidget->removeWidget(ui->stackedWidget->widget(i));
}
}

CodeWidget* CodeEditor::AddCodeWidget() {
CodeWidget* codeWidget = new CodeWidget(ui->stackedWidget);
ui->stackedWidget->addWidget(codeWidget);
connect(codeWidget, &CodeWidget::cursorPositionChanged, this, &CodeEditor::setCursorPositionLabel);
connect(codeWidget, &CodeWidget::lineCountChanged, this, &CodeEditor::setLineCountLabel);
return codeWidget;
}

void CodeEditor::setCursorPositionLabel(int line, int index) {
this->cursorPositionLabel->setText(tr("Ln %0, Col %1").arg(line).arg(index));
Expand All @@ -29,8 +72,10 @@ void CodeEditor::setCursorPositionLabel(int line, int index) {
void CodeEditor::setLineCountLabel(int lines) { this->lineCountLabel->setText(tr("Lines %0").arg(lines)); }

void CodeEditor::updateCursorPositionLabel() {
auto cursorPosition = this->ui->codeWidget->cursorPosition();
auto cursorPosition = static_cast<CodeWidget*>(ui->stackedWidget->currentWidget())->cursorPosition();
this->setCursorPositionLabel(cursorPosition.first, cursorPosition.second);
}

void CodeEditor::updateLineCountLabel() { this->setLineCountLabel(this->ui->codeWidget->lineCount()); }
void CodeEditor::updateLineCountLabel() {
this->setLineCountLabel(static_cast<CodeWidget*>(ui->stackedWidget->currentWidget())->lineCount());
}

0 comments on commit 30340ac

Please sign in to comment.