Skip to content

Commit

Permalink
Add system color combobox
Browse files Browse the repository at this point in the history
A system color combobox has been added now and is now used in the
state editor in the database.
  • Loading branch information
rueter37 committed Dec 3, 2021
1 parent 82ad776 commit 1566188
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ set(EDITOR_SOURCES
src/ui/common/rpg_slider.h
src/ui/common/rpg_spinbox.cpp
src/ui/common/rpg_spinbox.h
src/ui/common/system_color_combobox.cpp
src/ui/common/system_color_combobox.h
src/ui/common/widget_as_dialog_model_wrapper.h
src/ui/common/widget_as_dialog_wrapper.h
src/ui/database/actor_delegate.cpp
Expand Down
35 changes: 35 additions & 0 deletions src/ui/common/system_color_combobox.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#include "system_color_combobox.h"

SystemColorComboBox::SystemColorComboBox(QWidget *parent) : QComboBox(parent) {}

void SystemColorComboBox::setup(ProjectData& project) {
auto& database = project.database();

QPixmap systemimage = ImageLoader::Load(project.project().findFile("System", ToQString(database.system.system_name), FileFinder::FileType::Image));

clear();
for (int i = 0; i < 20; i++) {
QPixmap colorpixmap = systemimage.copy((i % 10) * 16, (i / 10) * 16 + 48, 16, 16);
QIcon coloricon;
coloricon.addPixmap(colorpixmap, QIcon::Normal);
coloricon.addPixmap(colorpixmap, QIcon::Disabled);
addItem(coloricon, QString("Color %1").arg(i), i);
}
}
34 changes: 34 additions & 0 deletions src/ui/common/system_color_combobox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QComboBox>
#include "src/model/project.h"
#include "src/model/rpg_base.h"
#include "src/common/dbstring.h"

class ProjectData;

class SystemColorComboBox : public QComboBox
{
Q_OBJECT
public:
explicit SystemColorComboBox(QWidget *parent = nullptr);

void setup(ProjectData& project);
};
14 changes: 5 additions & 9 deletions src/ui/database/state_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ StateWidget::StateWidget(ProjectData& project, QWidget *parent) :
ui->comboExtents->addItem("Ends after battle", 0);
ui->comboExtents->addItem("Persists after battle", 1);

for (int i = 0; i < 20; i++) {
ui->comboColor->addItem(QString("Color %1").arg(i), i);
}
ui->comboColor->setup(project);

ui->comboRestriction->addItem("No restriction", 0);
ui->comboRestriction->addItem("No action allowed", 1);
Expand Down Expand Up @@ -73,11 +71,12 @@ StateWidget::StateWidget(ProjectData& project, QWidget *parent) :

for (auto& uis : {
ui->comboExtents,
ui->comboColor,
ui->comboRestriction }) {
LcfWidgetBinding::connect<int32_t>(this, uis);
}

LcfWidgetBinding::connect<int32_t>(this, ui->comboColor);

for (auto& uis : {
ui->spinPriority,
ui->spinAccuracy }) {
Expand Down Expand Up @@ -245,11 +244,8 @@ void StateWidget::on_currentStateChanged(lcf::rpg::State *state) {
ui->checkStatAffectAgility }) {
uis->setEnabled(state->ID != 1);
}
for (auto& uis : {
ui->comboColor,
ui->comboRestriction }) {
uis->setEnabled(state->ID != 1);
}
ui->comboColor->setEnabled(state->ID != 1);
ui->comboRestriction->setEnabled(state->ID != 1);
for (auto& uis : {
ui->spinPriority,
ui->spinAccuracy,
Expand Down
9 changes: 8 additions & 1 deletion src/ui/database/state_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="comboColor"/>
<widget class="SystemColorComboBox" name="comboColor"/>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -1038,6 +1038,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SystemColorComboBox</class>
<extends>QComboBox</extends>
<header>ui/common/system_color_combobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 1566188

Please sign in to comment.