From ccdf5db6bc87e603ab5d53e4a827922d76e94af2 Mon Sep 17 00:00:00 2001 From: snipercup <50166150+snipercup@users.noreply.github.com> Date: Mon, 4 Sep 2023 09:53:07 +0200 Subject: [PATCH] Add splash screen to Object Creator (#67965) * 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 --- object_creator/creator_main.cpp | 21 +++++++++++++++-- object_creator/creator_main_window.cpp | 31 +++++++++++++++++--------- object_creator/creator_main_window.h | 5 +++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/object_creator/creator_main.cpp b/object_creator/creator_main.cpp index 3fa3224db107c..dd85ab9472ee5 100644 --- a/object_creator/creator_main.cpp +++ b/object_creator/creator_main.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #ifdef _WIN32 #include @@ -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 ); @@ -138,6 +153,7 @@ int main( int argc, char *argv[] ) world_generator = std::make_unique(); world_generator->init(); + std::vector mods; mods.push_back( mod_id( "dda" ) ); if( settings.contains( "mods/include" ) ) { @@ -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 ); } diff --git a/object_creator/creator_main_window.cpp b/object_creator/creator_main_window.cpp index 4c104abc03173..c298f8bba5f91 100644 --- a/object_creator/creator_main_window.cpp +++ b/object_creator/creator_main_window.cpp @@ -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 #include #include +#include +#include namespace io @@ -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(); } diff --git a/object_creator/creator_main_window.h b/object_creator/creator_main_window.h index a288218b8c94c..e43ed0a2a481c 100644 --- a/object_creator/creator_main_window.h +++ b/object_creator/creator_main_window.h @@ -3,6 +3,9 @@ #include "enum_traits.h" #include "mod_selection_window.h" +#include "item_group_window.h" +#include "spell_window.h" +#include //include thread for the sleep_for function class QApplication; @@ -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 {