comparison orpg/gametree/nodehandlers/StarWarsd20.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 3b2cfa13b610
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 # Copyright (C) 2000-2001 The OpenRPG Project
2 #
3 # openrpg-dev@lists.sourceforge.net
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 # --
19 #
20 # File: StarWarsd20.py
21 # Author: Chris Davis; Mark Twombley
22 # Maintainer: Mark Twombley
23 # Version:
24 # $Id: StarWarsd20.py,v 1.18 2006/11/15 12:11:23 digitalxero Exp $
25 #
26 # Description: The file contains code for the StarWarsd20 nodehanlers
27 #
28
29 __version__ = "$Id: StarWarsd20.py,v 1.18 2006/11/15 12:11:23 digitalxero Exp $"
30
31 from core import *
32
33 SWD20_EXPORT = wx.NewId()
34 ############################
35 ## StarWarsd20 character node handler
36 ############################
37 ##The whole look and easy of use redone by Digitalxero
38 class container_handler(node_handler):
39 """ should not be used! only a base class!
40 <nodehandler name='?' module='core' class='container_handler' />
41 """
42 def __init__(self,xml_dom,tree_node):
43 node_handler.__init__(self,xml_dom,tree_node)
44 self.load_children()
45
46 def load_children(self):
47 children = self.master_dom._get_childNodes()
48 for c in children:
49 self.tree.load_xml(c,self.mytree_node)
50
51
52 def on_drop(self,evt):
53 drag_obj = self.tree.drag_obj
54 #if self.is_my_child(self.mytree_node,drag_obj.mytree_node):
55 # return
56 if drag_obj == self:
57 return
58 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL)
59 if opt == wx.YES:
60 xml_dom = self.tree.drag_obj.delete()
61 xml_dom = self.master_dom.insertBefore(xml_dom,None)
62 self.tree.load_xml(xml_dom, self.mytree_node)
63 self.tree.Expand(self.mytree_node)
64 elif opt == wx.NO:
65 node_handler.on_drop(self,evt)
66
67 def tohtml(self):
68 cookie = 0
69 html_str = "<table border=\"1\" ><tr><td>"
70 html_str += "<b>"+self.master_dom.getAttribute("name") + "</b>"
71 html_str += "</td></tr>\n"
72 html_str += "<tr><td>"
73 max = tree.GetChildrenCount(handler.mytree_node)
74 try:
75 (child,cookie)=self.tree.GetFirstChild(self.mytree_node,cookie)
76 except: # If this happens we probably have a newer version of wxPython
77 (child,cookie)=self.tree.GetFirstChild(self.mytree_node)
78 obj = self.tree.GetPyData(child)
79 for m in xrange(max):
80 html_str += "<p>" + obj.tohtml()
81 if m < max-1:
82 child = self.tree.GetNextSibling(child)
83 obj = self.tree.GetPyData(child)
84 html_str += "</td></tr></table>"
85 return html_str
86
87 def get_size_constraint(self):
88 return 1
89
90 def get_char_name( self ):
91 return self.child_handlers['general'].get_char_name()
92
93 ## def set_char_pp(self,attr,evl):
94 ## return self.child_handlers['pp'].set_char_pp(attr,evl)
95 ##
96 ## def get_char_pp( self, attr ):
97 ## return self.child_handlers['pp'].get_char_pp(attr)
98 ##
99 def get_char_lvl( self, attr ):
100 return self.child_handlers['classes'].get_char_lvl(attr)
101
102
103
104 class SWd20char_handler(node_handler):
105 """ Node handler for a SWd20 charactor
106 <nodehandler name='?' module='StarWarsd20' class='SWd20char_handler' />
107 """
108 def __init__(self,xml_dom,tree_node):
109 node_handler.__init__(self,xml_dom,tree_node)
110 self.frame = open_rpg.get_component('frame')
111 self.child_handlers = {}
112 self.new_child_handler('howtouse','HowTO use this tool',SWd20howto,'note')
113 self.new_child_handler('general','General Information',SWd20general,'gear')
114 self.new_child_handler('inventory','Money and Inventory',SWd20inventory,'money')
115 self.new_child_handler('abilities','Abilities Scores',SWd20ability,'gear')
116 self.new_child_handler('classes','Classes',SWd20classes,'knight')
117 self.new_child_handler('saves','Saves',SWd20saves,'skull')
118 self.new_child_handler('skills','Skills',SWd20skill,'book')
119 self.new_child_handler('feats','Feats',SWd20feats,'book')
120 self.new_child_handler('wp','Wound Points',SWd20hp,'gear')
121 self.new_child_handler('vp','Vitality Points',SWd20vp,'gear')
122 self.new_child_handler('attacks','Attacks',SWd20attacks,'spears')
123 self.new_child_handler('ac','Armor',SWd20armor,'spears')
124 self.myeditor = None
125
126
127 def on_version(self,old_version):
128 node_handler.on_version(self,old_version)
129 if old_version == "":
130 tmp = open(orpg.dirpath.dir_struct["nodes"]+"StarWars_d20character.xml","r")
131 xml_dom = parseXml_with_dlg(self.tree,tmp.read())
132 xml_dom = xml_dom._get_firstChild()
133 tmp.close()
134 ## add new nodes
135 for tag in ("howtouse","inventory","powers","divine","pp"):
136 node_list = xml_dom.getElementsByTagName(tag)
137 self.master_dom.appendChild(node_list[0])
138
139 ## add new atts
140 melee_attack = self.master_dom.getElementsByTagName('melee')[0]
141 melee_attack.setAttribute("second","0")
142 melee_attack.setAttribute("third","0")
143 melee_attack.setAttribute("forth","0")
144 melee_attack.setAttribute("fifth","0")
145 melee_attack.setAttribute("sixth","0")
146 range_attack = self.master_dom.getElementsByTagName('ranged')[0]
147 range_attack.setAttribute("second","0")
148 range_attack.setAttribute("third","0")
149 range_attack.setAttribute("forth","0")
150 range_attack.setAttribute("fifth","0")
151 range_attack.setAttribute("sixth","0")
152
153 gen_list = self.master_dom.getElementsByTagName('general')[0]
154
155 for tag in ("currentxp","xptolevel"):
156 node_list = xml_dom.getElementsByTagName(tag)
157 gen_list.appendChild(node_list[0])
158 ## temp fix
159 #parent = self.master_dom._get_parentNode()
160 #old_dom = parent.replaceChild(xml_dom,self.master_dom)
161 #self.master_dom = xml_dom
162 print old_version
163
164
165 def get_char_name( self ):
166 return self.child_handlers['general'].get_char_name()
167
168 ## def set_char_pp(self,attr,evl):
169 ## return self.child_handlers['pp'].set_char_pp(attr,evl)
170 ##
171 ## def get_char_pp( self, attr ):
172 ## return self.child_handlers['pp'].get_char_pp(attr)
173
174 def get_char_lvl( self, attr ):
175 return self.child_handlers['classes'].get_char_lvl(attr)
176
177
178 def new_child_handler(self,tag,text,handler_class,icon='gear'):
179 node_list = self.master_dom.getElementsByTagName(tag)
180 tree = self.tree
181 i = self.tree.icons[icon]
182 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
183 handler = handler_class(node_list[0],new_tree_node,self)
184 tree.SetPyData(new_tree_node,handler)
185 self.child_handlers[tag] = handler
186
187 def get_design_panel(self,parent):
188 return tabbed_panel(parent,self,1)
189
190
191 def get_use_panel(self,parent):
192 return tabbed_panel(parent,self,2)
193
194
195 def tohtml(self):
196 html_str = "<table><tr><td colspan=2 >"+self.child_handlers['general'].tohtml()+"</td></tr>"
197 html_str += "<tr><td width='50%' valign=top >"+self.child_handlers['abilities'].tohtml()
198 html_str += "<P>" + self.child_handlers['saves'].tohtml()
199 html_str += "<P>" + self.child_handlers['attacks'].tohtml()
200 html_str += "<P>" + self.child_handlers['ac'].tohtml()
201 html_str += "<P>" + self.child_handlers['feats'].tohtml()
202 #html_str += "<P>" + self.child_handlers['spells'].tohtml()
203 #html_str += "<P>" + self.child_handlers['divine'].tohtml()
204 #html_str += "<P>" + self.child_handlers['powers'].tohtml()
205 html_str += "<P>" + self.child_handlers['inventory'].tohtml() +"</td>"
206 html_str += "<td width='50%' valign=top >"+self.child_handlers['classes'].tohtml()
207 html_str += "<P>" + self.child_handlers['wp'].tohtml()
208 html_str += "<P>" + self.child_handlers['vp'].tohtml()
209 #html_str += "<P>" + self.child_handlers['pp'].tohtml()
210 html_str += "<P>" + self.child_handlers['skills'].tohtml() +"</td>"
211 html_str += "</tr></table>"
212 return html_str
213
214 def about(self):
215 html_str = "<img src='" + orpg.dirpath.dir_struct["icon"]+'d20_logo.gif' "><br /><b>d20 Character Tool v0.7 beta</b>"
216 html_str += "<br />by Chris Davis<br />chris@rpgarchive.com"
217 return html_str
218
219 def get_char_name( self ):
220 return self.child_handlers['general'].get_char_name()
221 def get_armor_class( self ):
222 return self.child_handlers['ac'].get_armor_class()
223 def get_max_hp( self ):
224 return self.child_handlers['wp'].get_max_hp()
225 def get_current_hp( self ):
226 return self.child_handlers['wp'].get_current_hp()
227 def get_max_vp( self ):
228 return self.child_handlers['vp'].get_max_vp()
229 def get_current_vp( self ):
230 return self.child_handlers['vp'].get_current_vp()
231
232 ## def set_char_pp(self,attr,evl):
233 ## return self.child_handlers['pp'].set_char_pp(attr,evl)
234 ##
235 ## def get_char_pp( self, attr ):
236 ## return self.child_handlers['pp'].get_char_pp(attr)
237
238 def get_char_lvl( self, attr ):
239 return self.child_handlers['classes'].get_char_lvl(attr)
240
241 class tabbed_panel(wx.Notebook):
242 def __init__(self, parent, handler, mode):
243 wx.Notebook.__init__(self, parent, -1, size=(1200,800))
244 self.handler = handler
245 self.parent = parent
246 tree = self.handler.tree
247 max = tree.GetChildrenCount(handler.mytree_node)
248
249 cookie = 0
250 max = tree.GetChildrenCount(handler.mytree_node)
251 try:
252 (child,cookie)=tree.GetFirstChild(handler.mytree_node,cookie)
253 except: # If this happens we probably have a newer version of wxPython
254 (child,cookie)=tree.GetFirstChild(handler.mytree_node)
255 obj = tree.GetPyData(child)
256 for m in xrange(max):
257 if mode == 1:
258 panel = obj.get_design_panel(self)
259 else:
260 panel = obj.get_use_panel(self)
261 name = obj.master_dom.getAttribute("name")
262
263 if panel:
264 self.AddPage(panel,name)
265 if m < max-1:
266 child = tree.GetNextSibling(child)
267 obj = tree.GetPyData(child)
268
269
270 def about(self):
271 html_str = "<img src='" + orpg.dirpath.dir_struct["icon"]+'d20_logo.gif' "><br /><b>d20 Character Tool v0.7 beta</b>"
272 html_str += "<br />by Chris Davis<br />chris@rpgarchive.com"
273 return html_str
274
275 def get_char_name( self ):
276 return self.child_handlers['general'].get_char_name()
277
278 ## def set_char_pp(self,attr,evl):
279 ## return self.child_handlers['pp'].set_char_pp(attr,evl)
280 ##
281 ## def get_char_pp( self, attr ):
282 ## return self.child_handlers['pp'].get_char_pp(attr)
283
284 def get_char_lvl( self, attr ):
285 return self.child_handlers['classes'].get_char_lvl(attr)
286
287 class SWd20_char_child(node_handler):
288 """ Node Handler for skill. This handler will be
289 created by SWd20char_handler.
290 """
291 def __init__(self, xml_dom, tree_node, parent):
292 node_handler.__init__(self,xml_dom, tree_node)
293 self.char_hander = parent
294 self.drag = False
295 self.frame = open_rpg.get_component('frame')
296 self.myeditor = None
297
298
299 def on_drop(self,evt):
300 pass
301
302 def on_rclick(self,evt):
303 pass
304
305 def on_ldclick(self,evt):
306 return
307 if self.myeditor == None or self.myeditor.destroyed:
308 title = self.master_dom.getAttribute('name') + " Editor"
309 self.myeditor = orpgPFrame(self.frame,title,orpg.dirpath.dir_struct["icon"]+'grid.ico')
310 wnd = self.get_design_panel(self.myeditor)
311 self.myeditor.panel = wnd
312 self.wnd = wnd
313 self.myeditor.Show(1)
314 else:
315 self.myeditor.Raise()
316
317 def on_html(self,evt):
318 html_str = self.tohtml()
319 wnd = http_html_window(self.frame.note,-1)
320 wnd.title = self.master_dom.getAttribute('name')
321 self.frame.add_panel(wnd)
322 wnd.SetPage(html_str)
323
324 def get_design_panel(self,parent):
325 pass
326
327 def get_use_panel(self,parent):
328 return self.get_design_panel(parent)
329
330 def delete(self):
331 pass
332
333
334 class SWd20skill(SWd20_char_child):
335 """ Node Handler for skill. This handler will be
336 created by SWd20char_handler.
337 """
338 def __init__(self, xml_dom, tree_node, parent):
339 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
340 tree = self.tree
341 icons = self.tree.icons
342 node_list = self.master_dom.getElementsByTagName('skill')
343 self.skills={}
344 for n in node_list:
345 name = n.getAttribute('name')
346 self.skills[name] = n
347 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
348 tree.SetPyData(new_tree_node,self)
349
350 def get_mod(self,name):
351 skill = self.skills[name]
352 stat = skill.getAttribute('stat')
353 ac = int(skill.getAttribute('armorcheck'))
354 if ac:
355 ac = self.char_hander.child_handlers['ac'].get_check_pen()
356 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
357 rank = int(skill.getAttribute('rank'))
358 misc = int(skill.getAttribute('misc'))
359 total = stat_mod + rank + misc + ac
360 return total
361
362 def on_rclick(self,evt):
363 #updated with code for untrained use check
364 item = self.tree.GetSelection()
365 name = self.tree.GetItemText(item)
366 skill = self.skills[name]
367 rank = int(skill.getAttribute('rank'))
368 untrained = int(skill.getAttribute('untrained'))
369 chat = self.chat
370 if item == self.mytree_node:
371 SWd20_char_child.on_ldclick(self,evt)
372 else:
373 if rank == 0 and untrained == 0:
374 chat.Post('Can\'t use untrained!',True,True)
375 else:
376 mod = self.get_mod(name)
377 if mod >= 0:
378 mod1 = "+"
379 else:
380 mod1 = ""
381 txt = '%s Skill Check: [1d20%s%s]' % (name, mod1, mod)
382 chat.ParsePost(txt,True,True)
383
384 def get_design_panel(self,parent):
385 wnd = outline_panel(parent,self,skill_grid,"Skills")
386 wnd.title = "Skills (edit)"
387 return wnd
388
389 def tohtml(self):
390 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Skill</th><th>Key</th>
391 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>"""
392 node_list = self.master_dom.getElementsByTagName('skill')
393 for n in node_list:
394 name = n.getAttribute('name')
395 stat = n.getAttribute('stat')
396 rank = n.getAttribute('rank')
397 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+rank+"</td>"
398 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
399 misc = n.getAttribute('misc')
400 mod = str(self.get_mod(name))
401 if mod >= 0:
402 mod1 = "+"
403 else:
404 mod1 = ""
405 html_str = html_str + "<td>"+stat_mod+"</td><td>"+misc+'</td><td>%s%s</td></tr>' % (mod1, mod)
406 html_str = html_str + "</table>"
407 return html_str
408
409
410 class SWd20ability(SWd20_char_child):
411 """ Node Handler for ability. This handler will be
412 created by SWd20char_handler.
413 """
414 def __init__(self, xml_dom, tree_node, parent):
415 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
416 self.abilities = {}
417 node_list = self.master_dom.getElementsByTagName('stat')
418 tree = self.tree
419 icons = tree.icons
420 for n in node_list:
421 name = n.getAttribute('abbr')
422 self.abilities[name] = n
423 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
424 tree.SetPyData( new_tree_node, self )
425
426 def on_rclick( self, evt ):
427 item = self.tree.GetSelection()
428 name = self.tree.GetItemText( item )
429 if item == self.mytree_node:
430 SWd20_char_child.on_ldclick( self, evt )
431 else:
432 mod = self.get_mod( name )
433 if mod >= 0:
434 mod1 = "+"
435 else:
436 mod1 = ""
437 chat = self.chat
438 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod )
439 chat.ParsePost( txt, True, True )
440
441 def get_mod(self,abbr):
442 score = int(self.abilities[abbr].getAttribute('base'))
443 mod = (score - 10) / 2
444 return mod
445
446 def set_score(self,abbr,score):
447 if score >= 0:
448 self.abilities[abbr].setAttribute("base",str(score))
449
450 def get_design_panel(self,parent):
451 wnd = outline_panel(parent,self,abil_grid,"Abilities")
452 wnd.title = "Abilities (edit)"
453 return wnd
454
455 def tohtml(self):
456 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th>
457 <th>Base</th><th>Modifier</th></tr>"""
458 node_list = self.master_dom.getElementsByTagName('stat')
459 for n in node_list:
460 name = n.getAttribute('name')
461 abbr = n.getAttribute('abbr')
462 base = n.getAttribute('base')
463 mod = str(self.get_mod(abbr))
464 if mod >= 0:
465 mod1 = "+"
466 else:
467 mod1 = ""
468 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+base+'</td><td>%s%s</td></tr>' % (mod1, mod)
469 html_str = html_str + "</table>"
470 return html_str
471
472 class SWd20saves(SWd20_char_child):
473 """ Node Handler for saves. This handler will be
474 created by SWd20char_handler.
475 """
476 def __init__(self, xml_dom, tree_node, parent):
477 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
478 tree = self.tree
479 icons = self.tree.icons
480 node_list = self.master_dom.getElementsByTagName('save')
481 self.saves={}
482 for n in node_list:
483 name = n.getAttribute('name')
484 self.saves[name] = n
485 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
486 tree.SetPyData(new_tree_node,self)
487
488 def get_mod(self,name):
489 save = self.saves[name]
490 stat = save.getAttribute('stat')
491 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
492 base = int(save.getAttribute('base'))
493 miscmod = int(save.getAttribute('miscmod'))
494 # magmod = int(save.getAttribute('magmod'))
495 # total = stat_mod + base + miscmod + magmod
496 total = stat_mod + base + miscmod
497 return total
498
499 def on_rclick(self,evt):
500 item = self.tree.GetSelection()
501 name = self.tree.GetItemText(item)
502 if item == self.mytree_node:
503 SWd20_char_child.on_ldclick(self,evt)
504 #wnd = save_grid(self.frame.note,self)
505 #wnd.title = "Saves"
506 #self.frame.add_panel(wnd)
507 else:
508 mod = self.get_mod(name)
509 if mod >= 0:
510 mod1 = "+"
511 else:
512 mod1 = ""
513 chat = self.chat
514 txt = '%s save: [1d20%s%s]' % (name, mod1, mod)
515 chat.ParsePost( txt, True, True )
516
517 def get_design_panel(self,parent):
518 wnd = outline_panel(parent,self,save_grid,"Saves")
519 wnd.title = "Saves"
520 return wnd
521
522 def tohtml(self):
523 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Save</th>
524 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th>
525 <th>Misc</th><th>Total</th></tr>"""
526 node_list = self.master_dom.getElementsByTagName('save')
527 for n in node_list:
528 name = n.getAttribute('name')
529 stat = n.getAttribute('stat')
530 base = n.getAttribute('base')
531 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>"
532 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
533 mag = n.getAttribute('magmod')
534 misc = n.getAttribute('miscmod')
535 mod = str(self.get_mod(name))
536 if mod >= 0:
537 mod1 = "+"
538 else:
539 mod1 = ""
540 html_str = html_str + "<td>"+stat_mod+"</td><td>"+mag+"</td>"
541 html_str = html_str + '<td>'+misc+'</td><td>%s%s</td></tr>' % (mod1, mod)
542 html_str = html_str + "</table>"
543 return html_str
544
545
546 class SWd20general(SWd20_char_child):
547 """ Node Handler for general information. This handler will be
548 created by SWd20char_handler.
549 """
550 def __init__(self, xml_dom, tree_node, parent):
551 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
552
553 def get_design_panel(self,parent):
554 wnd = outline_panel(parent,self,gen_grid,"General Information")
555 wnd.title = "General Info"
556 return wnd
557
558 def tohtml(self):
559 n_list = self.master_dom._get_childNodes()
560 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
561 for n in n_list:
562 t_node = safe_get_text_node(n)
563 html_str += "<B>"+n._get_tagName().capitalize() +":</B> "
564 html_str += t_node._get_nodeValue() + ", "
565 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
566 return html_str
567
568 def on_name_change(self,name):
569 self.char_hander.rename(name)
570
571 def get_char_name( self ):
572 node = self.master_dom.getElementsByTagName( 'name' )[0]
573 t_node = safe_get_text_node( node )
574 return t_node._get_nodeValue()
575
576
577 class SWd20classes(SWd20_char_child):
578 """ Node Handler for classes. This handler will be
579 created by SWd20char_handler.
580 """
581 def __init__(self, xml_dom, tree_node, parent):
582 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
583
584 def get_design_panel(self,parent):
585 wnd = outline_panel(parent,self,class_panel,"Classes")
586 wnd.title = "Classes"
587 return wnd
588
589 def tohtml(self):
590 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>"
591 n_list = self.master_dom._get_childNodes()
592 for n in n_list:
593 html_str += n.getAttribute('name') + " ("+n.getAttribute('level')+"), "
594 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
595 return html_str
596
597 def get_char_lvl( self, attr ):
598 node_list = self.master_dom.getElementsByTagName('class')
599 for n in node_list:
600 lvl = n.getAttribute('level')
601 type = n.getAttribute('name')
602 if attr == "level":
603 return lvl
604 elif attr == "class":
605 return type
606
607
608 class SWd20feats(SWd20_char_child):
609 """ Node Handler for classes. This handler will be
610 created by d20char_handler.
611 """
612 def __init__(self, xml_dom, tree_node, parent):
613 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
614
615 def get_design_panel(self,parent):
616 wnd = outline_panel(parent,self,feat_panel,"Feats")
617 wnd.title = "Feats"
618 return wnd
619
620 def tohtml(self):
621 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>"
622 n_list = self.master_dom._get_childNodes()
623 for n in n_list:
624 html_str += n.getAttribute('name')+ ", "
625 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
626 return html_str
627
628 class SWd20howto(SWd20_char_child):
629 """ Node Handler for hit points. This handler will be
630 created by d20char_handler.
631 """
632 def __init__(self, xml_dom, tree_node, parent):
633 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
634
635 def get_design_panel(self,parent):
636 wnd = outline_panel(parent,self,howto_panel,"How To")
637 wnd.title = "How To"
638 return wnd
639
640 class SWd20inventory(SWd20_char_child):
641 """ Node Handler for general information. This handler will be
642 created by d20char_handler.
643 """
644 def __init__(self, xml_dom, tree_node, parent):
645 SWd20_char_child.__init__(self, xml_dom, tree_node, parent)
646
647 def get_design_panel(self,parent):
648 wnd = outline_panel(parent,self,inventory_grid,"Inventory")
649 wnd.title = "General Info"
650 return wnd
651
652 def tohtml(self):
653 n_list = self.master_dom._get_childNodes()
654 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
655 for n in n_list:
656 t_node = safe_get_text_node(n)
657 html_str += "<B>"+n._get_tagName().capitalize() +":</B> "
658 html_str += t_node._get_nodeValue() + "<br />"
659 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
660 return html_str
661
662 def on_name_change(self,name):
663 self.char_hander.rename(name)
664
665 def get_char_name( self ):
666 node = self.master_dom.getElementsByTagName( 'name' )[0]
667 t_node = safe_get_text_node( node )
668 return t_node._get_nodeValue()
669
670 class SWd20hp(SWd20_char_child):
671 """ Node Handler for hit points. This handler will be
672 created by d20char_handler.
673 """
674 def __init__(self,xml_dom,tree_node,parent):
675 SWd20_char_child.__init__(self,xml_dom,tree_node,parent)
676
677 def get_design_panel(self,parent):
678 wnd = outline_panel(parent,self,hp_panel,"Wound Points")
679 wnd.title = "Wound Points"
680 return wnd
681
682 def tohtml(self):
683 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=4>Wound Points</th></tr>"
684 html_str += "<tr><th>Max:</th><td>"+self.master_dom.getAttribute('max')+"</td>"
685 html_str += "<th>Current:</th><td>"+self.master_dom.getAttribute('current')+"</td>"
686 html_str += "</tr></table>"
687 return html_str
688
689 def get_max_hp( self ):
690 try:
691 return eval( self.master_dom.getAttribute( 'max' ) )
692 except:
693 return 0
694 def get_current_hp( self ):
695 try:
696 return eval( self.master_dom.getAttribute( 'current' ) )
697 except:
698 return 0
699
700 class SWd20vp(SWd20_char_child):
701 """ Node Handler for hit points. This handler will be
702 created by d20char_handler.
703 """
704 def __init__(self,xml_dom,tree_node,parent):
705 SWd20_char_child.__init__(self,xml_dom,tree_node,parent)
706
707 def get_design_panel(self,parent):
708 wnd = outline_panel(parent,self,vp_panel,"Vitality Points")
709 wnd.title = "Vitality Points"
710 return wnd
711
712 def tohtml(self):
713 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=4>Vitality Points</th></tr>"
714 html_str += "<tr><th>Max:</th><td>"+self.master_dom.getAttribute('max')+"</td>"
715 html_str += "<th>Current:</th><td>"+self.master_dom.getAttribute('current')+"</td>"
716 html_str += "</tr></table>"
717 return html_str
718
719 def get_max_vp( self ):
720 try:
721 return eval( self.master_dom.getAttribute( 'max' ) )
722 except:
723 return 0
724 def get_current_vp( self ):
725 try:
726 return eval( self.master_dom.getAttribute( 'current' ) )
727 except:
728 return 0
729
730 class SWd20attacks(SWd20_char_child):
731 """ Node Handler for attacks. This handler will be
732 created by d20char_handler.
733 """
734 def __init__(self,xml_dom,tree_node,parent):
735 SWd20_char_child.__init__(self,xml_dom,tree_node,parent)
736 node_list = self.master_dom.getElementsByTagName('melee')
737 self.melee = node_list[0]
738 node_list = self.master_dom.getElementsByTagName('ranged')
739 self.ranged = node_list[0]
740 self.refresh_weapons()
741
742 def refresh_weapons(self):
743 self.weapons = {}
744 tree = self.tree
745 icons = self.tree.icons
746 tree.CollapseAndReset(self.mytree_node)
747 node_list = self.master_dom.getElementsByTagName('weapon')
748 for n in node_list:
749 name = n.getAttribute('name')
750 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['sword'],icons['sword'])
751 tree.SetPyData(new_tree_node,self)
752 self.weapons[name]=n
753
754 def get_mod(self,type='m'):
755 (base, base2, base3, base4, base5, base6, stat_mod, misc) = self.get_attack_data(type)
756 return base + misc + stat_mod
757
758 def get_attack_data(self,type='m'):
759 if type=='m' or type=='0':
760 stat_mod = self.char_hander.child_handlers['abilities'].get_mod('Str')
761 temp = self.melee
762 else:
763 stat_mod = self.char_hander.child_handlers['abilities'].get_mod('Dex')
764 temp = self.ranged
765 base = int(temp.getAttribute('base'))
766 base2 = int(temp.getAttribute('second'))
767 base3 = int(temp.getAttribute('third'))
768 base4 = int(temp.getAttribute('forth'))
769 base5 = int(temp.getAttribute('fifth'))
770 base6 = int(temp.getAttribute('sixth'))
771 misc = int(temp.getAttribute('misc'))
772 return (base, base2, base3, base4, base5, base6, stat_mod ,misc)
773
774 def on_rclick(self,evt):
775 #removed the DnD specific code
776 item = self.tree.GetSelection()
777 name = self.tree.GetItemText(item)
778 if item == self.mytree_node:
779 SWd20_char_child.on_ldclick(self,evt)
780 #self.frame.add_panel(self.get_design_panel(self.frame.note))
781 else:
782 mod = int(self.weapons[name].getAttribute('mod'))
783 if self.weapons[name].getAttribute('range') == '0':
784 mod = mod + self.get_mod('m')
785 if mod >= 0:
786 mod1 = "+"
787 else:
788 mod1 = ""
789 else:
790 mod = mod + self.get_mod('r')
791 if mod >= 0:
792 mod1 = "+"
793 else:
794 mod1 = ""
795 chat = self.chat
796 dmg = self.weapons[name].getAttribute('damage')
797 lvl = self.get_char_lvl('level')
798 cname = self.char_hander.get_char_name()
799 txt = '%s %s Attack Roll: [1d20%s%s] ===> DMG: [%s%s%s]' % (cname, name, mod1, mod, dmg, mod1, mod)
800 chat.ParsePost( txt, True, False )
801 temp = self.melee
802 stat_mod = self.char_hander.child_handlers['abilities'].get_mod('Str')
803
804 def get_design_panel(self,parent):
805 wnd = outline_panel(parent,self,attack_panel,"Attacks")
806 wnd.title = "Attacks"
807 return wnd
808
809 def get_char_lvl( self, attr ):
810 return self.char_hander.get_char_lvl(attr)
811
812 def tohtml(self):
813 melee = self.get_attack_data('m')
814 ranged = self.get_attack_data('r')
815 html_str = """<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Attack</th>
816 <th>Total</th><th >Base</th><th>Abil</th><th>Misc</th></tr>"""
817 html_str += "<tr ALIGN='center' ><th >Melee:</th>"
818 html_str += "<td>"+str(melee[0]+melee[1]+melee[2])+"</td>"
819 html_str += "<td>"+str(melee[0])+"</td>"
820 html_str += "<td>"+str(melee[1])+"</td>"
821 html_str += "<td>"+str(melee[2])+"</td></tr>"
822
823 html_str += "<tr ALIGN='center' ><th >Ranged:</th>"
824 html_str += "<td>"+str(ranged[0]+ranged[1]+ranged[2])+"</td>"
825 html_str += "<td>"+str(ranged[0])+"</td>"
826 html_str += "<td>"+str(ranged[1])+"</td>"
827 html_str += "<td>"+str(ranged[2])+"</td></tr></table>"
828
829 n_list = self.master_dom.getElementsByTagName('weapon')
830 for n in n_list:
831 mod = n.getAttribute('mod')
832 if mod >= 0:
833 mod1 = "+"
834 else:
835 mod1 = ""
836 ran = n.getAttribute('range')
837 total = str(int(mod) + self.get_mod(ran))
838 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=2>Weapon</th>
839 <th>Attack</th><th >Damage</th><th>Critical</th></tr>"""
840 html_str += "<tr ALIGN='center' ><td colspan=2>"+n.getAttribute('name')+"</td><td>"+total+"</td>"
841 html_str += "<td>"+n.getAttribute('damage')+"</td><td>"+n.getAttribute('critical')+"</td></tr>"
842 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Range</th><th>Weight</th>
843 <th>Type</th><th>Size</th><th>Misc Mod</th></tr>"""
844 html_str += "<tr ALIGN='center'><td>"+ran+"</td><td>"+n.getAttribute('weight')+"</td>"
845 html_str += "<td>"+n.getAttribute('type')+"</td><td>"+n.getAttribute('size')+"</td>"
846 html_str += '<td>%s%s</td></tr></table>' % (mod1, mod)
847 return html_str
848
849 class SWd20armor(SWd20_char_child):
850 """ Node Handler for ac. This handler will be
851 created by d20char_handler.
852 """
853 def __init__(self,xml_dom,tree_node,parent):
854 SWd20_char_child.__init__(self,xml_dom,tree_node,parent)
855
856 def get_total_weight(self):
857 return self.get_total('weight')
858
859 def get_check_pen(self):
860 return self.get_total('checkpenalty')
861
862 def get_armor_class(self):
863 ac_total = 10
864 ac_total += self.get_total('bonus')
865 dex_mod = self.char_hander.child_handlers['abilities'].get_mod('Dex')
866 max_dex = self.get_max_dex()
867 if dex_mod < max_dex:
868 ac_total += dex_mod
869 else:
870 ac_total += max_dex
871 return ac_total
872
873 def get_max_dex(self):
874 armor_list = self.master_dom.getElementsByTagName('armor')
875 dex = 10
876 for a in armor_list:
877 temp = int(a.getAttribute("maxdex"))
878 if temp < dex:
879 dex = temp
880 return dex
881
882 def get_total(self,attr):
883 armor_list = self.master_dom.getElementsByTagName('armor')
884 total = 0
885 for a in armor_list:
886 total += int(a.getAttribute(attr))
887 return total
888
889 def get_design_panel(self,parent):
890 wnd = outline_panel(parent,self,ac_panel,"Armor")
891 wnd.title = "Armor"
892 return wnd
893
894 def tohtml(self):
895 html_str = """<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>AC</th>
896 <th>Check Penalty</th><th >Spell Failure</th><th>Max Dex</th><th>Total Weight</th></tr>"""
897 html_str += "<tr ALIGN='center' ><td>"+str(self.get_armor_class())+"</td>"
898 html_str += "<td>"+str(self.get_check_pen())+"</td>"
899 html_str += "<td>"+str(self.get_spell_failure())+"</td>"
900 html_str += "<td>"+str(self.get_max_dex())+"</td>"
901 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>"
902 n_list = self.master_dom._get_childNodes()
903 for n in n_list:
904 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=3>Armor</th>
905 <th>Type</th><th >Bonus</th></tr>"""
906 html_str += "<tr ALIGN='center' ><td colspan=3>"+n.getAttribute('name')+"</td>"
907 html_str += "<td>"+n.getAttribute('type')+"</td>"
908 html_str += "<td>"+n.getAttribute('bonus')+"</td></tr>"
909 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Check Penalty</th><th>Spell Failure</th>
910 <th>Max Dex</th><th>Speed</th><th>Weight</th></tr>"""
911 html_str += "<tr ALIGN='center'><td>"+n.getAttribute('checkpenalty')+"</td>"
912 html_str += "<td>"+n.getAttribute('maxdex')+"</td>"
913 html_str += "<td>"+n.getAttribute('speed')+"</td>"
914 html_str += "<td>"+n.getAttribute('weight')+"</td></tr></table>"
915 return html_str
916
917
918 ########################
919 ## d20 char windows
920 ########################
921
922 class base_panel(wx.Panel):
923 def __init__(self, parent):
924 wx.Panel.__init__(self, parent, -1)
925
926 #self.build_ctrls()
927 self.Bind(wx.EVT_SIZE, self.on_size)
928
929 def on_size(self,event):
930 s = self.GetClientSizeTuple()
931 #self.splitter.SetDimensions(0,0,s[0],s[1])
932
933 class outline_panel(wx.Panel):
934 def __init__(self, parent, handler, wnd, txt,):
935 wx.Panel.__init__(self, parent, -1)
936 self.panel = wnd(self,handler)
937 self.outline = wx.StaticBox(self,-1,txt)
938 self.Bind(wx.EVT_SIZE, self.on_size)
939
940 def on_size(self,event):
941 s = self.GetClientSizeTuple()
942 self.panel.SetDimensions(20,20,s[0]-40,s[1]-40)
943 self.outline.SetDimensions(5,5,s[0]-10,s[1]-10)
944
945 class char_panel(wx.ScrolledWindow):
946 def __init__(self, parent, handler):
947 pname = handler.master_dom.setAttribute("name", 'TWO')
948 wx.ScrolledWindow.__init__(self, parent, -1,style=wx.VSCROLL | wx.SUNKEN_BORDER )
949 self.height = 1200
950 self.SetScrollbars(10, 10,80, self.height/10)
951 self.main_sizer = wx.BoxSizer(wx.HORIZONTAL)
952 self.panels = {}
953 keys = handler.child_handlers.keys()
954 for k in keys:
955 self.panels[k] = handler.child_handlers[k].get_design_panel(self, [k])
956 self.sub_sizer = wx.BoxSizer(wx.VERTICAL)
957 self.sub_sizer2 = wx.BoxSizer(wx.VERTICAL)
958 self.sub_sizer.Add(self.panels['general'], 1, wx.EXPAND)
959 self.sub_sizer.Add(self.panels['abilities'], 1, wx.EXPAND)
960
961 self.sub_sizer.Add(self.panels['attacks'], 2, wx.EXPAND)
962 self.sub_sizer.Add(self.panels['ac'], 1, wx.EXPAND)
963 #self.sub_sizer.Add(self.panels['spells'], 1, wx.EXPAND)
964
965 self.sub_sizer2.Add(self.panels['classes'], 2, wx.EXPAND)
966 self.sub_sizer2.Add(self.panels['wp'], 1, wx.EXPAND)
967 self.sub_sizer2.Add(self.panels['vp'], 1, wx.EXPAND)
968 #self.sub_sizer2.Add(self.panels['pp'], 1, wx.EXPAND)
969 self.sub_sizer2.Add(self.panels['saves'], 2, wx.EXPAND)
970
971 self.sub_sizer2.Add(self.panels['feats'], 2, wx.EXPAND)
972 #self.sub_sizer2.Add(self.panels['powers'], 2, wx.EXPAND)
973 self.sub_sizer2.Add(self.panels['skills'], 3, wx.EXPAND)
974
975 self.main_sizer.Add(self.sub_sizer, 1, wx.EXPAND)
976 self.main_sizer.Add(self.sub_sizer2, 1, wx.EXPAND)
977 self.panels['abilities'].panel.char_wnd = self
978 self.SetSizer(self.main_sizer)
979 self.Bind(wx.EVT_SIZE, self.on_size)
980
981
982 def on_size(self,evt):
983 s = self.GetClientSizeTuple()
984 self.SetScrollbars(10, 10,s[0]/10, self.height/10)
985 dc = wx.ClientDC(self)
986 x = dc.DeviceToLogicalX(0)
987 y = dc.DeviceToLogicalY(0)
988 self.main_sizer.SetDimension(x,y,s[0],self.height)
989 evt.Skip()
990
991 def refresh_data(self):
992 self.panels['saves'].panel.refresh_data()
993 self.panels['skills'].panel.refresh_data()
994 self.panels['attacks'].panel.refresh_data()
995 # self.panels['powers'].panel.refresh_data()
996 # self.panels['spells'].panel.refresh_data()
997
998 HOWTO_MAX = wx.NewId()
999
1000 class howto_panel(wx.Panel):
1001 def __init__(self, parent, handler):
1002 wx.Panel.__init__(self, parent, -1)
1003 pname = handler.master_dom.setAttribute("name", 'How To')
1004 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1005 self.master_dom = handler.master_dom
1006 n_list = self.master_dom._get_childNodes()
1007 for n in n_list:
1008 t_node = safe_get_text_node(n)
1009 self.sizer.AddMany([ (wx.StaticText(self, -1, t_node._get_nodeValue()), 0, wx.ALIGN_CENTER_VERTICAL),
1010 ])
1011 self.sizer.AddGrowableCol(1)
1012 self.SetSizer(self.sizer)
1013
1014
1015 WP_CUR = wx.NewId()
1016 WP_MAX = wx.NewId()
1017
1018 class hp_panel(wx.Panel):
1019 def __init__(self, parent, handler):
1020 wx.Panel.__init__(self, parent, -1)
1021 pname = handler.master_dom.setAttribute("name", 'WoundPoints')
1022 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1023 self.master_dom = handler.master_dom
1024 self.sizer.AddMany([ (wx.StaticText(self, -1, "WP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
1025 (wx.TextCtrl(self, WP_CUR, self.master_dom.getAttribute('current')), 0, wx.EXPAND),
1026 (wx.StaticText(self, -1, "WP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1027 (wx.TextCtrl(self, WP_MAX, self.master_dom.getAttribute('max')), 0, wx.EXPAND),
1028 ])
1029 self.sizer.AddGrowableCol(1)
1030 self.Bind(wx.EVT_SIZE, self.on_size)
1031 self.Bind(wx.EVT_TEXT, self.on_text, id=WP_MAX)
1032 self.Bind(wx.EVT_TEXT, self.on_text, id=WP_CUR)
1033 self.SetSizer(self.sizer)
1034
1035 def on_text(self,evt):
1036 id = evt.GetId()
1037 if id == WP_CUR:
1038 self.master_dom.setAttribute('current',evt.GetString())
1039 elif id == WP_MAX:
1040 self.master_dom.setAttribute('max',evt.GetString())
1041
1042 def on_size(self,evt):
1043 s = self.GetClientSizeTuple()
1044 self.sizer.SetDimension(0,0,s[0],s[1])
1045
1046 VP_CUR = wx.NewId()
1047 VP_MAX = wx.NewId()
1048
1049 class vp_panel(wx.Panel):
1050 def __init__(self, parent, handler):
1051 wx.Panel.__init__(self, parent, -1)
1052 pname = handler.master_dom.setAttribute("name", 'VitalityPoints')
1053 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1054 self.master_dom = handler.master_dom
1055 self.sizer.AddMany([ (wx.StaticText(self, -1, "VP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
1056 (wx.TextCtrl(self, VP_CUR, self.master_dom.getAttribute('current')), 0, wx.EXPAND),
1057 (wx.StaticText(self, -1, "VP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1058 (wx.TextCtrl(self, VP_MAX, self.master_dom.getAttribute('max')), 0, wx.EXPAND),
1059 ])
1060 self.sizer.AddGrowableCol(1)
1061 self.Bind(wx.EVT_SIZE, self.on_size)
1062 self.Bind(wx.EVT_TEXT, self.on_text, id=VP_MAX)
1063 self.Bind(wx.EVT_TEXT, self.on_text, id=VP_CUR)
1064 self.SetSizer(self.sizer)
1065
1066 def on_text(self,evt):
1067 id = evt.GetId()
1068 if id == VP_CUR:
1069 self.master_dom.setAttribute('current',evt.GetString())
1070 elif id == VP_MAX:
1071 self.master_dom.setAttribute('max',evt.GetString())
1072
1073 def on_size(self,evt):
1074 s = self.GetClientSizeTuple()
1075 self.sizer.SetDimension(0,0,s[0],s[1])
1076
1077 #PP_CUR = wx.NewId()
1078 #PP_MAX = wx.NewId()
1079 #PP_FRE = wx.NewId()
1080 #PP_MFRE = wx.NewId()
1081
1082 #class pp_panel(wx.Panel):
1083 # def __init__(self, parent, handler):
1084 # wx.Panel.__init__(self, parent, -1)
1085 # pname = handler.master_dom.setAttribute("name", 'PowerPoints')
1086 # self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
1087 # self.master_dom = handler.master_dom
1088 #
1089 # self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
1090 # (wx.TextCtrl(self, PP_CUR, self.master_dom.getAttribute('current1')), 0, wx.EXPAND),
1091 # (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
1092 # (wx.TextCtrl(self, PP_MAX, self.master_dom.getAttribute('max1')), 0, wx.EXPAND),
1093 # (wx.StaticText(self, -1, "Current Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
1094 # (wx.TextCtrl(self, PP_FRE, self.master_dom.getAttribute('free')), 0, wx.EXPAND),
1095 # (wx.StaticText(self, -1, "Max Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
1096 # (wx.TextCtrl(self, PP_MFRE, self.master_dom.getAttribute('maxfree')), 0, wx.EXPAND),
1097 # ])
1098 # self.sizer.AddGrowableCol(1)
1099 # self.Bind(wx.EVT_SIZE, self.on_size)
1100 # self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MAX)
1101 # self.Bind(wx.EVT_TEXT, self.on_text, id=PP_CUR)
1102 # self.Bind(wx.EVT_TEXT, self.on_text, id=PP_FRE)
1103 # self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MFRE)
1104 #
1105 # def on_text(self,evt):
1106 # id = evt.GetId()
1107 # if id == PP_CUR:
1108 # self.master_dom.setAttribute('current1',evt.GetString())
1109 # elif id == PP_MAX:
1110 # self.master_dom.setAttribute('max1',evt.GetString())
1111 # elif id == PP_FRE:
1112 # self.master_dom.setAttribute('free',evt.GetString())
1113 # elif id == PP_MFRE:
1114 # self.master_dom.setAttribute('maxfree',evt.GetString())
1115 #
1116 # def on_size(self,evt):
1117 # s = self.GetClientSizeTuple()
1118 # self.sizer.SetDimension(0,0,s[0],s[1])
1119
1120
1121 class gen_grid(wx.grid.Grid):
1122 """grid for gen info"""
1123 def __init__(self, parent, handler):
1124 pname = handler.master_dom.setAttribute("name", 'General')
1125 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1126 self.Bind(wx.EVT_SIZE, self.on_size)
1127 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1128 self.handler = handler
1129 n_list = handler.master_dom._get_childNodes()
1130 self.CreateGrid(len(n_list),2)
1131 self.SetRowLabelSize(0)
1132 self.SetColLabelSize(0)
1133 self.n_list = n_list
1134 i = 0
1135 for i in range(len(n_list)):
1136 self.refresh_row(i)
1137
1138 def on_cell_change(self,evt):
1139 row = evt.GetRow()
1140 col = evt.GetCol()
1141 value = self.GetCellValue(row,col)
1142 t_node = self.n_list[row]._get_firstChild()
1143 t_node._set_nodeValue(value)
1144 if row==0: self.handler.on_name_change(value)
1145
1146 def refresh_row(self,rowi):
1147 t_node = safe_get_text_node(self.n_list[rowi])
1148 self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
1149 self.SetReadOnly(rowi,0)
1150 self.SetCellValue(rowi,1,t_node._get_nodeValue())
1151
1152 def on_size(self,evt):
1153 (w,h) = self.GetClientSizeTuple()
1154 cols = self.GetNumberCols()
1155 col_w = w/(cols)
1156 for i in range(0,cols):
1157 self.SetColSize(i,col_w)
1158 evt.Skip()
1159 self.Refresh()
1160
1161 class inventory_grid(wx.grid.Grid):
1162 """grid for gen info"""
1163 def __init__(self, parent, handler):
1164 pname = handler.master_dom.setAttribute("name", 'Money and Inventory')
1165 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1166 self.Bind(wx.EVT_SIZE, self.on_size)
1167 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1168 self.handler = handler
1169 n_list = handler.master_dom._get_childNodes()
1170 self.CreateGrid(len(n_list),2)
1171 self.SetRowLabelSize(0)
1172 self.SetColLabelSize(0)
1173 self.n_list = n_list
1174 i = 0
1175 for i in range(len(n_list)):
1176 self.refresh_row(i)
1177
1178 def on_cell_change(self,evt):
1179 row = evt.GetRow()
1180 col = evt.GetCol()
1181 value = self.GetCellValue(row,col)
1182 t_node = self.n_list[row]._get_firstChild()
1183 t_node._set_nodeValue(value)
1184 if row==0: self.handler.on_name_change(value)
1185
1186 def refresh_row(self,rowi):
1187 t_node = safe_get_text_node(self.n_list[rowi])
1188 self.SetCellValue(rowi,0,self.n_list[rowi]._get_tagName())
1189 self.SetReadOnly(rowi,0)
1190 self.SetCellValue(rowi,1,t_node._get_nodeValue())
1191
1192 def on_size(self,evt):
1193 (w,h) = self.GetClientSizeTuple()
1194 cols = self.GetNumberCols()
1195 col_w = w/(cols)
1196 for i in range(0,cols):
1197 self.SetColSize(i,col_w)
1198 evt.Skip()
1199 self.Refresh()
1200
1201 class abil_grid(wx.grid.Grid):
1202 """grid for abilities"""
1203 def __init__(self, parent, handler):
1204 pname = handler.master_dom.setAttribute("name", 'Stats')
1205 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1206 self.Bind(wx.EVT_SIZE, self.on_size)
1207 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1208 self.handler = handler
1209 stats = handler.master_dom.getElementsByTagName('stat')
1210 self.CreateGrid(len(stats),3)
1211 self.SetRowLabelSize(0)
1212 col_names = ['Ability','Score','Modifier']
1213 for i in range(len(col_names)):
1214 self.SetColLabelValue(i,col_names[i])
1215 self.stats = stats
1216 i = 0
1217 for i in range(len(stats)):
1218 self.refresh_row(i)
1219 self.char_wnd = None
1220
1221 def on_cell_change(self,evt):
1222 row = evt.GetRow()
1223 col = evt.GetCol()
1224 value = self.GetCellValue(row,col)
1225 try:
1226 int(value)
1227 self.stats[row].setAttribute('base',value)
1228 self.refresh_row(row)
1229 except:
1230 self.SetCellValue(row,col,"0")
1231 if self.char_wnd:
1232 self.char_wnd.refresh_data()
1233
1234 def refresh_row(self,rowi):
1235 s = self.stats[rowi]
1236 name = s.getAttribute('name')
1237 abbr = s.getAttribute('abbr')
1238 self.SetCellValue(rowi,0,name)
1239 self.SetReadOnly(rowi,0)
1240 self.SetCellValue(rowi,1,s.getAttribute('base'))
1241 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
1242 self.SetReadOnly(rowi,2)
1243
1244 def on_size(self,evt):
1245 (w,h) = self.GetClientSizeTuple()
1246 cols = self.GetNumberCols()
1247 col_w = w/(cols+2)
1248 self.SetColSize(0,col_w*3)
1249 for i in range(1,cols):
1250 self.SetColSize(i,col_w)
1251 evt.Skip()
1252 self.Refresh()
1253
1254 def refresh_data(self):
1255 for r in range(self.GetNumberRows()-1):
1256 self.refresh_row(r)
1257
1258
1259 class save_grid(wx.grid.Grid):
1260 """grid for saves"""
1261 def __init__(self, parent, handler):
1262 pname = handler.master_dom.setAttribute("name", 'Saves')
1263 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1264 self.Bind(wx.EVT_SIZE, self.on_size)
1265 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1266 self.handler = handler
1267 saves = handler.master_dom.getElementsByTagName('save')
1268 self.stats = handler.char_hander.child_handlers['abilities']
1269 self.CreateGrid(len(saves),7)
1270 self.SetRowLabelSize(0)
1271 col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
1272 for i in range(len(col_names)):
1273 self.SetColLabelValue(i,col_names[i])
1274 self.saves = saves
1275 i = 0
1276 for i in range(len(saves)):
1277 self.refresh_row(i)
1278
1279 def on_cell_change(self,evt):
1280 row = evt.GetRow()
1281 col = evt.GetCol()
1282 value = self.GetCellValue(row,col)
1283 try:
1284 int(value)
1285 if col == 2:
1286 self.saves[row].setAttribute('base',value)
1287 elif col ==4:
1288 self.saves[row].setAttribute('magmod',value)
1289 elif col ==4:
1290 self.saves[row].setAttribute('miscmod',value)
1291 self.refresh_row(row)
1292 except:
1293 self.SetCellValue(row,col,"0")
1294
1295 def refresh_row(self,rowi):
1296 s = self.saves[rowi]
1297 name = s.getAttribute('name')
1298 self.SetCellValue(rowi,0,name)
1299 self.SetReadOnly(rowi,0)
1300 stat = s.getAttribute('stat')
1301 self.SetCellValue(rowi,1,stat)
1302 self.SetReadOnly(rowi,1)
1303 self.SetCellValue(rowi,2,s.getAttribute('base'))
1304 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat)))
1305 self.SetReadOnly(rowi,3)
1306 self.SetCellValue(rowi,4,s.getAttribute('magmod'))
1307 self.SetCellValue(rowi,5,s.getAttribute('miscmod'))
1308 mod = str(self.handler.get_mod(name))
1309 self.SetCellValue(rowi,6,mod)
1310 self.SetReadOnly(rowi,6)
1311
1312 def on_size(self,evt):
1313 (w,h) = self.GetClientSizeTuple()
1314 cols = self.GetNumberCols()
1315 col_w = w/(cols+2)
1316 self.SetColSize(0,col_w*3)
1317 for i in range(1,cols):
1318 self.SetColSize(i,col_w)
1319 evt.Skip()
1320 self.Refresh()
1321
1322 def refresh_data(self):
1323 for r in range(self.GetNumberRows()):
1324 self.refresh_row(r)
1325
1326
1327 class skill_grid(wx.grid.Grid):
1328 """ panel for skills """
1329 def __init__(self, parent, handler):
1330 pname = handler.master_dom.setAttribute("name", 'Skills')
1331 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1332 self.Bind(wx.EVT_SIZE, self.on_size)
1333 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1334 self.handler = handler
1335 skills = handler.master_dom.getElementsByTagName('skill')
1336 self.stats = handler.char_hander.child_handlers['abilities']
1337 self.CreateGrid(len(skills),7)
1338 self.SetRowLabelSize(0)
1339 col_names = ['Skill','Key','Rank','Abil','Misc','Total']
1340 for i in range(len(col_names)):
1341 self.SetColLabelValue(i,col_names[i])
1342 rowi = 0
1343 self.skills = skills
1344 for i in range(len(skills)):
1345 self.refresh_row(i)
1346
1347 def on_cell_change(self,evt):
1348 row = evt.GetRow()
1349 col = evt.GetCol()
1350 value = self.GetCellValue(row,col)
1351 #print value
1352 try:
1353 int(value)
1354 if col == 3:
1355 self.skills[row].setAttribute('rank',value)
1356 elif col ==5:
1357 self.skills[row].setAttribute('misc',value)
1358 elif col == 1:
1359 self.skills[row].setAttribute('untrained',value)
1360 self.refresh_row(row)
1361 except:
1362 self.SetCellValue(row,col,"0")
1363
1364 def refresh_row(self,rowi):
1365 s = self.skills[rowi]
1366 name = s.getAttribute('name')
1367 self.SetCellValue(rowi,0,name)
1368 self.SetReadOnly(rowi,0)
1369 self.SetCellValue(rowi,1,s.getAttribute('untrained'))
1370 stat = s.getAttribute('stat')
1371 self.SetCellValue(rowi,2,stat)
1372 self.SetReadOnly(rowi,2)
1373 self.SetCellValue(rowi,3,s.getAttribute('rank'))
1374 self.SetCellValue(rowi,4,str(self.stats.get_mod(stat)))
1375 self.SetReadOnly(rowi,4)
1376 self.SetCellValue(rowi,5,s.getAttribute('misc'))
1377 mod = str(self.handler.get_mod(name))
1378 self.SetCellValue(rowi,6,mod)
1379 self.SetReadOnly(rowi,6)
1380
1381 def on_size(self,evt):
1382 (w,h) = self.GetClientSizeTuple()
1383 cols = self.GetNumberCols()
1384 col_w = w/(cols+2)
1385 self.SetColSize(0,col_w*3)
1386 for i in range(1,cols):
1387 self.SetColSize(i,col_w)
1388 evt.Skip()
1389 self.Refresh()
1390
1391 def refresh_data(self):
1392 for r in range(self.GetNumberRows()):
1393 self.refresh_row(r)
1394
1395
1396
1397 class feat_panel(wx.Panel):
1398 def __init__(self, parent, handler):
1399 pname = handler.master_dom.setAttribute("name", 'Feats')
1400 wx.Panel.__init__(self, parent, -1)
1401 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1402 sizer = wx.BoxSizer(wx.HORIZONTAL)
1403 sizer.Add(wx.Button(self, 10, "Remove Feat"), 1, wx.EXPAND)
1404 sizer.Add(wx.Size(10,10))
1405 sizer.Add(wx.Button(self, 20, "Add Feat"), 1, wx.EXPAND)
1406 self.sizer = sizer
1407 self.SetSizer(self.sizer)
1408 self.Bind(wx.EVT_SIZE, self.on_size)
1409 EVT_BUTTON(self, 10, self.on_remove)
1410 EVT_BUTTON(self, 20, self.on_add)
1411
1412 n_list = handler.master_dom._get_childNodes()
1413 self.n_list = n_list
1414 self.master_dom = handler.master_dom
1415 self.grid.CreateGrid(len(n_list),2,1)
1416 self.grid.SetRowLabelSize(0)
1417 self.grid.SetColLabelValue(0,"Feat")
1418 self.grid.SetColLabelValue(1,"Type")
1419 for i in range(len(n_list)):
1420 self.refresh_row(i)
1421 self.temp_dom = None
1422
1423 def refresh_row(self,i):
1424 feat = self.n_list[i]
1425 name = feat.getAttribute('name')
1426 type = feat.getAttribute('type')
1427 self.grid.SetCellValue(i,0,name)
1428 self.grid.SetReadOnly(i,0)
1429 self.grid.SetCellValue(i,1,type)
1430 self.grid.SetReadOnly(i,1)
1431
1432 def on_remove(self,evt):
1433 rows = self.grid.GetNumberRows()
1434 for i in range(rows):
1435 if self.grid.IsInSelection(i,0):
1436 self.grid.DeleteRows(i)
1437 self.master_dom.removeChild(self.n_list[i])
1438
1439 def on_add(self,evt):
1440 if not self.temp_dom:
1441 tmp = open(orpg.dirpath.dir_struct["SWd20"]+"d20feats.xml","r")
1442 xml_dom = parseXml_with_dlg(self,tmp.read())
1443 xml_dom = xml_dom._get_firstChild()
1444 tmp.close()
1445 self.temp_dom = xml_dom
1446 f_list = self.temp_dom.getElementsByTagName('feat')
1447 opts = []
1448 for f in f_list:
1449 opts.append(f.getAttribute('name'))
1450 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
1451 if dlg.ShowModal() == wx.ID_OK:
1452 i = dlg.GetSelection()
1453 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
1454 self.grid.AppendRows(1)
1455 self.refresh_row(self.grid.GetNumberRows()-1)
1456 dlg.Destroy()
1457
1458
1459 def on_size(self,event):
1460 s = self.GetClientSizeTuple()
1461 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1462 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1463 (w,h) = self.grid.GetClientSizeTuple()
1464 cols = self.grid.GetNumberCols()
1465 col_w = w/(cols)
1466 for i in range(0,cols):
1467 self.grid.SetColSize(i,col_w)
1468
1469 class attack_grid(wx.grid.Grid):
1470 """grid for attacks"""
1471 def __init__(self, parent, handler):
1472 pname = handler.master_dom.setAttribute("name", 'Melee')
1473 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1474 self.parent = parent
1475 self.handler = handler
1476 self.rows = (self.handler.melee,self.handler.ranged)
1477 self.CreateGrid(2,10)
1478 self.SetRowLabelSize(0)
1479 col_names = ['Type','base','base 2','base 3','base 4','base 5','base 6','abil','misc','Total']
1480 for i in range(len(col_names)):
1481 self.SetColLabelValue(i,col_names[i])
1482 self.SetCellValue(0,0,"Melee")
1483 self.SetCellValue(1,0,"Ranged")
1484 self.refresh_data()
1485 self.Bind(wx.EVT_SIZE, self.on_size)
1486 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1487
1488 def on_cell_change(self,evt):
1489 row = evt.GetRow()
1490 col = evt.GetCol()
1491 value = self.GetCellValue(row,col)
1492 try:
1493 int(value)
1494 if col==1:
1495 self.rows[row].setAttribute('base',value)
1496 elif col==2:
1497 self.rows[row].setAttribute('second',value)
1498 elif col==3:
1499 self.rows[row].setAttribute('third',value)
1500 elif col==4:
1501 self.rows[row].setAttribute('forth',value)
1502 elif col==5:
1503 self.rows[row].setAttribute('fifth',value)
1504 elif col==6:
1505 self.rows[row].setAttribute('sixth',value)
1506 elif col==8:
1507 self.rows[row].setAttribute('misc',value)
1508 self.parent.refresh_data()
1509 except:
1510 self.SetCellValue(row,col,"0")
1511
1512 def refresh_data(self):
1513 melee = self.handler.get_attack_data('m')
1514 ranged = self.handler.get_attack_data('r')
1515 for i in range(0,7):
1516 self.SetCellValue(0,i+1,str(melee[i]))
1517 self.SetCellValue(1,i+1,str(ranged[i]))
1518 self.SetCellValue(0,9,str(melee[0]+melee[6]+melee[7]))
1519 self.SetCellValue(1,9,str(ranged[0]+ranged[6]+ranged[7]))
1520 self.SetReadOnly(0,0)
1521 self.SetReadOnly(1,0)
1522 self.SetReadOnly(0,7)
1523 self.SetReadOnly(1,7)
1524 self.SetReadOnly(0,9)
1525 self.SetReadOnly(1,9)
1526
1527
1528 def on_size(self,evt):
1529 (w,h) = self.GetClientSizeTuple()
1530 cols = self.GetNumberCols()
1531 col_w = w/(cols+1)
1532 self.SetColSize(0,col_w*2)
1533 for i in range(1,cols):
1534 self.SetColSize(i,col_w)
1535 evt.Skip()
1536 self.Refresh()
1537
1538 class weapon_panel(wx.Panel):
1539 def __init__(self, parent, handler):
1540 pname = handler.master_dom.setAttribute("name", 'Weapons')
1541 wx.Panel.__init__(self, parent, -1)
1542 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1543 sizer = wx.BoxSizer(wx.HORIZONTAL)
1544 sizer.Add(wx.Button(self, 10, "Remove Weapon"), 1, wx.EXPAND)
1545 sizer.Add(wx.Size(10,10))
1546 sizer.Add(wx.Button(self, 20, "Add Weapon"), 1, wx.EXPAND)
1547 self.sizer = sizer
1548 self.SetSizer(self.sizer)
1549 self.Bind(wx.EVT_SIZE, self.on_size)
1550 EVT_BUTTON(self, 10, self.on_remove)
1551 EVT_BUTTON(self, 20, self.on_add)
1552 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1553 n_list = handler.master_dom.getElementsByTagName('weapon')
1554 self.n_list = n_list
1555 self.master_dom = handler.master_dom
1556 self.handler = handler
1557 self.grid.CreateGrid(len(n_list),9,1)
1558 self.grid.SetRowLabelSize(0)
1559 col_names = ['Name','damage','mod','critical','type','weight','range','size','Total']
1560 for i in range(len(col_names)):
1561 self.grid.SetColLabelValue(i,col_names[i])
1562 self.refresh_data()
1563 self.temp_dom = None
1564
1565 def on_cell_change(self,evt):
1566 row = evt.GetRow()
1567 col = evt.GetCol()
1568 value = self.grid.GetCellValue(row,col)
1569 if col == 0:
1570 self.n_list[row].setAttribute('name',value)
1571 elif col == 2:
1572 try:
1573 int(value)
1574 self.n_list[row].setAttribute('mod',value)
1575 self.refresh_row(row)
1576 except:
1577 self.grid.SetCellValue(row,col,"1")
1578 else:
1579 self.n_list[row].setAttribute(self.grid.GetColLabelValue(col),value)
1580
1581 def refresh_row(self,i):
1582 n = self.n_list[i]
1583 name = n.getAttribute('name')
1584 mod = n.getAttribute('mod')
1585 ran = n.getAttribute('range')
1586 total = str(int(mod) + self.handler.get_mod(ran))
1587 self.grid.SetCellValue(i,0,name)
1588 self.grid.SetCellValue(i,1,n.getAttribute('damage'))
1589 self.grid.SetCellValue(i,2,mod)
1590 self.grid.SetCellValue(i,3,n.getAttribute('critical'))
1591 self.grid.SetCellValue(i,4,n.getAttribute('type'))
1592 self.grid.SetCellValue(i,5,n.getAttribute('weight'))
1593 self.grid.SetCellValue(i,6,ran)
1594 self.grid.SetCellValue(i,7,n.getAttribute('size') )
1595 self.grid.SetCellValue(i,8,total)
1596 self.grid.SetReadOnly(i,8)
1597
1598 def on_remove(self,evt):
1599 rows = self.grid.GetNumberRows()
1600 for i in range(rows):
1601 if self.grid.IsInSelection(i,0):
1602 self.grid.DeleteRows(i)
1603 self.master_dom.removeChild(self.n_list[i])
1604 self.n_list = self.master_dom.getElementsByTagName('weapon')
1605 self.handler.refresh_weapons()
1606
1607 def on_add(self,evt):
1608 if not self.temp_dom:
1609 tmp = open(orpg.dirpath.dir_struct["SWd20"]+"d20weapons.xml","r")
1610 xml_dom = parseXml_with_dlg(self,tmp.read())
1611 xml_dom = xml_dom._get_firstChild()
1612 tmp.close()
1613 self.temp_dom = xml_dom
1614 f_list = self.temp_dom.getElementsByTagName('weapon')
1615 opts = []
1616 for f in f_list:
1617 opts.append(f.getAttribute('name'))
1618 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
1619 if dlg.ShowModal() == wx.ID_OK:
1620 i = dlg.GetSelection()
1621 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
1622 self.grid.AppendRows(1)
1623 self.n_list = self.master_dom.getElementsByTagName('weapon')
1624 self.refresh_row(self.grid.GetNumberRows()-1)
1625 self.handler.refresh_weapons()
1626 dlg.Destroy()
1627
1628 def on_size(self,event):
1629 s = self.GetClientSizeTuple()
1630 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1631 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1632 (w,h) = self.grid.GetClientSizeTuple()
1633 cols = self.grid.GetNumberCols()
1634 col_w = w/(cols+1)
1635 self.grid.SetColSize(0,col_w*2)
1636 for i in range(1,cols):
1637 self.grid.SetColSize(i,col_w)
1638
1639 def refresh_data(self):
1640 for i in range(len(self.n_list)):
1641 self.refresh_row(i)
1642
1643
1644 class attack_panel(wx.Panel):
1645 def __init__(self, parent, handler):
1646 pname = handler.master_dom.setAttribute("name", 'Melee')
1647 wx.Panel.__init__(self, parent, -1)
1648
1649 self.a_grid = attack_grid(self, handler)
1650 self.w_panel = weapon_panel(self, handler)
1651 self.sizer = wx.BoxSizer(wx.VERTICAL)
1652 self.sizer.Add(self.a_grid, 1, wx.EXPAND)
1653 self.sizer.Add(self.w_panel, 2, wx.EXPAND)
1654 self.SetSizer(self.sizer)
1655 self.Bind(wx.EVT_SIZE, self.on_size)
1656
1657 def on_size(self,event):
1658 s = self.GetClientSizeTuple()
1659 self.sizer.SetDimension(0,0,s[0],s[1])
1660
1661 def refresh_data(self):
1662 self.w_panel.refresh_data()
1663 self.a_grid.refresh_data()
1664
1665
1666 class ac_panel(wx.Panel):
1667 def __init__(self, parent, handler):
1668 pname = handler.master_dom.setAttribute("name", 'Armor')
1669 wx.Panel.__init__(self, parent, -1)
1670 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1671 sizer = wx.BoxSizer(wx.HORIZONTAL)
1672 sizer.Add(wx.Button(self, 10, "Remove Armor"), 1, wx.EXPAND)
1673 sizer.Add(wx.Size(10,10))
1674 sizer.Add(wx.Button(self, 20, "Add Armor"), 1, wx.EXPAND)
1675 self.sizer = sizer
1676 self.SetSizer(self.sizer)
1677 self.Bind(wx.EVT_SIZE, self.on_size)
1678 EVT_BUTTON(self, 10, self.on_remove)
1679 EVT_BUTTON(self, 20, self.on_add)
1680 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1681 self.master_dom = handler.master_dom
1682 n_list = handler.master_dom._get_childNodes()
1683 self.n_list = n_list
1684 col_names = ['Armor','DR','Max Dex','Check Penalty','Weight','Speed (10)','Speed (6)','type']
1685 self.grid.CreateGrid(len(n_list),len(col_names),1)
1686 self.grid.SetRowLabelSize(0)
1687 for i in range(len(col_names)):
1688 self.grid.SetColLabelValue(i,col_names[i])
1689 self.atts =['name','bonus','maxdex','checkpenalty','weight','speed','speed6','type']
1690 for i in range(len(n_list)):
1691 self.refresh_row(i)
1692 self.temp_dom = None
1693
1694
1695 def on_cell_change(self,evt):
1696 row = evt.GetRow()
1697 col = evt.GetCol()
1698 value = self.grid.GetCellValue(row,col)
1699 if col >= 1 and col <= 5:
1700 try:
1701 int(value)
1702 self.n_list[row].setAttribute(self.atts[col],value)
1703 except:
1704 self.grid.SetCellValue(row,col,"0")
1705 else:
1706 self.n_list[row].setAttribute(self.atts[col],value)
1707
1708 def refresh_row(self,i):
1709 n = self.n_list[i]
1710 for y in range(len(self.atts)):
1711 self.grid.SetCellValue(i,y,n.getAttribute(self.atts[y]))
1712
1713 def on_remove(self,evt):
1714 rows = self.grid.GetNumberRows()
1715 for i in range(rows):
1716 if self.grid.IsInSelection(i,0):
1717 self.grid.DeleteRows(i)
1718 self.master_dom.removeChild(self.n_list[i])
1719
1720 def on_add(self,evt):
1721 if not self.temp_dom:
1722 tmp = open(orpg.dirpath.dir_struct["SWd20"]+"d20armor.xml","r")
1723 xml_dom = parseXml_with_dlg(self,tmp.read())
1724 xml_dom = xml_dom._get_firstChild()
1725 tmp.close()
1726 self.temp_dom = xml_dom
1727 f_list = self.temp_dom.getElementsByTagName('armor')
1728 opts = []
1729 for f in f_list:
1730 opts.append(f.getAttribute('name'))
1731 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
1732 if dlg.ShowModal() == wx.ID_OK:
1733 i = dlg.GetSelection()
1734 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
1735 self.grid.AppendRows(1)
1736 self.refresh_row(self.grid.GetNumberRows()-1)
1737 dlg.Destroy()
1738
1739 def on_size(self,event):
1740 s = self.GetClientSizeTuple()
1741 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1742 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1743 (w,h) = self.grid.GetClientSizeTuple()
1744 cols = self.grid.GetNumberCols()
1745 col_w = w/(cols+2)
1746 self.grid.SetColSize(0,col_w*3)
1747 for i in range(1,cols):
1748 self.grid.SetColSize(i,col_w)
1749
1750
1751 class class_panel(wx.Panel):
1752 def __init__(self, parent, handler):
1753 pname = handler.master_dom.setAttribute("name", 'Class')
1754 wx.Panel.__init__(self, parent, -1)
1755 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
1756 sizer = wx.BoxSizer(wx.HORIZONTAL)
1757 sizer.Add(wx.Button(self, 10, "Remove Class"), 1, wx.EXPAND)
1758 sizer.Add(wx.Size(10,10))
1759 sizer.Add(wx.Button(self, 20, "Add Class"), 1, wx.EXPAND)
1760 self.sizer = sizer
1761 self.SetSizer(self.sizer)
1762 self.Bind(wx.EVT_SIZE, self.on_size)
1763 EVT_BUTTON(self, 10, self.on_remove)
1764 EVT_BUTTON(self, 20, self.on_add)
1765 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
1766
1767 n_list = handler.master_dom._get_childNodes()
1768 self.n_list = n_list
1769 self.master_dom = handler.master_dom
1770 self.grid.CreateGrid(len(n_list),2,1)
1771 self.grid.SetRowLabelSize(0)
1772 self.grid.SetColLabelValue(0,"Class")
1773 self.grid.SetColLabelValue(1,"Level")
1774 for i in range(len(n_list)):
1775 self.refresh_row(i)
1776 self.temp_dom = None
1777
1778 def on_cell_change(self,evt):
1779 row = evt.GetRow()
1780 col = evt.GetCol()
1781 value = self.grid.GetCellValue(row,col)
1782 try:
1783 int(value)
1784 self.n_list[row].setAttribute('level',value)
1785 except:
1786 self.grid.SetCellValue(row,col,"1")
1787
1788
1789 def refresh_row(self,i):
1790 n = self.n_list[i]
1791 name = n.getAttribute('name')
1792 level = n.getAttribute('level')
1793 self.grid.SetCellValue(i,0,name)
1794 self.grid.SetReadOnly(i,0)
1795 self.grid.SetCellValue(i,1,level)
1796 #self.grid.SetReadOnly(i,1)
1797
1798 def on_remove(self,evt):
1799 rows = self.grid.GetNumberRows()
1800 for i in range(rows):
1801 if self.grid.IsInSelection(i,0):
1802 self.grid.DeleteRows(i)
1803 self.master_dom.removeChild(self.n_list[i])
1804
1805 def on_add(self,evt):
1806 if not self.temp_dom:
1807 tmp = open(orpg.dirpath.dir_struct["SWd20"]+"SWd20classes.xml","r")
1808 xml_dom = parseXml_with_dlg(self,tmp.read())
1809 xml_dom = xml_dom._get_firstChild()
1810 tmp.close()
1811 self.temp_dom = xml_dom
1812 f_list = self.temp_dom.getElementsByTagName('class')
1813 opts = []
1814 for f in f_list:
1815 opts.append(f.getAttribute('name'))
1816 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
1817 if dlg.ShowModal() == wx.ID_OK:
1818 i = dlg.GetSelection()
1819 new_node = self.master_dom.appendChild(f_list[i].cloneNode(False))
1820 self.grid.AppendRows(1)
1821 self.refresh_row(self.grid.GetNumberRows()-1)
1822 dlg.Destroy()
1823
1824
1825 def on_size(self,event):
1826 s = self.GetClientSizeTuple()
1827 self.grid.SetDimensions(0,0,s[0],s[1]-25)
1828 self.sizer.SetDimension(0,s[1]-25,s[0],25)
1829 (w,h) = self.grid.GetClientSizeTuple()
1830 cols = self.grid.GetNumberCols()
1831 col_w = w/(cols)
1832 for i in range(0,cols):
1833 self.grid.SetColSize(i,col_w)