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
# include <components/interpreter/interpreter.hpp>
# include <components/interpreter/runtime.hpp>
# include <components/interpreter/opcodes.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"
2012-08-12 18:11:09 +02:00
# include "../mwbase/windowmanager.hpp"
2015-02-09 17:45:48 +01:00
# include "../mwbase/world.hpp"
2014-01-08 17:19:43 +01:00
# include "../mwbase/mechanicsmanager.hpp"
2015-08-21 21:12:39 +12:00
# include "../mwmechanics/actorutil.hpp"
2010-07-07 20:12:00 +02:00
# include "interpretercontext.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-07 20:12:00 +02:00
public :
2011-07-12 21:26:58 +02:00
2010-07-17 14:01:47 +02:00
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 ( ) ,
2014-01-08 17:19:43 +01:00
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 :
2011-07-12 21:26:58 +02:00
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
{
std : : string cell = ( runtime . getStringLiteral ( runtime [ 0 ] . mInteger ) ) ;
2015-12-07 22:49:15 +01:00
: : Misc : : StringUtils : : lowerCaseInPlace ( cell ) ;
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
2012-11-05 22:34:08 +04:00
const MWWorld : : Store < ESM : : Cell > & cells =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : Cell > ( ) ;
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
{
2012-11-05 22:34:08 +04:00
std : : string name = it - > mName ;
2015-12-07 22:49:15 +01:00
: : Misc : : StringUtils : : lowerCaseInPlace ( name ) ;
2021-07-03 01:03:57 +03:00
if ( name . length ( ) > = cell . length ( ) & & name . substr ( 0 , cell . length ( ) ) = = cell )
winMgr - > addVisitedLocation ( it - > mName , 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
{
2012-11-05 22:34:08 +04: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 18:02:37 +02:00
{
2012-11-05 22:34:08 +04:00
std : : string name = it - > mName ;
2012-09-20 18:02:37 +02:00
if ( name ! = " " )
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 )
{
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableBirthMenu ,
2010-07-17 14:01:47 +02:00
new OpShowDialogue ( MWGui : : GM_Birth ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableClassMenu ,
2010-07-17 14:01:47 +02:00
new OpShowDialogue ( MWGui : : GM_Class ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableNameMenu ,
2010-07-17 14:01:47 +02:00
new OpShowDialogue ( MWGui : : GM_Name ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableRaceMenu ,
2010-07-17 14:01:47 +02:00
new OpShowDialogue ( MWGui : : GM_Race ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableStatsReviewMenu ,
2010-07-17 14:01:47 +02:00
new OpShowDialogue ( MWGui : : GM_Review ) ) ;
2015-01-22 21:39:07 +01:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableLevelupMenu ,
new OpShowDialogue ( MWGui : : GM_Levelup ) ) ;
2010-07-07 20:12:00 +02:00
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableInventoryMenu ,
2010-07-17 14:01:47 +02:00
new OpEnableWindow ( MWGui : : GW_Inventory ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableMagicMenu ,
2010-07-17 14:01:47 +02:00
new OpEnableWindow ( MWGui : : GW_Magic ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableMapMenu ,
2010-07-17 14:01:47 +02:00
new OpEnableWindow ( MWGui : : GW_Map ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableStatsMenu ,
2010-07-17 14:01:47 +02:00
new OpEnableWindow ( MWGui : : GW_Stats ) ) ;
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeEnableRest ,
2012-09-15 20:18:41 +02:00
new OpEnableRest ( ) ) ;
2010-07-07 20:12:00 +02:00
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeShowRestMenu ,
2014-01-08 17:19:43 +01:00
new OpShowRestMenu < ImplicitRef > ) ;
interpreter . installSegment5 ( Compiler : : Gui : : opcodeShowRestMenuExplicit , new OpShowRestMenu < ExplicitRef > ) ;
2011-07-12 21:26:58 +02:00
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeGetButtonPressed , new OpGetButtonPressed ) ;
2012-03-29 19:45:19 +02:00
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeToggleFogOfWar , new OpToggleFogOfWar ) ;
2012-04-16 15:00:44 +02:00
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeToggleFullHelp , new OpToggleFullHelp ) ;
2012-09-20 18:02:37 +02:00
2013-08-06 20:38:41 -04:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeShowMap , new OpShowMap ) ;
interpreter . installSegment5 ( Compiler : : Gui : : opcodeFillMap , new OpFillMap ) ;
2014-06-10 17:47:59 +02:00
interpreter . installSegment3 ( Compiler : : Gui : : opcodeMenuTest , new OpMenuTest ) ;
2014-06-20 18:49:19 +02:00
interpreter . installSegment5 ( Compiler : : Gui : : opcodeToggleMenus , new OpToggleMenus ) ;
2010-07-07 20:12:00 +02:00
}
}
}