Skip to content

Commit

Permalink
Add splash screen to Object Creator (CleverRaven#67965)
Browse files Browse the repository at this point in the history
* Add splash screen to creator_main

* Add another splash screen to the main window

* Streamline initialization of windows

* Properly show the splashscreen with loading message

- Favor showmessage() instead of QPainter since it's less lines of code
- Remove unnecessary code
- Put in the sleep so it actually works on linux too.

* Apparently the windows version requires the unistd import

* Wrap unistd in a linux condition

* Change sleep to std::this_thread::sleep_for
  • Loading branch information
snipercup authored Sep 4, 2023
1 parent dbd8b2b commit ccdf5db
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
21 changes: 19 additions & 2 deletions object_creator/creator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <QtWidgets/qapplication.h>
#include <QtCore/QSettings>
#include <QtWidgets/qsplashscreen.h>
#include <QtGui/qpainter.h>

#ifdef _WIN32
#include <QtCore/QtPlugin>
Expand Down Expand Up @@ -108,10 +110,23 @@ int main( int argc, char *argv[] )

MAP_SHARING::setDefaults();

QApplication app( argc, argv );
//Create a splash screen that tells the user we're loading
//First we create a pixmap with the desired size
QPixmap splash( QSize(640, 480) );
splash.fill(Qt::gray);

//Then we create the splash screen and show it
QSplashScreen splashscreen( splash );
splashscreen.show();
splashscreen.showMessage( "Initializing Object Creator...", Qt::AlignCenter );
//let the thread sleep for two seconds to show the splashscreen
std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
app.processEvents();

QSettings settings( QSettings::IniFormat, QSettings::UserScope,
"CleverRaven", "Cataclysm - DDA" );


cli_opts cli;

rng_set_engine_seed( cli.seed );
Expand All @@ -138,6 +153,7 @@ int main( int argc, char *argv[] )

world_generator = std::make_unique<worldfactory>();
world_generator->init();

std::vector<mod_id> mods;
mods.push_back( mod_id( "dda" ) );
if( settings.contains( "mods/include" ) ) {
Expand All @@ -150,7 +166,8 @@ int main( int argc, char *argv[] )

g->load_core_data( ui );
g->load_world_modfiles( ui );

splashscreen.finish( nullptr ); //Destroy the splashscreen

QApplication app( argc, argv );
creator::main_window().execute( app );
}
31 changes: 20 additions & 11 deletions object_creator/creator_main_window.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "creator_main_window.h"

#include "spell_window.h"
#include "item_group_window.h"
#include "enum_conversions.h"
#include "translations.h"

#include <QtWidgets/qapplication.h>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/qtabwidget.h>
#include <QtWidgets/qsplashscreen.h>
#include <QtGui/qpainter.h>


namespace io
Expand All @@ -30,29 +29,39 @@ namespace io

int creator::main_window::execute( QApplication &app )
{

//Create the main window
QMainWindow creator_main_window;
//Create a splash screen that tells the user we're loading
//First we create a pixmap with the desired size
QPixmap splash( QSize(640, 480) );
splash.fill(Qt::gray);

//Then we create the splash screen and show it
QSplashScreen splashscreen( splash );
splashscreen.show();
splashscreen.showMessage( "Loading mainwindow...", Qt::AlignCenter );
//let the thread sleep for a second to show the splashscreen
std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
app.processEvents();

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

//Create the spell window and add it as a tab
spell_window spell_editor;
tabWidget->addTab(&spell_editor, "Spell");
spell_editor = new spell_window();
tabWidget->addTab(spell_editor, "Spell");

//Create the item group window and add it as a tab
item_group_window item_group_editor;
tabWidget->addTab(&item_group_editor, "Item group");
item_group_editor = new item_group_window();
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();

creator_main_window.showMaximized();
splashscreen.finish( &creator_main_window ); //Destroy the splashscreen

return app.exec();
}
5 changes: 5 additions & 0 deletions object_creator/creator_main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "enum_traits.h"
#include "mod_selection_window.h"
#include "item_group_window.h"
#include "spell_window.h"
#include <thread> //include thread for the sleep_for function

class QApplication;

Expand All @@ -14,6 +17,8 @@ class main_window
int execute( QApplication &app );
private:
mod_selection_window* mod_selection;
item_group_window* item_group_editor;
spell_window* spell_editor;
};

enum class jsobj_type {
Expand Down

0 comments on commit ccdf5db

Please sign in to comment.