Go to the documentation of this file.00001 '''
00002 Anoria (c) Gsk 2010
00003 '''
00004
00005 import BigWorld
00006 import GUI
00007 from Helpers import PyGUI
00008 from Keys import *
00009
00010
00011 import Cursor
00012 from Helpers.PyGUI.ToolTip import ToolTipManager
00013
00014 import FX
00015
00016
00017
00018 from Base import Base
00019 from LabeledTextField import LabeledTextField
00020 from TextField import TextField
00021 from TextField2 import TextField2
00022 from StatsWindow import StatsWindow
00023 from ChatConsole import ChatConsole
00024 from Button import Button
00025 from ProficienciesWindow import ProficienciesWindow
00026 from AvatarHud import AvatarHud
00027 from Listener import Listener
00028 from TargetHud import TargetHud
00029
00030 class GuiEvent():
00031 def __init__(self, triggerName, triggerAction='ACTIVATE'):
00032 self.name=triggerName
00033 self.action=triggerAction
00034
00035
00036
00037 class AnGUI(Listener):
00038 __instance = None
00039
00040
00041 def __init__(self):
00042 if AnGUI.__instance: return
00043 Listener.__init__(self, self.__class__)
00044 AnGUI.__instance=self;
00045 self.name = "AnGUI"
00046 self.listeners = {}
00047
00048 self.root = None
00049 self.console = None
00050 self.hotkeybarGui = None
00051 self.hotkeys = {}
00052
00053 def setupGUI(self):
00054 print "AnGUI.setupGUI() executing"
00055 self.root = GUI.Simple("")
00056 GUI.addRoot(self.root)
00057
00058
00059
00060 self.tooltip_manager = ToolTipManager(self.root, -1)
00061
00062
00063 self.targetHud = TargetHud()
00064
00065
00066 self.console = GUI.load("gui/chat_window.gui")
00067 self.console.script.active(True)
00068
00069
00070 self.hotkeybarGui = GUI.load("gui/hotkeybar.gui")
00071 self.hotkeybarGui.script.active=True
00072 self.root.addChild(self.hotkeybarGui, "hotkeybarGui")
00073
00074
00075
00076 self.buttonBar_1 = GUI.load("gui/hotkeybutton.gui")
00077 self.buttonBar_1.script.name="AutoAttackToggle"
00078 self.hotkeybarGui.addChild(self.buttonBar_1, "buttonBar_1")
00079 self.buttonBar_1.script.setFx("onMouseEnter", FX.fxNop())
00080 self.buttonBar_1.script.setFx("onMouseLeave", FX.fxNop())
00081
00082 self.buttonBar_2 = GUI.load("gui/hotkeybutton.gui")
00083 self.buttonBar_2.script.name="ProficienciesWindowToggle"
00084 self.buttonBar_2.position.x = self.buttonBar_2.position.x + 64
00085 self.buttonBar_2.textureName = "gui/maps/icons/rz_WK_Student.dds"
00086 self.hotkeybarGui.addChild(self.buttonBar_2, "buttonBar_2")
00087 self.buttonBar_2.script.setFx("onMouseEnter", FX.fxNop())
00088 self.buttonBar_2.script.setFx("onMouseLeave", FX.fxNop())
00089
00090
00091 self.proficienciesWindow = ProficienciesWindow()
00092 self.root.addChild(self.proficienciesWindow.Gui, "proficienciesGui")
00093 self.proficienciesWindow.setVisible(False)
00094 self.addListener(self, GuiEvent('ProficienciesWindowToggle'))
00095
00096
00097 self.avatarHud = AvatarHud()
00098 self.root.addChild(self.avatarHud.Gui, "AvatarHud")
00099
00100 def addHotkey(self, key, name):
00101 self.hotkeys[key] = name
00102
00103
00104
00105
00106
00107
00108 def handleGuiEvent(self, guiEvent):
00109 eventName = guiEvent.name
00110 eventAction = guiEvent.action
00111
00112 if eventName == "ProficienciesWindowToggle":
00113 self.proficienciesWindow.toggleActive()
00114
00115
00116
00117 def handleKeyEvent(self, down, key, mods ):
00118
00119 chatConsole = self.console
00120 if chatConsole and chatConsole.script.isActive:
00121 if down and key == KEY_PGUP:
00122 chatConsole.script.scrollUp()
00123 return True
00124 elif down and key == KEY_PGDN:
00125 chatConsole.script.scrollDown()
00126 return True
00127 elif down and (key == KEY_RETURN and mods == 0):
00128
00129 if not chatConsole.script.editing:
00130 chatConsole.script.edit(1)
00131 return True
00132 elif down and (key == KEY_SLASH and mods == 0):
00133
00134 if not chatConsole.script.editing:
00135 chatConsole.script.edit(1)
00136 return True
00137 elif down and (key == KEY_ESCAPE and mods == 0) and chatConsole.script.component.visible:
00138 chatConsole.script.hideNow()
00139 return True
00140
00141
00142 if down and key == KEY_P and mods == MODIFIER_ALT:
00143 BigWorld.setWatcher("Debug/activeConsole", "Python")
00144 return True
00145
00146
00147 if self.hotkeys.has_key(key):
00148
00149 if down:
00150 self.dispatchGuiEvent(GuiEvent(self.hotkeys[key], 'ACTIVATE'))
00151 else:
00152 self.dispatchGuiEvent(GuiEvent(self.hotkeys[key], 'RELEASE'))
00153
00154 return True
00155
00156
00157
00158 handled = PyGUI.handleKeyEvent( down, key, mods )
00159
00160
00161 handled = GUI.handleKeyEvent(down, key, mods)
00162
00163 return handled
00164
00165
00166
00167
00168
00169 def addListener(self, listener, guiEvent):
00170
00171
00172 key = guiEvent.name
00173 try:
00174 list = self.listeners[key]
00175 except:
00176 list = []
00177 self.listeners[key] = list
00178
00179 list.append([listener, guiEvent])
00180
00181 def cancelListener(self, listener):
00182 ''' cancelListener() removes all event listen entries for a given object from the AnGUI listners directory
00183 @param: listener is the object to remove '''
00184
00185 for list in self.listeners.values():
00186 delEntries = []
00187 for entry in list:
00188 if entry[0] == listener:
00189 delEntries.append(list.index(entry))
00190
00191 for index in delEntries:
00192
00193 del list[index]
00194
00195
00196 def dispatchGuiEvent(self, guiEvent):
00197 print "AnGUI.dispatchGuiEvent(): event.name=%s event.action=%s" % (guiEvent.name, guiEvent.action)
00198 key = guiEvent.name
00199 try:
00200 list = self.listeners[key]
00201 except:
00202 return
00203
00204 for entry in list:
00205 listenerEvent = entry[1]
00206 if listenerEvent.action == 'ANY' or listenerEvent.action == guiEvent.action:
00207 listener = entry[0]
00208
00209 listener.handleGuiEvent(guiEvent)
00210 else:
00211 pass
00212 print "guiEvent.match() no match"
00213
00214
00215 service = AnGUI()