comparison orpg/main.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children c0da99091e1d
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 #!/usr/bin/env python
2 # Copyright (C) 2000-2001 The OpenRPG Project
3 #
4 # openrpg-dev@lists.sourceforge.net
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # --
20 #
21 # File: main.py
22 # Author: Chris Davis
23 # Maintainer:
24 # Version:
25 # $Id: main.py,v 1.153 2008/01/24 03:52:03 digitalxero Exp $
26 #
27 # Description: This is the main entry point of the oprg application
28 #
29
30 __version__ = "$Id: main.py,v 1.153 2008/01/24 03:52:03 digitalxero Exp $"
31
32 from orpg.orpg_wx import *
33 from orpg.orpgCore import *
34 from orpg_version import *
35 from orpg.orpg_windows import *
36 import orpg.dirpath
37 import orpg.orpg_xml
38 import orpg.player_list
39 import orpg.tools.pluginui as pluginUI
40 import orpg.tools.orpg_settings
41 import orpg.tools.orpg_log
42 import orpg.tools.aliaslib
43 from orpg.tools.metamenus import MenuBarEx
44 import orpg.tools.toolBars
45 import orpg.tools.passtool
46 import orpg.tools.orpg_sound
47 import orpg.tools.validate
48 import orpg.tools.rgbhex
49 import orpg.gametree.gametree
50 import orpg.chat.chatwnd
51 import orpg.dieroller.utils
52 import orpg.networking.mplay_client
53 import orpg.networking.gsclient
54 import orpg.mapper.map
55 import orpg.mapper.images
56 import wx.py
57
58 ####################################
59 ## Main Frame
60 ####################################
61
62
63 class orpgFrame(wx.Frame):
64 def __init__(self, parent, id, title):
65 wx.Frame.__init__(self, parent, id, title, wx.Point(100, 100), wx.Size(600,420), style=wx.DEFAULT_FRAME_STYLE)
66 self.log = open_rpg.get_component("log")
67 self.xml = open_rpg.get_component("xml")
68 self.dir_struct = open_rpg.get_component("dir_struct")
69 self.validate = open_rpg.get_component("validate")
70 self.settings = open_rpg.get_component("settings")
71 self.log.log("Enter orpgFrame", ORPG_DEBUG)
72 self.rgbcovert = orpg.tools.rgbhex.RGBHex()
73 self._mgr = AUI.AuiManager(self)
74
75 # Determine which icon format to use
76 icon = None
77 if wx.Platform == '__WXMSW__':
78 icon = wx.Icon(orpg.dirpath.dir_struct["icon"]+'d20.ico', wx.BITMAP_TYPE_ICO)
79 else:
80 icon = wx.Icon(orpg.dirpath.dir_struct["icon"]+"d20.xpm", wx.BITMAP_TYPE_XPM) # create the object, then determine if it needs to be replaced. It calculates 2 less calculations.
81
82 # Set it if we have it
83 if icon != None:
84 self.SetIcon( icon )
85
86 # create session
87 call_backs = {"on_receive":self.on_receive,
88 "on_mplay_event":self.on_mplay_event,
89 "on_group_event":self.on_group_event,
90 "on_player_event":self.on_player_event,
91 "on_status_event":self.on_status_event,
92 "on_password_signal":self.on_password_signal,
93 "orpgFrame":self}
94 self.session = orpg.networking.mplay_client.mplay_client(self.settings.get_setting("player"), call_backs)
95 self.poll_timer = wx.Timer(self, wx.NewId())
96 self.Bind(wx.EVT_TIMER, self.session.poll, self.poll_timer)
97 self.poll_timer.Start(100)
98 self.ping_timer = wx.Timer(self, wx.NewId())
99 self.Bind(wx.EVT_TIMER, self.session.update, self.ping_timer)
100
101 # create roller manager
102 self.DiceManager = orpg.dieroller.utils.roller_manager(self.settings.get_setting("dieroller"))
103
104 #create password manager --SD 8/03
105 self.password_manager = orpg.tools.passtool.PassTool()
106 open_rpg.add_component("session", self.session)
107 open_rpg.add_component('frame', self)
108 open_rpg.add_component('DiceManager', self.DiceManager)
109 open_rpg.add_component('password_manager', self.password_manager)
110
111 # build frame windows
112 self.build_menu()
113 self.build_gui()
114 self.build_hotkeys()
115 self.log.log("GUI Built", ORPG_DEBUG)
116 open_rpg.add_component("chat",self.chat)
117 open_rpg.add_component("map",self.map)
118 open_rpg.add_component("alias", self.aliaslib)
119 self.log.log("openrpg components all added", ORPG_DEBUG)
120 self.tree.load_tree(self.settings.get_setting("gametree"))
121 self.log.log("Tree Loaded", ORPG_DEBUG)
122 self.players.size_cols()
123 self.log.log("player window cols sized", ORPG_DEBUG)
124
125 #Load the Plugins This has to be after the chat component has been added
126 open_rpg.add_component('pluginmenu', self.pluginMenu)
127 self.pluginsFrame.Start()
128 self.log.log("plugins reloaded and startup plugins launched", ORPG_DEBUG)
129 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
130 self.log.log("Exit orpgFrame", ORPG_DEBUG)
131
132 def post_show_init(self):
133 """Some Actions need to be done after the main fram is drawn"""
134 self.log.log("Enter orpgFrame->post_show_init(self)", ORPG_DEBUG)
135 self.players.size_cols()
136 self.log.log("Exit orpgFrame->post_show_init(self)", ORPG_DEBUG)
137
138 def get_activeplugins(self):
139 self.log.log("Enter orpgFrame->get_activeplugins(self)", ORPG_DEBUG)
140 try:
141 tmp = self.pluginsFrame.get_activeplugins()
142 except:
143 tmp = {}
144 self.log.log("Exit orpgFrame->get_activeplugins(self)", ORPG_DEBUG)
145 return tmp
146
147 def get_startplugins(self):
148 self.log.log("Enter orpgFrame->get_startplugins(self)", ORPG_DEBUG)
149 try:
150 tmp = self.pluginsFrame.get_startplugins()
151 except:
152 tmp = {}
153 self.log.log("Exit orpgFrame->get_startplugins(self)", ORPG_DEBUG)
154 return tmp
155
156 def on_password_signal(self,signal,type,id,data):
157 self.log.log("Enter orpgFrame->on_password_signal(self,signal,type,id,data)", ORPG_DEBUG)
158
159 try:
160 self.log.log("DEBUG: password response= "+str(signal)+" (T:"+str(type)+" #"+str(id)+")", ORPG_DEBUG)
161 id = int(id)
162 type = str(type)
163 data = str(data)
164 signal = str(signal)
165 if signal == "fail":
166 if type == "server":
167 self.password_manager.ClearPassword("server", 0)
168 elif type == "admin":
169 self.password_manager.ClearPassword("admin", int(id))
170 elif type == "room":
171 self.password_manager.ClearPassword("room", int(id))
172 else:
173 pass
174 except:
175 traceback.print_exc()
176 self.log.log("Exit orpgFrame->on_password_signal(self,signal,type,id,data)", ORPG_DEBUG)
177
178 def build_menu(self):
179 self.log.log("Enter orpgFrame->build_menu()", ORPG_DEBUG)
180 menu = \
181 [[
182 ['&OpenRPG'],
183 [' &Settings\tCtrl-S'],
184 [' -'],
185 [' Tab Styles'],
186 [' Slanted'],
187 [' Colorful', "check"],
188 [' Black and White', "check"],
189 [' Aqua', "check"],
190 [' Custom', "check"],
191 [' Flat'],
192 [' Black and White', "check"],
193 [' Aqua', "check"],
194 [' Custom', "check"],
195 [' NewMap'],
196 [' -'],
197 [' &Exit']
198 ],
199 [
200 ['&Game Server'],
201 [' &Browse Servers\tCtrl-B'],
202 [' -'],
203 [' Server Heartbeat', "check"],
204 [' -'],
205 [' &Start Server']
206 ],
207 [
208 ['&Tools'],
209 [' Logging Level'],
210 [' Debug', "check"],
211 [' Note', "check"],
212 [' Info', "check"],
213 [' General', "check"],
214 [' -'],
215 [' Password Manager', "check"],
216 [' -'],
217 [' Sound Toolbar', "check"],
218 [' Dice Bar\tCtrl-D', "check"],
219 [' Map Bar', "check"],
220 [' Status Bar\tCtrl-T', "check"],
221 ],
222 [
223 ['&Help'],
224 [' &About'],
225 [' Online User Guide'],
226 [' Change Log'],
227 [' Report a Bug']
228 ]]
229
230 self.mainmenu = MenuBarEx(self, menu)
231 if self.settings.get_setting('Heartbeat') == '1':
232 self.mainmenu.SetMenuState("GameServerServerHeartbeat", True)
233 tabtheme = self.settings.get_setting('TabTheme')
234
235 #This change is stable. TaS.
236 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedColorful", tabtheme == 'slanted&colorful')
237 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedBlackandWhite", tabtheme == 'slanted&bw')
238 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedAqua", tabtheme == 'slanted&aqua')
239 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatBlackandWhite", tabtheme == 'flat&bw')
240 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatAqua", tabtheme == 'flat&aqua')
241 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedCustom", tabtheme == 'customslant')
242 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatCustom", tabtheme == 'customflat')
243
244 lvl = int(self.settings.get_setting('LoggingLevel'))
245 if lvl & ORPG_DEBUG:
246 self.mainmenu.SetMenuState("ToolsLoggingLevelDebug", True)
247 if lvl & ORPG_DEBUG:
248 self.mainmenu.SetMenuState("ToolsLoggingLevelNote", True)
249 if lvl & ORPG_INFO:
250 self.mainmenu.SetMenuState("ToolsLoggingLevelInfo", True)
251 if lvl & ORPG_GENERAL:
252 self.mainmenu.SetMenuState("ToolsLoggingLevelGeneral", True)
253 self.pluginMenu = wx.Menu()
254 item = wx.MenuItem(self.pluginMenu, wx.ID_ANY, "Control Panel", "Control Panel")
255 self.Bind(wx.EVT_MENU, self.OnMB_PluginControlPanel, item)
256 self.pluginMenu.AppendItem(item)
257 self.pluginMenu.AppendSeparator()
258 self.mainmenu.Insert(2, self.pluginMenu, "&Plugins")
259 self.log.log("Exit orpgFrame->build_menu()", ORPG_DEBUG)
260
261 #################################
262 ## All Menu Events
263 #################################
264 #Tab Styles Menus
265 def SetTabStyles(self, *args, **kwargs):
266 self.log.log("Enter orpgFrame->SetTabStyles(self, *args, **kwargs)", ORPG_DEBUG)
267 if kwargs.has_key('style'):
268 newstyle = kwargs['style']
269 else:
270 try:
271 newstyle = args[1]
272 except:
273 self.log.log('Invalid Syntax for orpgFrame->SetTabStyles(self, *args, **kwargs)', ORPG_GENERAL)
274 return
275 if kwargs.has_key('menu'):
276 menu = kwargs['menu']
277 else:
278 try:
279 menu = args[0]
280 except:
281 self.log.log('Invalid Syntax for orpgFrame->SetTabStyles(self, *args, **kwargs)', ORPG_GENERAL)
282 return
283 if kwargs.has_key('graidentTo'):
284 graidentTo = kwargs['graidentTo']
285 else:
286 graidentTo = None
287 if kwargs.has_key('graidentFrom'):
288 graidentFrom = kwargs['graidentFrom']
289 else:
290 graidentFrom = None
291 if kwargs.has_key('textColor'):
292 textColor = kwargs['textColor']
293 else:
294 textColor = None
295
296 #Set all menu's to unchecked
297 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedColorful", False)
298 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedBlackandWhite", False)
299 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedAqua", False)
300 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedCustom", False)
301 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatBlackandWhite", False)
302 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatAqua", False)
303 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatCustom", False)
304
305 #check the proper menu
306 self.mainmenu.SetMenuState(menu, True)
307
308 #Run though the current tabbed window list and remove those that have been closed
309 tabbedwindows = open_rpg.get_component("tabbedWindows")
310 rgbc = orpg.tools.rgbhex.RGBHex()
311 new = []
312 for wnd in tabbedwindows:
313 try:
314 style = wnd.GetWindowStyleFlag()
315 new.append(wnd)
316 except:
317 pass
318 tabbedwindows = new
319 open_rpg.add_component("tabbedWindows", tabbedwindows)
320
321 #Run though the new list and set the proper styles
322 tabbg = self.settings.get_setting('TabBackgroundGradient')
323 rgbc = orpg.tools.rgbhex.RGBHex()
324 (red, green, blue) = rgbc.rgb_tuple(tabbg)
325
326 for wnd in tabbedwindows:
327 style = wnd.GetWindowStyleFlag()
328 # remove old tabs style
329 mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_COLORFUL_TABS)
330 style &= mirror
331 style |= newstyle
332 wnd.SetWindowStyleFlag(style)
333 wnd.SetTabAreaColour(wx.Color(red, green, blue))
334 if graidentTo != None:
335 wnd.SetGradientColourTo(graidentTo)
336 if graidentFrom != None:
337 wnd.SetGradientColourFrom(graidentFrom)
338 if textColor != None:
339 wnd.SetNonActiveTabTextColour(textColor)
340 wnd.Refresh()
341
342 def OnMB_OpenRPGNewMap(self):
343 self.log.log("Enter orpgFrame->OnMB_OpenRPGNewMap(self)", ORPG_DEBUG)
344 self.log.log("Exit orpgFrame->OnMB_OpenRPGNewMap(self)", ORPG_DEBUG)
345
346 def OnMB_OpenRPGTabStylesSlantedColorful(self):
347 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesSlantedColorful(self)", ORPG_DEBUG)
348 if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedColorful"):
349 self.settings.set_setting('TabTheme', 'slanted&colorful')
350 self.SetTabStyles("OpenRPGTabStylesSlantedColorful", FNB.FNB_VC8|FNB.FNB_COLORFUL_TABS)
351 else:
352 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedColorful", True)
353 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesSlantedColorful(self)", ORPG_DEBUG)
354
355 def OnMB_OpenRPGTabStylesSlantedBlackandWhite(self):
356 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesSlantedBlackandWhite(self)", ORPG_DEBUG)
357 if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedBlackandWhite"):
358 self.settings.set_setting('TabTheme', 'slanted&bw')
359 self.SetTabStyles("OpenRPGTabStylesSlantedBlackandWhite", FNB.FNB_VC8, graidentTo=wx.WHITE, graidentFrom=wx.WHITE, textColor=wx.BLACK)
360 else:
361 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedBlackandWhite", True)
362 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesSlantedBlackandWhite(self)", ORPG_DEBUG)
363
364 def OnMB_OpenRPGTabStylesSlantedAqua(self):
365 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesSlantedAqua(self)", ORPG_DEBUG)
366 if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedAqua"):
367 self.settings.set_setting('TabTheme', 'slanted&aqua')
368 self.SetTabStyles("OpenRPGTabStylesSlantedAqua", FNB.FNB_VC8, graidentTo=wx.Color(0, 128, 255), graidentFrom=wx.WHITE, textColor=wx.BLACK)
369 else:
370 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedAqua", True)
371 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesSlantedBlackandWhite(self)", ORPG_DEBUG)
372
373 def OnMB_OpenRPGTabStylesSlantedCustom(self):
374 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesSlantedCustom(self)", ORPG_DEBUG)
375
376 if self.mainmenu.GetMenuState("OpenRPGTabStylesSlantedCustom"):
377 self.settings.set_setting('TabTheme', 'customslant')
378 rgbc = orpg.tools.rgbhex.RGBHex()
379 gfrom = self.settings.get_setting('TabGradientFrom')
380 (fred, fgreen, fblue) = rgbc.rgb_tuple(gfrom)
381 gto = self.settings.get_setting('TabGradientTo')
382 (tored, togreen, toblue) = rgbc.rgb_tuple(gto)
383 tabtext = self.settings.get_setting('TabTextColor')
384 (tred, tgreen, tblue) = rgbc.rgb_tuple(tabtext)
385 tabbg = self.settings.get_setting('TabBackgroundGradient')
386 (red, green, blue) = rgbc.rgb_tuple(tabbg)
387 self.SetTabStyles("OpenRPGTabStylesSlantedCustom", FNB.FNB_VC8, graidentTo=wx.Color(tored, togreen, toblue), graidentFrom=wx.Color(fred, fgreen, fblue), textColor=wx.Color(tred, tgreen, tblue))
388 else:
389 self.mainmenu.SetMenuState("OpenRPGTabStylesSlantedCustom", True)
390 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesSlantedCustom(self)", ORPG_DEBUG)
391
392 def OnMB_OpenRPGTabStylesFlatBlackandWhite(self):
393 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesFlatBlackandWhite(self)", ORPG_DEBUG)
394 if self.mainmenu.GetMenuState("OpenRPGTabStylesFlatBlackandWhite"):
395 self.settings.set_setting('TabTheme', 'flat&bw')
396 self.SetTabStyles("OpenRPGTabStylesFlatBlackandWhite", FNB.FNB_FANCY_TABS, graidentTo=wx.WHITE, graidentFrom=wx.WHITE, textColor=wx.BLACK)
397 else:
398 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatBlackandWhite", True)
399 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesFlatBlackandWhite(self)", ORPG_DEBUG)
400
401 def OnMB_OpenRPGTabStylesFlatAqua(self):
402 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesFlatAqua(self)", ORPG_DEBUG)
403 if self.mainmenu.GetMenuState("OpenRPGTabStylesFlatAqua"):
404 self.settings.set_setting('TabTheme', 'flat&aqua')
405 self.SetTabStyles("OpenRPGTabStylesFlatAqua", FNB.FNB_FANCY_TABS, graidentTo=wx.Color(0, 128, 255), graidentFrom=wx.WHITE, textColor=wx.BLACK)
406 else:
407 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatAqua", True)
408 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesFlatAqua(self)", ORPG_DEBUG)
409
410 def OnMB_OpenRPGTabStylesFlatCustom(self):
411 self.log.log("Enter orpgFrame->OnMB_OpenRPGTabStylesFlatCustom(self)", ORPG_DEBUG)
412 if self.mainmenu.GetMenuState("OpenRPGTabStylesFlatCustom"):
413 self.settings.set_setting('TabTheme', 'customflat')
414 rgbc = orpg.tools.rgbhex.RGBHex()
415 gfrom = self.settings.get_setting('TabGradientFrom')
416 (fred, fgreen, fblue) = rgbc.rgb_tuple(gfrom)
417 gto = self.settings.get_setting('TabGradientTo')
418 (tored, togreen, toblue) = rgbc.rgb_tuple(gto)
419 tabtext = self.settings.get_setting('TabTextColor')
420 (tred, tgreen, tblue) = rgbc.rgb_tuple(tabtext)
421 tabbg = self.settings.get_setting('TabBackgroundGradient')
422 (red, green, blue) = rgbc.rgb_tuple(tabbg)
423 self.SetTabStyles("OpenRPGTabStylesFlatCustom", FNB.FNB_FANCY_TABS, graidentTo=wx.Color(tored, togreen, toblue), graidentFrom=wx.Color(fred, fgreen, fblue), textColor=wx.Color(tred, tgreen, tblue))
424 else:
425 self.mainmenu.SetMenuState("OpenRPGTabStylesFlatCustom", True)
426 self.log.log("Exit orpgFrame->OnMB_OpenRPGTabStylesFlatCustom(self)", ORPG_DEBUG)
427
428 #Window Menu
429 def OnMB_WindowsMenu(self, event):
430 self.log.log("Enter orpgFrame->OnMB_WindowsMenu(self, event)", ORPG_DEBUG)
431 menuid = event.GetId()
432 name = self.mainwindows[menuid]
433 if name == 'Alias Lib':
434 if self.aliaslib.IsShown() == True:
435 self.aliaslib.Hide()
436 else:
437 self.aliaslib.Show()
438 else:
439 if self._mgr.GetPane(name).IsShown() == True:
440 self._mgr.GetPane(name).Hide()
441 else:
442 self._mgr.GetPane(name).Show()
443 self._mgr.Update()
444 self.log.log("Exit orpgFrame->OnMB_WindowsMenu(self, event)", ORPG_DEBUG)
445
446 #OpenRPG Menu
447 def OnMB_OpenRPGSettings(self):
448 self.log.log("Enter orpgFrame->OnMB_OpenRPGSettings()", ORPG_DEBUG)
449 dlg = orpg.tools.orpg_settings.orpgSettingsWnd(self)
450 dlg.Centre()
451 dlg.ShowModal()
452 self.log.log("Exit orpgFrame->OnMB_OpenRPGSettings()", ORPG_DEBUG)
453
454 def OnMB_OpenRPGExit(self):
455 self.OnCloseWindow(0)
456
457 #Game Server Menu
458 def OnMB_GameServerBrowseServers(self):
459 self.log.log("Enter orpgFrame->OnMB_GameServerBrowseServers(self)", ORPG_DEBUG)
460 if self._mgr.GetPane("Browse Server Window").IsShown() == True:
461 self._mgr.GetPane("Browse Server Window").Hide()
462 else:
463 self._mgr.GetPane("Browse Server Window").Show()
464 self._mgr.Update()
465 self.log.log("Exit orpgFrame->OnMB_GameServerBrowseServers(self)", ORPG_DEBUG)
466
467 def OnMB_GameServerServerHeartbeat(self):
468 self.log.log("Enter orpgFrame->OnMB_GameServerServerHeartbeat(self)", ORPG_DEBUG)
469 if self.mainmenu.GetMenuState("GameServerServerHeartbeat"):
470 self.settings.set_setting('Heartbeat', '1')
471 else:
472 self.settings.set_setting('Heartbeat', '0')
473 self.log.log("Exit orpgFrame->OnMB_GameServerServerHeartbeat(self)", ORPG_DEBUG)
474
475 def OnMB_GameServerStartServer(self):
476 self.log.log("Enter orpgFrame->OnMB_GameServerStartServer(self)", ORPG_DEBUG)
477 start_dialog = wx.ProgressDialog( "Server Loading", "Server Loading, Please Wait...", 1, self )
478 # Spawn the new process and close the stdout handle from it
479 start_dialog.Update( 0 )
480 # Adjusted following code to work with win32, can't test for Unix
481 # as per reported bug 586227
482 if wx.Platform == "__WXMSW__":
483 arg = '\"' + os.path.normpath(orpg.dirpath.dir_struct["home"] + 'start_server_gui.py') + '\"'
484 args = ( sys.executable, arg )
485 else:
486 arg = orpg.dirpath.dir_struct["home"] + 'start_server_gui.py'
487 args = (arg,arg)
488 os.spawnv( os.P_NOWAIT, sys.executable, args )
489 start_dialog.Update( 1 )
490 start_dialog.Show(False)
491 start_dialog.Destroy()
492 self.log.log("Exit orpgFrame->OnMB_GameServerStartServer(self)", ORPG_DEBUG)
493
494 # Tools Menu
495 def OnMB_PluginControlPanel(self, evt):
496 self.log.log("Enter orpgFrame->OnMB_ToolsPlugins(self)", ORPG_DEBUG)
497 if self.pluginsFrame.IsShown() == True:
498 self.pluginsFrame.Hide()
499 else:
500 self.pluginsFrame.Show()
501 self.log.log("Exit orpgFrame->OnMB_ToolsPlugins(self)", ORPG_DEBUG)
502
503 def OnMB_ToolsLoggingLevelDebug(self):
504 self.log.log("Enter orpgFrame->OnMB_ToolsLoggingLevelDebug(self)", ORPG_DEBUG)
505 lvl = self.log.getLogLevel()
506 if self.mainmenu.GetMenuState("ToolsLoggingLevelDebug"):
507 lvl |= ORPG_DEBUG
508 else:
509 lvl &= ~ORPG_DEBUG
510 self.log.setLogLevel(lvl)
511 self.settings.set_setting('LoggingLevel', lvl)
512 self.log.log("Exit orpgFrame->OnMB_ToolsLoggingLevelDebug(self)", ORPG_DEBUG)
513
514 def OnMB_ToolsLoggingLevelNote(self):
515 self.log.log("Enter orpgFrame->OnMB_ToolsLoggingLevelNote(self)", ORPG_DEBUG)
516 lvl = self.log.getLogLevel()
517 if self.mainmenu.GetMenuState("ToolsLoggingLevelNote"):
518 lvl |= ORPG_DEBUG
519 else:
520 lvl &= ~ORPG_DEBUG
521 self.log.setLogLevel(lvl)
522 self.settings.set_setting('LoggingLevel', lvl)
523 self.log.log("Exit orpgFrame->OnMB_ToolsLoggingLevelNote(self)", ORPG_DEBUG)
524
525 def OnMB_ToolsLoggingLevelInfo(self):
526 self.log.log("Enter orpgFrame->OnMB_ToolsLoggingLevelInfo(self)", ORPG_DEBUG)
527 lvl = self.log.getLogLevel()
528 if self.mainmenu.GetMenuState("ToolsLoggingLevelInfo"):
529 lvl |= ORPG_INFO
530 else:
531 lvl &= ~ORPG_INFO
532 self.log.setLogLevel(lvl)
533 self.settings.set_setting('LoggingLevel', lvl)
534 self.log.log("Exit orpgFrame->OnMB_ToolsLoggingLevelInfo(self)", ORPG_DEBUG)
535
536 def OnMB_ToolsLoggingLevelGeneral(self):
537 self.log.log("Enter orpgFrame->OnMB_ToolsLoggingLevelGeneral(self)", ORPG_DEBUG)
538 lvl = self.log.getLogLevel()
539 if self.mainmenu.GetMenuState("ToolsLoggingLevelGeneral"):
540 lvl |= ORPG_GENERAL
541 else:
542 lvl &= ~ORPG_GENERAL
543 self.log.setLogLevel(lvl)
544 self.settings.set_setting('LoggingLevel', lvl)
545 self.log.log("Exit orpgFrame->OnMB_ToolsLoggingLevelGeneral(self)", ORPG_DEBUG)
546
547 def OnMB_ToolsPasswordManager(self):
548 self.log.log("Enter orpgFrame->OnMB_ToolsPasswordManager(self)", ORPG_DEBUG)
549 if self.mainmenu.GetMenuState("ToolsPasswordManager"):
550 self.password_manager.Enable()
551 else:
552 self.password_manager.Disable()
553 self.log.log("Exit orpgFrame->OnMB_ToolsPasswordManager(self)", ORPG_DEBUG)
554
555 def OnMB_ToolsStatusBar(self):
556 self.log.log("Enter orpgFrame->OnMB_ToolsStatusBar(self)", ORPG_DEBUG)
557 if self._mgr.GetPane("Status Window").IsShown() == True:
558 self.mainmenu.SetMenuState("ToolsStatusBar", False)
559 self._mgr.GetPane("Status Window").Hide()
560 else:
561 self.mainmenu.SetMenuState("ToolsStatusBar", True)
562 self._mgr.GetPane("Status Window").Show()
563 self._mgr.Update()
564 self.log.log("Exit orpgFrame->OnMB_ToolsStatusBar(self)", ORPG_DEBUG)
565
566 def OnMB_ToolsSoundToolbar(self):
567 self.log.log("Enter orpgFrame->OnMB_ToolsSoundToolbar(self)", ORPG_DEBUG)
568 if self._mgr.GetPane("Sound Control Toolbar").IsShown() == True:
569 self.mainmenu.SetMenuState("ToolsSoundToolbar", False)
570 self._mgr.GetPane("Sound Control Toolbar").Hide()
571 else:
572 self.mainmenu.SetMenuState("ToolsSoundToolbar", True)
573 self._mgr.GetPane("Sound Control Toolbar").Show()
574 self._mgr.Update()
575 self.log.log("Exit orpgFrame->OnMB_ToolsSoundToolbar(self)", ORPG_DEBUG)
576
577 def OnMB_ToolsDiceBar(self):
578 self.log.log("Enter orpgFrame->OnMB_ToolsDiceBar(self)", ORPG_DEBUG)
579 if self._mgr.GetPane("Dice Tool Bar").IsShown() == True:
580 self.mainmenu.SetMenuState("ToolsDiceBar", False)
581 self._mgr.GetPane("Dice Tool Bar").Hide()
582 else:
583 self.mainmenu.SetMenuState("ToolsDiceBar", True)
584 self._mgr.GetPane("Dice Tool Bar").Show()
585 self._mgr.Update()
586 self.log.log("Exit orpgFrame->OnMB_ToolsDiceBar(self)", ORPG_DEBUG)
587
588 def OnMB_ToolsMapBar(self):
589 self.log.log("Enter orpgFrame->OnMB_ToolsMapBar(self)", ORPG_DEBUG)
590 if self._mgr.GetPane("Map Tool Bar").IsShown() == True:
591 self.mainmenu.SetMenuState("ToolsMapBar", False)
592 self._mgr.GetPane("Map Tool Bar").Hide()
593 else:
594 self.mainmenu.SetMenuState("ToolsMapBar", True)
595 self._mgr.GetPane("Map Tool Bar").Show()
596 self._mgr.Update()
597 self.log.log("Exit orpgFrame->OnMB_ToolsMapBar(self)", ORPG_DEBUG)
598
599 #Help Menu
600 def OnMB_HelpAbout(self):
601 "The about box. We're making it n HTML about box because it's pretty cool!"
602 "Inspired by the wxWindows about.cpp sample."
603 topSizer = wx.BoxSizer( wx.VERTICAL )
604 dlg = wx.Dialog( self, -1, "About" )
605 html = AboutHTMLWindow( dlg, -1, wx.DefaultPosition, wx.Size(400, 200), wx.html.HW_SCROLLBAR_NEVER )
606 html.SetBorders( 0 )
607 replace_text = "VeRsIoNrEpLaCeMeNtStRiNg"
608 about_file = open(orpg.dirpath.dir_struct["template"]+"about.html","r")
609 about_text = about_file.read()
610 about_file.close()
611 display_text = string.replace(about_text,replace_text,VERSION)
612 html.SetPage(display_text)
613 html.SetSize( wx.Size(html.GetInternalRepresentation().GetWidth(),
614 html.GetInternalRepresentation().GetHeight()) )
615 topSizer.Add( html, 1, wx.ALL, 10 )
616 topSizer.Add( wx.StaticLine( dlg, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10 )
617 Okay = wx.Button( dlg, wx.ID_OK, "Okay" )
618 Okay.SetDefault()
619 topSizer.Add( Okay, 0, wx.ALL | wx.ALIGN_RIGHT, 15 )
620 dlg.SetAutoLayout( True )
621 dlg.SetSizer( topSizer )
622 topSizer.Fit( dlg )
623 dlg.ShowModal()
624 dlg.Destroy()
625
626 def OnMB_HelpOnlineUserGuide(self):
627 wb = webbrowser.get()
628 wb.open("https://www.assembla.com/wiki/show/openrpg/User_Manual")
629
630 def OnMB_HelpChangeLog(self):
631 wb = webbrowser.get()
632 wb.open("http://www.assembla.com/spaces/milestones/index/openrpg?spaces_tool_id=Milestones")
633
634 def OnMB_HelpReportaBug(self):
635 wb = webbrowser.get()
636 wb.open("http://www.assembla.com/spaces/tickets/index/openrpg?spaces_tool_id=Tickets")
637
638
639 #################################
640 ## Build the GUI
641 #################################
642 def build_gui(self):
643 self.log.log("Enter orpgFrame->build_gui()", ORPG_DEBUG)
644 self.Freeze()
645 self.validate.config_file("layout.xml","default_layout.xml")
646 filename = orpg.dirpath.dir_struct["user"] + "layout.xml"
647 temp_file = open(filename)
648 txt = temp_file.read()
649 xml_dom = self.xml.parseXml(txt)._get_documentElement()
650 temp_file.close()
651
652 #Plugins Window
653 self.pluginsFrame = pluginUI.PluginFrame(self)
654 open_rpg.add_component("plugins", self.get_activeplugins())
655 open_rpg.add_component("startplugs", self.get_startplugins())
656 self.windowsmenu = wx.Menu()
657 self.mainwindows = {}
658 self.log.log("Menu Created", ORPG_DEBUG)
659 h = int(xml_dom.getAttribute("height"))
660 w = int(xml_dom.getAttribute("width"))
661 posx = int(xml_dom.getAttribute("posx"))
662 posy = int(xml_dom.getAttribute("posy"))
663 maximized = int(xml_dom.getAttribute("maximized"))
664 self.SetDimensions(posx, posy, w, h)
665 self.log.log("Dimensions Set", ORPG_DEBUG)
666
667 # Sound Manager
668 self.sound_player = orpg.tools.orpg_sound.orpgSound(self)
669 open_rpg.add_component("sound", self.sound_player)
670 wndinfo = AUI.AuiPaneInfo()
671 wndinfo.DestroyOnClose(False)
672 wndinfo.Name("Sound Control Toolbar")
673 wndinfo.Caption("Sound Control Toolbar")
674 wndinfo.Float()
675 wndinfo.ToolbarPane()
676 wndinfo.Hide()
677 self._mgr.AddPane(self.sound_player, wndinfo)
678 children = xml_dom._get_childNodes()
679 for c in children:
680 self.build_window(c, self)
681
682 # status window
683 self.status = status_bar(self)
684 wndinfo = AUI.AuiPaneInfo()
685 wndinfo.DestroyOnClose(False)
686 wndinfo.Name("Status Window")
687 wndinfo.Caption("Status Window")
688 wndinfo.Float()
689 wndinfo.ToolbarPane()
690 wndinfo.Hide()
691 self._mgr.AddPane(self.status, wndinfo)
692 self.log.log("Status Window Created", ORPG_DEBUG)
693
694 # Create and show the floating dice toolbar
695 self.dieToolBar = orpg.tools.toolBars.DiceToolBar(self, callBack = self.chat.ParsePost)
696 wndinfo = AUI.AuiPaneInfo()
697 wndinfo.DestroyOnClose(False)
698 wndinfo.Name("Dice Tool Bar")
699 wndinfo.Caption("Dice Tool Bar")
700 wndinfo.Float()
701 wndinfo.ToolbarPane()
702 wndinfo.Hide()
703 self._mgr.AddPane(self.dieToolBar, wndinfo)
704 self.log.log("Dice Tool Bar Created", ORPG_DEBUG)
705
706 #Create the Map tool bar
707 self.mapToolBar = orpg.tools.toolBars.MapToolBar(self, callBack = self.map.MapBar)
708 wndinfo = AUI.AuiPaneInfo()
709 wndinfo.DestroyOnClose(False)
710 wndinfo.Name("Map Tool Bar")
711 wndinfo.Caption("Map Tool Bar")
712 wndinfo.Float()
713 wndinfo.ToolbarPane()
714 wndinfo.Hide()
715 self._mgr.AddPane(self.mapToolBar, wndinfo)
716 self.log.log("Map Tool Bar Created", ORPG_DEBUG)
717
718 #Create the Browse Server Window
719 self.gs = orpg.networking.gsclient.game_server_panel(self)
720 wndinfo = AUI.AuiPaneInfo()
721 wndinfo.DestroyOnClose(False)
722 wndinfo.Name("Browse Server Window")
723 wndinfo.Caption("Game Server")
724 wndinfo.Float()
725 wndinfo.Dockable(False)
726 wndinfo.MinSize(wx.Size(640,480))
727 wndinfo.Hide()
728 self._mgr.AddPane(self.gs, wndinfo)
729 self.log.log("Game Server Window Created", ORPG_DEBUG)
730
731 #Create the Alias Lib Window
732 self.aliaslib = orpg.tools.aliaslib.AliasLib()
733 self.aliaslib.Hide()
734 self.log.log("Alias Window Created", ORPG_DEBUG)
735 menuid = wx.NewId()
736 self.windowsmenu.Append(menuid, "Alias Lib", kind=wx.ITEM_CHECK)
737 self.windowsmenu.Check(menuid, False)
738 self.Bind(wx.EVT_MENU, self.OnMB_WindowsMenu, id=menuid)
739 self.mainwindows[menuid] = "Alias Lib"
740 self.mainmenu.Insert(3, self.windowsmenu, 'Windows')
741 self.log.log("Windows Menu Done", ORPG_DEBUG)
742 self._mgr.Update()
743 if wx.VERSION_STRING > "2.8":
744 self.Bind(AUI.EVT_AUI_PANE_CLOSE, self.onPaneClose)
745 else:
746 self.Bind(AUI.EVT_AUI_PANECLOSE, self.onPaneClose)
747 self.log.log("AUI Bindings Done", ORPG_DEBUG)
748
749 #Load the layout if one exists
750 layout = xml_dom.getElementsByTagName("DockLayout")
751 try:
752 textnode = self.xml.safe_get_text_node(layout[0])
753 self._mgr.LoadPerspective(textnode._get_nodeValue())
754 except:
755 pass
756 xml_dom.unlink()
757 self.log.log("Perspective Loaded", ORPG_DEBUG)
758 self._mgr.GetPane("Browse Server Window").Hide()
759 self._mgr.Update()
760 self.Maximize(maximized)
761 self.log.log("GUI is all created", ORPG_DEBUG)
762 self.Thaw()
763 self.log.log("Exit orpgFrame->build_gui()", ORPG_DEBUG)
764
765 def do_tab_window(self,xml_dom,parent_wnd):
766 self.log.log("Enter orpgFrame->do_tab_window(self,xml_dom,parent_wnd)", ORPG_DEBUG)
767
768 # if container window loop through childern and do a recursive call
769 temp_wnd = orpgTabberWnd(parent_wnd, style=FNB.FNB_ALLOW_FOREIGN_DND)
770 children = xml_dom._get_childNodes()
771 for c in children:
772 wnd = self.build_window(c,temp_wnd)
773 name = c.getAttribute("name")
774 temp_wnd.AddPage(wnd, name, False)
775 self.log.log("Exit orpgFrame->do_tab_window(self,xml_dom,parent_wnd)", ORPG_DEBUG)
776 return temp_wnd
777
778 def build_window(self, xml_dom, parent_wnd):
779 name = xml_dom._get_nodeName()
780 self.log.log("Enter orpgFrame->build_window(" + name + ")", ORPG_DEBUG)
781 if name == "DockLayout" or name == "dock":
782 return
783 dir = xml_dom.getAttribute("direction")
784 pos = xml_dom.getAttribute("pos")
785 height = xml_dom.getAttribute("height")
786 width = xml_dom.getAttribute("width")
787 cap = xml_dom.getAttribute("caption")
788 dockable = xml_dom.getAttribute("dockable")
789 layer = xml_dom.getAttribute("layer")
790
791 try:
792 layer = int(layer)
793 dockable = int(dockable)
794 except:
795 layer = 0
796 dockable = 1
797
798 if name == "tab":
799 temp_wnd = self.do_tab_window(xml_dom, parent_wnd)
800 elif name == "map":
801 temp_wnd = orpg.mapper.map.map_wnd(parent_wnd, -1)
802 self.map = temp_wnd
803 elif name == "tree":
804 temp_wnd = orpg.gametree.gametree.game_tree(parent_wnd, -1)
805 self.tree = temp_wnd
806 if self.settings.get_setting('ColorTree') == '1':
807 self.tree.SetBackgroundColour(self.settings.get_setting('bgcolor'))
808 self.tree.SetForegroundColour(self.settings.get_setting('textcolor'))
809 else:
810 self.tree.SetBackgroundColour('white')
811 self.tree.SetForegroundColour('black')
812
813 elif name == "chat":
814 temp_wnd = orpg.chat.chatwnd.chat_notebook(parent_wnd, wx.DefaultSize)
815 self.chattabs = temp_wnd
816 self.chat = temp_wnd.MainChatPanel
817
818 elif name == "player":
819 temp_wnd = orpg.player_list.player_list(parent_wnd)
820 self.players = temp_wnd
821 if self.settings.get_setting('ColorTree') == '1':
822 self.players.SetBackgroundColour(self.settings.get_setting('bgcolor'))
823 self.players.SetForegroundColour(self.settings.get_setting('textcolor'))
824 else:
825 self.players.SetBackgroundColour('white')
826 self.players.SetForegroundColour('black')
827 if parent_wnd != self:
828 #We dont need this if the window are beeing tabed
829 return temp_wnd
830 menuid = wx.NewId()
831 self.windowsmenu.Append(menuid, cap, kind=wx.ITEM_CHECK)
832 self.windowsmenu.Check(menuid, True)
833 self.Bind(wx.EVT_MENU, self.OnMB_WindowsMenu, id=menuid)
834 self.mainwindows[menuid] = cap
835 wndinfo = AUI.AuiPaneInfo()
836 wndinfo.DestroyOnClose(False)
837 wndinfo.Name(cap)
838 wndinfo.FloatingSize(wx.Size(int(width), int(height)))
839 wndinfo.BestSize(wx.Size(int(width), int(height)))
840 wndinfo.Layer(int(layer))
841 wndinfo.Caption(cap)
842
843 # Lambda here should work! (future dev)
844 if dir.lower() == 'top':
845 wndinfo.Top()
846 elif dir.lower() == 'bottom':
847 wndinfo.Bottom()
848 elif dir.lower() == 'left':
849 wndinfo.Left()
850 elif dir.lower() == 'right':
851 wndinfo.Right()
852 elif dir.lower() == 'center':
853 wndinfo.Center()
854 wndinfo.CaptionVisible(False)
855
856 if dockable != 1:
857 wndinfo.Dockable(False)
858 wndinfo.Floatable(False)
859 if pos != '' or pos != '0' or pos != None:
860 wndinfo.Position(int(pos))
861 wndinfo.Show()
862 self._mgr.AddPane(temp_wnd, wndinfo)
863 self.log.log("Exit orpgFrame->build_window(" + name + ")", ORPG_DEBUG)
864 return temp_wnd
865
866 def onPaneClose(self, evt):
867 self.log.log("Enter orpgFrame->onPaneClose()", ORPG_DEBUG)
868 pane = evt.GetPane()
869 for wndid, wname in self.mainwindows.iteritems():
870 if pane.name == wname:
871 self.windowsmenu.Check(wndid, False)
872 break
873 evt.Skip()
874 self._mgr.Update()
875 self.log.log("Exit orpgFrame->onPaneClose()", ORPG_DEBUG)
876
877 def saveLayout(self):
878 self.log.log("Enter orpgFrame->saveLayout()", ORPG_DEBUG)
879 filename = orpg.dirpath.dir_struct["user"] + "layout.xml"
880 temp_file = open(filename)
881 txt = temp_file.read()
882 xml_dom = self.xml.parseXml(txt)._get_documentElement()
883 temp_file.close()
884 (x_size,y_size) = self.GetClientSize()
885 (x_pos,y_pos) = self.GetPositionTuple()
886 if self.IsMaximized():
887 max = 1
888 else:
889 max = 0
890 xml_dom.setAttribute("height", str(y_size))
891 xml_dom.setAttribute("width", str(x_size))
892 xml_dom.setAttribute("posx", str(x_pos))
893 xml_dom.setAttribute("posy", str(y_pos))
894 xml_dom.setAttribute("maximized", str(max))
895 layout = xml_dom.getElementsByTagName("DockLayout")
896 try:
897 textnode = self.xml.safe_get_text_node(layout[0])
898 textnode._set_nodeValue(str(self._mgr.SavePerspective()))
899 except:
900 elem = self.xml.minidom.Element('DockLayout')
901 elem.setAttribute("DO_NO_EDIT","True")
902 textnode = self.xml.safe_get_text_node(elem)
903 textnode._set_nodeValue(str(self._mgr.SavePerspective()))
904 xml_dom.appendChild(elem)
905 temp_file = open(filename, "w")
906 temp_file.write(xml_dom.toxml(1))
907 temp_file.close()
908 self.log.log("Exit saveLayout()", ORPG_DEBUG)
909
910 def build_hotkeys(self):
911 self.log.log("Enter orpgFrame->build_hotkeys(self)", ORPG_DEBUG)
912 self.mainmenu.accel.xaccel.extend(self.chat.get_hot_keys())
913 self.mainmenu.accel.xaccel.extend(self.map.get_hot_keys())
914 self.log.log("Exit orpgFrame->build_hotkeys(self)", ORPG_DEBUG)
915
916 def start_timer(self):
917 self.log.log("Enter orpgFrame->start_timer(self)", ORPG_DEBUG)
918 self.poll_timer.Start(100)
919 s = open_rpg.get_component('settings')
920 if s.get_setting("Heartbeat") == "1":
921 self.ping_timer.Start(1000*60)
922 self.log.log("starting heartbeat...", ORPG_DEBUG, True)
923 self.log.log("Exit orpgFrame->start_timer(self)", ORPG_DEBUG)
924
925 def kill_mplay_session(self):
926 self.log.log("Enter orpgFrame->kill_mplay_session(self)", ORPG_DEBUG)
927 self.game_name = ""
928 self.session.start_disconnect()
929 self.log.log("Exit orpgFrame->kill_mplay_session(self)", ORPG_DEBUG)
930
931 def quit_game(self, evt):
932 self.log.log("Enter orpgFrame->quit_game(self, evt)", ORPG_DEBUG)
933 dlg = wx.MessageDialog(self,"Exit gaming session?","Game Session",wx.YES_NO)
934 if dlg.ShowModal() == wx.ID_YES:
935 self.session.exitCondition.notifyAll()
936 dlg.Destroy()
937 self.kill_mplay_session()
938 self.log.log("Exit orpgFrame->quit_game(self, evt)", ORPG_DEBUG)
939
940 def on_status_event(self, evt):
941 self.log.log("Enter orpgFrame->on_status_event(self, evt)", ORPG_DEBUG)
942 id = evt.get_id()
943 status = evt.get_data()
944 if id == orpg.networking.mplay_client.STATUS_SET_URL:
945 self.status.set_url(status)
946 self.log.log("Exit orpgFrame->on_status_event(self, evt)", ORPG_DEBUG)
947
948 def on_player_event(self, evt):
949 self.log.log("Enter orpgFrame->on_player_event(self, evt)", ORPG_DEBUG)
950 id = evt.get_id()
951 player = evt.get_data()
952 display_name = self.chat.chat_display_name(player)
953 time_str = time.strftime("%H:%M", time.localtime())
954 if id == orpg.networking.mplay_client.PLAYER_NEW:
955 self.players.add_player(player)
956 self.chat.InfoPost(display_name + " (enter): " + time_str)
957 elif id == orpg.networking.mplay_client.PLAYER_DEL:
958 self.players.del_player(player)
959 self.chat.InfoPost(display_name + " (exit): " + time_str)
960 elif id == orpg.networking.mplay_client.PLAYER_UPDATE:
961 self.players.update_player(player)
962 self.players.Refresh()
963 self.log.log("Exit orpgFrame->on_player_event(self, evt)", ORPG_DEBUG)
964
965 def on_group_event(self, evt):
966 self.log.log("Enter orpgFrame->on_group_event(self, evt)", ORPG_DEBUG)
967 id = evt.get_id()
968 data = evt.get_data()
969
970 if id == orpg.networking.mplay_client.GROUP_NEW:
971 self.gs.add_room(data)
972 elif id == orpg.networking.mplay_client.GROUP_DEL:
973 self.password_manager.RemoveGroupData(data)
974 self.gs.del_room(data)
975 elif id == orpg.networking.mplay_client.GROUP_UPDATE:
976 self.gs.update_room(data)
977 self.log.log("Exit orpgFrame->on_group_event(self, evt)", ORPG_DEBUG)
978
979 def on_receive(self, data, player):
980 self.log.log("Enter orpgFrame->on_receive(self, data, player)", ORPG_DEBUG)
981
982 # see if we are ignoring this user
983 (ignore_id,ignore_name) = self.session.get_ignore_list()
984 for m in ignore_id:
985 if m == player[2]:
986 # yes we are
987 self.log.log("ignoring message from player:" + player[0], ORPG_INFO, True)
988 return
989
990 # ok we are not ignoring this message
991 #recvSound = "RecvSound" # this will be the default sound. Whisper will change this below
992 if player:
993 display_name = self.chat.chat_display_name(player)
994 else:
995 display_name = "Server Administrator"
996
997 if data[:5] == "<tree":
998 self.tree.on_receive_data(data,player)
999 self.chat.InfoPost(display_name + " has sent you a tree node...")
1000 #self.tree.OnNewData(data)
1001
1002 elif data[:4] == "<map":
1003 self.map.new_data(data)
1004
1005 elif data[:5] == "<chat":
1006 msg = orpg.chat.chat_msg.chat_msg(data)
1007 self.chat.post_incoming_msg(msg,player)
1008 else:
1009 ##############################################################################################
1010 # all this below code is for comptiablity with older clients and can be removed after a bit #
1011 ##############################################################################################
1012 if data[:3] == "/me":
1013 # This fixes the emote coloring to comply with what has been asked for by the user
1014 # population, not to mention, what I committed to many moons ago.
1015 # In doing so, Woody's scheme has been tossed out. I'm sure Woody won't be
1016 # happy but I'm invoking developer priveledge to satisfy user request, not to mention,
1017 # this scheme actually makes more sense. In Woody's scheme, a user could over-ride another
1018 # users emote color. This doesn't make sense, rather, people dictate their OWN colors...which is as
1019 # it should be in the first place and is as it has been with normal text. In short, this makes
1020 # sense and is consistent.
1021 data = data.replace( "/me", "" )
1022
1023 # Check to see if we find the closing ">" for the font within the first 22 values
1024 index = data[:22].find( ">" )
1025 if index == -1:
1026 data = "** " + self.chat.colorize( self.chat.infocolor, display_name + data ) + " **"
1027
1028 else:
1029 # This means that we found a valid font string, so we can simply plug the name into
1030 # the string between the start and stop font delimiter
1031 print "pre data = " + data
1032 data = data[:22] + "** " + display_name + " " + data[22:] + " **"
1033 print "post data = " + data
1034
1035 elif data[:2] == "/w":
1036 data = data.replace("/w","")
1037 data = "<b>" + display_name + "</b> (whispering): " + data
1038
1039 else:
1040 # Normal text
1041 if player:
1042 data = "<b>" + display_name + "</b>: " + data
1043 else:
1044 data = "<b><i><u>" + display_name + "</u>-></i></b> " + data
1045 self.chat.Post(data)
1046 self.log.log("Exit orpgFrame->on_receive(self, data, player)", ORPG_DEBUG)
1047
1048 def on_mplay_event(self, evt):
1049 self.log.log("Enter orpgFrame->on_mplay_event(self, evt)", ORPG_DEBUG)
1050
1051 id = evt.get_id()
1052 if id == orpg.networking.mplay_client.MPLAY_CONNECTED:
1053 self.chat.InfoPost("Game connected!")
1054 self.gs.set_connected(1)
1055 self.password_manager.ClearPassword("ALL")
1056
1057 elif id == orpg.networking.mplay_client.MPLAY_DISCONNECTED:
1058 self.poll_timer.Stop()
1059 self.ping_timer.Stop()
1060 self.chat.SystemPost("Game disconnected!")
1061 self.players.reset()
1062 self.gs.set_connected(0)
1063 self.status.set_connect_status("Not Connected")
1064
1065 ####Begin changes for Custom Exit Message by mDuo13######
1066 elif id == orpg.networking.mplay_client.MPLAY_DISCONNECTING:
1067 settings = open_rpg.get_component('settings')
1068 custom_msg = settings.get_setting("dcmsg")
1069 custom_msg=custom_msg[:80]
1070 if custom_msg[:3]=="/me":
1071 self.chat.send_chat_message(custom_msg[3:], 3)
1072 else:
1073 self.chat.system_message(custom_msg)
1074 #####End Changes for Custom Exit Message by mDuo13
1075
1076 elif id== orpg.networking.mplay_client.MPLAY_GROUP_CHANGE:
1077 group = evt.get_data()
1078 self.chat.InfoPost("Moving to room '"+group[1]+"'..")
1079 if self.gs : self.gs.set_cur_room_text(group[1])
1080 self.players.reset()
1081 elif id== orpg.networking.mplay_client.MPLAY_GROUP_CHANGE_F:
1082 self.chat.SystemPost("Room access denied!")
1083 self.log.log("Exit orpgFrame->on_mplay_event(self, evt)", ORPG_DEBUG)
1084
1085 def OnCloseWindow(self, event):
1086 self.log.log("Enter orpgFrame->OnCloseWindow(self, event)", ORPG_DEBUG)
1087 dlg = wx.MessageDialog(self, "Quit OpenRPG?", "OpenRPG", wx.YES_NO)
1088 if dlg.ShowModal() == wx.ID_YES:
1089 dlg.Destroy()
1090 self.closed_confirmed()
1091 self.log.log("Exit orpgFrame->OnCloseWindow(self, event)", ORPG_DEBUG)
1092
1093 def closed_confirmed(self):
1094 self.log.log("Enter orpgFrame->closed_confirmed(self)", ORPG_DEBUG)
1095 self.activeplugins = open_rpg.get_component('plugins')
1096 self.aliaslib.OnMB_FileSave(None)
1097
1098 #following lines added by mDuo13
1099 #########plugin_disabled()#########
1100 for plugin_fname in self.activeplugins.keys():
1101 plugin = self.activeplugins[plugin_fname]
1102 try:
1103 plugin.plugin_disabled()
1104 except Exception, e:
1105 if str(e) != "'module' object has no attribute 'plugin_disabled'":
1106 #print e
1107 traceback.print_exc()
1108 #end mDuo13 added code
1109 self.saveLayout()
1110 try:
1111 self.settings.save()
1112 except:
1113 self.log.log("[WARNING] Error saving 'settings' component", ORPG_GENERAL, True)
1114
1115 try:
1116 self.map.pre_exit_cleanup()
1117 except:
1118 self.log.log("[WARNING] Map error pre_exit_cleanup()", ORPG_GENERAL, True)
1119
1120 try:
1121 save_tree = string.upper(self.settings.get_setting("SaveGameTreeOnExit"))
1122 if (save_tree != "0") and (save_tree != "False") and (save_tree != "NO"):
1123 self.tree.save_tree(self.settings.get_setting("gametree"))
1124 except:
1125 self.log.log("[WARNING] Error saving gametree", ORPG_GENERAL, True)
1126
1127 if self.session.get_status() == orpg.networking.mplay_client.MPLAY_CONNECTED:
1128 self.kill_mplay_session()
1129
1130 try:
1131 #Kill all the damn timers
1132 self.sound_player.timer.Stop()
1133 del self.sound_player.timer
1134 except:
1135 self.log.log("sound didn't die properly.",ORPG_GENERAL, True)
1136
1137 try:
1138 self.poll_timer.Stop()
1139 self.ping_timer.Stop()
1140 self.chat.parent.chat_timer.Stop()
1141 self.map.canvas.zoom_display_timer.Stop()
1142 self.map.canvas.image_timer.Stop()
1143 self.status.timer.Stop()
1144 del self.ping_timer
1145 del self.poll_timer
1146 del self.chat.parent.chat_timer
1147 del self.map.canvas.zoom_display_timer
1148 del self.map.canvas.image_timer
1149 del self.status.timer
1150 except:
1151 self.log.log("some timer didn't die properly.",ORPG_GENERAL, True)
1152 self._mgr.UnInit()
1153 mainapp = wx.GetApp()
1154 mainapp.ExitMainLoop()
1155 self.Destroy()
1156
1157 try:
1158 if self.server_pipe != None:
1159 dlg = wx.ProgressDialog("Exit","Stoping server",2,self)
1160 dlg.Update(2)
1161 dlg.Show(True)
1162 self.server_pipe.write("\nkill\n")
1163 self.log.log("Killing Server process:", ORPG_GENERAL, True)
1164 time.sleep(5)
1165 self.server_stop()
1166 self.server_pipe.close()
1167 self.std_out.close()
1168 self.server_thread.exit()
1169 dlg.Destroy()
1170 self.log.log("Server killed:", ORPG_GENERAL, True)
1171 except:
1172 pass
1173 self.log.log("Exit orpgFrame->closed_confirmed(self)", ORPG_DEBUG)
1174
1175
1176 ########################################
1177 ## Application class
1178 ########################################
1179 class orpgSplashScreen(wx.SplashScreen):
1180 def __init__(self, parent, bitmapfile, duration, callback):
1181 wx.SplashScreen.__init__(self, wx.Bitmap(bitmapfile), wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, duration, None, -1)
1182 self.callback = callback
1183 self.closing = False
1184 self.Bind(wx.EVT_CLOSE, self.callback)
1185
1186 class orpgApp(wx.App):
1187 def OnInit(self):
1188 self.log = orpg.tools.orpg_log.orpgLog(orpg.dirpath.dir_struct["user"] + "runlogs/")
1189 self.log.setLogToConsol(False)
1190 self.log.log("Main Application Start", ORPG_DEBUG)
1191 #Add the initial global components of the openrpg class
1192 #Every class should be passed openrpg
1193 open_rpg.add_component("log", self.log)
1194 open_rpg.add_component("xml", orpg.orpg_xml)
1195 open_rpg.add_component("dir_struct", orpg.dirpath.dir_struct)
1196 open_rpg.add_component("tabbedWindows", [])
1197 self.validate = orpg.tools.validate.Validate()
1198 open_rpg.add_component("validate", self.validate)
1199 self.settings = orpg.tools.orpg_settings.orpgSettings()
1200 open_rpg.add_component("settings", self.settings)
1201 self.log.setLogLevel(int(self.settings.get_setting('LoggingLevel')))
1202 self.called = False
1203 wx.InitAllImageHandlers()
1204 self.splash = orpgSplashScreen(None, orpg.dirpath.dir_struct["icon"] + 'splash13.jpg', 3000, self.AfterSplash)
1205 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPress)
1206 self._crust = None
1207 wx.Yield()
1208 return True
1209
1210 def OnKeyPress(self, evt):
1211 #Event handler
1212 if evt.AltDown() and evt.CmdDown() and evt.KeyCode == ord('I'):
1213 self.ShowShell()
1214 else:
1215 evt.Skip()
1216
1217 def ShowShell(self):
1218 #Show the PyCrust window.
1219 if not self._crust:
1220 self._crust = wx.py.crust.CrustFrame(self.GetTopWindow())
1221 self._crust.shell.interp.locals['app'] = self
1222 win = wx.FindWindowAtPointer()
1223 self._crust.shell.interp.locals['win'] = win
1224 self._crust.Show()
1225
1226 def AfterSplash(self,evt):
1227 if not self.called:
1228 self.splash.Hide()
1229 self.called = True
1230 self.frame = orpgFrame(None, wx.ID_ANY, MENU_TITLE)
1231 self.frame.Raise()
1232 self.frame.Refresh()
1233 self.frame.Show(True)
1234 self.SetTopWindow(self.frame)
1235 #self.frame.show_dlgs()
1236 self.frame.post_show_init()
1237 wx.CallAfter(self.splash.Close)
1238 return True
1239
1240 def OnExit(self):
1241 self.log.log("Main Application Exit\n\n", ORPG_DEBUG)