Skip to content

Commit

Permalink
Object creator merge windows into a tabbed view (CleverRaven#67955)
Browse files Browse the repository at this point in the history
* Move mods selector to it's own window

Remove the mods selector from the main page into it's own window

* Make the spell window and the item group window into a page

Instead of showing the itemgroup window and the spell window as separate
windows, they become a page inside the main window

* Add menubar to main window and clean up code

The navigation menu allows you to switch between pages. We don't need
the removed code anymore

* Add json output to the same window as spell editor

- Added the json output to the same window as the spell editor. This
allows the spell editor to be included in a tabbed view in the main
application
- Changed the spell editor to be a QWidged instead of a Qframe since a
QFrame is more then we need here.

* modselector- Removed layout code and changed to QWidget

- Changed the mod selector window to a QWidget since a Qframe is more
then we need
- Removed some layout code that's no longer needed
- This change will cause a segfault when the mod selection is tested so
an additional fix is needed.

* item_group_window- Change to QWidged and add json output

- Changed the item group window from a QFrame to a QWidget
- Added the json output to the window (which is now in a tab)

* mainwindow- changed to tabbed view

- Changed the main window to become a tabbed view that includes all of
the other pages.
- The menubar is not needed right now so it's removed
- The stackedwidget is not fit for this use case and was replaced with
the tabbed widget

* Mod selector- Move settings and mods_box to h file

The application lost track of settings and crashed bause of it. This
will fix it.

* move mod_selection window to h file in creator_main_window

This fixes a crash that would occur when the application is closed. It
crashed probably because it lost track of mod_selection_window

* Move item_group_json to the third column and set size
  • Loading branch information
snipercup authored Aug 31, 2023
1 parent 56996f4 commit ae81fcc
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 105 deletions.
108 changes: 19 additions & 89 deletions object_creator/creator_main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
#include "item_group_window.h"
#include "enum_conversions.h"
#include "translations.h"
#include "worldfactory.h"
#include "mod_manager.h"

#include <QtWidgets/qapplication.h>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/qpushbutton.h>
#include <QtCore/QSettings>
#include <QtWidgets/qtabwidget.h>


namespace io
{
Expand All @@ -32,97 +30,29 @@ namespace io

int creator::main_window::execute( QApplication &app )
{
const int default_text_box_height = 20;
const int default_text_box_width = 100;
const QSize default_text_box_size( default_text_box_width, default_text_box_height );

int row = 0;
int col = 0;
int max_row = 0;
int max_col = 0;

//Does nothing on it's own but once settings.setvalue() is called it will create
//an ini file in C:\Users\User\AppData\Roaming\CleverRaven or equivalent directory
QSettings settings( QSettings::IniFormat, QSettings::UserScope,
"CleverRaven", "Cataclysm - DDA" );

// =========================================================================================
// first column of boxes
row = 0;

QMainWindow title_menu;
spell_window spell_editor( &title_menu );
item_group_window item_group_editor( &title_menu );

QLabel mods_label;
mods_label.setParent( &title_menu );
mods_label.setText( QString( "Select mods (restart required):" ) );
mods_label.resize( default_text_box_size * 2 );
mods_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
mods_label.show();
row++;

//We always load 'dda' so we exclude it from the mods list
QStringList all_mods;
for( const mod_id &e : world_generator->get_mod_manager().all_mods() ) {
if( !e->obsolete && e->ident.str() != "dda" ) {
all_mods.append( e->ident.c_str() );
}
}

dual_list_box mods_box;
mods_box.initialize( all_mods );
mods_box.resize( QSize( default_text_box_width * 8, default_text_box_height * 10 ) );
mods_box.setParent( &title_menu );
mods_box.move( QPoint( col * default_text_box_width, row * default_text_box_height ) );
mods_box.show();
//The user's mod selection gets saved to a file
QObject::connect( &mods_box, &dual_list_box::pressed, [&]() {
settings.setValue( "mods/include", mods_box.get_included() );
} );

//A previous selection of mods is loaded from disk and applied to the modlist widget
if( settings.contains( "mods/include" ) ) {
QStringList modlist = settings.value( "mods/include" ).value<QStringList>();
mods_box.set_included( modlist );
}

row += 11;
//Create the main window
QMainWindow creator_main_window;

QPushButton spell_button( _( "Spell Creator" ), &title_menu );
spell_button.move( QPoint( col * default_text_box_width, row * default_text_box_height ) );
QObject::connect( &spell_button, &QPushButton::released,
[&]() {
title_menu.hide();
spell_editor.show();
} );

//Create a tab widget and add it to the main window
QTabWidget* tabWidget = new QTabWidget(&creator_main_window);
creator_main_window.setCentralWidget(tabWidget);

// =========================================================================================
// second column of boxes
col++;
//Create the spell window and add it as a tab
spell_window spell_editor;
tabWidget->addTab(&spell_editor, "Spell");

QPushButton item_group_button( _( "Item group Creator" ), &title_menu );
item_group_button.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
item_group_button.resize( 150, 30 );

QObject::connect( &item_group_button, &QPushButton::released,
[&]() {
title_menu.hide();
item_group_editor.show();
} );

title_menu.show();
spell_button.show();
item_group_button.show();

row += 3;
col += 6;
max_row = std::max( max_row, row );
max_col = std::max( max_col, col );
title_menu.resize( QSize( ( max_col + 1 ) * default_text_box_width,
( max_row )*default_text_box_height ) );
//Create the item group window and add it as a tab
item_group_window item_group_editor;
tabWidget->addTab(&item_group_editor, "Item group");

//Create the mod selection window and add it as a tab
mod_selection = new mod_selection_window();
tabWidget->addTab(mod_selection, "Mod selection");

//Make the main window maximized
creator_main_window.showMaximized();

return app.exec();
}
2 changes: 2 additions & 0 deletions object_creator/creator_main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CATA_OBJECT_CREATOR_CREATOR_MAIN_WINDOW_H

#include "enum_traits.h"
#include "mod_selection_window.h"

class QApplication;

Expand All @@ -12,6 +13,7 @@ class main_window
public:
int execute( QApplication &app );
private:
mod_selection_window* mod_selection;
};

enum class jsobj_type {
Expand Down
24 changes: 14 additions & 10 deletions object_creator/item_group_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@
#include <QtCore/QCoreApplication>

creator::item_group_window::item_group_window( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
: QWidget ( parent, flags )
{
QWidget* wid = new QWidget( this );
this->setCentralWidget( wid );

this->setAcceptDrops( true );

QHBoxLayout* mainRow = new QHBoxLayout;
QVBoxLayout* mainColumn1 = new QVBoxLayout;
QVBoxLayout* mainColumn2 = new QVBoxLayout;
QVBoxLayout* mainColumn3 = new QVBoxLayout;

wid->setLayout( mainRow );
this->setLayout( mainRow );
mainRow->addLayout( mainColumn1, 0 );
mainRow->addLayout( mainColumn2, 1 );

item_group_json.resize( QSize( 800, 600 ) );
item_group_json.setReadOnly( true );

mainRow->addLayout( mainColumn3, 2 );

// =========================================================================================
// first column of boxes
Expand Down Expand Up @@ -165,12 +162,19 @@ creator::item_group_window::item_group_window( QWidget *parent, Qt::WindowFlags
scrollArea->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
scrollArea->setWidgetResizable( true );


group_container = new nested_group_container( scrollArea, this );
scrollArea->setWidget( group_container );
mainColumn2->addWidget( scrollArea );


// =========================================================================================
// third column

item_group_json.setMinimumSize( QSize( 400, 300 ) );
item_group_json.setMaximumWidth(500);
item_group_json.setReadOnly( true );
mainColumn3->addWidget( &item_group_json );

// =========================================================================================
// Finalize

Expand Down Expand Up @@ -328,7 +332,7 @@ bool creator::item_group_window::event( QEvent* event )
return true;
}
//call the event method of the base class for the events that aren't handled
return QMainWindow::event( event );
return QWidget::event( event );
}


Expand Down
2 changes: 1 addition & 1 deletion object_creator/item_group_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace creator
{
class nested_group_container;
class item_group_window : public QMainWindow
class item_group_window : public QWidget
{

public:
Expand Down
38 changes: 38 additions & 0 deletions object_creator/mod_selection_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef CATA_OBJECT_CREATOR_MOD_SELECTION_WINDOW_H
#define CATA_OBJECT_CREATOR_MOD_SELECTION_WINDOW_H

//Include Qframe, QLabel and QSpinBox for the mod selection window
#include <QtWidgets/qframe.h>
#include <QtWidgets/qlabel.h>
#include <QtWidgets/qspinbox.h>
#include <QtCore/QSettings>

#include "dual_list_box.h"
#include "mod_manager.h"
#include "worldfactory.h"


namespace creator
{
class mod_selection_window : public QWidget
{


public:
mod_selection_window( QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );

void show() {
QWidget::show();
}

void hide() {
QWidget::hide();
}

private:
dual_list_box mods_box;
QSettings* settings;
};
}

#endif // CATA_OBJECT_CREATOR_MOD_SELECTION_WINDOW_H
43 changes: 43 additions & 0 deletions object_creator/mods_selection_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "mod_selection_window.h"


creator::mod_selection_window::mod_selection_window( QWidget *parent, Qt::WindowFlags flags )
: QWidget ( parent, flags )
{
QVBoxLayout* mod_layout = new QVBoxLayout();
this->setLayout( mod_layout ) ;


QLabel* mods_label = new QLabel( "Select mods (restart required):", this );
mod_layout->addWidget( mods_label );

//We always load 'dda' so we exclude it from the mods list
QStringList all_mods;
for( const mod_id &e : world_generator->get_mod_manager().all_mods() ) {
if( !e->obsolete && e->ident.str() != "dda" ) {
all_mods.append( e->ident.c_str() );
}
}

//Does nothing on it's own but once settings.setvalue() is called it will create
//an ini file in C:\Users\User\AppData\Roaming\CleverRaven or equivalent directory
settings = new QSettings( QSettings::IniFormat, QSettings::UserScope,
"CleverRaven", "Cataclysm - DDA" );


mods_box.initialize( all_mods );
mod_layout->addWidget( &mods_box );

//When one of the buttons on the mods_box is pressed,
//Get all items from the included list and save them to the ini file
QObject::connect( &mods_box, &dual_list_box::pressed, [&]() {
settings->setValue( "mods/include", mods_box.get_included() );
} );

//A previous selection of mods is loaded from disk and applied to the modlist widget
if( settings->contains( "mods/include" ) ) {
QStringList modlist = settings->value( "mods/include" ).value<QStringList>();
mods_box.set_included( modlist );
}

}
18 changes: 14 additions & 4 deletions object_creator/spell_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static spell_type default_spell_type()
}

creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
: QWidget ( parent, flags )
{
editable_spell = default_spell_type();

Expand All @@ -78,9 +78,6 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags )
int max_row = 0;
int max_col = 0;

spell_json.resize( QSize( 800, 600 ) );
spell_json.setReadOnly( true );


// =========================================================================================
// first column of boxes (just the spell list)
Expand Down Expand Up @@ -1242,6 +1239,19 @@ creator::spell_window::spell_window( QWidget *parent, Qt::WindowFlags flags )
write_json();
} );


// =========================================================================================
// eight column of boxes (just json output)
max_row = std::max( max_row, row );
row = 0;
col++;

spell_json.setParent( this );
spell_json.resize( QSize( 800, 600 ) );
spell_json.setReadOnly( true );
spell_json.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
spell_json.show();

max_row = std::max( max_row, row );
max_col = std::max( max_col, col );
this->resize( QSize( ( max_col + 1 ) * default_text_box_width,
Expand Down
2 changes: 1 addition & 1 deletion object_creator/spell_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace creator
{
class spell_window : public QMainWindow
class spell_window : public QWidget
{
public:
spell_window( QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
Expand Down

0 comments on commit ae81fcc

Please sign in to comment.