2010-07-07 20:12:00 +02:00
|
|
|
#include "guiextensions.hpp"
|
|
|
|
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2010-07-07 20:12:00 +02:00
|
|
|
|
2023-07-28 15:23:53 +02:00
|
|
|
#include <components/interpreter/context.hpp>
|
2010-07-07 20:12:00 +02:00
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-09-20 18:02:37 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2014-01-08 17:19:43 +01:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2014-01-08 17:19:43 +01:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2014-01-08 17:19:43 +01:00
|
|
|
#include "ref.hpp"
|
2010-07-07 20:12:00 +02:00
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Gui
|
2011-07-12 21:26:58 +02:00
|
|
|
{
|
2010-07-07 20:12:00 +02:00
|
|
|
class OpEnableWindow : public Interpreter::Opcode0
|
|
|
|
{
|
2010-07-17 14:01:47 +02:00
|
|
|
MWGui::GuiWindow mWindow;
|
2011-07-12 21:26:58 +02:00
|
|
|
|
2010-07-17 14:01:47 +02:00
|
|
|
public:
|
|
|
|
OpEnableWindow(MWGui::GuiWindow window)
|
|
|
|
: mWindow(window)
|
|
|
|
{
|
|
|
|
}
|
2011-07-12 21:26:58 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-07 20:12:00 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->allow(mWindow);
|
2011-07-12 21:26:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-15 20:18:41 +02:00
|
|
|
class OpEnableRest : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2012-09-15 20:18:41 +02:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->enableRest();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-08 17:19:43 +01:00
|
|
|
template <class R>
|
|
|
|
class OpShowRestMenu : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2014-01-08 17:19:43 +01:00
|
|
|
{
|
2014-01-09 02:14:08 +01:00
|
|
|
MWWorld::Ptr bed = R()(runtime, false);
|
2014-01-08 17:19:43 +01:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
if (bed.isEmpty()
|
|
|
|
|| !MWBase::Environment::get().getMechanicsManager()->sleepInBed(MWMechanics::getPlayer(), bed))
|
2017-09-23 15:06:11 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Rest, bed);
|
2014-01-08 17:19:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-07 20:12:00 +02:00
|
|
|
class OpShowDialogue : public Interpreter::Opcode0
|
|
|
|
{
|
2010-07-17 14:01:47 +02:00
|
|
|
MWGui::GuiMode mDialogue;
|
2011-07-12 21:26:58 +02:00
|
|
|
|
2010-07-07 20:12:00 +02:00
|
|
|
public:
|
2010-07-17 14:01:47 +02:00
|
|
|
OpShowDialogue(MWGui::GuiMode dialogue)
|
2010-07-07 20:12:00 +02:00
|
|
|
: mDialogue(dialogue)
|
|
|
|
{
|
|
|
|
}
|
2011-07-12 21:26:58 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-07 20:12:00 +02:00
|
|
|
{
|
2012-05-23 12:23:35 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(mDialogue);
|
2011-07-12 21:26:58 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpGetButtonPressed : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2011-07-12 21:26:58 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
runtime.push(MWBase::Environment::get().getWindowManager()->readPressedButton());
|
2011-07-12 21:26:58 +02:00
|
|
|
}
|
|
|
|
};
|
2010-07-07 20:12:00 +02:00
|
|
|
|
2012-03-29 19:45:19 +02:00
|
|
|
class OpToggleFogOfWar : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2012-03-29 19:45:19 +02:00
|
|
|
{
|
2014-05-16 09:21:08 +02:00
|
|
|
runtime.getContext().report(MWBase::Environment::get().getWindowManager()->toggleFogOfWar()
|
|
|
|
? "Fog of war -> On"
|
|
|
|
: "Fog of war -> Off");
|
2012-03-29 19:45:19 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-16 15:00:44 +02:00
|
|
|
class OpToggleFullHelp : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2012-04-16 15:00:44 +02:00
|
|
|
{
|
2014-05-16 09:21:08 +02:00
|
|
|
runtime.getContext().report(MWBase::Environment::get().getWindowManager()->toggleFullHelp()
|
|
|
|
? "Full help -> On"
|
|
|
|
: "Full help -> Off");
|
2012-04-16 15:00:44 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-20 18:02:37 +02:00
|
|
|
class OpShowMap : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2012-09-20 18:02:37 +02:00
|
|
|
{
|
2022-08-27 13:07:59 +02:00
|
|
|
std::string_view cell = runtime.getStringLiteral(runtime[0].mInteger);
|
2012-09-20 18:02:37 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
// "Will match complete or partial cells, so ShowMap, "Vivec" will show cells Vivec and Vivec, Fred's
|
|
|
|
// House as well." http://www.uesp.net/wiki/Tes3Mod:ShowMap
|
|
|
|
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::Store<ESM::Cell>& cells = MWBase::Environment::get().getESMStore()->get<ESM::Cell>();
|
2012-11-05 22:34:08 +04:00
|
|
|
|
2021-07-03 01:03:57 +03:00
|
|
|
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
|
|
|
|
|
|
|
|
for (auto it = cells.extBegin(); it != cells.extEnd(); ++it)
|
2012-09-20 18:02:37 +02:00
|
|
|
{
|
2023-01-19 17:31:45 +01:00
|
|
|
const auto& cellName = it->mName;
|
2022-12-01 19:37:35 +01:00
|
|
|
if (Misc::StringUtils::ciStartsWith(cellName, cell))
|
|
|
|
winMgr->addVisitedLocation(cellName, it->getGridX(), it->getGridY());
|
2012-09-20 18:02:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpFillMap : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2012-09-20 18:02:37 +02:00
|
|
|
{
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::Store<ESM::Cell>& cells = MWBase::Environment::get().getESMStore()->get<ESM::Cell>();
|
2012-11-05 22:34:08 +04:00
|
|
|
|
2022-08-27 13:07:59 +02:00
|
|
|
for (auto it = cells.extBegin(); it != cells.extEnd(); ++it)
|
2012-09-20 18:02:37 +02:00
|
|
|
{
|
2023-01-19 17:31:45 +01:00
|
|
|
const std::string& name = it->mName;
|
2022-08-27 13:07:59 +02:00
|
|
|
if (!name.empty())
|
2012-11-05 22:34:08 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->addVisitedLocation(
|
|
|
|
name, it->getGridX(), it->getGridY());
|
2012-09-20 18:02:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-10 17:47:59 +02:00
|
|
|
class OpMenuTest : public Interpreter::Opcode1
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
|
2014-06-10 17:47:59 +02:00
|
|
|
{
|
|
|
|
int arg = 0;
|
|
|
|
if (arg0 > 0)
|
|
|
|
{
|
|
|
|
arg = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg == 0)
|
|
|
|
{
|
|
|
|
MWGui::GuiMode modes[] = { MWGui::GM_Inventory, MWGui::GM_Container };
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->containsMode(modes[i]))
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(modes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MWGui::GuiWindow gw = MWGui::GW_None;
|
|
|
|
if (arg == 3)
|
|
|
|
gw = MWGui::GW_Stats;
|
|
|
|
if (arg == 4)
|
|
|
|
gw = MWGui::GW_Inventory;
|
|
|
|
if (arg == 5)
|
|
|
|
gw = MWGui::GW_Magic;
|
|
|
|
if (arg == 6)
|
|
|
|
gw = MWGui::GW_Map;
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->pinWindow(gw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-20 18:49:19 +02:00
|
|
|
class OpToggleMenus : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2014-06-20 18:49:19 +02:00
|
|
|
{
|
2017-09-23 12:58:28 +02:00
|
|
|
bool state = MWBase::Environment::get().getWindowManager()->toggleHud();
|
2014-06-20 18:49:19 +02:00
|
|
|
runtime.getContext().report(state ? "GUI -> On" : "GUI -> Off");
|
2014-12-01 14:48:53 +01:00
|
|
|
|
|
|
|
if (!state)
|
|
|
|
{
|
|
|
|
while (MWBase::Environment::get().getWindowManager()->getMode()
|
|
|
|
!= MWGui::GM_None) // don't use isGuiMode, or we get an infinite loop for modal message boxes!
|
|
|
|
MWBase::Environment::get().getWindowManager()->popGuiMode();
|
|
|
|
}
|
2014-06-20 18:49:19 +02:00
|
|
|
}
|
|
|
|
};
|
2012-09-20 18:02:37 +02:00
|
|
|
|
2010-07-07 20:12:00 +02:00
|
|
|
void installOpcodes(Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2022-01-27 19:18:57 +00:00
|
|
|
interpreter.installSegment5<OpShowDialogue>(Compiler::Gui::opcodeEnableBirthMenu, MWGui::GM_Birth);
|
|
|
|
interpreter.installSegment5<OpShowDialogue>(Compiler::Gui::opcodeEnableClassMenu, MWGui::GM_Class);
|
|
|
|
interpreter.installSegment5<OpShowDialogue>(Compiler::Gui::opcodeEnableNameMenu, MWGui::GM_Name);
|
|
|
|
interpreter.installSegment5<OpShowDialogue>(Compiler::Gui::opcodeEnableRaceMenu, MWGui::GM_Race);
|
|
|
|
interpreter.installSegment5<OpShowDialogue>(Compiler::Gui::opcodeEnableStatsReviewMenu, MWGui::GM_Review);
|
|
|
|
interpreter.installSegment5<OpShowDialogue>(Compiler::Gui::opcodeEnableLevelupMenu, MWGui::GM_Levelup);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpEnableWindow>(Compiler::Gui::opcodeEnableInventoryMenu, MWGui::GW_Inventory);
|
|
|
|
interpreter.installSegment5<OpEnableWindow>(Compiler::Gui::opcodeEnableMagicMenu, MWGui::GW_Magic);
|
|
|
|
interpreter.installSegment5<OpEnableWindow>(Compiler::Gui::opcodeEnableMapMenu, MWGui::GW_Map);
|
|
|
|
interpreter.installSegment5<OpEnableWindow>(Compiler::Gui::opcodeEnableStatsMenu, MWGui::GW_Stats);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpEnableRest>(Compiler::Gui::opcodeEnableRest);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpShowRestMenu<ImplicitRef>>(Compiler::Gui::opcodeShowRestMenu);
|
|
|
|
interpreter.installSegment5<OpShowRestMenu<ExplicitRef>>(Compiler::Gui::opcodeShowRestMenuExplicit);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpGetButtonPressed>(Compiler::Gui::opcodeGetButtonPressed);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpToggleFogOfWar>(Compiler::Gui::opcodeToggleFogOfWar);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpToggleFullHelp>(Compiler::Gui::opcodeToggleFullHelp);
|
|
|
|
|
|
|
|
interpreter.installSegment5<OpShowMap>(Compiler::Gui::opcodeShowMap);
|
|
|
|
interpreter.installSegment5<OpFillMap>(Compiler::Gui::opcodeFillMap);
|
|
|
|
interpreter.installSegment3<OpMenuTest>(Compiler::Gui::opcodeMenuTest);
|
|
|
|
interpreter.installSegment5<OpToggleMenus>(Compiler::Gui::opcodeToggleMenus);
|
2010-07-07 20:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|