2010-07-07 18:12:00 +00:00
# include "guiextensions.hpp"
# include <components/compiler/extensions.hpp>
2013-08-07 00:38:41 +00:00
# include <components/compiler/opcodes.hpp>
2010-07-07 18:12:00 +00:00
# include <components/interpreter/interpreter.hpp>
# include <components/interpreter/runtime.hpp>
# include <components/interpreter/opcodes.hpp>
2012-10-01 15:17:04 +00:00
# include "../mwworld/esmstore.hpp"
2012-09-20 16:02:37 +00:00
2012-04-23 13:27:03 +00:00
# include "../mwbase/environment.hpp"
2012-08-12 16:11:09 +00:00
# include "../mwbase/windowmanager.hpp"
2015-02-09 16:45:48 +00:00
# include "../mwbase/world.hpp"
2014-01-08 16:19:43 +00:00
# include "../mwbase/mechanicsmanager.hpp"
2015-08-21 09:12:39 +00:00
# include "../mwmechanics/actorutil.hpp"
2010-07-07 18:12:00 +00:00
# include "interpretercontext.hpp"
2014-01-08 16:19:43 +00:00
# include "ref.hpp"
2010-07-07 18:12:00 +00:00
namespace MWScript
{
namespace Gui
2011-07-12 19:26:58 +00:00
{
2010-07-07 18:12:00 +00:00
class OpEnableWindow : public Interpreter : : Opcode0
{
2010-07-17 12:01:47 +00:00
MWGui : : GuiWindow mWindow ;
2011-07-12 19:26:58 +00:00
2010-07-07 18:12:00 +00:00
public :
2011-07-12 19:26:58 +00:00
2010-07-17 12:01:47 +00:00
OpEnableWindow ( MWGui : : GuiWindow window ) : mWindow ( window ) { }
2011-07-12 19:26:58 +00:00
2010-07-07 18:12:00 +00:00
virtual void execute ( Interpreter : : Runtime & runtime )
{
2012-04-23 13:27:03 +00:00
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 ( ) ;
}
} ;
2014-01-08 16:19:43 +00:00
template < class R >
class OpShowRestMenu : public Interpreter : : Opcode0
{
public :
virtual void execute ( Interpreter : : Runtime & runtime )
{
2014-01-09 01:14:08 +00:00
MWWorld : : Ptr bed = R ( ) ( runtime , false ) ;
2014-01-08 16:19:43 +00:00
2015-08-21 09:12:39 +00:00
if ( bed . isEmpty ( ) | | ! MWBase : : Environment : : get ( ) . getMechanicsManager ( ) - > sleepInBed ( MWMechanics : : getPlayer ( ) ,
2014-01-08 16:19:43 +00:00
bed ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_RestBed ) ;
}
} ;
2010-07-07 18:12:00 +00:00
class OpShowDialogue : public Interpreter : : Opcode0
{
2010-07-17 12:01:47 +00:00
MWGui : : GuiMode mDialogue ;
2011-07-12 19:26:58 +00:00
2010-07-07 18:12:00 +00:00
public :
2011-07-12 19:26:58 +00:00
2010-07-17 12:01:47 +00:00
OpShowDialogue ( MWGui : : GuiMode dialogue )
2010-07-07 18:12:00 +00:00
: mDialogue ( dialogue )
{ }
2011-07-12 19:26:58 +00:00
2010-07-07 18:12:00 +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 )
{
2012-04-23 13:27:03 +00:00
runtime . push ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > readPressedButton ( ) ) ;
2011-07-12 19:26:58 +00:00
}
} ;
2010-07-07 18:12:00 +00:00
2012-03-29 17:45:19 +00:00
class OpToggleFogOfWar : public Interpreter : : Opcode0
{
public :
virtual void execute ( Interpreter : : Runtime & runtime )
{
2014-05-16 07:21:08 +00:00
runtime . getContext ( ) . report ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > toggleFogOfWar ( ) ? " Fog of war -> On "
: " Fog of war -> Off " ) ;
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 )
{
2014-05-16 07:21:08 +00:00
runtime . getContext ( ) . report ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > toggleFullHelp ( ) ? " Full help -> On "
: " Full help -> Off " ) ;
2012-04-16 13:00:44 +00:00
}
} ;
2012-09-20 16:02:37 +00:00
class OpShowMap : public Interpreter : : Opcode0
{
public :
virtual void execute ( Interpreter : : Runtime & runtime )
{
std : : string cell = ( runtime . getStringLiteral ( runtime [ 0 ] . mInteger ) ) ;
2014-03-16 22:38:51 +00:00
: : Misc : : StringUtils : : toLower ( cell ) ;
2012-09-20 16:02:37 +00: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
2012-11-05 18:34:08 +00:00
const MWWorld : : Store < ESM : : Cell > & cells =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : Cell > ( ) ;
MWWorld : : Store < ESM : : Cell > : : iterator it = cells . extBegin ( ) ;
for ( ; it ! = cells . extEnd ( ) ; + + it )
2012-09-20 16:02:37 +00:00
{
2012-11-05 18:34:08 +00:00
std : : string name = it - > mName ;
2014-03-16 22:38:51 +00:00
: : Misc : : StringUtils : : toLower ( name ) ;
2012-09-20 16:02:37 +00:00
if ( name . find ( cell ) ! = std : : string : : npos )
2012-11-05 18:34:08 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > addVisitedLocation (
it - > mName ,
it - > getGridX ( ) ,
it - > getGridY ( )
) ;
2012-09-20 16:02:37 +00:00
}
}
} ;
class OpFillMap : public Interpreter : : Opcode0
{
public :
virtual void execute ( Interpreter : : Runtime & runtime )
{
2012-11-05 18:34:08 +00:00
const MWWorld : : Store < ESM : : Cell > & cells =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : Cell > ( ) ;
MWWorld : : Store < ESM : : Cell > : : iterator it = cells . extBegin ( ) ;
for ( ; it ! = cells . extEnd ( ) ; + + it )
2012-09-20 16:02:37 +00:00
{
2012-11-05 18:34:08 +00:00
std : : string name = it - > mName ;
2012-09-20 16:02:37 +00:00
if ( name ! = " " )
2012-11-05 18:34:08 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > addVisitedLocation (
name ,
it - > getGridX ( ) ,
it - > getGridY ( )
) ;
2012-09-20 16:02:37 +00:00
}
}
} ;
2014-06-10 15:47:59 +00:00
class OpMenuTest : public Interpreter : : Opcode1
{
public :
virtual void execute ( Interpreter : : Runtime & runtime , unsigned int arg0 )
{
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 16:49:19 +00:00
class OpToggleMenus : public Interpreter : : Opcode0
{
public :
virtual void execute ( Interpreter : : Runtime & runtime )
{
bool state = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > toggleGui ( ) ;
runtime . getContext ( ) . report ( state ? " GUI -> On " : " GUI -> Off " ) ;
2014-12-01 13:48:53 +00: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 16:49:19 +00:00
}
} ;
2012-09-20 16:02:37 +00:00
2010-07-07 18:12:00 +00:00
void installOpcodes ( Interpreter : : Interpreter & interpreter )
{
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableBirthMenu ,
2010-07-17 12:01:47 +00:00
new OpShowDialogue ( MWGui : : GM_Birth ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableClassMenu ,
2010-07-17 12:01:47 +00:00
new OpShowDialogue ( MWGui : : GM_Class ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableNameMenu ,
2010-07-17 12:01:47 +00:00
new OpShowDialogue ( MWGui : : GM_Name ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableRaceMenu ,
2010-07-17 12:01:47 +00:00
new OpShowDialogue ( MWGui : : GM_Race ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableStatsReviewMenu ,
2010-07-17 12:01:47 +00:00
new OpShowDialogue ( MWGui : : GM_Review ) ) ;
2015-01-22 20:39:07 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableLevelupMenu ,
new OpShowDialogue ( MWGui : : GM_Levelup ) ) ;
2010-07-07 18:12:00 +00:00
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableInventoryMenu ,
2010-07-17 12:01:47 +00:00
new OpEnableWindow ( MWGui : : GW_Inventory ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableMagicMenu ,
2010-07-17 12:01:47 +00:00
new OpEnableWindow ( MWGui : : GW_Magic ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableMapMenu ,
2010-07-17 12:01:47 +00:00
new OpEnableWindow ( MWGui : : GW_Map ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableStatsMenu ,
2010-07-17 12:01:47 +00:00
new OpEnableWindow ( MWGui : : GW_Stats ) ) ;
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableRest ,
2012-09-15 18:18:41 +00:00
new OpEnableRest ( ) ) ;
2010-07-07 18:12:00 +00:00
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeShowRestMenu ,
2014-01-08 16:19:43 +00:00
new OpShowRestMenu < ImplicitRef > ) ;
interpreter . installSegment5 ( Compiler : : Gui : : opcodeShowRestMenuExplicit , new OpShowRestMenu < ExplicitRef > ) ;
2011-07-12 19:26:58 +00:00
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeGetButtonPressed , new OpGetButtonPressed ) ;
2012-03-29 17:45:19 +00:00
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeToggleFogOfWar , new OpToggleFogOfWar ) ;
2012-04-16 13:00:44 +00:00
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeToggleFullHelp , new OpToggleFullHelp ) ;
2012-09-20 16:02:37 +00:00
2013-08-07 00:38:41 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeShowMap , new OpShowMap ) ;
interpreter . installSegment5 ( Compiler : : Gui : : opcodeFillMap , new OpFillMap ) ;
2014-06-10 15:47:59 +00:00
interpreter . installSegment3 ( Compiler : : Gui : : opcodeMenuTest , new OpMenuTest ) ;
2014-06-20 16:49:19 +00:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeToggleMenus , new OpToggleMenus ) ;
2010-07-07 18:12:00 +00:00
}
}
}