From 711643b454d925b9405538c6848e597199192552 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 6 Aug 2015 16:02:59 +0200 Subject: [PATCH] Refactored CMainDialog --- po/colobot.pot | 22 +- po/de.po | 32 +-- po/fr.po | 32 +-- po/pl.po | 30 ++- po/ru.po | 32 +-- src/common/restext.cpp | 13 +- src/common/restext.h | 14 +- src/object/robotmain.cpp | 6 +- src/ui/maindialog.cpp | 301 ++++++++++--------------- src/ui/maindialog.h | 55 +++-- src/ui/mainui.cpp | 11 - src/ui/mainui.h | 8 +- src/ui/screen/screen_player_select.cpp | 12 +- src/ui/screen/screen_player_select.h | 2 +- 14 files changed, 257 insertions(+), 313 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index e168b1d2..7a8c1e0e 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -137,24 +137,12 @@ msgstr "" msgid "Strip color:" msgstr "" -msgid "Do you want to quit Colobot: Gold Edition?" -msgstr "" - -msgid "Quit\\Quit Colobot: Gold Edition" -msgstr "" - -msgid "Quit the mission?" -msgstr "" - msgid "Abort\\Abort the current mission" msgstr "" msgid "Continue\\Continue the current mission" msgstr "" -msgid "Continue\\Continue the game" -msgstr "" - msgid "Do you really want to destroy the selected building?" msgstr "" @@ -162,10 +150,10 @@ msgstr "" msgid "Do you want to delete %s's saved games? " msgstr "" -msgid "Delete" +msgid "Yes" msgstr "" -msgid "Cancel" +msgid "No" msgstr "" msgid "LOADING" @@ -255,6 +243,9 @@ msgstr "" msgid "OK" msgstr "" +msgid "Cancel" +msgstr "" + msgid "Next" msgstr "" @@ -294,6 +285,9 @@ msgstr "" msgid "\\Return to Colobot: Gold Edition" msgstr "" +msgid "Quit\\Quit Colobot: Gold Edition" +msgstr "" + msgid "<< Back \\Back to the previous screen" msgstr "" diff --git a/po/de.po b/po/de.po index 327dca86..d4f60ade 100644 --- a/po/de.po +++ b/po/de.po @@ -436,9 +436,6 @@ msgstr "Weitermachen" msgid "Continue\\Continue the current mission" msgstr "Weitermachen\\Mission weitermachen" -msgid "Continue\\Continue the game" -msgstr "Weitermachen\\Weitermachen" - msgid "Controls\\Keyboard, joystick and mouse settings" msgstr "Steuerung\\Auswahl der Tasten" @@ -463,9 +460,6 @@ msgstr "Ausschneiden (Ctrl+x)" msgid "Defense tower" msgstr "Geschützturm" -msgid "Delete" -msgstr "Zerstören" - #, fuzzy msgid "Delete mark" msgstr "Zerstören" @@ -510,10 +504,6 @@ msgstr "Wollen Sie das angewählte Gebäude wirklich zerstören ?" msgid "Do you want to delete %s's saved games? " msgstr "Wollen Sie die gespeicherten Missionen von %s löschen ?" -#, fuzzy -msgid "Do you want to quit Colobot: Gold Edition?" -msgstr "Wollen Sie COLOBOT schließen ?" - msgid "Doors blocked by a robot or another object " msgstr "Die Türen werden von einem Gegenstand blockiert" @@ -902,6 +892,9 @@ msgstr "Nächster" msgid "Next object\\Selects the next object" msgstr "Nächstes auswählen\\Nächstes Objekt auswählen" +msgid "No" +msgstr "" + msgid "No energy in the subsoil" msgstr "Kein unterirdisches Energievorkommen" @@ -1182,9 +1175,6 @@ msgstr "Öffentlich\\Gemeinsamer Ordner für alle Spieler" msgid "Quake at explosions\\The screen shakes at explosions" msgstr "Beben bei Explosionen\\Die Kamera bebt bei Explosionen" -msgid "Quit the mission?" -msgstr "Mission abbrechen ?" - msgid "Quit\\Quit Colobot: Gold Edition" msgstr "" @@ -1708,6 +1698,9 @@ msgstr "Der Ausdruck ergibt einen falschen Typ für die Zuweisung" msgid "Yellow flag" msgstr "Gelbe Fahne" +msgid "Yes" +msgstr "" + msgid "You can fly with the keys (\\key gup;) and (\\key gdown;)" msgstr "Sie können jetzt mit den Tasten \\key gup; und \\key gdown; fliegen" @@ -1855,15 +1848,28 @@ msgstr "www.epsitec.com" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Continue\\Continue the game" +#~ msgstr "Weitermachen\\Weitermachen" + +#~ msgid "Delete" +#~ msgstr "Zerstören" + #~ msgid "Developed by :" #~ msgstr "Entwickelt von:" +#, fuzzy +#~ msgid "Do you want to quit Colobot: Gold Edition?" +#~ msgstr "Wollen Sie COLOBOT schließen ?" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Hilfe über Begriff\\Hilfe über einen Begriff" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Schatten unter der Maus\\Ein Schatten erscheint unter der Maus" +#~ msgid "Quit the mission?" +#~ msgstr "Mission abbrechen ?" + #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Schließen\\COLOBOT schließen" diff --git a/po/fr.po b/po/fr.po index 33088823..11e05097 100644 --- a/po/fr.po +++ b/po/fr.po @@ -431,9 +431,6 @@ msgstr "Continuer" msgid "Continue\\Continue the current mission" msgstr "Continuer\\Continuer la mission en cours" -msgid "Continue\\Continue the game" -msgstr "Continuer\\Continuer de jouer" - msgid "Controls\\Keyboard, joystick and mouse settings" msgstr "Commandes\\Touches du clavier" @@ -458,9 +455,6 @@ msgstr "Couper (Ctrl+x)" msgid "Defense tower" msgstr "Tour de défense" -msgid "Delete" -msgstr "Détruire" - #, fuzzy msgid "Delete mark" msgstr "Détruire" @@ -505,10 +499,6 @@ msgstr "Voulez-vous vraiment détruire le bâtiment sélectionné ?" msgid "Do you want to delete %s's saved games? " msgstr "Voulez-vous détruire les sauvegardes de %s ?" -#, fuzzy -msgid "Do you want to quit Colobot: Gold Edition?" -msgstr "Voulez-vous quitter COLOBOT ?" - msgid "Doors blocked by a robot or another object " msgstr "Portes bloquées par un robot ou un objet" @@ -898,6 +888,9 @@ msgstr "Suivant" msgid "Next object\\Selects the next object" msgstr "Sélectionner l'objet suivant\\Sélectionner l'objet suivant" +msgid "No" +msgstr "" + msgid "No energy in the subsoil" msgstr "Pas d'énergie en sous-sol" @@ -1178,9 +1171,6 @@ msgstr "Public\\Dossier commun à tous les joueurs" msgid "Quake at explosions\\The screen shakes at explosions" msgstr "Secousses lors d'explosions\\L'écran vibre lors d'une explosion" -msgid "Quit the mission?" -msgstr "Quitter la mission ?" - msgid "Quit\\Quit Colobot: Gold Edition" msgstr "" @@ -1703,6 +1693,9 @@ msgstr "Mauvais type de résultat pour l'assignation" msgid "Yellow flag" msgstr "Drapeau jaune" +msgid "Yes" +msgstr "" + msgid "You can fly with the keys (\\key gup;) and (\\key gdown;)" msgstr "" "Il est possible de voler avec les touches (\\key gup;) et (\\key gdown;)" @@ -1851,15 +1844,28 @@ msgstr "www.epsitec.com" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Continue\\Continue the game" +#~ msgstr "Continuer\\Continuer de jouer" + +#~ msgid "Delete" +#~ msgstr "Détruire" + #~ msgid "Developed by :" #~ msgstr "Développé par :" +#, fuzzy +#~ msgid "Do you want to quit Colobot: Gold Edition?" +#~ msgstr "Voulez-vous quitter COLOBOT ?" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Instructions mot-clé\\Explication sur le mot-clé" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Souris ombrée\\Jolie souris avec une ombre" +#~ msgid "Quit the mission?" +#~ msgstr "Quitter la mission ?" + #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Quitter\\Quitter COLOBOT" diff --git a/po/pl.po b/po/pl.po index 155f6586..9d745c9b 100644 --- a/po/pl.po +++ b/po/pl.po @@ -439,9 +439,6 @@ msgstr "Kontynuuj" msgid "Continue\\Continue the current mission" msgstr "Kontynuuj\\Kontynuuje bieżącą misję" -msgid "Continue\\Continue the game" -msgstr "Kontynuuj\\Kontynuuje grę" - msgid "Controls\\Keyboard, joystick and mouse settings" msgstr "Sterowanie\\Ustawienia klawiatury, joysticka i myszy" @@ -466,9 +463,6 @@ msgstr "Wytnij (Ctrl+X)" msgid "Defense tower" msgstr "Wieża obronna" -msgid "Delete" -msgstr "Usuń" - msgid "Delete mark" msgstr "Usuń znacznik" @@ -512,9 +506,6 @@ msgstr "Czy na pewno chcesz zniszczyć zaznaczony budynek?" msgid "Do you want to delete %s's saved games? " msgstr "Czy na pewno chcesz skasować zapisane gry gracza %s? " -msgid "Do you want to quit Colobot: Gold Edition?" -msgstr "Czy na pewno chcesz opuścić grę Colobot: Gold Edition?" - msgid "Doors blocked by a robot or another object " msgstr "Drzwi zablokowane przez robota lub inny obiekt " @@ -902,6 +893,9 @@ msgstr "Następny" msgid "Next object\\Selects the next object" msgstr "Następny obiekt\\Zaznacza następny obiekt" +msgid "No" +msgstr "Nie" + msgid "No energy in the subsoil" msgstr "Brak energii w ziemi" @@ -1183,9 +1177,6 @@ msgstr "Publiczny\\Folder ogólnodostępny" msgid "Quake at explosions\\The screen shakes at explosions" msgstr "Wstrząsy przy wybuchach\\Ekran trzęsie się podczas wybuchów" -msgid "Quit the mission?" -msgstr "Opuścić misję?" - msgid "Quit\\Quit Colobot: Gold Edition" msgstr "Wyjdź\\Kończy grę Colobot: Gold Edition" @@ -1704,6 +1695,9 @@ msgstr "Zły typ dla przypisania" msgid "Yellow flag" msgstr "Żółta flaga" +msgid "Yes" +msgstr "Tak" + msgid "You can fly with the keys (\\key gup;) and (\\key gdown;)" msgstr "Możesz latać używając klawiszy (\\key gup;) oraz (\\key gdown;)" @@ -1845,6 +1839,15 @@ msgstr "www.epsitec.com" #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Dźwięk 3D\\Przestrzenne pozycjonowanie dźwięków" +#~ msgid "Continue\\Continue the game" +#~ msgstr "Kontynuuj\\Kontynuuje grę" + +#~ msgid "Delete" +#~ msgstr "Usuń" + +#~ msgid "Do you want to quit Colobot: Gold Edition?" +#~ msgstr "Czy na pewno chcesz opuścić grę Colobot: Gold Edition?" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "" #~ "Pomoc dot. słów kluczowych\\Dokładniejsza pomoc na temat słów kluczowych" @@ -1852,5 +1855,8 @@ msgstr "www.epsitec.com" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Cień kursora myszy\\Dodaje cień kursorowi myszy" +#~ msgid "Quit the mission?" +#~ msgstr "Opuścić misję?" + #~ msgid "Textures\\Quality of textures " #~ msgstr "Tekstury\\Jakość tekstur " diff --git a/po/ru.po b/po/ru.po index 6e497be5..236a23eb 100644 --- a/po/ru.po +++ b/po/ru.po @@ -430,9 +430,6 @@ msgstr "Продолжить" msgid "Continue\\Continue the current mission" msgstr "Продолжить\\Продолжить текущую миссию" -msgid "Continue\\Continue the game" -msgstr "Продолжить\\Продолжить игру" - msgid "Controls\\Keyboard, joystick and mouse settings" msgstr "Управление\\Настройки клавиатуры, джойстика и мыши" @@ -457,9 +454,6 @@ msgstr "Вырезать (Ctrl+X)" msgid "Defense tower" msgstr "Защитная башня" -msgid "Delete" -msgstr "Удалить" - #, fuzzy msgid "Delete mark" msgstr "Удалить" @@ -504,10 +498,6 @@ msgstr "Вы действительно хотите уничтожить выб msgid "Do you want to delete %s's saved games? " msgstr "Вы действительно хотите удалить сохраненные игры игрока %s?" -#, fuzzy -msgid "Do you want to quit Colobot: Gold Edition?" -msgstr "Вы хотите закрыть COLOBOT?" - msgid "Doors blocked by a robot or another object " msgstr "Двери заблокированы роботом или другим объектом" @@ -895,6 +885,9 @@ msgstr "Следующий" msgid "Next object\\Selects the next object" msgstr "Следующий объект\\Выбор следующего объекта" +msgid "No" +msgstr "" + msgid "No energy in the subsoil" msgstr "Под землей нет запасов энергии" @@ -1178,9 +1171,6 @@ msgstr "Общее\\Общая папка" msgid "Quake at explosions\\The screen shakes at explosions" msgstr "Землетряс. при взрывах\\Тряска экрана при взрывах" -msgid "Quit the mission?" -msgstr "Завершить миссию?" - msgid "Quit\\Quit Colobot: Gold Edition" msgstr "" @@ -1700,6 +1690,9 @@ msgstr "Неверный тип для назначения" msgid "Yellow flag" msgstr "Желтый флаг" +msgid "Yes" +msgstr "" + msgid "You can fly with the keys (\\key gup;) and (\\key gdown;)" msgstr "Вы можете лететь с помощью клавиш (\\key gup;) и (\\key gdown;)" @@ -1847,15 +1840,28 @@ msgstr "www.epsitec.com" #~ msgid "COLOBOT" #~ msgstr "КОЛОБОТ" +#~ msgid "Continue\\Continue the game" +#~ msgstr "Продолжить\\Продолжить игру" + +#~ msgid "Delete" +#~ msgstr "Удалить" + #~ msgid "Developed by :" #~ msgstr "Разработка :" +#, fuzzy +#~ msgid "Do you want to quit Colobot: Gold Edition?" +#~ msgstr "Вы хотите закрыть COLOBOT?" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Помощь по командам\\Более подробная справку по командам" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Тень мыши\\Мышь отбрасывает тень" +#~ msgid "Quit the mission?" +#~ msgstr "Завершить миссию?" + #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Выход\\Выход из COLOBOT" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index c7a41f6f..7b1346c6 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -103,17 +103,12 @@ void InitializeRestext() stringsText[RT_PERSO_COMBI] = TR("Suit color:"); stringsText[RT_PERSO_BAND] = TR("Strip color:"); - stringsText[RT_DIALOG_QUIT] = TR("Do you want to quit Colobot: Gold Edition?"); - stringsText[RT_DIALOG_TITLE] = TR("Colobot: Gold Edition"); - stringsText[RT_DIALOG_YESQUIT] = TR("Quit\\Quit Colobot: Gold Edition"); - stringsText[RT_DIALOG_ABORT] = TR("Quit the mission?"); - stringsText[RT_DIALOG_YES] = TR("Abort\\Abort the current mission"); - stringsText[RT_DIALOG_NO] = TR("Continue\\Continue the current mission"); - stringsText[RT_DIALOG_NOQUIT] = TR("Continue\\Continue the game"); + stringsText[RT_DIALOG_ABORT] = TR("Abort\\Abort the current mission"); + stringsText[RT_DIALOG_CONTINUE] = TR("Continue\\Continue the current mission"); stringsText[RT_DIALOG_DELOBJ] = TR("Do you really want to destroy the selected building?"); stringsText[RT_DIALOG_DELGAME] = TR("Do you want to delete %s's saved games? "); - stringsText[RT_DIALOG_YESDEL] = TR("Delete"); - stringsText[RT_DIALOG_NODEL] = TR("Cancel"); + stringsText[RT_DIALOG_YES] = TR("Yes"); + stringsText[RT_DIALOG_NO] = TR("No"); stringsText[RT_DIALOG_LOADING] = TR("LOADING"); stringsText[RT_STUDIO_LISTTT] = TR("Keyword help(\\key cbot;)"); diff --git a/src/common/restext.h b/src/common/restext.h index 1f689aeb..654e3baf 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -99,18 +99,13 @@ enum ResTextType RT_PERSO_COMBI = 93, RT_PERSO_BAND = 94, - RT_DIALOG_TITLE = 100, - RT_DIALOG_ABORT = 101, - RT_DIALOG_QUIT = 102, - RT_DIALOG_YES = 103, - RT_DIALOG_NO = 104, + RT_DIALOG_ABORT = 103, + RT_DIALOG_CONTINUE = 104, RT_DIALOG_DELOBJ = 105, RT_DIALOG_DELGAME = 106, - RT_DIALOG_YESDEL = 107, - RT_DIALOG_NODEL = 108, + RT_DIALOG_YES = 107, + RT_DIALOG_NO = 108, RT_DIALOG_LOADING = 109, - RT_DIALOG_YESQUIT = 110, - RT_DIALOG_NOQUIT = 111, RT_STUDIO_LISTTT = 120, RT_STUDIO_COMPOK = 121, @@ -158,4 +153,3 @@ void InitializeRestext(); void SetGlobalGamerName(std::string name); bool GetResource(ResType type, unsigned int num, std::string& text); - diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 85386a23..78b21e98 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -805,7 +805,7 @@ bool CRobotMain::ProcessEvent(Event &event) else if (m_lostDelay > 0.0f) ChangePhase(PHASE_LOST); else if (!m_cmdEdit) - m_ui->GetDialog()->StartAbort(); // do you want to leave? + m_ui->GetDialog()->StartPauseMenu(); // do you want to leave? } if (event.key.slot == INPUT_SLOT_PAUSE) { @@ -963,7 +963,9 @@ bool CRobotMain::ProcessEvent(Event &event) break; case EVENT_OBJECT_DELETE: - m_ui->GetDialog()->StartDeleteObject(); // do you want to destroy it? + m_ui->GetDialog()->StartQuestion(RT_DIALOG_DELOBJ, true, false, [&]() { + DeleteObject(); + }); break; case EVENT_OBJECT_BHELP: diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 99048673..72477396 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -28,7 +28,6 @@ #include "common/logger.h" #include "common/make_unique.h" #include "common/settings.h" -#include "common/stringutils.h" #include "object/player_profile.h" #include "object/robotmain.h" @@ -37,7 +36,6 @@ #include "ui/controls/button.h" #include "ui/controls/interface.h" -#include "ui/mainui.h" #include "ui/controls/window.h" #include "ui/screen/screen_setup.h" @@ -58,7 +56,7 @@ CMainDialog::CMainDialog() m_phase = PHASE_PLAYER_SELECT; - m_bDialog = false; + m_dialogOpen = false; } // Destructor of robot application. @@ -77,7 +75,7 @@ void CMainDialog::ChangePhase(Phase phase) bool CMainDialog::EventProcess(const Event &event) { - if ( m_bDialog ) // this dialogue? + if ( m_dialogOpen ) // this dialogue? { if ( event.type == EVENT_FRAME ) { @@ -85,61 +83,84 @@ bool CMainDialog::EventProcess(const Event &event) return true; } - if ( event.type == EVENT_DIALOG_OK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(RETURN) ) ) + EventType pressedButton = event.type; + if (event.type == EVENT_KEY_DOWN && event.key.key == KEY(RETURN) ) { - StopDialog(); - if ( m_phase == PHASE_PLAYER_SELECT ) + pressedButton = EVENT_DIALOG_OK; + } + if (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE) ) + { + pressedButton = EVENT_DIALOG_CANCEL; + } + + if ( m_dialogType == DialogType::PauseMenu ) + { + if ( pressedButton == EVENT_DIALOG_CANCEL ) { - CMainUserInterface::GetInstancePointer()->NameDelete(); // TODO: Clean this up + StopDialog(); } - if ( m_phase == PHASE_SIMUL ) + + if ( pressedButton == EVENT_INTERFACE_SETUP ) { - if ( m_bDialogDelete ) - { - m_main->DeleteObject(); - } - else - { - m_main->ChangePhase(PHASE_LEVEL_LIST); - } + StopDialog(); + m_main->StartSuspend(); + #if PLATFORM_LINUX + if ( CScreenSetup::GetTab() == PHASE_SETUPd ) m_main->ChangePhase(PHASE_SETUPds); + #else + if ( CScreenSetup::GetTab() == PHASE_SETUPd ) m_main->ChangePhase(PHASE_SETUPgs); + #endif + if ( CScreenSetup::GetTab() == PHASE_SETUPg ) m_main->ChangePhase(PHASE_SETUPgs); + if ( CScreenSetup::GetTab() == PHASE_SETUPp ) m_main->ChangePhase(PHASE_SETUPps); + if ( CScreenSetup::GetTab() == PHASE_SETUPc ) m_main->ChangePhase(PHASE_SETUPcs); + if ( CScreenSetup::GetTab() == PHASE_SETUPs ) m_main->ChangePhase(PHASE_SETUPss); + } + + if ( pressedButton == EVENT_INTERFACE_WRITE ) + { + StopDialog(); + m_main->StartSuspend(); + m_main->ChangePhase(PHASE_WRITEs); + } + + if ( pressedButton == EVENT_INTERFACE_READ ) + { + StopDialog(); + m_main->StartSuspend(); + m_main->ChangePhase(PHASE_READs); + } + + if ( pressedButton == EVENT_INTERFACE_AGAIN ) + { + StopDialog(); + m_main->ChangePhase(PHASE_LOADING); + } + + if ( pressedButton == EVENT_DIALOG_OK ) + { + StopDialog(); + m_main->ChangePhase(PHASE_LEVEL_LIST); } } - if ( event.type == EVENT_DIALOG_CANCEL || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE) ) ) + + if ( m_dialogType == DialogType::Question ) { - StopDialog(); - } - if ( event.type == EVENT_INTERFACE_SETUP ) - { - StopDialog(); - m_main->StartSuspend(); - #if PLATFORM_LINUX - if ( CScreenSetup::GetTab() == PHASE_SETUPd ) m_main->ChangePhase(PHASE_SETUPds); - #else - if ( CScreenSetup::GetTab() == PHASE_SETUPd ) m_main->ChangePhase(PHASE_SETUPgs); - #endif - if ( CScreenSetup::GetTab() == PHASE_SETUPg ) m_main->ChangePhase(PHASE_SETUPgs); - if ( CScreenSetup::GetTab() == PHASE_SETUPp ) m_main->ChangePhase(PHASE_SETUPps); - if ( CScreenSetup::GetTab() == PHASE_SETUPc ) m_main->ChangePhase(PHASE_SETUPcs); - if ( CScreenSetup::GetTab() == PHASE_SETUPs ) m_main->ChangePhase(PHASE_SETUPss); - } - if ( event.type == EVENT_INTERFACE_AGAIN ) - { - StopDialog(); - m_main->ChangePhase(PHASE_LOADING); - } - if ( event.type == EVENT_INTERFACE_WRITE ) - { - StopDialog(); - m_main->StartSuspend(); - m_main->ChangePhase(PHASE_WRITEs); - } - if ( event.type == EVENT_INTERFACE_READ ) - { - StopDialog(); - m_main->StartSuspend(); - m_main->ChangePhase(PHASE_READs); + if ( pressedButton == EVENT_DIALOG_OK ) + { + StopDialog(); + if (m_callbackYes != nullptr) + { + m_callbackYes(); + } + } + + if ( pressedButton == EVENT_DIALOG_CANCEL ) + { + StopDialog(); + if (m_callbackNo != nullptr) + { + m_callbackNo(); + } + } } return false; @@ -150,15 +171,15 @@ bool CMainDialog::EventProcess(const Event &event) // Do you want to quit the current mission? -void CMainDialog::StartAbort() +void CMainDialog::StartPauseMenu() { CWindow* pw; CButton* pb; Math::Point pos, dim; std::string name; - StartDialog(Math::Point(0.3f, 0.8f), true, false, false); - m_bDialogDelete = false; + StartDialog(Math::Point(0.3f, 0.8f), true); + m_dialogType = DialogType::PauseMenu; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == 0 ) return; @@ -181,7 +202,7 @@ void CMainDialog::StartAbort() pos.y = 0.74f; pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_CANCEL); pb->SetState(STATE_SHADOW); - GetResource(RES_TEXT, RT_DIALOG_NO, name); + GetResource(RES_TEXT, RT_DIALOG_CONTINUE, name); pb->SetName(name); if ( m_main->GetLevelCategory() == LevelCategory::Missions || // missions ? @@ -219,123 +240,74 @@ void CMainDialog::StartAbort() pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_OK); pb->SetState(STATE_SHADOW); pb->SetState(STATE_WARNING); - GetResource(RES_TEXT, RT_DIALOG_YES, name); + GetResource(RES_TEXT, RT_DIALOG_ABORT, name); pb->SetName(name); } -// Do you want to destroy the building? - -void CMainDialog::StartDeleteObject() +void CMainDialog::StartQuestion(const std::string& text, bool warningYes, bool warningNo, DialogCallback yes, DialogCallback no) { CWindow* pw; CButton* pb; - Math::Point pos, dim; + Math::Point pos, dim, ddim; std::string name; - StartDialog(Math::Point(0.7f, 0.3f), false, true, true); - m_bDialogDelete = true; + dim.x = 0.7f; + dim.y = 0.3f; + + StartDialog(dim, false); + m_dialogType = DialogType::Question; + m_callbackYes = yes; + m_callbackNo = no; pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); if ( pw == 0 ) return; pos.x = 0.00f; pos.y = 0.50f; - dim.x = 1.00f; - dim.y = 0.05f; - GetResource(RES_TEXT, RT_DIALOG_DELOBJ, name); - pw->CreateLabel(pos, dim, -1, EVENT_DIALOG_LABEL, name); + ddim.x = 1.00f; + ddim.y = 0.05f; + pw->CreateLabel(pos, ddim, -1, EVENT_DIALOG_LABEL, text); - pb = static_cast(pw->SearchControl(EVENT_DIALOG_OK)); - if ( pb == 0 ) return; - GetResource(RES_TEXT, RT_DIALOG_YESDEL, name); + pos.x = 0.50f-0.15f-0.02f; + pos.y = 0.50f-dim.y/2.0f+0.03f; + ddim.x = 0.15f; + ddim.y = 0.06f; + pb = pw->CreateButton(pos, ddim, -1, EVENT_DIALOG_OK); + pb->SetState(STATE_SHADOW); + GetResource(RES_TEXT, RT_DIALOG_YES, name); pb->SetName(name); - pb->SetState(STATE_WARNING); + if (warningYes) + { + pb->SetState(STATE_WARNING); + } - pb = static_cast(pw->SearchControl(EVENT_DIALOG_CANCEL)); - if ( pb == 0 ) return; - GetResource(RES_TEXT, RT_DIALOG_NODEL, name); + pos.x = 0.50f+0.02f; + pos.y = 0.50f-dim.y/2.0f+0.03f; + ddim.x = 0.15f; + ddim.y = 0.06f; + pb = pw->CreateButton(pos, ddim, -1, EVENT_DIALOG_CANCEL); + pb->SetState(STATE_SHADOW); + GetResource(RES_TEXT, RT_DIALOG_NO, name); pb->SetName(name); + if (warningNo) + { + pb->SetState(STATE_WARNING); + } } -// Do you want to delete the player? - -void CMainDialog::StartDeleteGame(char *gamer) +void CMainDialog::StartQuestion(ResTextType text, bool warningYes, bool warningNo, DialogCallback yes, DialogCallback no) { - CWindow* pw; - CButton* pb; - Math::Point pos, dim; - - StartDialog(Math::Point(0.7f, 0.3f), false, true, true); - m_bDialogDelete = true; - - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); - if (pw == nullptr) - return; - std::string name; - - pos.x = 0.00f; - pos.y = 0.50f; - dim.x = 1.00f; - dim.y = 0.05f; - GetResource(RES_TEXT, RT_DIALOG_DELGAME, name); - std::string text = StrUtils::Format(name.c_str(), gamer); - pw->CreateLabel(pos, dim, -1, EVENT_DIALOG_LABEL, text); - - pb = static_cast(pw->SearchControl(EVENT_DIALOG_OK)); - if ( pb == 0 ) return; - GetResource(RES_TEXT, RT_DIALOG_YESDEL, name); - pb->SetName(name); - pb->SetState(STATE_WARNING); - - pb = static_cast(pw->SearchControl(EVENT_DIALOG_CANCEL)); - if ( pb == 0 ) return; - GetResource(RES_TEXT, RT_DIALOG_NODEL, name); - pb->SetName(name); -} - -// Would you quit the game? - -void CMainDialog::StartQuit() -{ - CWindow* pw; - CButton* pb; - Math::Point pos, dim; - - StartDialog(Math::Point(0.6f, 0.3f), false, true, true); - - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); - if (pw == nullptr) - return; - - std::string name; - - pos.x = 0.00f; - pos.y = 0.50f; - dim.x = 1.00f; - dim.y = 0.05f; - GetResource(RES_TEXT, RT_DIALOG_QUIT, name); - pw->CreateLabel(pos, dim, -1, EVENT_DIALOG_LABEL, name); - - pb = static_cast(pw->SearchControl(EVENT_DIALOG_OK)); - if ( pb == 0 ) return; - GetResource(RES_TEXT, RT_DIALOG_YESQUIT, name); - pb->SetName(name); - pb->SetState(STATE_WARNING); - - pb = static_cast(pw->SearchControl(EVENT_DIALOG_CANCEL)); - if ( pb == 0 ) return; - GetResource(RES_TEXT, RT_DIALOG_NOQUIT, name); - pb->SetName(name); + GetResource(RES_TEXT, text, name); + StartQuestion(name, warningYes, warningNo, yes, no); } // Beginning of displaying a dialog. -void CMainDialog::StartDialog(Math::Point dim, bool bFire, bool bOK, bool bCancel) +void CMainDialog::StartDialog(Math::Point dim, bool fireParticles) { CWindow* pw; - CButton* pb; - Math::Point pos, ddim; + Math::Point pos, ddim; m_main->StartSuspend(); @@ -366,14 +338,13 @@ void CMainDialog::StartDialog(Math::Point dim, bool bFire, bool bOK, bool bCance pw = static_cast(m_interface->SearchControl(EVENT_WINDOW8)); if ( pw != 0 ) pw->ClearState(STATE_ENABLE); - m_bDialogFire = bFire; - - std::string name; + m_dialogFireParticles = fireParticles; pos.x = (1.0f-dim.x)/2.0f; pos.y = (1.0f-dim.y)/2.0f; - pw = m_interface->CreateWindows(pos, dim, bFire?12:8, EVENT_WINDOW9); + pw = m_interface->CreateWindows(pos, dim, m_dialogFireParticles ? 12 : 8, EVENT_WINDOW9); pw->SetState(STATE_SHADOW); + std::string name; GetResource(RES_TEXT, RT_TITLE_BASE, name); pw->SetName(name); @@ -382,32 +353,8 @@ void CMainDialog::StartDialog(Math::Point dim, bool bFire, bool bOK, bool bCance m_dialogTime = 0.0f; m_dialogParti = 999.0f; - if ( bOK ) - { - pos.x = 0.50f-0.15f-0.02f; - pos.y = 0.50f-dim.y/2.0f+0.03f; - ddim.x = 0.15f; - ddim.y = 0.06f; - pb = pw->CreateButton(pos, ddim, -1, EVENT_DIALOG_OK); - pb->SetState(STATE_SHADOW); - GetResource(RES_EVENT, EVENT_DIALOG_OK, name); - pb->SetName(name); - } - - if ( bCancel ) - { - pos.x = 0.50f+0.02f; - pos.y = 0.50f-dim.y/2.0f+0.03f; - ddim.x = 0.15f; - ddim.y = 0.06f; - pb = pw->CreateButton(pos, ddim, -1, EVENT_DIALOG_CANCEL); - pb->SetState(STATE_SHADOW); - GetResource(RES_EVENT, EVENT_DIALOG_CANCEL, name); - pb->SetName(name); - } - m_sound->Play(SOUND_TZOING); - m_bDialog = true; + m_dialogOpen = true; } // Animation of a dialog. @@ -458,7 +405,7 @@ void CMainDialog::FrameDialog(float rTime) if ( m_dialogParti < m_engine->ParticleAdapt(0.05f) ) return; m_dialogParti = 0.0f; - if ( !m_bDialogFire ) return; + if ( !m_dialogFireParticles ) return; dpos = m_dialogPos; ddim = m_dialogDim; @@ -549,7 +496,7 @@ void CMainDialog::StopDialog() m_main->StopSuspend(); m_interface->DeleteControl(EVENT_WINDOW9); - m_bDialog = false; + m_dialogOpen = false; } @@ -557,7 +504,7 @@ void CMainDialog::StopDialog() bool CMainDialog::IsDialog() { - return m_bDialog; + return m_dialogOpen; } } // namespace Ui diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index 4321341e..badc7894 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -19,6 +19,7 @@ #pragma once #include "common/event.h" +#include "common/restext.h" #include "object/robotmain.h" @@ -39,25 +40,6 @@ namespace Ui class CInterface; -class CScreen; -class CScreenApperance; -class CScreenIORead; -class CScreenIOWrite; -class CScreenLevelList; -class CScreenLoading; -class CScreenMainMenu; -class CScreenPlayerSelect; -class CScreenQuit; -class CScreenSetup; -class CScreenSetupControls; -class CScreenSetupDisplay; -class CScreenSetupGame; -class CScreenSetupGraphics; -class CScreenSetupSound; -class CScreenWelcome; - - - class CMainDialog { public: @@ -67,15 +49,22 @@ public: bool EventProcess(const Event &event); void ChangePhase(Phase phase); - void StartAbort(); - void StartDeleteObject(); - void StartDeleteGame(char *gamer); - void StartQuit(); - void StartDialog(Math::Point dim, bool bFire, bool bOK, bool bCancel); - void FrameDialog(float rTime); + + typedef std::function DialogCallback; + void StartQuestion(const std::string& text, + bool warningYes, bool warningNo, + DialogCallback yes = nullptr, DialogCallback no = nullptr); + void StartQuestion(ResTextType text, + bool warningYes, bool warningNo, + DialogCallback yes = nullptr, DialogCallback no = nullptr); + void StartPauseMenu(); void StopDialog(); bool IsDialog(); +protected: + void StartDialog(Math::Point dim, bool fireParticles); + void FrameDialog(float rTime); + protected: CRobotMain* m_main; Gfx::CEngine* m_engine; @@ -86,13 +75,21 @@ protected: Phase m_phase; // copy of CRobotMain - bool m_bDialog; // this dialogue? - bool m_bDialogFire; // setting on fire? - bool m_bDialogDelete; + enum class DialogType { + Question, + PauseMenu + }; + + bool m_dialogOpen; + DialogType m_dialogType; + bool m_dialogFireParticles; Math::Point m_dialogPos; Math::Point m_dialogDim; - float m_dialogParti; float m_dialogTime; + float m_dialogParti; + + DialogCallback m_callbackYes; + DialogCallback m_callbackNo; }; } // namespace Ui diff --git a/src/ui/mainui.cpp b/src/ui/mainui.cpp index ecaba50e..e6450acc 100644 --- a/src/ui/mainui.cpp +++ b/src/ui/mainui.cpp @@ -56,8 +56,6 @@ #include "ui/maindialog.h" #include "ui/controls/window.h" -template<> Ui::CMainUserInterface* CSingleton::m_instance = nullptr; - namespace Ui { @@ -803,15 +801,6 @@ void CMainUserInterface::ShowSoluceUpdate() } } -// TODO: Clean this up -void CMainUserInterface::NameDelete() -{ - if ( m_phase == PHASE_PLAYER_SELECT ) - { - m_screenPlayerSelect->NameDelete(); - } -} - // Whether to show the solution. bool CMainUserInterface::GetSceneSoluce() diff --git a/src/ui/mainui.h b/src/ui/mainui.h index 28e589c8..6b763d51 100644 --- a/src/ui/mainui.h +++ b/src/ui/mainui.h @@ -18,8 +18,6 @@ */ #pragma once -#include "common/singleton.h" - #include "object/robotmain.h" #include @@ -57,8 +55,7 @@ class CScreenSetupSound; class CScreenWelcome; - -class CMainUserInterface : public CSingleton +class CMainUserInterface { public: CMainUserInterface(); @@ -67,7 +64,6 @@ public: CMainDialog* GetDialog(); - bool EventProcess(const Event &event); void ChangePhase(Phase phase); @@ -82,8 +78,6 @@ public: void AllMissionUpdate(); void ShowSoluceUpdate(); - void NameDelete(); - void UpdateCustomLevelList(); std::string GetCustomLevelName(int id); const std::vector& GetCustomLevelList(); diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index 987207f5..4a9cb4c7 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -22,6 +22,7 @@ #include "app/app.h" #include "common/logger.h" +#include "common/stringutils.h" #include "object/player_profile.h" @@ -37,7 +38,7 @@ namespace Ui { CScreenPlayerSelect::CScreenPlayerSelect(CMainDialog* mainDialog) - : m_mainDialog(mainDialog) + : m_dialog(mainDialog) { } @@ -151,6 +152,8 @@ bool CScreenPlayerSelect::EventProcess(const Event &event) CWindow* pw; CButton* pb; CList* pl; + std::string name; + char* gamer; switch( event.type ) { @@ -199,7 +202,12 @@ bool CScreenPlayerSelect::EventProcess(const Event &event) if ( pw == 0 ) break; pl = static_cast(pw->SearchControl(EVENT_INTERFACE_NLIST)); if ( pl == 0 ) break; - m_mainDialog->StartDeleteGame(pl->GetItemName(pl->GetSelect())); + + GetResource(RES_TEXT, RT_DIALOG_DELGAME, name); + gamer = pl->GetItemName(pl->GetSelect()); + m_dialog->StartQuestion(StrUtils::Format(name.c_str(), gamer), true, false, [&]() { + NameDelete(); + }); break; default: diff --git a/src/ui/screen/screen_player_select.h b/src/ui/screen/screen_player_select.h index 70923697..a6b00684 100644 --- a/src/ui/screen/screen_player_select.h +++ b/src/ui/screen/screen_player_select.h @@ -45,7 +45,7 @@ protected: bool NameCreate(); private: - CMainDialog* m_mainDialog; + CMainDialog* m_dialog; }; } // namespace Ui