From a80e3b6867df016e51acb2801c4cebe3f90caaf8 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 29 Nov 2021 18:40:58 +0100 Subject: [PATCH 1/5] Fix Chipset Widget compilation in Database tab --- src/ui/database/chipset_widget.cpp | 8 ++++---- src/ui/database/chipset_widget.h | 10 +++++----- src/ui/database/chipset_widget.ui | 4 ++-- src/ui/database/database_dialog.cpp | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ui/database/chipset_widget.cpp b/src/ui/database/chipset_widget.cpp index 01243eef..8dbdb40a 100644 --- a/src/ui/database/chipset_widget.cpp +++ b/src/ui/database/chipset_widget.cpp @@ -18,20 +18,20 @@ #include "chipset_widget.h" #include "ui_chipset_widget.h" -ChipSetWidget::ChipSetWidget(ProjectData& project, QWidget *parent) : +ChipsetWidget::ChipsetWidget(ProjectData& project, QWidget *parent) : QWidget(parent), - ui(new Ui::ChipSetWidget), + ui(new Ui::ChipsetWidget), m_project(project) { ui->setupUi(this); } -ChipSetWidget::~ChipSetWidget() +ChipsetWidget::~ChipsetWidget() { delete ui; } -void ChipSetWidget::setData(lcf::rpg::Chipset* /* chipset */) +void ChipsetWidget::setData(lcf::rpg::Chipset* /* chipset */) { } diff --git a/src/ui/database/chipset_widget.h b/src/ui/database/chipset_widget.h index d60458d5..9ef0c0f4 100644 --- a/src/ui/database/chipset_widget.h +++ b/src/ui/database/chipset_widget.h @@ -23,23 +23,23 @@ class ProjectData; namespace Ui { -class ChipSetWidget; +class ChipsetWidget; } -class ChipSetWidget : public QWidget +class ChipsetWidget : public QWidget { Q_OBJECT public: using value_type = lcf::rpg::Chipset; - explicit ChipSetWidget(ProjectData& project, QWidget *parent = nullptr); - ~ChipSetWidget(); + explicit ChipsetWidget(ProjectData& project, QWidget *parent = nullptr); + ~ChipsetWidget(); void setData(lcf::rpg::Chipset* chipset); private: - Ui::ChipSetWidget *ui; + Ui::ChipsetWidget *ui; ProjectData& m_project; }; diff --git a/src/ui/database/chipset_widget.ui b/src/ui/database/chipset_widget.ui index f1f8ac2f..a18f36c2 100644 --- a/src/ui/database/chipset_widget.ui +++ b/src/ui/database/chipset_widget.ui @@ -1,7 +1,7 @@ - ChipSetWidget - + ChipsetWidget + 0 diff --git a/src/ui/database/database_dialog.cpp b/src/ui/database/database_dialog.cpp index bb727031..190fffaa 100644 --- a/src/ui/database/database_dialog.cpp +++ b/src/ui/database/database_dialog.cpp @@ -46,7 +46,7 @@ DatabaseDialog::DatabaseDialog(ProjectData& project, QWidget *parent) : pageBattleAnimations2 = new DatabaseSplitWidget(m_projectDataCopy, this); pageBattleScreen = new BattleScreenWidget(m_projectDataCopy, this); pageTerrain = new DatabaseSplitWidget(m_projectDataCopy, this); - // FIXME: This fails to compile pageChipset = new DatabaseSplitWidget(m_projectDataCopy, this); + pageChipset = new DatabaseSplitWidget(m_projectDataCopy, this); pageCommonevents = new DatabaseSplitWidget(m_projectDataCopy, this); pageSwitches = new DatabaseSplitWidget(m_projectDataCopy, this); pageVariables = new DatabaseSplitWidget(m_projectDataCopy, this); @@ -66,7 +66,7 @@ DatabaseDialog::DatabaseDialog(ProjectData& project, QWidget *parent) : ui->tabOld_Pages->insertTab(9, pageBattleAnimations2, tr("Battle Animation 2")); ui->tabOld_Pages->insertTab(10, pageBattleScreen, tr("Battle screen")); ui->tabOld_Pages->insertTab(11, pageTerrain, tr("Terrain")); - // FIXME ui->tabOld_Pages->insertTab(12, pageChipset, tr("Chipset")); + ui->tabOld_Pages->insertTab(12, pageChipset, tr("Chipset")); ui->tabOld_Pages->insertTab(13, pageVocabulary, tr("Vocabulary")); ui->tabOld_Pages->insertTab(14, pageSystem, tr("System")); ui->tabOld_Pages->insertTab(15, pageSystem2, tr("System")); From 850a99eaf54ec2fe94f6a929a367be5c5a780315 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 29 Nov 2021 22:05:01 +0100 Subject: [PATCH 2/5] Chipset Widget: Start implementation, including a Tilemap renderer --- CMakeLists.txt | 6 + src/ui/database/chipset_widget.cpp | 63 +- src/ui/database/chipset_widget.h | 10 + src/ui/database/chipset_widget.ui | 928 ++++++------------------ src/ui/picker/picker_chipset_widget.cpp | 29 + src/ui/picker/picker_chipset_widget.h | 35 + src/ui/viewer/chipset_graphics_view.cpp | 119 +++ src/ui/viewer/chipset_graphics_view.h | 89 +++ src/ui/viewer/rpg_graphics_view.h | 2 + src/ui/viewer/tile_graphics_item.cpp | 143 ++++ src/ui/viewer/tile_graphics_item.h | 59 ++ 11 files changed, 768 insertions(+), 715 deletions(-) create mode 100644 src/ui/picker/picker_chipset_widget.cpp create mode 100644 src/ui/picker/picker_chipset_widget.h create mode 100644 src/ui/viewer/chipset_graphics_view.cpp create mode 100644 src/ui/viewer/chipset_graphics_view.h create mode 100644 src/ui/viewer/tile_graphics_item.cpp create mode 100644 src/ui/viewer/tile_graphics_item.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ac79748..a9bfaf46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,8 @@ set(EDITOR_SOURCES src/ui/picker/picker_child_widget.h src/ui/picker/picker_charset_widget.cpp src/ui/picker/picker_charset_widget.h + src/ui/picker/picker_chipset_widget.cpp + src/ui/picker/picker_chipset_widget.h src/ui/picker/picker_faceset_widget.cpp src/ui/picker/picker_faceset_widget.h src/ui/picker/picker_dialog.cpp @@ -308,12 +310,16 @@ set(EDITOR_SOURCES src/ui/viewer/battle_animation_graphics_item.h src/ui/viewer/charset_graphics_item.cpp src/ui/viewer/charset_graphics_item.h + src/ui/viewer/chipset_graphics_view.cpp + src/ui/viewer/chipset_graphics_view.h src/ui/viewer/faceset_graphics_item.cpp src/ui/viewer/faceset_graphics_item.h src/ui/viewer/rpg_graphics_view.cpp src/ui/viewer/rpg_graphics_view.h src/ui/viewer/stat_curve_graphics_item.cpp src/ui/viewer/stat_curve_graphics_item.h + src/ui/viewer/tile_graphics_item.cpp + src/ui/viewer/tile_graphics_item.cpp ) add_library(${PROJECT_NAME} STATIC ${EDITOR_SOURCES}) diff --git a/src/ui/database/chipset_widget.cpp b/src/ui/database/chipset_widget.cpp index 8dbdb40a..4ceeb16f 100644 --- a/src/ui/database/chipset_widget.cpp +++ b/src/ui/database/chipset_widget.cpp @@ -18,12 +18,44 @@ #include "chipset_widget.h" #include "ui_chipset_widget.h" +#include "common/lcf_widget_binding.h" +#include "ui/picker/picker_chipset_widget.h" +#include "ui/picker/picker_dialog.h" + +#include + ChipsetWidget::ChipsetWidget(ProjectData& project, QWidget *parent) : QWidget(parent), ui(new Ui::ChipsetWidget), m_project(project) { ui->setupUi(this); + + QListView& list = *ui->listTerrain; + list.setModel(new RpgModel(project, project.database().terrains, parent)); + + LcfWidgetBinding::connect(this, ui->lineName); + + m_buttonGroupSequence = new QButtonGroup(this); + m_buttonGroupSequence->addButton(ui->radioLowerAnim1232); + m_buttonGroupSequence->setId(ui->radioLowerAnim1232, 0); + m_buttonGroupSequence->addButton(ui->radioLowerAnim123); + m_buttonGroupSequence->setId(ui->radioLowerAnim123, 1); + LcfWidgetBinding::connect(this, m_buttonGroupSequence); + + m_buttonGroupSpeed = new QButtonGroup(this); + m_buttonGroupSpeed->addButton(ui->radioLowerAnimSlow); + m_buttonGroupSpeed->setId(ui->radioLowerAnimSlow, 0); + m_buttonGroupSpeed->addButton(ui->radioLowerAnimFast); + m_buttonGroupSpeed->setId(ui->radioLowerAnimFast, 1); + LcfWidgetBinding::connect(this, m_buttonGroupSpeed); + + ui->graphicsChipsetLower->setProjectData(project); + ui->graphicsChipsetLower->setLayer(ChipsetGraphicsView::Layer::Lower); + ui->graphicsChipsetUpper->setProjectData(project); + ui->graphicsChipsetUpper->setLayer(ChipsetGraphicsView::Layer::Upper); + + QObject::connect(ui->pushTileset, &QPushButton::clicked, this, &ChipsetWidget::chipsetClicked); } ChipsetWidget::~ChipsetWidget() @@ -31,7 +63,36 @@ ChipsetWidget::~ChipsetWidget() delete ui; } -void ChipsetWidget::setData(lcf::rpg::Chipset* /* chipset */) +void ChipsetWidget::setData(lcf::rpg::Chipset* chipset) { + if (!chipset) { + chipset = &dummy; + } + m_current = chipset; + + LcfWidgetBinding::bind(ui->lineName, chipset->name); + LcfWidgetBinding::bind(m_buttonGroupSpeed, chipset->animation_speed); + LcfWidgetBinding::bind(m_buttonGroupSequence, chipset->animation_type); + + ui->graphicsChipsetLower->setChipset(*chipset); + ui->graphicsChipsetUpper->setChipset(*chipset); + + ui->graphicsChipsetLower->refresh(); + ui->graphicsChipsetUpper->refresh(); + + ui->pushTileset->setText(ToQString(chipset->chipset_name)); + + this->setEnabled(chipset != &dummy); +} +void ChipsetWidget::chipsetClicked() { + auto* widget = new PickerChipsetWidget(this); + PickerDialog dialog(m_project, FileFinder::FileType::Image, widget, this); + QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) { + m_current->chipset_name = ToDBString(baseName); + ui->pushTileset->setText(ToQString(m_current->chipset_name)); + //m_charsetItem->refresh(*m_current); + }); + dialog.setDirectoryAndFile(CHIPSET, ToQString(m_current->chipset_name)); + dialog.exec(); } diff --git a/src/ui/database/chipset_widget.h b/src/ui/database/chipset_widget.h index 9ef0c0f4..26345995 100644 --- a/src/ui/database/chipset_widget.h +++ b/src/ui/database/chipset_widget.h @@ -26,6 +26,8 @@ namespace Ui { class ChipsetWidget; } +class QButtonGroup; + class ChipsetWidget : public QWidget { Q_OBJECT @@ -39,7 +41,15 @@ class ChipsetWidget : public QWidget void setData(lcf::rpg::Chipset* chipset); private: + void chipsetClicked(); + + lcf::rpg::Chipset dummy; + lcf::rpg::Chipset *m_current = nullptr; + Ui::ChipsetWidget *ui; ProjectData& m_project; + + QButtonGroup* m_buttonGroupSequence = nullptr; + QButtonGroup* m_buttonGroupSpeed = nullptr; }; diff --git a/src/ui/database/chipset_widget.ui b/src/ui/database/chipset_widget.ui index a18f36c2..f2a9645c 100644 --- a/src/ui/database/chipset_widget.ui +++ b/src/ui/database/chipset_widget.ui @@ -6,764 +6,264 @@ 0 0 - 690 - 557 + 929 + 599 Form - - - - 10 - 10 - 151 - 23 - - - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 220 - - - - - - - 0 - 0 - 0 - - - - - - - - - 10 - 75 - true - - - - true - - - Titleset - - - Qt::AlignCenter - - - - - - 10 - 60 - 150 - 465 - - - - - 150 - 16777215 - - - - true - - - - - - 180 - 10 - 491 - 501 - - - - - 1 - 0 - - - - QFrame::WinPanel - - - QFrame::Sunken - - - - - - - - Name - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - 0 - 0 - + + + + + 0 + + + + Lower Layer + + + + + + + + Editing Mode + + + + + Terrain + + + groupLowerEditMode + + + + + + + Passability + + + groupLowerEditMode + + + + + + + Passage + + + groupLowerEditMode + + + + - - + + + + Set uniform Terrain + + + + + - Title File + Water Animation - - - 3 - - - 5 - - - 5 - - - 5 - - - 5 - + - + - - - ... + + + Sequence + + + + + 1-2-3-2 + + + + + + + 1-2-3 + + + + + + + + + + Speed + + + + + + Slow + + + + + + + Fast + + + + - - - - - - - - GroupBox - + + + + + - - - - - 0 - - - - LowerLayer - - - - - 180 - 20 - 201 - 341 - - - - - - - 10 - 20 - 151 - 111 - - - - Editing Mode - - - - - 0 - 20 - 151 - 100 - + + + Upper Layer + + + + + + + 0 + 0 + + + + Editing Mode - - - + + + - Terrain + Counter + + groupUpperEditMode + - - + + Passability + + groupUpperEditMode + - - + + - Directional Pass + Passage + + groupUpperEditMode + - - - - - 20 - 140 - 141 - 21 - - - - Set uniform Terrain - - - - - - 20 - 200 - 141 - 161 - - - - Water Animation - - - - - 10 - 40 - 121 - 51 - + + + + + + + + Qt::Vertical - - Sequence + + + 20 + 315 + + + + + + + + + + + + + + + + + + + Name: - - - - 20 - 10 - 82 - 17 - - - - 1-2-3-2 - - - - - - 20 - 30 - 82 - 17 - - - - 1-2-3 - - - - - - 10 - 100 - 121 - 51 - + + + + + + + + + + + + Tileset: - - Speed + + + + + + PushButton - - - - 20 - 10 - 82 - 17 - - - - Slow - - - - - - 20 - 30 - 82 - 17 - - - - Fast - - - - - - - UpperLayer - - - - - - - - - - 10 - 40 - 150 - 20 - - - - Filter - - + + + + + + + + + TileGraphicsView + QGraphicsView +
ui/viewer/rpg_graphics_view.h
+
+ + ChipsetGraphicsView + QGraphicsView +
ui/viewer/chipset_graphics_view.h
+
+
+ + + +
diff --git a/src/ui/picker/picker_chipset_widget.cpp b/src/ui/picker/picker_chipset_widget.cpp new file mode 100644 index 00000000..00fd07e8 --- /dev/null +++ b/src/ui/picker/picker_chipset_widget.cpp @@ -0,0 +1,29 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#include "picker_chipset_widget.h" +#include "ui/viewer/rpg_graphics_view.h" +#include + +void PickerChipsetWidget::imageChanged(QPixmap image) { + if (!m_pixmap) { + m_pixmap = new QGraphicsPixmapItem(image); + } + + m_pixmap->setPixmap(image); + m_view->setItem(m_pixmap); +} diff --git a/src/ui/picker/picker_chipset_widget.h b/src/ui/picker/picker_chipset_widget.h new file mode 100644 index 00000000..79ead99c --- /dev/null +++ b/src/ui/picker/picker_chipset_widget.h @@ -0,0 +1,35 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#pragma once + +#include +#include "picker_child_widget.h" + +class QGraphicsScene; +class QGraphicsPixmapItem; + +class PickerChipsetWidget : public PickerChildWidget { + Q_OBJECT +public: + PickerChipsetWidget(QWidget* parent = nullptr) : PickerChildWidget(parent) {} + + void imageChanged(QPixmap image) override; + +private: + QGraphicsPixmapItem* m_pixmap = nullptr; +}; diff --git a/src/ui/viewer/chipset_graphics_view.cpp b/src/ui/viewer/chipset_graphics_view.cpp new file mode 100644 index 00000000..16e9ac5d --- /dev/null +++ b/src/ui/viewer/chipset_graphics_view.cpp @@ -0,0 +1,119 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#include "chipset_graphics_view.h" +#include "model/project.h" +#include "common/dbstring.h" +#include "common/image_loader.h" +#include "defines.h" +#include "tile_graphics_item.h" +#include + +ChipsetGraphicsView::ChipsetGraphicsView(QWidget* parent) : QGraphicsView(parent) { + setScene(new QGraphicsScene(this)); + scale(2, 2); +} + +void ChipsetGraphicsView::setProjectData(ProjectData& project) { + m_project = &project; +} + +void ChipsetGraphicsView::setChipset(lcf::rpg::Chipset& chipset) { + if (m_chipset == &chipset) { + return; + } + + m_chipset = &chipset; + m_chipset_pix = ImageLoader::Load(m_project->project().findFile(CHIPSET, ToQString(chipset.chipset_name), FileFinder::FileType::Image)); +} + +void ChipsetGraphicsView::enableTimer() { + /*m_timer.reset(new QTimer()); + QObject::connect(m_timer.get(), &QTimer::timeout, scene(), &QGraphicsScene::advance); + m_timer->start(1000 / 33);*/ +} + +void ChipsetGraphicsView::mousePressEvent(QMouseEvent* event) { + /*if (event->button() == Qt::LeftButton && m_item) { + const auto& p = mapToScene(event->pos()); + if (m_item->boundingRect().contains(p)) { + emit clicked(p); + } + } + QGraphicsView::mousePressEvent(event);*/ +} + +bool ChipsetGraphicsView::drawGrid() const { + return m_draw_grid; +} + +void ChipsetGraphicsView::setDrawGrid(bool draw_grid) { + m_draw_grid = draw_grid; +} + +int ChipsetGraphicsView::tilesPerCol() const { + return m_tiles_per_col; +} + +void ChipsetGraphicsView::setTilesPerCol(int tiles_per_col) { + m_tiles_per_col = tiles_per_col; +} + +ChipsetGraphicsView::Layer ChipsetGraphicsView::layer() const { + return m_layer; +} + +void ChipsetGraphicsView::setLayer(ChipsetGraphicsView::Layer layer) { + m_layer = layer; +} + +ChipsetGraphicsView::EditMode ChipsetGraphicsView::editMode() const { + return m_editmode; +} + +void ChipsetGraphicsView::setEditMode(ChipsetGraphicsView::EditMode edit_mode) { + m_editmode = edit_mode; +} + +void ChipsetGraphicsView::refresh() { + assert(m_project); + assert(m_chipset); + + const int TILE_SIZE = 16; + + if (layer() == Layer::Lower) { + scene()->clear(); + for (int terrain_id = 0; terrain_id < 162; terrain_id++) { + auto* tile = new TileGraphicsItem(*m_project, *m_chipset, m_chipset_pix); + tile->setTileIndex(terrain_id); + tile->setLayer(Layer::Lower); + tile->setEditMode(m_editmode); + tile->setPos(QPointF(terrain_id * TILE_SIZE % (TILE_SIZE * m_tiles_per_col), terrain_id / m_tiles_per_col * TILE_SIZE)); + scene()->addItem(tile); + } + } else if (layer() == Layer::Upper) { + scene()->clear(); + for (int terrain_id = 0; terrain_id < 144; terrain_id++) { + auto* tile = new TileGraphicsItem(*m_project, *m_chipset, m_chipset_pix); + tile->setTileIndex(terrain_id); + tile->setLayer(Layer::Upper); + tile->setEditMode(m_editmode); + tile->setPos(QPointF(terrain_id * TILE_SIZE % (TILE_SIZE * m_tiles_per_col), terrain_id / m_tiles_per_col * TILE_SIZE)); + scene()->addItem(tile); + } + } +} diff --git a/src/ui/viewer/chipset_graphics_view.h b/src/ui/viewer/chipset_graphics_view.h new file mode 100644 index 00000000..f687d46b --- /dev/null +++ b/src/ui/viewer/chipset_graphics_view.h @@ -0,0 +1,89 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +class ProjectData; + +namespace lcf::rpg { + class Chipset; +} + +class ChipsetGraphicsView : public QGraphicsView { +Q_OBJECT + +public: + enum class Layer { + None, + Lower, + Upper + }; + + enum class EditMode { + None, + Terrain, + Passability, + Passage, + Counter + }; + + explicit ChipsetGraphicsView(QWidget* parent); + + void setProjectData(ProjectData& project); + + void setChipset(lcf::rpg::Chipset& chipset); + + void enableTimer(); + + bool drawGrid() const; + void setDrawGrid(bool draw_grid); + + int tilesPerCol() const; + void setTilesPerCol(int tiles_per_col); + + Layer layer() const; + void setLayer(Layer layer); + + EditMode editMode() const; + void setEditMode(EditMode edit_mode); + + void refresh(); + +signals: + void clicked(const QPointF&); + +protected: + void mousePressEvent(QMouseEvent* event) override; + + ProjectData* m_project = nullptr; + lcf::rpg::Chipset* m_chipset = nullptr; + std::unique_ptr m_timer; + QPixmap m_chipset_pix; + + bool m_draw_grid = false; + int m_tiles_per_col = 6; + EditMode m_editmode = EditMode::Terrain; + Layer m_layer = Layer::None; +}; diff --git a/src/ui/viewer/rpg_graphics_view.h b/src/ui/viewer/rpg_graphics_view.h index 1b3d3bf0..f665fcba 100644 --- a/src/ui/viewer/rpg_graphics_view.h +++ b/src/ui/viewer/rpg_graphics_view.h @@ -27,6 +27,7 @@ #include "charset_graphics_item.h" #include "faceset_graphics_item.h" +#include "tile_graphics_item.h" class RpgGraphicsViewBase : public QGraphicsView { Q_OBJECT @@ -79,4 +80,5 @@ class RpgGraphicsView : public RpgGraphicsViewBase { using CharSetGraphicsView = RpgGraphicsView; using FaceSetGraphicsView = RpgGraphicsView; +using TileGraphicsView = RpgGraphicsView; using PixmapGraphicsView = RpgGraphicsView; diff --git a/src/ui/viewer/tile_graphics_item.cpp b/src/ui/viewer/tile_graphics_item.cpp new file mode 100644 index 00000000..54cca6c2 --- /dev/null +++ b/src/ui/viewer/tile_graphics_item.cpp @@ -0,0 +1,143 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#include "tile_graphics_item.h" +#include "core.h" +#include "common/image_loader.h" +#include "common/dbstring.h" +#include "model/project_data.h" + +#include + +TileGraphicsItem::TileGraphicsItem(ProjectData& project, lcf::rpg::Chipset& chipset, const QPixmap pix) : + QGraphicsItem(), m_project(project), m_chipset(&chipset), m_image(pix) { +} + +QRectF TileGraphicsItem::tileRect() const { + const int TILE_SIZE = 16; + + int sub_tile_id = 0; + int x; + int y; + + if (layer() == ChipsetGraphicsView::Layer::Lower) { + if (m_tile_index > 0 && m_tile_index < 3) { + x = m_tile_index % 2 * TILE_SIZE * 3; + y = m_tile_index / 2 * TILE_SIZE * 4; + } else if (m_tile_index >= 3 && m_tile_index < 6) { + sub_tile_id = m_tile_index - 3; + x = 3 * TILE_SIZE; + y = 4 * TILE_SIZE; + } else if (m_tile_index >= 6 && m_tile_index < 10) { + x = m_tile_index % 2 * TILE_SIZE * 3; + y = 128 + (m_tile_index - 6) / 2 * TILE_SIZE * 4; + } else if (m_tile_index >= 10 && m_tile_index < 18) { + x = m_tile_index % 2 * TILE_SIZE * 3 + 6 * TILE_SIZE; + y = (m_tile_index - 10) / 2 * TILE_SIZE * 4; + } else if (m_tile_index >= 18 && m_tile_index < 114) { + sub_tile_id = m_tile_index - 18; + x = 192; + y = 0; + } else if (m_tile_index >= 114 && m_tile_index < 170) { + sub_tile_id = m_tile_index - 114; + x = 288; + y = 0; + } else { // Invalid -> Use water tile (first one) + x = 0; + y = 0; + } + + x += sub_tile_id % 6 * 16; + y += sub_tile_id / 6 * 16; + + return QRectF(x, y, TILE_SIZE, TILE_SIZE); + } else if (layer() == ChipsetGraphicsView::Layer::Upper) { + if (m_tile_index > 0 && m_tile_index < 48) { + sub_tile_id = m_tile_index; + x = 288; + y = 128; + } else if (m_tile_index >= 48 && m_tile_index < 96) { + sub_tile_id = m_tile_index - 48; + x = 384; + y = 0; + } else if (m_tile_index >= 96 && m_tile_index < 144) { + sub_tile_id = m_tile_index - 96; + x = 384; + y = 128; + } else { // Invalid -> Use empty tile (first one) + x = 288; + y = 128; + } + + x += sub_tile_id % 6 * 16; + y += sub_tile_id / 6 * 16; + + return QRectF(x, y, TILE_SIZE, TILE_SIZE); + } else { + assert(false); + } + + return QRectF(); +} + +QRectF TileGraphicsItem::boundingRect() const { + return {0., 0., 16., 16.}; +} + +void TileGraphicsItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) { + painter->drawPixmap(boundingRect(), m_image, tileRect()); +} + +void TileGraphicsItem::refresh(const lcf::rpg::Chipset& chipset) { + refresh(ToQString(chipset.chipset_name)); +} + +void TileGraphicsItem::refresh(const QString& filename) { + if (m_filename != filename) { + m_filename = filename; + m_image = ImageLoader::Load(m_project.project().findFile(CHIPSET, filename, FileFinder::FileType::Image)); + } + update(); +} + +void TileGraphicsItem::clicked() { + // todo +} + +int TileGraphicsItem::tileIndex() const { + return m_tile_index; +} + +void TileGraphicsItem::setTileIndex(int index) { + m_tile_index = index; +} + +ChipsetGraphicsView::Layer TileGraphicsItem::layer() const { + return m_layer; +} + +void TileGraphicsItem::setLayer(ChipsetGraphicsView::Layer layer) { + m_layer = layer; +} + +ChipsetGraphicsView::EditMode TileGraphicsItem::editMode() const { + return m_editmode; +} + +void TileGraphicsItem::setEditMode(ChipsetGraphicsView::EditMode edit_mode) { + m_editmode = edit_mode; +} diff --git a/src/ui/viewer/tile_graphics_item.h b/src/ui/viewer/tile_graphics_item.h new file mode 100644 index 00000000..7f5a9373 --- /dev/null +++ b/src/ui/viewer/tile_graphics_item.h @@ -0,0 +1,59 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#pragma once + +#include +#include "chipset_graphics_view.h" + +namespace lcf::rpg { + class Chipset; +} + +class ProjectData; + +class TileGraphicsItem : public QGraphicsItem { +public: + explicit TileGraphicsItem(ProjectData& project, lcf::rpg::Chipset& chipset, const QPixmap pix = QPixmap(16,16)); + + QRectF boundingRect() const override; + QRectF tileRect() const; + void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override; + + void refresh(const lcf::rpg::Chipset& chipset); + void refresh(const QString& filename); + + void clicked(); + + int tileIndex() const; + void setTileIndex(int index); + + ChipsetGraphicsView::Layer layer() const; + void setLayer(ChipsetGraphicsView::Layer layer); + + ChipsetGraphicsView::EditMode editMode() const; + void setEditMode(ChipsetGraphicsView::EditMode edit_mode); + +private: + ProjectData& m_project; + int m_tile_index = 0; + ChipsetGraphicsView::Layer m_layer = ChipsetGraphicsView::Layer::None; + ChipsetGraphicsView::EditMode m_editmode = ChipsetGraphicsView::EditMode::None; + QString m_filename; + lcf::rpg::Chipset* m_chipset = nullptr; + QPixmap m_image; +}; From 098a64153520d7edb76b1212ba82c4c8ea66cb25 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 29 Nov 2021 22:22:58 +0100 Subject: [PATCH 3/5] ChipsetGraphicsView: Support rendering of a grid --- src/ui/database/chipset_widget.cpp | 10 ++++---- src/ui/database/chipset_widget.ui | 4 ++-- src/ui/viewer/chipset_graphics_view.cpp | 32 ++++++++++++++++++++----- src/ui/viewer/chipset_graphics_view.h | 6 ++--- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/ui/database/chipset_widget.cpp b/src/ui/database/chipset_widget.cpp index 4ceeb16f..e6aaf253 100644 --- a/src/ui/database/chipset_widget.cpp +++ b/src/ui/database/chipset_widget.cpp @@ -74,11 +74,11 @@ void ChipsetWidget::setData(lcf::rpg::Chipset* chipset) LcfWidgetBinding::bind(m_buttonGroupSpeed, chipset->animation_speed); LcfWidgetBinding::bind(m_buttonGroupSequence, chipset->animation_type); - ui->graphicsChipsetLower->setChipset(*chipset); - ui->graphicsChipsetUpper->setChipset(*chipset); - - ui->graphicsChipsetLower->refresh(); - ui->graphicsChipsetUpper->refresh(); + for (auto* view: {ui->graphicsChipsetLower, ui->graphicsChipsetUpper}) { + view->setChipset(*chipset); + view->setShowGrid(true); + view->refresh(); + } ui->pushTileset->setText(ToQString(chipset->chipset_name)); diff --git a/src/ui/database/chipset_widget.ui b/src/ui/database/chipset_widget.ui index f2a9645c..2ee3767b 100644 --- a/src/ui/database/chipset_widget.ui +++ b/src/ui/database/chipset_widget.ui @@ -238,7 +238,7 @@ - PushButton + @@ -263,7 +263,7 @@ - + diff --git a/src/ui/viewer/chipset_graphics_view.cpp b/src/ui/viewer/chipset_graphics_view.cpp index 16e9ac5d..cb0f4b83 100644 --- a/src/ui/viewer/chipset_graphics_view.cpp +++ b/src/ui/viewer/chipset_graphics_view.cpp @@ -57,12 +57,12 @@ void ChipsetGraphicsView::mousePressEvent(QMouseEvent* event) { QGraphicsView::mousePressEvent(event);*/ } -bool ChipsetGraphicsView::drawGrid() const { - return m_draw_grid; +bool ChipsetGraphicsView::showGrid() const { + return m_show_grid; } -void ChipsetGraphicsView::setDrawGrid(bool draw_grid) { - m_draw_grid = draw_grid; +void ChipsetGraphicsView::setShowGrid(bool show_grid) { + m_show_grid = show_grid; } int ChipsetGraphicsView::tilesPerCol() const { @@ -95,9 +95,12 @@ void ChipsetGraphicsView::refresh() { const int TILE_SIZE = 16; + int num_tiles = 0; + if (layer() == Layer::Lower) { scene()->clear(); - for (int terrain_id = 0; terrain_id < 162; terrain_id++) { + num_tiles = 162; + for (int terrain_id = 0; terrain_id < num_tiles; terrain_id++) { auto* tile = new TileGraphicsItem(*m_project, *m_chipset, m_chipset_pix); tile->setTileIndex(terrain_id); tile->setLayer(Layer::Lower); @@ -107,7 +110,8 @@ void ChipsetGraphicsView::refresh() { } } else if (layer() == Layer::Upper) { scene()->clear(); - for (int terrain_id = 0; terrain_id < 144; terrain_id++) { + num_tiles = 144; + for (int terrain_id = 0; terrain_id < num_tiles; terrain_id++) { auto* tile = new TileGraphicsItem(*m_project, *m_chipset, m_chipset_pix); tile->setTileIndex(terrain_id); tile->setLayer(Layer::Upper); @@ -116,4 +120,20 @@ void ChipsetGraphicsView::refresh() { scene()->addItem(tile); } } + + if (showGrid() && num_tiles > 0) { + // Draw X Grid + for (int i = 1; i < num_tiles - 1; ++i) { + if (i % m_tiles_per_col == 0) { + int y = i / m_tiles_per_col * TILE_SIZE; + scene()->addLine(0, y, m_tiles_per_col * TILE_SIZE, y); + } + } + + // Draw Y Grid + for (int i = 1; i < m_tiles_per_col; ++i) { + int x = i * TILE_SIZE; + scene()->addLine(x, 0, x, num_tiles / m_tiles_per_col * TILE_SIZE); + } + } } diff --git a/src/ui/viewer/chipset_graphics_view.h b/src/ui/viewer/chipset_graphics_view.h index f687d46b..8afc07f0 100644 --- a/src/ui/viewer/chipset_graphics_view.h +++ b/src/ui/viewer/chipset_graphics_view.h @@ -57,8 +57,8 @@ Q_OBJECT void enableTimer(); - bool drawGrid() const; - void setDrawGrid(bool draw_grid); + bool showGrid() const; + void setShowGrid(bool show_grid); int tilesPerCol() const; void setTilesPerCol(int tiles_per_col); @@ -82,7 +82,7 @@ Q_OBJECT std::unique_ptr m_timer; QPixmap m_chipset_pix; - bool m_draw_grid = false; + bool m_show_grid = false; int m_tiles_per_col = 6; EditMode m_editmode = EditMode::Terrain; Layer m_layer = Layer::None; From 9a0052038ffb6034744cc7232fbe8d580f5f6726 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 29 Nov 2021 22:28:52 +0100 Subject: [PATCH 4/5] Chipset: Do not load empty filenames. Improve Ui --- src/ui/database/chipset_widget.ui | 48 ++++++++++++++++++++++--- src/ui/viewer/chipset_graphics_view.cpp | 5 ++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/ui/database/chipset_widget.ui b/src/ui/database/chipset_widget.ui index 2ee3767b..502fc995 100644 --- a/src/ui/database/chipset_widget.ui +++ b/src/ui/database/chipset_widget.ui @@ -16,6 +16,12 @@ + + + 4 + 0 + + 0 @@ -79,7 +85,14 @@ - + + + + 0 + 0 + + + @@ -127,13 +140,33 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + - + + + + 0 + 0 + + + @@ -208,7 +241,14 @@ - + + + + 1 + 0 + + + @@ -263,7 +303,7 @@ - + diff --git a/src/ui/viewer/chipset_graphics_view.cpp b/src/ui/viewer/chipset_graphics_view.cpp index cb0f4b83..537638f8 100644 --- a/src/ui/viewer/chipset_graphics_view.cpp +++ b/src/ui/viewer/chipset_graphics_view.cpp @@ -38,7 +38,10 @@ void ChipsetGraphicsView::setChipset(lcf::rpg::Chipset& chipset) { } m_chipset = &chipset; - m_chipset_pix = ImageLoader::Load(m_project->project().findFile(CHIPSET, ToQString(chipset.chipset_name), FileFinder::FileType::Image)); + QString file = m_project->project().findFile(CHIPSET, ToQString(chipset.chipset_name), FileFinder::FileType::Image); + if (!file.isEmpty()) { + m_chipset_pix = ImageLoader::Load(file); + } } void ChipsetGraphicsView::enableTimer() { From b8684ed651256466d7e3f6b80de7852933c96963 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 29 Nov 2021 23:13:17 +0100 Subject: [PATCH 5/5] Chipset: Add animated water tile but the animation is not perfect yet --- src/ui/database/chipset_widget.cpp | 29 ++++++++++++++++- src/ui/database/chipset_widget.h | 2 ++ src/ui/database/chipset_widget.ui | 4 +-- src/ui/viewer/chipset_graphics_view.cpp | 8 ++--- src/ui/viewer/rpg_graphics_view.cpp | 3 +- src/ui/viewer/tile_graphics_item.cpp | 43 ++++++++++++++++++++++--- src/ui/viewer/tile_graphics_item.h | 15 ++++++++- 7 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/ui/database/chipset_widget.cpp b/src/ui/database/chipset_widget.cpp index e6aaf253..6fd6e0e3 100644 --- a/src/ui/database/chipset_widget.cpp +++ b/src/ui/database/chipset_widget.cpp @@ -42,6 +42,12 @@ ChipsetWidget::ChipsetWidget(ProjectData& project, QWidget *parent) : m_buttonGroupSequence->addButton(ui->radioLowerAnim123); m_buttonGroupSequence->setId(ui->radioLowerAnim123, 1); LcfWidgetBinding::connect(this, m_buttonGroupSequence); + connect(m_buttonGroupSequence, QOverload::of(&QButtonGroup::buttonClicked), + [=](QAbstractButton*){ + if (m_water_tile) { + m_water_tile->setAnimType(m_buttonGroupSequence->checkedId()); + } + }); m_buttonGroupSpeed = new QButtonGroup(this); m_buttonGroupSpeed->addButton(ui->radioLowerAnimSlow); @@ -49,12 +55,21 @@ ChipsetWidget::ChipsetWidget(ProjectData& project, QWidget *parent) : m_buttonGroupSpeed->addButton(ui->radioLowerAnimFast); m_buttonGroupSpeed->setId(ui->radioLowerAnimFast, 1); LcfWidgetBinding::connect(this, m_buttonGroupSpeed); + connect(m_buttonGroupSpeed, QOverload::of(&QButtonGroup::buttonClicked), + [=](QAbstractButton*){ + if (m_water_tile) { + m_water_tile->setAnimSpeed(m_buttonGroupSpeed->checkedId()); + } + }); ui->graphicsChipsetLower->setProjectData(project); ui->graphicsChipsetLower->setLayer(ChipsetGraphicsView::Layer::Lower); ui->graphicsChipsetUpper->setProjectData(project); ui->graphicsChipsetUpper->setLayer(ChipsetGraphicsView::Layer::Upper); + ui->viewWaterAnim->scale(2., 2.); + ui->viewWaterAnim->enableTimer(); + QObject::connect(ui->pushTileset, &QPushButton::clicked, this, &ChipsetWidget::chipsetClicked); } @@ -80,6 +95,18 @@ void ChipsetWidget::setData(lcf::rpg::Chipset* chipset) view->refresh(); } + QString file = m_project.project().findFile(CHIPSET, ToQString(m_current->chipset_name), FileFinder::FileType::Image); + if (!file.isEmpty()) { + m_water_tile = new TileGraphicsItem(m_project, nullptr, ImageLoader::Load(file)); + m_water_tile->setLayer(ChipsetGraphicsView::Layer::Lower); + m_water_tile->setTileIndex(2); + m_water_tile->setAnimType(m_current->animation_type); + m_water_tile->setAnimSpeed(m_current->animation_speed); + ui->viewWaterAnim->setItem(m_water_tile); + } else { + ui->viewWaterAnim->setItem(nullptr); + } + ui->pushTileset->setText(ToQString(chipset->chipset_name)); this->setEnabled(chipset != &dummy); @@ -91,7 +118,7 @@ void ChipsetWidget::chipsetClicked() { QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) { m_current->chipset_name = ToDBString(baseName); ui->pushTileset->setText(ToQString(m_current->chipset_name)); - //m_charsetItem->refresh(*m_current); + setData(m_current); }); dialog.setDirectoryAndFile(CHIPSET, ToQString(m_current->chipset_name)); dialog.exec(); diff --git a/src/ui/database/chipset_widget.h b/src/ui/database/chipset_widget.h index 26345995..c46d0ed1 100644 --- a/src/ui/database/chipset_widget.h +++ b/src/ui/database/chipset_widget.h @@ -27,6 +27,7 @@ class ChipsetWidget; } class QButtonGroup; +class TileGraphicsItem; class ChipsetWidget : public QWidget { @@ -49,6 +50,7 @@ class ChipsetWidget : public QWidget Ui::ChipsetWidget *ui; ProjectData& m_project; + TileGraphicsItem* m_water_tile = nullptr; QButtonGroup* m_buttonGroupSequence = nullptr; QButtonGroup* m_buttonGroupSpeed = nullptr; }; diff --git a/src/ui/database/chipset_widget.ui b/src/ui/database/chipset_widget.ui index 502fc995..bc3f4be5 100644 --- a/src/ui/database/chipset_widget.ui +++ b/src/ui/database/chipset_widget.ui @@ -7,7 +7,7 @@ 0 0 929 - 599 + 605 @@ -85,7 +85,7 @@ - + 0 diff --git a/src/ui/viewer/chipset_graphics_view.cpp b/src/ui/viewer/chipset_graphics_view.cpp index 537638f8..abfcd63b 100644 --- a/src/ui/viewer/chipset_graphics_view.cpp +++ b/src/ui/viewer/chipset_graphics_view.cpp @@ -33,10 +33,6 @@ void ChipsetGraphicsView::setProjectData(ProjectData& project) { } void ChipsetGraphicsView::setChipset(lcf::rpg::Chipset& chipset) { - if (m_chipset == &chipset) { - return; - } - m_chipset = &chipset; QString file = m_project->project().findFile(CHIPSET, ToQString(chipset.chipset_name), FileFinder::FileType::Image); if (!file.isEmpty()) { @@ -104,7 +100,7 @@ void ChipsetGraphicsView::refresh() { scene()->clear(); num_tiles = 162; for (int terrain_id = 0; terrain_id < num_tiles; terrain_id++) { - auto* tile = new TileGraphicsItem(*m_project, *m_chipset, m_chipset_pix); + auto* tile = new TileGraphicsItem(*m_project, m_chipset, m_chipset_pix); tile->setTileIndex(terrain_id); tile->setLayer(Layer::Lower); tile->setEditMode(m_editmode); @@ -115,7 +111,7 @@ void ChipsetGraphicsView::refresh() { scene()->clear(); num_tiles = 144; for (int terrain_id = 0; terrain_id < num_tiles; terrain_id++) { - auto* tile = new TileGraphicsItem(*m_project, *m_chipset, m_chipset_pix); + auto* tile = new TileGraphicsItem(*m_project, m_chipset, m_chipset_pix); tile->setTileIndex(terrain_id); tile->setLayer(Layer::Upper); tile->setEditMode(m_editmode); diff --git a/src/ui/viewer/rpg_graphics_view.cpp b/src/ui/viewer/rpg_graphics_view.cpp index c3f709d7..41fda574 100644 --- a/src/ui/viewer/rpg_graphics_view.cpp +++ b/src/ui/viewer/rpg_graphics_view.cpp @@ -17,13 +17,14 @@ #include "rpg_graphics_view.h" #include +#include RpgGraphicsViewBase::RpgGraphicsViewBase(QWidget* parent) : QGraphicsView(parent) { setScene(new QGraphicsScene(this)); } void RpgGraphicsViewBase::enableTimer() { - m_timer.reset(new QTimer()); + m_timer = std::make_unique(); QObject::connect(m_timer.get(), &QTimer::timeout, scene(), &QGraphicsScene::advance); m_timer->start(1000 / 33); } diff --git a/src/ui/viewer/tile_graphics_item.cpp b/src/ui/viewer/tile_graphics_item.cpp index 54cca6c2..2e3e4b02 100644 --- a/src/ui/viewer/tile_graphics_item.cpp +++ b/src/ui/viewer/tile_graphics_item.cpp @@ -23,8 +23,8 @@ #include -TileGraphicsItem::TileGraphicsItem(ProjectData& project, lcf::rpg::Chipset& chipset, const QPixmap pix) : - QGraphicsItem(), m_project(project), m_chipset(&chipset), m_image(pix) { +TileGraphicsItem::TileGraphicsItem(ProjectData& project, lcf::rpg::Chipset* chipset, const QPixmap pix) : + QGraphicsItem(), m_project(project), m_chipset(chipset), m_image(pix) { } QRectF TileGraphicsItem::tileRect() const { @@ -61,7 +61,7 @@ QRectF TileGraphicsItem::tileRect() const { y = 0; } - x += sub_tile_id % 6 * 16; + x += sub_tile_id % 6 * 16 + (m_anim_step * TILE_SIZE); y += sub_tile_id / 6 * 16; return QRectF(x, y, TILE_SIZE, TILE_SIZE); @@ -83,7 +83,7 @@ QRectF TileGraphicsItem::tileRect() const { y = 128; } - x += sub_tile_id % 6 * 16; + x += sub_tile_id % 6 * 16 + (m_anim_step * TILE_SIZE); y += sub_tile_id / 6 * 16; return QRectF(x, y, TILE_SIZE, TILE_SIZE); @@ -126,6 +126,22 @@ void TileGraphicsItem::setTileIndex(int index) { m_tile_index = index; } +int TileGraphicsItem::animType() const { + return m_anim_type; +} + +void TileGraphicsItem::setAnimType(int anim_type) { + m_anim_type = anim_type; +} + +int TileGraphicsItem::animSpeed() const { + return m_anim_speed; +} + +void TileGraphicsItem::setAnimSpeed(int anim_speed) { + m_anim_speed = (anim_speed + 1) * 12; +} + ChipsetGraphicsView::Layer TileGraphicsItem::layer() const { return m_layer; } @@ -141,3 +157,22 @@ ChipsetGraphicsView::EditMode TileGraphicsItem::editMode() const { void TileGraphicsItem::setEditMode(ChipsetGraphicsView::EditMode edit_mode) { m_editmode = edit_mode; } + +void TileGraphicsItem::advance(int phase) { + if (!phase) { + m_anim_step = frames / animSpeed(); + if (animType() == lcf::rpg::Chipset::AnimType_reciprocating) { + m_anim_step %= 3; + } else if (animType() == lcf::rpg::Chipset::AnimType_cyclic) { + m_anim_step %= 4; + if (m_anim_step == 3) { + m_anim_step = 1; + } + } else { + return; + } + ++frames; + } else { + update(); + } +} diff --git a/src/ui/viewer/tile_graphics_item.h b/src/ui/viewer/tile_graphics_item.h index 7f5a9373..3fc4261e 100644 --- a/src/ui/viewer/tile_graphics_item.h +++ b/src/ui/viewer/tile_graphics_item.h @@ -28,7 +28,7 @@ class ProjectData; class TileGraphicsItem : public QGraphicsItem { public: - explicit TileGraphicsItem(ProjectData& project, lcf::rpg::Chipset& chipset, const QPixmap pix = QPixmap(16,16)); + explicit TileGraphicsItem(ProjectData& project, lcf::rpg::Chipset* chipset = nullptr, const QPixmap pix = QPixmap(16,16)); QRectF boundingRect() const override; QRectF tileRect() const; @@ -42,18 +42,31 @@ class TileGraphicsItem : public QGraphicsItem { int tileIndex() const; void setTileIndex(int index); + int animType() const; + void setAnimType(int anim_type); + + int animSpeed() const; + void setAnimSpeed(int anim_speed); + ChipsetGraphicsView::Layer layer() const; void setLayer(ChipsetGraphicsView::Layer layer); ChipsetGraphicsView::EditMode editMode() const; void setEditMode(ChipsetGraphicsView::EditMode edit_mode); +protected: + void advance(int phase) override; + private: ProjectData& m_project; int m_tile_index = 0; + int m_anim_type = -1; + int m_anim_speed = 12; + int m_anim_step = 0; ChipsetGraphicsView::Layer m_layer = ChipsetGraphicsView::Layer::None; ChipsetGraphicsView::EditMode m_editmode = ChipsetGraphicsView::EditMode::None; QString m_filename; lcf::rpg::Chipset* m_chipset = nullptr; QPixmap m_image; + int frames = 0; };