Skip to content

Commit

Permalink
Updated for 0.9.15.1 and the new AS3 Windows system.
Browse files Browse the repository at this point in the history
Added a "Debug" option in config.xml which enables much more messages when set to "true".
Update the textures position when the window is resized.
  • Loading branch information
Tey committed Jul 28, 2016
1 parent 5a377f3 commit d06b365
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import SoundGroups
import BigWorld
import GUI
# Importing gui.Scaleform.Battle breaks the dynamic platoon feature, so we use BattleWindow instead
from gui.Scaleform.windows import BattleWindow
from gui.shared import g_eventBus, events
from gui.app_loader.settings import APP_NAME_SPACE as _SPACE
from debug_utils import LOG_DEBUG, LOG_NOTE
from debug_utils import LOG_NOTE
from functools import partial
from gui.shared.utils.HangarSpace import _HangarSpace
from gui import GUI_SETTINGS
Expand All @@ -16,6 +14,15 @@
from CurrentVehicle import g_currentVehicle
from plugins.Engine.Plugin import Plugin

from gui.Scaleform.daapi.view.battle.shared.indicators import SixthSenseIndicator
from gui.battle_control.battle_constants import VEHICLE_VIEW_STATE

from account_helpers.settings_core.SettingsCore import g_settingsCore

def LOG_DEBUG(msg):
if SixthSenseDuration.myConf['Debug']:
LOG_NOTE(msg)

class SixthSenseDuration(Plugin):
myConf = {
'reloadConfigKey': 'KEY_NUMPAD2',
Expand Down Expand Up @@ -46,16 +53,16 @@ class SixthSenseDuration(Plugin):
'IconSpottedSize': (52,52),
'IconUnspottedSize': (52,52),
'IconInactiveSize': (52,52),
'materialFX': 'ADD'
'materialFX': 'ADD',
'Debug': False,
}
guiCountDown = None
backupVolume = None
hasSixthSense = False
guiUnspotted = None
guiInactive = None
guiSpotted = None



# --------------- audio ------------- #
@staticmethod
def playSound(sound,i):
Expand Down Expand Up @@ -93,23 +100,26 @@ def playExtSound(i):

@staticmethod
def new_playSound2D(self, event):
# LOG_NOTE("playSound2D(%s)" % event)
LOG_DEBUG("playSound2D(%s)" % event)

if event == 'observed_by_enemy' or event == 'xvm_sixthSense' or event == 'lightbulb':
LOG_NOTE("playSound2D: %s => BLOCKED" % (event))
return

old_playSound2D(self, event)

@staticmethod
def new_BattleWindow_call(self, methodName, args = None):
if methodName != 'sixthSenseIndicator.show':
old_BattleWindow_call(self, methodName, args)
def new_SixthSenseIndicator___onVehicleStateUpdated(self, state, value):
LOG_DEBUG("SixthSenseIndicator.__onVehicleStateUpdated(%s, %s)" % (state, value))

if state != VEHICLE_VIEW_STATE.OBSERVED_BY_ENEMY:
old_SixthSenseIndicator___onVehicleStateUpdated(self, state, value)
return

isShow = args[0]
# LOG_NOTE("sixthSenseIndicator.show(%s)" % isShow)
isShow = value
LOG_DEBUG("sixthSenseIndicator.show(%s)" % isShow)
if SixthSenseDuration.myConf['DisplayOriginalIcon'] or not isShow:
old_BattleWindow_call(self, methodName, args)
old_SixthSenseIndicator___onVehicleStateUpdated(self, state, value)

SixthSenseDuration.initGuiSpotted()
SixthSenseDuration.initGuiUnspotted()
Expand Down Expand Up @@ -137,6 +147,8 @@ def invertIcons():
# --------------- icon ------------- #
@staticmethod
def onChangedVeh():
LOG_DEBUG('onChangedVeh()')

if g_currentVehicle.item is None:
return
for c in g_currentVehicle.item.crew:
Expand All @@ -154,6 +166,8 @@ def onChangedVeh():

@staticmethod
def new_changeDone(self):
LOG_DEBUG("_HangarSpace.__changeDone()")

old_changeDoneFromSixthSenseDuration(self)
GUI_SETTINGS._GuiSettings__settings['sixthSenseDuration'] = SixthSenseDuration.myConf['IconRange']
SixthSenseDuration.onChangedVeh()
Expand All @@ -164,7 +178,6 @@ def new_changeDone(self):
def initGuiCountDown():
if SixthSenseDuration.guiCountDown is not None:
return
SixthSenseDuration.fixPosition('TimerPosition')
SixthSenseDuration.guiCountDown = GUI.Text('')
GUI.addRoot(SixthSenseDuration.guiCountDown)
SixthSenseDuration.guiCountDown.widthMode = 'PIXEL'
Expand All @@ -176,27 +189,24 @@ def initGuiCountDown():
SixthSenseDuration.guiCountDown.colourFormatting = True
SixthSenseDuration.guiCountDown.font = SixthSenseDuration.myConf['TimerFont']
SixthSenseDuration.guiCountDown.visible = False
SixthSenseDuration.guiCountDown.position = SixthSenseDuration.myConf['TimerPosition']
SixthSenseDuration.guiCountDown.position = SixthSenseDuration.fixPosition('TimerPosition')

@staticmethod
def initGuiSpotted():
if SixthSenseDuration.guiSpotted is None:
SixthSenseDuration.fixPosition('IconSpottedPosition')
SixthSenseDuration.guiSpotted = SixthSenseDuration.createTexture(SixthSenseDuration.myConf['IconSpottedPath'], SixthSenseDuration.myConf['IconSpottedPosition'],SixthSenseDuration.myConf['IconSpottedSize'])
SixthSenseDuration.guiSpotted = SixthSenseDuration.createTexture(SixthSenseDuration.myConf['IconSpottedPath'], SixthSenseDuration.fixPosition('IconSpottedPosition'),SixthSenseDuration.myConf['IconSpottedSize'])
SixthSenseDuration.guiSpotted.visible = False

@staticmethod
def initGuiUnspotted():
if SixthSenseDuration.guiUnspotted is None:
SixthSenseDuration.fixPosition('IconUnspottedPosition')
SixthSenseDuration.guiUnspotted = SixthSenseDuration.createTexture(SixthSenseDuration.myConf['IconUnspottedPath'], SixthSenseDuration.myConf['IconUnspottedPosition'],SixthSenseDuration.myConf['IconUnspottedSize'])
SixthSenseDuration.guiUnspotted = SixthSenseDuration.createTexture(SixthSenseDuration.myConf['IconUnspottedPath'], SixthSenseDuration.fixPosition('IconUnspottedPosition'),SixthSenseDuration.myConf['IconUnspottedSize'])
SixthSenseDuration.guiUnspotted.visible = SixthSenseDuration.hasSixthSense

@staticmethod
def initGuiInactive():
if SixthSenseDuration.guiInactive is None:
SixthSenseDuration.fixPosition('IconInactivePosition')
SixthSenseDuration.guiInactive = SixthSenseDuration.createTexture(SixthSenseDuration.myConf['IconInactivePath'], SixthSenseDuration.myConf['IconInactivePosition'],SixthSenseDuration.myConf['IconInactiveSize'])
SixthSenseDuration.guiInactive = SixthSenseDuration.createTexture(SixthSenseDuration.myConf['IconInactivePath'], SixthSenseDuration.fixPosition('IconInactivePosition'),SixthSenseDuration.myConf['IconInactiveSize'])
SixthSenseDuration.guiInactive.visible = not SixthSenseDuration.hasSixthSense

@staticmethod
Expand Down Expand Up @@ -258,28 +268,56 @@ def tickGuiCountDown(i):
@staticmethod
def fixPosition(type):
x, y = GUI.screenResolution()
SixthSenseDuration.myConf[type] = eval(SixthSenseDuration.myConf[type])
return eval(SixthSenseDuration.myConf[type])

@staticmethod
def onAppInitializing(event):
LOG_DEBUG('onAppInitializing(%s)' % event.ns)

if event.ns == _SPACE.SF_BATTLE:
SixthSenseDuration.initGuiCountDown()
SixthSenseDuration.initGuiInactive()
SixthSenseDuration.initGuiSpotted()
SixthSenseDuration.initGuiUnspotted()

# Not sure this is the correct way to monitor screen size changes, but it works...
g_settingsCore.interfaceScale.onScaleChanged += SixthSenseDuration.onScaleChanged

# @staticmethod
# def onAppInitialized(event):
# LOG_NOTE("__onAppInitialized(%s)" % event.ns)

@staticmethod
def onAppDestroyed(event):
LOG_DEBUG('onAppDestroyed(%s)' % event.ns)

if event.ns == _SPACE.SF_BATTLE:
SixthSenseDuration.endGuiCountDown()
SixthSenseDuration.endGuiInactive()
SixthSenseDuration.endGuiSpotted()
SixthSenseDuration.endGuiUnspotted()


g_settingsCore.interfaceScale.onScaleChanged -= SixthSenseDuration.onScaleChanged

@staticmethod
def onScaleChanged(scale):
width, height = GUI.screenResolution()
LOG_DEBUG('onScaleChanged(%s) [%dx%d]' % (scale, width, height))

# Screen size has changed, update the position of icons

if SixthSenseDuration.guiCountDown is not None:
SixthSenseDuration.guiCountDown.position = SixthSenseDuration.fixPosition('TimerPosition')

if SixthSenseDuration.guiSpotted is not None:
SixthSenseDuration.guiSpotted.position = SixthSenseDuration.fixPosition('IconSpottedPosition')

if SixthSenseDuration.guiUnspotted is not None:
SixthSenseDuration.guiUnspotted.position = SixthSenseDuration.fixPosition('IconUnspottedPosition')

if SixthSenseDuration.guiInactive is not None:
SixthSenseDuration.guiInactive.position = SixthSenseDuration.fixPosition('IconInactivePosition')

@classmethod
def readConfig(cls):
super(SixthSenseDuration, SixthSenseDuration).readConfig()
Expand All @@ -301,16 +339,16 @@ def run(cls):
injectNewFuncs()

def saveOldFuncs():
global old_BattleWindow_call,old_changeDoneFromSixthSenseDuration,old_playSound2D
DecorateUtils.ensureGlobalVarNotExist('old_BattleWindow_call')
global old_changeDoneFromSixthSenseDuration, old_playSound2D, old_SixthSenseIndicator___onVehicleStateUpdated
DecorateUtils.ensureGlobalVarNotExist('old_SixthSenseIndicator___onVehicleStateUpdated')
DecorateUtils.ensureGlobalVarNotExist('old_changeDoneFromSixthSenseDuration')
DecorateUtils.ensureGlobalVarNotExist('old_playSound2D')
old_BattleWindow_call = BattleWindow.call
old_SixthSenseIndicator___onVehicleStateUpdated = SixthSenseIndicator._SixthSenseIndicator__onVehicleStateUpdated
old_changeDoneFromSixthSenseDuration = _HangarSpace._HangarSpace__changeDone
old_playSound2D = SoundGroups.SoundGroups.playSound2D

def injectNewFuncs():
BattleWindow.call = SixthSenseDuration.new_BattleWindow_call
SixthSenseIndicator._SixthSenseIndicator__onVehicleStateUpdated = SixthSenseDuration.new_SixthSenseIndicator___onVehicleStateUpdated
_HangarSpace._HangarSpace__changeDone = SixthSenseDuration.new_changeDone
SoundGroups.SoundGroups.playSound2D = SixthSenseDuration.new_playSound2D
add = g_eventBus.addListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,7 @@
* "%s": 9 -->
<TimerText>Spotted for %s seconds</TimerText>
<!-- ***************************************************** -->

<Debug>false</Debug>

</config.xml>

0 comments on commit d06b365

Please sign in to comment.