Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Music and Sound Picker #165

Merged
merged 3 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ add_library(${PROJECT_NAME} STATIC
src/ui/common/picker_scene.h
src/ui/common/rpg_combobox.h
src/ui/common/rpg_model.h
src/ui/common/rpg_audio_lineedit.cpp
src/ui/common/rpg_audio_lineedit.h
src/ui/common/rpg_slider.cpp
src/ui/common/rpg_slider.h
src/ui/common/rpg_spinbox.cpp
Expand Down Expand Up @@ -290,6 +292,9 @@ add_library(${PROJECT_NAME} STATIC
src/ui/other/splash_dialog.ui
src/ui/other/volumebutton.cpp
src/ui/other/volumebutton.h
src/ui/picker/picker_audio_widget.cpp
src/ui/picker/picker_audio_widget.h
src/ui/picker/picker_audio_widget.ui
src/ui/picker/picker_child_widget.cpp
src/ui/picker/picker_child_widget.h
src/ui/picker/picker_charset_widget.cpp
Expand Down
98 changes: 98 additions & 0 deletions src/ui/common/rpg_audio_lineedit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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 "rpg_audio_lineedit.h"

#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <lcf/rpg/music.h>
#include <lcf/rpg/sound.h>

#include "defines.h"
#include "model/project_data.h"
#include "ui/picker/picker_audio_widget.h"
#include "ui/picker/picker_dialog.h"

RpgAudioLineEdit::RpgAudioLineEdit(QWidget *parent) : QWidget(parent) {
m_lineEdit = new QLineEdit(this);
m_lineEdit->setReadOnly(true);
m_editButton = new QPushButton("...", this);

auto* layout = new QHBoxLayout(this);
layout->addWidget(m_lineEdit);
layout->addWidget(m_editButton);

QSizePolicy policy;
policy.setHorizontalPolicy(QSizePolicy::Maximum);
m_editButton->setSizePolicy(policy);
}

QLineEdit* RpgAudioLineEdit::lineEdit() const {
return m_lineEdit;
}

void RpgAudioLineEdit::makeModel(ProjectData& project) {
m_project = &project;

QObject::connect(m_editButton, &QPushButton::pressed, [&] {
editPressed();
});
}

void RpgMusicLineEdit::editPressed() {
Q_ASSERT_X(m_music, "RpgMusicLineEdit::editPressed", "bindMusic not called");

auto* widget = new PickerAudioWidget(*m_music, this);
PickerDialog dialog(*m_project, FileFinder::FileType::Music, widget, this);
QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) {
m_lineEdit->setText(baseName);
m_music->name = baseName.toStdString();
m_music->fadein = widget->fadeInTime();
m_music->volume = widget->volume();
m_music->tempo = widget->tempo();
m_music->balance = widget->balance();
});
dialog.setDirectoryAndFile(MUSIC, m_lineEdit->text());
dialog.exec();
}

void RpgMusicLineEdit::bindMusic(lcf::rpg::Music& music) {
m_music = &music;
m_lineEdit->setText(QString::fromStdString(music.name));
}

void RpgSoundLineEdit::editPressed() {
Q_ASSERT_X(m_sound, "RpgSoundLineEdit::editPressed", "bindSound not called");

auto* widget = new PickerAudioWidget(*m_sound, this);
PickerDialog dialog(*m_project, FileFinder::FileType::Sound, widget, this);
QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) {
m_lineEdit->setText(baseName);
m_sound->name = baseName.toStdString();
m_sound->volume = widget->volume();
m_sound->tempo = widget->tempo();
m_sound->balance = widget->balance();
});
dialog.setDirectoryAndFile(SOUND, m_lineEdit->text());
dialog.exec();
}

void RpgSoundLineEdit::bindSound(lcf::rpg::Sound& sound) {
m_sound = &sound;
m_lineEdit->setText(QString::fromStdString(sound.name));
}
69 changes: 69 additions & 0 deletions src/ui/common/rpg_audio_lineedit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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 <QObject>
#include <QWidget>

class QLineEdit;
class QPushButton;
class ProjectData;

namespace lcf::rpg {
class Music;
class Sound;
}

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

void makeModel(ProjectData& project);

QLineEdit* lineEdit() const;

virtual void editPressed() = 0;

protected:
QLineEdit* m_lineEdit = nullptr;
QPushButton* m_editButton = nullptr;
ProjectData* m_project = nullptr;
};

class RpgMusicLineEdit : public RpgAudioLineEdit {
public:
explicit RpgMusicLineEdit(QWidget *parent = nullptr) : RpgAudioLineEdit(parent) {}

void editPressed() override;
void bindMusic(lcf::rpg::Music& music);

private:
lcf::rpg::Music* m_music = nullptr;
};

class RpgSoundLineEdit : public RpgAudioLineEdit {
public:
explicit RpgSoundLineEdit(QWidget *parent = nullptr) : RpgAudioLineEdit(parent) {}

void editPressed() override;
void bindSound(lcf::rpg::Sound& sound);

private:
lcf::rpg::Sound* m_sound = nullptr;
};
16 changes: 12 additions & 4 deletions src/ui/database/system_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
#include "system_widget.h"
#include "ui_system_widget.h"

#include "src/common/lcf_widget_binding.h"

SystemWidget::SystemWidget(ProjectData& project, QWidget *parent) :
QWidget(parent),
ui(new Ui::SystemWidget),
m_project(project)
{
m_project(project) {
ui->setupUi(this);

ui->lineTitleBgm->makeModel(project);
ui->lineCursorSound->makeModel(project);

auto& sys = project.database().system;

ui->lineTitleBgm->bindMusic(sys.title_music);
ui->lineCursorSound->bindSound(sys.cursor_se);
}

SystemWidget::~SystemWidget()
{
SystemWidget::~SystemWidget() {
delete ui;
}
42 changes: 14 additions & 28 deletions src/ui/database/system_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<property name="title">
<string>Cursor</string>
</property>
<widget class="QLineEdit" name="lineEdit_18">
<widget class="RpgSoundLineEdit" name="lineCursorSound">
<property name="geometry">
<rect>
<x>10</x>
Expand All @@ -198,19 +198,6 @@
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_25">
<property name="geometry">
<rect>
<x>70</x>
<y>20</y>
<width>16</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_115">
<property name="geometry">
Expand Down Expand Up @@ -717,7 +704,7 @@
<property name="title">
<string>Title Screen</string>
</property>
<widget class="QLineEdit" name="lineEdit_9">
<widget class="RpgMusicLineEdit" name="lineTitleBgm">
<property name="geometry">
<rect>
<x>10</x>
Expand All @@ -727,19 +714,6 @@
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_16">
<property name="geometry">
<rect>
<x>70</x>
<y>20</y>
<width>16</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_107">
<property name="geometry">
Expand Down Expand Up @@ -1225,6 +1199,18 @@
</widget>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>RpgMusicLineEdit</class>
<extends>QLineEdit</extends>
<header>ui/common/rpg_audio_lineedit.h</header>
</customwidget>
<customwidget>
<class>RpgSoundLineEdit</class>
<extends>QLineEdit</extends>
<header>ui/common/rpg_audio_lineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
69 changes: 69 additions & 0 deletions src/ui/picker/picker_audio_widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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 "picker_audio_widget.h"
#include "ui_picker_audio_widget.h"

#include <lcf/rpg/music.h>
#include <lcf/rpg/sound.h>

PickerAudioWidget::PickerAudioWidget(const lcf::rpg::Music& music, QWidget *parent) :
PickerChildWidget(parent),
ui(new Ui::PickerAudioWidget) {
ui->setupUi(this);

ui->sliderFadeIn->setValue(music.fadein);
ui->sliderVolume->setValue(music.volume);
ui->sliderTempo->setValue(music.tempo);
ui->sliderBalance->setValue(music.balance);
}

PickerAudioWidget::PickerAudioWidget(const lcf::rpg::Sound& sound, QWidget *parent) :
PickerChildWidget(parent),
ui(new Ui::PickerAudioWidget) {
ui->setupUi(this);

ui->sliderVolume->setValue(sound.volume);
ui->sliderTempo->setValue(sound.tempo);
ui->sliderBalance->setValue(sound.balance);

ui->groupFadeIn->hide();
}

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

void PickerAudioWidget::fileChanged(const QString& filename) {
m_filename = filename;
}

int PickerAudioWidget::fadeInTime() const {
return ui->sliderFadeIn->value();
}

int PickerAudioWidget::volume() const {
return ui->sliderVolume->value();
}

int PickerAudioWidget::tempo() const {
return ui->sliderTempo->value();
}

int PickerAudioWidget::balance() const {
return ui->sliderBalance->value();
}
Loading