diff --git a/CMakeLists.txt b/CMakeLists.txt index e318271ef..152029edd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(GAMESCRIPT apps/openmw/mwscript/interpretercontext.cpp apps/openmw/mwscript/cellextensions.cpp apps/openmw/mwscript/miscextensions.cpp + apps/openmw/mwscript/guiextensions.cpp apps/openmw/mwscript/extensions.cpp apps/openmw/mwscript/globalscripts.cpp ) @@ -50,6 +51,7 @@ set(GAMESCRIPT_HEADER apps/openmw/mwscript/interpretercontext.hpp apps/openmw/mwscript/cellextensions.hpp apps/openmw/mwscript/miscextensions.hpp + apps/openmw/mwscript/guiextensions.hpp apps/openmw/mwscript/extensions.hpp apps/openmw/mwscript/globalscripts.hpp ) diff --git a/apps/openmw/mwgui/guimanager.cpp b/apps/openmw/mwgui/guimanager.cpp index 3ce17260f..b169ffac2 100644 --- a/apps/openmw/mwgui/guimanager.cpp +++ b/apps/openmw/mwgui/guimanager.cpp @@ -5,61 +5,26 @@ namespace MWGui { - void GuiManager::showBirthDialogue() + void GuiManager::enableWindow (GuiWindow window) { - std::cout << "" << std::endl; + std::cout << "enable window: " << window << std::endl; } - void GuiManager::showClassDialogue() + void GuiManager::showOneTimeDialogue (GuiOneTimeDialogue dialogue) { - std::cout << "" << std::endl; - } - - void GuiManager::showNameDialogue() - { - std::cout << "" << std::endl; - } - - void GuiManager::showRaceDialogue() - { - std::cout << "" << std::endl; + std::cout << "show one time dialogue: " << dialogue << std::endl; } - void GuiManager::showReviewDialogue() + void GuiManager::enableDialogue (GuiDialogue dialogue) { - std::cout << "" << std::endl; - } - - void GuiManager::enableInventoryWindow() - { - std::cout << "" << std::endl; + std::cout << "enable dialogue: " << dialogue << std::endl; } - void GuiManager::enableMagicWindow() + void GuiManager::showDialogue (GuiDialogue dialogue) { - std::cout << "" << std::endl; + std::cout << "show dialogue: " << dialogue << std::endl; } - - void GuiManager::enableMapWindow() - { - std::cout << "" << std::endl; - } - - void GuiManager::enableStatsMenu() - { - std::cout << "" << std::endl; - } - - void GuiManager::enableLevelUpDialogue() - { - std::cout << "" << std::endl; - } - - void GuiManager::showRestDialogue() - { - std::cout << "" << std::endl; - } - + bool GuiManager::isGuiActive() const { return false; diff --git a/apps/openmw/mwgui/guimanager.hpp b/apps/openmw/mwgui/guimanager.hpp index c20aeae35..2a27c9aa3 100644 --- a/apps/openmw/mwgui/guimanager.hpp +++ b/apps/openmw/mwgui/guimanager.hpp @@ -7,38 +7,31 @@ namespace MWGui { public: - void showBirthDialogue(); - ///< Birthsign (part of the character generation process) + enum GuiWindow + { + Gui_Inventory, Gui_Magic, Gui_Map, Gui_Status + }; - void showClassDialogue(); - ///< Class selection (part of the character generation process) + enum GuiOneTimeDialogue // used only once + { + // character generation + Gui_Birth, Gui_Class, Gui_Name, Gui_Race, Gui_Review + }; + + enum GuiDialogue + { + Gui_Rest + }; - void showNameDialogue(); - ///< Enter character name (part of the character generation process) - - void showRaceDialogue(); - ///< Race selection (part of the character generation process) + void enableWindow (GuiWindow window); + ///< diabled by default. - void showReviewDialogue(); - ///< Character generation review (final part of the character generation process) - - void enableInventoryWindow(); - ///< Initially disabled. + void showOneTimeDialogue (GuiOneTimeDialogue dialogue); - void enableMagicWindow(); - ///< Initially disabled. - - void enableMapWindow(); - ///< Initially disabled. - - void enableStatsMenu(); - ///< Initially disabled. + void enableDialogue (GuiDialogue dialogue); + ///< disabled by default. - void enableLevelUpDialogue(); - ///< Rest/Level-up. Initially disabled. - - void showRestDialogue(); - ///< Rest dialogue: ask player how many hours he wants to sleep. + void showDialogue (GuiDialogue dialogue); bool isGuiActive() const; ///< Any non-HUD GUI element active (dialogues and windows)? diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 7e3776e18..1cda9aeaa 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -35,5 +35,16 @@ op 0x200000a: StopSound op 0x200000b: GetSoundPlaying op 0x200000c: XBox (always 0) op 0x200000d: OnActivate -opcodes 0x200000e-0x3ffffff unused +op 0x200000e: EnableBirthMenu +op 0x200000f: EnableClassMenu +op 0x2000010: EnableNameMenu +op 0x2000011: EnableRaceMenu +op 0x2000012: EnableStatsReviewMenu +op 0x2000013: EnableInventoryMenu +op 0x2000014: EnableMagicMenu +op 0x2000015: EnableMapMenu +op 0x2000016: EnableStatsMenu +op 0x2000017: EnableRest +op 0x2000018: ShowRestMenu +opcodes 0x2000019-0x3ffffff unused diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp index ea968b458..e309d632c 100644 --- a/apps/openmw/mwscript/extensions.cpp +++ b/apps/openmw/mwscript/extensions.cpp @@ -5,6 +5,7 @@ #include "cellextensions.hpp" #include "miscextensions.hpp" +#include "guiextensions.hpp" namespace MWScript { @@ -12,6 +13,7 @@ namespace MWScript { Cell::registerExtensions (extensions); Misc::registerExtensions (extensions); + Gui::registerExtensions (extensions); MWSound::registerExtensions (extensions); } } diff --git a/apps/openmw/mwscript/guiextensions.cpp b/apps/openmw/mwscript/guiextensions.cpp new file mode 100644 index 000000000..5758899a8 --- /dev/null +++ b/apps/openmw/mwscript/guiextensions.cpp @@ -0,0 +1,153 @@ + +#include "guiextensions.hpp" + +#include + +#include +#include +#include + +#include "interpretercontext.hpp" + +#include "../mwgui/guimanager.hpp" + +namespace MWScript +{ + namespace Gui + { + class OpEnableWindow : public Interpreter::Opcode0 + { + MWGui::GuiManager::GuiWindow mWindow; + + public: + + OpEnableWindow (MWGui::GuiManager::GuiWindow window) : mWindow (window) {} + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getGuiManager().enableWindow (mWindow); + } + }; + + class OpShowOneTimeDialogue : public Interpreter::Opcode0 + { + MWGui::GuiManager::GuiOneTimeDialogue mOneTimeDialogue; + + public: + + OpShowOneTimeDialogue (MWGui::GuiManager::GuiOneTimeDialogue OneTimeDialogue) + : mOneTimeDialogue (OneTimeDialogue) + {} + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getGuiManager().showOneTimeDialogue (mOneTimeDialogue); + } + }; + + class OpShowDialogue : public Interpreter::Opcode0 + { + MWGui::GuiManager::GuiDialogue mDialogue; + + public: + + OpShowDialogue (MWGui::GuiManager::GuiDialogue dialogue) + : mDialogue (dialogue) + {} + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getGuiManager().enableDialogue (mDialogue); + } + }; + + class OpEnableDialogue : public Interpreter::Opcode0 + { + MWGui::GuiManager::GuiDialogue mDialogue; + + public: + + OpEnableDialogue (MWGui::GuiManager::GuiDialogue dialogue) + : mDialogue (dialogue) + {} + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getGuiManager().showDialogue (mDialogue); + } + }; + + const int opcodeEnableBirthMenu = 0x200000e; + const int opcodeEnableClassMenu = 0x200000f; + const int opcodeEnableNameMenu = 0x2000010; + const int opcodeEnableRaceMenu = 0x2000011; + const int opcodeEnableStatsReviewMenu = 0x2000012; + const int opcodeEnableInventoryMenu = 0x2000013; + const int opcodeEnableMagicMenu = 0x2000014; + const int opcodeEnableMapMenu = 0x2000015; + const int opcodeEnableStatsMenu = 0x2000016; + const int opcodeEnableRest = 0x2000017; + const int opcodeShowRestMenu = 0x2000018; + + void registerExtensions (Compiler::Extensions& extensions) + { + extensions.registerInstruction ("enablebirthmenu", "", opcodeEnableBirthMenu); + extensions.registerInstruction ("enableclassmenu", "", opcodeEnableClassMenu); + extensions.registerInstruction ("enablenamemenu", "", opcodeEnableNameMenu); + extensions.registerInstruction ("enableracemenu", "", opcodeEnableRaceMenu); + extensions.registerInstruction ("enablestatsreviewmenu", "", + opcodeEnableStatsReviewMenu); + + extensions.registerInstruction ("enableinventorymenu", "", opcodeEnableInventoryMenu); + extensions.registerInstruction ("enablemagicmenu", "", opcodeEnableMagicMenu); + extensions.registerInstruction ("enablemapmenu", "", opcodeEnableMapMenu); + extensions.registerInstruction ("enablestatsmenu", "", opcodeEnableStatsMenu); + + extensions.registerInstruction ("enablerestmenu", "", opcodeEnableRest); + extensions.registerInstruction ("enablelevelupmenu", "", opcodeEnableRest); + + extensions.registerInstruction ("showrestmenu", "", opcodeShowRestMenu); + } + + void installOpcodes (Interpreter::Interpreter& interpreter) + { + interpreter.installSegment5 (opcodeEnableBirthMenu, + new OpShowOneTimeDialogue (MWGui::GuiManager::Gui_Birth)); + interpreter.installSegment5 (opcodeEnableClassMenu, + new OpShowOneTimeDialogue (MWGui::GuiManager::Gui_Class)); + interpreter.installSegment5 (opcodeEnableNameMenu, + new OpShowOneTimeDialogue (MWGui::GuiManager::Gui_Name)); + interpreter.installSegment5 (opcodeEnableRaceMenu, + new OpShowOneTimeDialogue (MWGui::GuiManager::Gui_Race)); + interpreter.installSegment5 (opcodeEnableStatsReviewMenu, + new OpShowOneTimeDialogue (MWGui::GuiManager::Gui_Review)); + + interpreter.installSegment5 (opcodeEnableInventoryMenu, + new OpEnableWindow (MWGui::GuiManager::Gui_Inventory)); + interpreter.installSegment5 (opcodeEnableMagicMenu, + new OpEnableWindow (MWGui::GuiManager:: Gui_Magic)); + interpreter.installSegment5 (opcodeEnableMapMenu, + new OpEnableWindow (MWGui::GuiManager::Gui_Map)); + interpreter.installSegment5 (opcodeEnableStatsMenu, + new OpEnableWindow (MWGui::GuiManager::Gui_Status)); + + interpreter.installSegment5 (opcodeEnableRest, + new OpEnableDialogue (MWGui::GuiManager::Gui_Rest)); + + interpreter.installSegment5 (opcodeShowRestMenu, + new OpShowDialogue (MWGui::GuiManager::Gui_Rest)); + } + } +} diff --git a/apps/openmw/mwscript/guiextensions.hpp b/apps/openmw/mwscript/guiextensions.hpp new file mode 100644 index 000000000..83447e8fb --- /dev/null +++ b/apps/openmw/mwscript/guiextensions.hpp @@ -0,0 +1,26 @@ +#ifndef GAME_SCRIPT_GUIEXTENSIONS_H +#define GAME_SCRIPT_GUIEXTENSIONS_H + +namespace Compiler +{ + class Extensions; +} + +namespace Interpreter +{ + class Interpreter; +} + +namespace MWScript +{ + /// \brief GUI-related script functionality + namespace Gui + { + void registerExtensions (Compiler::Extensions& extensions); + + void installOpcodes (Interpreter::Interpreter& interpreter); + } +} + +#endif + diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 31b351cb5..92840fdd5 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -9,6 +9,8 @@ #include "../mwworld/world.hpp" +#include "../mwgui/guimanager.hpp" + #include "locals.hpp" #include "globalscripts.hpp" @@ -78,7 +80,7 @@ namespace MWScript bool InterpreterContext::menuMode() { - return false; + return mEnvironment.mGuiManager->isGuiActive(); } int InterpreterContext::getGlobalShort (const std::string& name) const @@ -164,6 +166,11 @@ namespace MWScript return mEnvironment.mFrameDuration; } + MWGui::GuiManager& InterpreterContext::getGuiManager() + { + return *mEnvironment.mGuiManager; + } + MWWorld::World& InterpreterContext::getWorld() { return *mEnvironment.mWorld; diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index c12554dec..4b3dfa124 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -72,10 +72,12 @@ namespace MWScript virtual bool hasBeenActivated() const; virtual float getSecondsPassed() const; - + MWWorld::World& getWorld(); MWSound::SoundManager& getSoundManager(); + + MWGui::GuiManager& getGuiManager(); MWWorld::Ptr getReference(); ///< Reference, that the script is running from (can be empty) diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp index 42ece2f32..912e959ae 100644 --- a/apps/openmw/mwscript/scriptmanager.cpp +++ b/apps/openmw/mwscript/scriptmanager.cpp @@ -19,6 +19,7 @@ #include "cellextensions.hpp" #include "miscextensions.hpp" +#include "guiextensions.hpp" namespace MWScript { @@ -123,6 +124,7 @@ namespace MWScript Interpreter::installOpcodes (interpreter); Cell::installOpcodes (interpreter); Misc::installOpcodes (interpreter); + Gui::installOpcodes (interpreter); MWSound::installOpcodes (interpreter); } }