1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 15:39:02 +00:00
OpenMW/apps/openmw/mwscript/guiextensions.cpp

227 lines
8.8 KiB
C++
Raw Normal View History

#include "guiextensions.hpp"
#include <boost/algorithm/string.hpp>
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include <components/esm_store/store.hpp>
#include <components/esm_store/reclists.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "interpretercontext.hpp"
namespace MWScript
{
namespace Gui
2011-07-12 19:26:58 +00:00
{
class OpEnableWindow : public Interpreter::Opcode0
{
MWGui::GuiWindow mWindow;
2011-07-12 19:26:58 +00:00
public:
2011-07-12 19:26:58 +00:00
OpEnableWindow (MWGui::GuiWindow window) : mWindow (window) {}
2011-07-12 19:26:58 +00:00
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getWindowManager()->allow (mWindow);
2011-07-12 19:26:58 +00:00
}
};
2012-09-15 18:18:41 +00:00
class OpEnableRest : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getWindowManager()->enableRest();
}
};
class OpShowDialogue : public Interpreter::Opcode0
{
MWGui::GuiMode mDialogue;
2011-07-12 19:26:58 +00:00
public:
2011-07-12 19:26:58 +00:00
OpShowDialogue (MWGui::GuiMode dialogue)
: mDialogue (dialogue)
{}
2011-07-12 19:26:58 +00:00
virtual void execute (Interpreter::Runtime& runtime)
{
2012-05-23 10:23:35 +00:00
MWBase::Environment::get().getWindowManager()->pushGuiMode(mDialogue);
2011-07-12 19:26:58 +00:00
}
};
class OpGetButtonPressed : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
runtime.push (MWBase::Environment::get().getWindowManager()->readPressedButton());
2011-07-12 19:26:58 +00:00
}
};
2012-03-29 17:45:19 +00:00
class OpToggleFogOfWar : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getWindowManager()->toggleFogOfWar();
2012-03-29 17:45:19 +00:00
}
};
2012-04-16 13:00:44 +00:00
class OpToggleFullHelp : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getWindowManager()->toggleFullHelp();
2012-04-16 13:00:44 +00:00
}
};
class OpShowMap : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
std::string cell = (runtime.getStringLiteral (runtime[0].mInteger));
boost::algorithm::to_lower(cell);
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
const ESMS::CellList::ExtCells& extCells = MWBase::Environment::get().getWorld ()->getStore ().cells.extCells;
for (ESMS::CellList::ExtCells::const_iterator it = extCells.begin(); it != extCells.end(); ++it)
{
2012-09-21 08:49:34 +00:00
std::string name = it->second->mName;
boost::algorithm::to_lower(name);
if (name.find(cell) != std::string::npos)
2012-09-21 08:49:34 +00:00
MWBase::Environment::get().getWindowManager()->addVisitedLocation (it->second->mName, it->first.first, it->first.second);
}
}
};
class OpFillMap : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
const ESMS::CellList::ExtCells& extCells = MWBase::Environment::get().getWorld ()->getStore ().cells.extCells;
for (ESMS::CellList::ExtCells::const_iterator it = extCells.begin(); it != extCells.end(); ++it)
{
2012-09-21 08:49:34 +00:00
std::string name = it->second->mName;
if (name != "")
MWBase::Environment::get().getWindowManager()->addVisitedLocation (name, it->first.first, it->first.second);
}
}
};
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;
2011-07-12 19:26:58 +00:00
const int opcodeGetButtonPressed = 0x2000137;
2012-03-29 17:45:19 +00:00
const int opcodeToggleFogOfWar = 0x2000145;
2012-04-16 13:00:44 +00:00
const int opcodeToggleFullHelp = 0x2000151;
const int opcodeShowMap = 0x20001a0;
const int opcodeFillMap = 0x20001a1;
2011-07-12 19:26:58 +00:00
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerInstruction ("enablebirthmenu", "", opcodeEnableBirthMenu);
extensions.registerInstruction ("enableclassmenu", "", opcodeEnableClassMenu);
extensions.registerInstruction ("enablenamemenu", "", opcodeEnableNameMenu);
extensions.registerInstruction ("enableracemenu", "", opcodeEnableRaceMenu);
2012-06-16 14:38:54 +00:00
extensions.registerInstruction ("enablestatreviewmenu", "",
2012-04-16 13:00:44 +00:00
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);
2011-07-12 19:26:58 +00:00
extensions.registerInstruction ("showrestmenu", "", opcodeShowRestMenu);
2011-07-12 19:26:58 +00:00
extensions.registerFunction ("getbuttonpressed", 'l', "", opcodeGetButtonPressed);
2012-03-29 17:45:19 +00:00
extensions.registerInstruction ("togglefogofwar", "", opcodeToggleFogOfWar);
extensions.registerInstruction ("tfow", "", opcodeToggleFogOfWar);
2012-04-16 13:00:44 +00:00
extensions.registerInstruction ("togglefullhelp", "", opcodeToggleFullHelp);
extensions.registerInstruction ("tfh", "", opcodeToggleFullHelp);
extensions.registerInstruction ("showmap", "S", opcodeShowMap);
extensions.registerInstruction ("fillmap", "", opcodeFillMap);
}
2011-07-12 19:26:58 +00:00
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeEnableBirthMenu,
new OpShowDialogue (MWGui::GM_Birth));
interpreter.installSegment5 (opcodeEnableClassMenu,
new OpShowDialogue (MWGui::GM_Class));
interpreter.installSegment5 (opcodeEnableNameMenu,
new OpShowDialogue (MWGui::GM_Name));
interpreter.installSegment5 (opcodeEnableRaceMenu,
new OpShowDialogue (MWGui::GM_Race));
interpreter.installSegment5 (opcodeEnableStatsReviewMenu,
new OpShowDialogue (MWGui::GM_Review));
interpreter.installSegment5 (opcodeEnableInventoryMenu,
new OpEnableWindow (MWGui::GW_Inventory));
interpreter.installSegment5 (opcodeEnableMagicMenu,
new OpEnableWindow (MWGui::GW_Magic));
interpreter.installSegment5 (opcodeEnableMapMenu,
new OpEnableWindow (MWGui::GW_Map));
interpreter.installSegment5 (opcodeEnableStatsMenu,
new OpEnableWindow (MWGui::GW_Stats));
interpreter.installSegment5 (opcodeEnableRest,
2012-09-15 18:18:41 +00:00
new OpEnableRest ());
interpreter.installSegment5 (opcodeShowRestMenu,
new OpShowDialogue (MWGui::GM_RestBed));
2011-07-12 19:26:58 +00:00
interpreter.installSegment5 (opcodeGetButtonPressed, new OpGetButtonPressed);
2012-03-29 17:45:19 +00:00
interpreter.installSegment5 (opcodeToggleFogOfWar, new OpToggleFogOfWar);
2012-04-16 13:00:44 +00:00
interpreter.installSegment5 (opcodeToggleFullHelp, new OpToggleFullHelp);
interpreter.installSegment5 (opcodeShowMap, new OpShowMap);
interpreter.installSegment5 (opcodeFillMap, new OpFillMap);
}
}
}