annotate orpg/gametree/nodehandlers/d20.py @ 156:3b6888bb53b5 beta

Traipse Beta 'OpenRPG' {091125-02} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 12:34:04 -0600
parents 6081bdc2b8d5
children dcae32e219f1
rev   line source
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
3 # openrpg-dev@lists.sourceforge.net
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
4 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
5 # This program is free software; you can redistribute it and/or modify
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
6 # it under the terms of the GNU General Public License as published by
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
8 # (at your option) any later version.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
9 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
10 # This program is distributed in the hope that it will be useful,
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
13 # GNU General Public License for more details.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
14 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
15 # You should have received a copy of the GNU General Public License
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
16 # along with this program; if not, write to the Free Software
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
18 # --
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
19 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
20 # File: d20.py
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
21 # Author: Chris Davis
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
22 # Maintainer:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
23 # Version:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
24 # $Id: d20.py,v 1.30 2007/05/22 00:50:57 digitalxero Exp $
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
25 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
26 # Description: The file contains code for the d20 nodehanlers
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
27 #
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
28
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
29 __version__ = "$Id: d20.py,v 1.30 2007/05/22 00:50:57 digitalxero Exp $"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
30
152
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
31 from core import *
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
32 from containers import *
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
33 import re
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
34 from xml.etree.ElementTree import ElementTree, Element, iselement
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 67
diff changeset
35 from xml.etree.ElementTree import fromstring, tostring, parse, XML
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
36 from orpg.tools.orpg_log import debug
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
37
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
38 D20_EXPORT = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
39 ############################
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
40 ## d20 character node handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
41 ############################
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
42 ## Spells code - added by Dragonstar
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
43 ##Powers, Divine spells, inventory, howto, power points by Digitalxero
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
44 ##The whole look and easy of use redone by Digitalxero
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
45 class container_handler(node_handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
46 """ should not be used! only a base class!
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
47 <nodehandler name='?' module='core' class='container_handler' />
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
48 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
49 def __init__(self,xml,tree_node):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
50 node_handler.__init__(self,xml,tree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
51 self.load_children()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
52
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
53 def load_children(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
54 children = self.xml.getchildren()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
55 for c in children:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
56 self.tree.load_xml(c,self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
57
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
58 def on_drop(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
59 drag_obj = self.tree.drag_obj
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
60 if drag_obj == self: return
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
61 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
62 if opt == wx.YES:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
63 xml = self.tree.drag_obj.delete()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
64 xml = self.xml.append(xml,None)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
65 self.tree.load_xml(xml, self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
66 self.tree.Expand(self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
67 elif opt == wx.NO: node_handler.on_drop(self,evt)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
68
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
69 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
70 cookie = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
71 html_str = "<table border=\"1\" ><tr><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
72 html_str += "<b>"+self.xml.get("name") + "</b>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
73 html_str += "</td></tr>\n"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
74 html_str += "<tr><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
75 max = tree.GetChildrenCount(handler.mytree_node,0)
152
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
76 try: (child,cookie)=self.tree.GetFirstChild(self.mytree_node,cookie)
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
77 # If this happens we probably have a newer version of wxPython
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
78 except: (child,cookie)=self.tree.GetFirstChild(self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
79 obj = self.tree.GetPyData(child)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
80 for m in range(max):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
81 html_str += "<p>" + obj.tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
82 if m < max-1:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
83 child = self.tree.GetNextSibling(child)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
84 if child.IsOk(): obj = self.tree.GetPyData(child)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
85 html_str += "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
86 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
87
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
88 def get_size_constraint(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
89 return 1
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
90
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
91 def get_char_name( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
92 return self.child_handlers['general'].get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
93
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
94 def set_char_pp(self,attr,evl):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
95 return self.child_handlers['pp'].set_char_pp(attr,evl)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
96
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
97 def get_char_pp( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
98 return self.child_handlers['pp'].get_char_pp(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
99
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
100 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
101 return self.child_handlers['classes'].get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
102
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
103
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
104 class d20char_handler(node_handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
105 """ Node handler for a d20 charactor
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
106 <nodehandler name='?' module='d20' class='d20char_handler2' />
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
107 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
108 def __init__(self,xml,tree_node):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
109 node_handler.__init__(self,xml,tree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
110 self.frame = component.get('frame')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
111 self.child_handlers = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
112 self.new_child_handler('howtouse','HowTO use this tool',d20howto,'note')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
113 self.new_child_handler('general','General Information',d20general,'gear')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
114 self.new_child_handler('inventory','Money and Inventory',d20inventory,'money')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
115 self.new_child_handler('abilities','Abilities Scores',d20ability,'gear')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
116 self.new_child_handler('classes','Classes',d20classes,'knight')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
117 self.new_child_handler('saves','Saves',d20saves,'skull')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
118 self.new_child_handler('skills','Skills',d20skill,'book')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
119 self.new_child_handler('feats','Feats',d20feats,'book')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
120 self.new_child_handler('spells','Spells',d20spells,'book')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
121 self.new_child_handler('divine','Divine Spells',d20divine,'book')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
122 self.new_child_handler('powers','Powers',d20powers,'questionhead')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
123 self.new_child_handler('hp','Hit Points',d20hp,'gear')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
124 self.new_child_handler('pp','Power Points',d20pp,'gear')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
125 self.new_child_handler('attacks','Attacks',d20attacks,'spears')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
126 self.new_child_handler('ac','Armor',d20armor,'spears')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
127 self.myeditor = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
128
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
129 def on_version(self,old_version):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
130 node_handler.on_version(self,old_version)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
131 if old_version == "":
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
132 data = parse(orpg.dirpath.dir_struct["nodes"]+"d20character.xml").getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
133 for tag in ("howtouse","inventory","powers","divine","pp"):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
134 self.xml.append(data.find(tag))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
135
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
136 ## add new atts
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
137 melee_attack = self.xml.find('melee')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
138 melee_attack.set("second","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
139 melee_attack.set("third","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
140 melee_attack.set("forth","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
141 melee_attack.set("fifth","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
142 melee_attack.set("sixth","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
143 range_attack = self.xml.find('ranged')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
144 range_attack.set("second","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
145 range_attack.set("third","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
146 range_attack.set("forth","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
147 range_attack.set("fifth","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
148 range_attack.set("sixth","0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
149
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
150 gen_list = self.xml.find('general')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
151
152
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
152 for tag in ("currentxp","xptolevel"): gen_list.append(data.find(tag))
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
153 print old_version
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
154
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
155
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
156 def get_char_name( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
157 return self.child_handlers['general'].get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
158
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
159 def set_char_pp(self,attr,evl):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
160 return self.child_handlers['pp'].set_char_pp(attr,evl)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
161
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
162 def get_char_pp( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
163 return self.child_handlers['pp'].get_char_pp(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
164
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
165 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
166 return self.child_handlers['classes'].get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
167
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
168 def new_child_handler(self,tag,text,handler_class,icon='gear'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
169 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
170 i = self.tree.icons[icon]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
171 new_tree_node = tree.AppendItem(self.mytree_node,text,i,i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
172 handler = handler_class(self.xml.find(tag),new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
173 tree.SetPyData(new_tree_node,handler)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
174 self.child_handlers[tag] = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
175
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
176 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
177 return tabbed_panel(parent,self,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
178
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
179 def get_use_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
180 return tabbed_panel(parent,self,2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
181
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
182 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
183 html_str = "<table><tr><td colspan=2 >"+self.child_handlers['general'].tohtml()+"</td></tr>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
184 html_str += "<tr><td width='50%' valign=top >"+self.child_handlers['abilities'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
185 html_str += "<P>" + self.child_handlers['saves'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
186 html_str += "<P>" + self.child_handlers['attacks'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
187 html_str += "<P>" + self.child_handlers['ac'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
188 html_str += "<P>" + self.child_handlers['feats'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
189 html_str += "<P>" + self.child_handlers['spells'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
190 html_str += "<P>" + self.child_handlers['divine'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
191 html_str += "<P>" + self.child_handlers['powers'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
192 html_str += "<P>" + self.child_handlers['inventory'].tohtml() +"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
193 html_str += "<td width='50%' valign=top >"+self.child_handlers['classes'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
194 html_str += "<P>" + self.child_handlers['hp'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
195 html_str += "<P>" + self.child_handlers['pp'].tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
196 html_str += "<P>" + self.child_handlers['skills'].tohtml() +"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
197 html_str += "</tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
198 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
199
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
200 def about(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
201 """html_str = "<img src='" + orpg.dirpath.dir_struct["icon"]+'d20_logo.gif' "><br /><b>d20 Character Tool v0.7 beta</b>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
202 html_str += "<br />by Chris Davis<br />chris@rpgarchive.com"
152
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
203 return html_str"""
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
204 text = 'd20 Character Tool 0.7 beta\n'
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
205 text += 'by Chris Davis chris@rpgarchive.com'
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
206 return text
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
207
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
208 def get_char_name( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
209 return self.child_handlers['general'].get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
210 def get_armor_class( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
211 return self.child_handlers['ac'].get_armor_class()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
212 def get_max_hp( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
213 return self.child_handlers['hp'].get_max_hp()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
214 def get_current_hp( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
215 return self.child_handlers['hp'].get_current_hp()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
216
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
217 def set_char_pp(self,attr,evl):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
218 return self.child_handlers['pp'].set_char_pp(attr,evl)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
219
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
220 def get_char_pp( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
221 return self.child_handlers['pp'].get_char_pp(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
222
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
223 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
224 return self.child_handlers['classes'].get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
225
152
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
226 """ Removed to use the supplied Tabbed Panel
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
227 class tabbed_panel(wx.Notebook):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
228 def __init__(self, parent, handler, mode):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
229 wx.Notebook.__init__(self, parent, -1, size=(1200,800))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
230 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
231 self.parent = parent
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
232 tree = self.handler.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
233 max = tree.GetChildrenCount(handler.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
234 cookie = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
235
152
6081bdc2b8d5 Traipse Beta 'OpenRPG' {091125-00}
sirebral
parents: 135
diff changeset
236 try: (child,cookie)=tree.GetFirstChild(handler.mytree_node,cookie)
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
237 # If this happens we probably have a newer version of wxPython
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
238 except: (child,cookie)=tree.GetFirstChild(handler.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
239 if not child.IsOk(): return
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
240 obj = tree.GetPyData(child)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
241 for m in range(max):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
242 if mode == 1: panel = obj.get_design_panel(self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
243 else: panel = obj.get_use_panel(self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
244 name = obj.xml.get("name")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
245 if panel: self.AddPage(panel,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
246 if m < max-1:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
247 child = tree.GetNextSibling(child)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
248 if child.IsOk(): obj = tree.GetPyData(child)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
249 else: break
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
250
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
251 def about(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
252 html_str = "<img src='" + orpg.dirpath.dir_struct["icon"]+'d20_logo.gif' "><br /><b>d20 Character Tool v0.7 beta</b>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
253 html_str += "<br />by Chris Davis<br />chris@rpgarchive.com"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
254 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
255
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
256 def get_char_name( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
257 return self.child_handlers['general'].get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
258
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
259 def set_char_pp(self,attr,evl):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
260 return self.child_handlers['pp'].set_char_pp(attr,evl)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
261
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
262 def get_char_pp( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
263 return self.child_handlers['pp'].get_char_pp(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
264
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
265 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
266 return self.child_handlers['classes'].get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
267 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
268 class d20_char_child(node_handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
269 """ Node Handler for skill. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
270 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
271 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
272 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
273 node_handler.__init__(self,xml,tree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
274 self.char_hander = parent
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
275 self.drag = False
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
276 self.frame = component.get('frame')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
277 self.myeditor = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
278
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
279 def on_drop(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
280 pass
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
281
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
282 def on_rclick(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
283 pass
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
284
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
285 def on_ldclick(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
286 return
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
287 if self.myeditor == None or self.myeditor.destroyed:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
288 title = self.xml.get('name') + " Editor"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
289 self.myeditor = wx.Frame(self.frame, -1, title)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
290 if wx.Platform == '__WXMSW__':
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
291 icon = wx.Icon(orpg.dirpath.dir_struct["icon"]+'grid.ico', wx.BITMAP_TYPE_ICO)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
292 self.myeditor.SetIcon(icon)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
293 del icon
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
294 wnd = self.get_design_panel(self.myeditor)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
295 self.myeditor.panel = wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
296 self.wnd = wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
297 self.myeditor.Show(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
298 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
299 self.myeditor.Raise()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
300
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
301 def on_html(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
302 html_str = self.tohtml()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
303 wnd = http_html_window(self.frame.note,-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
304 wnd.title = self.xml.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
305 self.frame.add_panel(wnd)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
306 wnd.SetPage(html_str)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
307
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
308 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
309 pass
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
310
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
311 def get_use_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
312 return self.get_design_panel(parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
313
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
314 def delete(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
315 pass
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
316
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
317
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
318 class d20skill(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
319 """ Node Handler for skill. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
320 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
321 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
322 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
323 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
324 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
325 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
326 self.skills={}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
327 for n in self.xml.findall('skill'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
328 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
329 self.skills[name] = n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
330 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
331 tree.SetPyData(new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
332
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
333 def get_mod(self,name):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
334 skill = self.skills[name]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
335 stat = skill.get('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
336 ac = int(skill.get('armorcheck'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
337 if ac:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
338 ac = self.char_hander.child_handlers['ac'].get_check_pen()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
339 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
340 rank = int(skill.get('rank'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
341 misc = int(skill.get('misc'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
342 total = stat_mod + rank + misc + ac
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
343 return total
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
344
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
345 def on_rclick(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
346 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
347 name = self.tree.GetItemText(item)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
348 if item == self.mytree_node: d20_char_child.on_ldclick(self,evt)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
349 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
350 skill = self.skills[name];
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
351 untrained = skill.get('untrained');
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
352 rank = skill.get('rank');
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
353 if untrained == "0" and rank == "0": txt = '%s Skill Check: Untrained' % (name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
354 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
355 mod = self.get_mod(name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
356 if mod >= 0: mod1 = "+"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
357 else: mod1 = ""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
358 txt = '%s Skill Check: [1d20%s%s]' % (name, mod1, mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
359 chat = self.chat
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
360 chat.ParsePost(txt,True,True)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
361
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
362 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
363 wnd = outline_panel(parent,self,skill_grid,"Skills")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
364 wnd.title = "Skills (edit)"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
365 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
366
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
367 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
368 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Skill</th><th>Key</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
369 <th>Rank</th><th>Abil</th><th>Misc</th><th>Total</th></tr>"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
370 for n in self.xml.findall('skill'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
371 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
372 stat = n.get('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
373 rank = n.get('rank')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
374 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+rank+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
375 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
376 misc = n.get('misc')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
377 mod = str(self.get_mod(name))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
378 if mod >= 0: mod1 = "+"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
379 else: mod1 = ""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
380 html_str = html_str + "<td>"+stat_mod+"</td><td>"+misc+'</td><td>%s%s</td></tr>' % (mod1, mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
381 html_str = html_str + "</table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
382 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
383
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
384
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
385 class d20ability(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
386 """ Node Handler for ability. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
387 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
388 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
389 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
390 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
391 self.abilities = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
392 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
393 icons = tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
394 for n in self.xml.findall('stat'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
395 name = n.get('abbr')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
396 self.abilities[name] = n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
397 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
398 tree.SetPyData( new_tree_node, self )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
399
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
400 def on_rclick( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
401 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
402 name = self.tree.GetItemText( item )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
403 if item == self.mytree_node:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
404 d20_char_child.on_ldclick( self, evt )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
405 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
406 mod = self.get_mod( name )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
407 if mod >= 0: mod1 = "+"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
408 else: mod1 = ""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
409 chat = self.chat
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
410 txt = '%s check: [1d20%s%s]' % ( name, mod1, mod )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
411 chat.ParsePost( txt, True, True )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
412
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
413 def get_mod(self,abbr):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
414 score = int(self.abilities[abbr].get('base'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
415 mod = (score - 10) / 2
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
416 return mod
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
417
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
418 def set_score(self,abbr,score):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
419 if score >= 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
420 self.abilities[abbr].set("base",str(score))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
421
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
422 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
423 wnd = outline_panel(parent,self,abil_grid,"Abilities")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
424 wnd.title = "Abilities (edit)"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
425 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
426
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
427 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
428 html_str = """<table border='1' width=100%><tr BGCOLOR=#E9E9E9 ><th width='50%'>Ability</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
429 <th>Base</th><th>Modifier</th></tr>"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
430 for n in self.xml.findall('stat'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
431 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
432 abbr = n.get('abbr')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
433 base = n.get('base')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
434 mod = str(self.get_mod(abbr))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
435 if mod >= 0: mod1 = "+"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
436 else: mod1 = ""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
437 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+base+'</td><td>%s%s</td></tr>' % (mod1, mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
438 html_str = html_str + "</table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
439 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
440
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
441
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
442 class d20saves(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
443 """ Node Handler for saves. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
444 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
445 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
446 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
447 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
448 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
449 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
450 self.saves={}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
451 for n in self.xml.findall('save'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
452 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
453 self.saves[name] = n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
454 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
455 tree.SetPyData(new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
456
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
457 def get_mod(self,name):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
458 save = self.saves[name]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
459 stat = save.get('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
460 stat_mod = self.char_hander.child_handlers['abilities'].get_mod(stat)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
461 base = int(save.get('base'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
462 miscmod = int(save.get('miscmod'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
463 magmod = int(save.get('magmod'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
464 total = stat_mod + base + miscmod + magmod
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
465 return total
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
466
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
467 def on_rclick(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
468 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
469 name = self.tree.GetItemText(item)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
470 if item == self.mytree_node:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
471 d20_char_child.on_ldclick(self,evt)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
472
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
473 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
474 mod = self.get_mod(name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
475 if mod >= 0: mod1 = "+"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
476 else: mod1 = ""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
477 chat = self.chat
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
478 txt = '%s save: [1d20%s%s]' % (name, mod1, mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
479 chat.ParsePost( txt, True, True )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
480
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
481 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
482 wnd = outline_panel(parent,self,save_grid,"Saves")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
483 wnd.title = "Saves"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
484 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
485
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
486 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
487 html_str = """<table border='1' width=100% ><tr BGCOLOR=#E9E9E9 ><th width='30%'>Save</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
488 <th>Key</th><th>Base</th><th>Abil</th><th>Magic</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
489 <th>Misc</th><th>Total</th></tr>"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
490 for n in self.xml.findall('save'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
491 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
492 stat = n.get('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
493 base = n.get('base')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
494 html_str = html_str + "<tr ALIGN='center'><td>"+name+"</td><td>"+stat+"</td><td>"+base+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
495 stat_mod = str(self.char_hander.child_handlers['abilities'].get_mod(stat))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
496 mag = n.get('magmod')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
497 misc = n.get('miscmod')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
498 mod = str(self.get_mod(name))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
499 if mod >= 0: mod1 = "+"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
500 else: mod1 = ""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
501 html_str = html_str + "<td>"+stat_mod+"</td><td>"+mag+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
502 html_str = html_str + '<td>'+misc+'</td><td>%s%s</td></tr>' % (mod1, mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
503 html_str = html_str + "</table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
504 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
505
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
506
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
507 class d20general(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
508 """ Node Handler for general information. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
509 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
510 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
511 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
512 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
513
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
514 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
515 wnd = outline_panel(parent,self,gen_grid,"General Information")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
516 wnd.title = "General Info"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
517 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
518
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
519 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
520 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
521 for n in self.xml:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
522 html_str += "<B>"+n.tag.capitalize() +":</B> "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
523 html_str += n.text + ", "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
524 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
525 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
526
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
527 def on_name_change(self,name):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
528 self.char_hander.rename(name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
529
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
530 def get_char_name( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
531 return self.xml.find( 'name' ).text
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
532
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
533
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
534 class d20classes(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
535 """ Node Handler for classes. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
536 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
537 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
538 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
539 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
540
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
541 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
542 wnd = outline_panel(parent,self,class_panel,"Classes")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
543 wnd.title = "Classes"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
544 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
545
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
546 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
547 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Classes</th></tr><tr><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
548 for n in self.xml: html_str += n.get('name') + " ("+n.get('level')+"), "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
549 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
550 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
551
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
552 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
553 for n in self.xml.findall('class'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
554 lvl = n.get('level')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
555 type = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
556 if attr == "level": return lvl
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
557 elif attr == "class": return type
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
558
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
559
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
560 class d20feats(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
561 """ Node Handler for classes. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
562 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
563 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
564 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
565 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
566
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
567 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
568 wnd = outline_panel(parent,self,feat_panel,"Feats")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
569 wnd.title = "Feats"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
570 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
571
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
572 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
573 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Feats</th></tr><tr><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
574 for n in self.xml: html_str += n.get('name')+ ", "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
575 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
576 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
577
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
578
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
579 class d20spells(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
580 """ Node Handler for classes. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
581 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
582 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
583 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
584 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
585 self.spells = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
586 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
587 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
588 for n in self.xml.findall( 'spell' ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
589 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
590 self.spells[ name ] = n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
591 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
592 tree.SetPyData( new_tree_node, self )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
593
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
594 def on_rclick( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
595 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
596 name = self.tree.GetItemText( item )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
597 if item == self.mytree_node:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
598 d20_char_child.on_ldclick( self, evt )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
599 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
600 level = self.spells[ name ].get( 'level' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
601 descr = self.spells[ name ].get( 'desc' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
602 use = self.spells[ name ].get( 'used' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
603 memrz = self.spells[ name ].get( 'memrz' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
604 cname = self.char_hander.get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
605 use += '+1'
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
606 left = eval( '%s - ( %s )' % ( memrz, use ) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
607 if left < 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
608 txt = '%s Tried to cast %s but has used all of them for today, "Please rest so I can cast more."' % ( cname, name )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
609 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
610 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
611 txt = '%s casts %s ( level %s, "%s" )' % ( cname, name, level, descr )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
612 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
613 s = ''
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
614 if left != 1: s = 's'
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
615 txt = '%s can cast %s %d more time%s' % ( cname, name, left, s )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
616 self.chat.ParsePost( txt, False, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
617 self.spells[ name ].set( 'used', `eval( use )` )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
618
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
619 def refresh_spells(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
620 self.spells = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
621 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
622 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
623 tree.CollapseAndReset(self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
624 for n in self.xml.findall('spell'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
625 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
626 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear'])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
627 tree.SetPyData(new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
628 self.spells[name]=n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
629
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
630 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
631 wnd = outline_panel(parent,self,spell_panel,"Spells")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
632 wnd.title = "Spells"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
633 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
634
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
635 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
636 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Arcane Spells</th></tr><tr><td><br />"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
637 for n in self.xml: html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
638 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
639 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
640
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
641 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
642 return self.char_hander.get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
643
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
644 class d20divine(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
645 """ Node Handler for classes. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
646 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
647 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
648 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
649 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
650 self.spells = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
651 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
652 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
653 for n in self.xml.findall( 'gift' ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
654 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
655 self.spells[ name ] = n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
656 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['flask'], icons['flask'] )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
657 tree.SetPyData( new_tree_node, self )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
658
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
659 def on_rclick( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
660 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
661 name = self.tree.GetItemText( item )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
662 if item == self.mytree_node:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
663 d20_char_child.on_ldclick( self, evt )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
664 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
665 level = self.spells[ name ].get( 'level' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
666 descr = self.spells[ name ].get( 'desc' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
667 use = self.spells[ name ].get( 'used' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
668 memrz = self.spells[ name ].get( 'memrz' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
669 cname = self.char_hander.get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
670 use += '+1'
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
671 left = eval( '%s - ( %s )' % ( memrz, use ) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
672 if left < 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
673 txt = '%s Tried to cast %s but has used all of them for today, "Please rest so I can cast more."' % ( cname, name )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
674 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
675 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
676 txt = '%s casts %s ( level %s, "%s" )' % ( cname, name, level, descr )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
677 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
678 s = ''
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
679 if left != 1: s = 's'
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
680 txt = '%s can cast %s %d more time%s' % ( cname, name, left, s )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
681 self.chat.ParsePost( txt, False, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
682 self.spells[ name ].set( 'used', `eval( use )` )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
683
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
684 def refresh_spells(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
685 self.spells = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
686 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
687 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
688 tree.CollapseAndReset(self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
689 for n in self.xml.findall('gift'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
690 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
691 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['flask'],icons['flask'])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
692 tree.SetPyData(new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
693 self.spells[name]=n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
694
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
695 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
696 wnd = outline_panel(parent,self,divine_panel,"Spells")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
697 wnd.title = "Spells"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
698 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
699
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
700 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
701 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Divine Spells</th></tr><tr><td><br />"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
702 for n in self.xml: html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
703 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
704 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
705
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
706 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
707 return self.char_hander.get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
708
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
709 class d20powers(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
710 """ Node Handler for classes. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
711 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
712 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
713 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
714 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
715 #cpp = self.xml.findall( 'pp' ).get('current1')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
716 self.powers = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
717 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
718 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
719 for n in self.xml.findall( 'power' ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
720 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
721 self.powers[ name ] = n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
722 new_tree_node = tree.AppendItem( self.mytree_node, name, icons['gear'], icons['gear'] )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
723 tree.SetPyData( new_tree_node, self )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
724
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
725 def on_rclick( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
726 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
727 name = self.tree.GetItemText( item )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
728 if item == self.mytree_node:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
729 d20_char_child.on_ldclick( self, evt )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
730 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
731 level = self.powers[ name ].get( 'level' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
732 descr = self.powers[ name ].get( 'desc' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
733 use = self.powers[ name ].get( 'used' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
734 points = self.powers[ name ].get( 'point' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
735 cpp = self.char_hander.get_char_pp('current1')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
736 fre = self.char_hander.get_char_pp('free')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
737 cname = self.char_hander.get_char_name()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
738 if level == "0" and fre != "0":
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
739 left = eval('%s - ( %s )' % ( fre, points ))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
740 numcast = eval('%s / %s' % (left, points))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
741 if left < 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
742 txt = '%s doesnt have enough PowerPoints to use %s' % ( cname, name )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
743 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
744 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
745 txt = '%s uses %s as a Free Talent ( level %s, "%s" )' % ( cname, name, level, descr )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
746 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
747 s = ''
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
748 if left != 1: s = 's'
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
749 txt = '%s can use %s %d more time%s' % ( cname, name, numcast, s )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
750 self.chat.ParsePost( txt, False, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
751 self.char_hander.set_char_pp('free', left)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
752 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
753 left = eval('%s - ( %s )' % ( cpp, points ))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
754 numcast = eval('%s / %s' % (left, points))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
755 if left < 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
756 txt = '%s doesnt have enough PowerPoints to use %s' % ( cname, name )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
757 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
758 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
759 txt = '%s uses %s ( level %s, "%s" )' % ( cname, name, level, descr )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
760 self.chat.ParsePost( txt, True, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
761 s = ''
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
762 if left != 1: s = 's'
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
763 txt = '%s can use %s %d more time%s' % ( cname, name, numcast, s )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
764 txt += ' - And has %d more Powerpoints left' % (left)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
765 self.chat.ParsePost( txt, False, False )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
766 self.char_hander.set_char_pp('current1', left)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
767
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
768 def refresh_powers(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
769 self.powers = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
770 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
771 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
772 tree.CollapseAndReset(self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
773 for n in self.xml.findall('power'):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
774 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
775 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['questionhead'],icons['questionhead'])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
776 tree.SetPyData(new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
777 self.powers[name]=n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
778
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
779 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
780 wnd = outline_panel(parent,self,power_panel,"Powers")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
781 wnd.title = "Powers"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
782 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
783
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
784 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
785 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>Powers</th></tr><tr><td><br />"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
786 for n in self.xml: html_str += "(" + n.get('level') + ") " + n.get('name')+ ", "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
787 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
788 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
789
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
790 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
791 return self.char_hander.get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
792
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
793 def set_char_pp(self,attr,evl):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
794 return self.char_hander.set_char_pp(attr,evl)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
795
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
796 def get_char_pp( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
797 return self.char_hander.get_char_pp(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
798
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
799 class d20howto(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
800 """ Node Handler for hit points. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
801 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
802 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
803 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
804 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
805
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
806 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
807 wnd = outline_panel(parent,self,howto_panel,"How To")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
808 wnd.title = "How To"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
809 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
810
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
811 class d20inventory(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
812 """ Node Handler for general information. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
813 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
814 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
815 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
816 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
817
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
818 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
819 wnd = outline_panel(parent,self,inventory_grid,"Inventory")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
820 wnd.title = "General Info"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
821 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
822
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
823 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
824 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>General Information</th></tr><tr><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
825 for n in self.xml:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
826 html_str += "<B>"+n.tag.capitalize() +":</B> "
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
827 html_str += n.text + "<br />"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
828 html_str = html_str[:len(html_str)-2] + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
829 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
830
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
831 def on_name_change(self,name):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
832 self.char_hander.rename(name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
833
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
834 def get_char_name( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
835 return self.xml.find( 'name' ).text
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
836
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
837
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
838 class d20hp(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
839 """ Node Handler for hit points. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
840 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
841 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
842 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
843 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
844
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
845 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
846 wnd = outline_panel(parent,self,hp_panel,"Hit Points")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
847 wnd.title = "Hit Points"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
848 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
849
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
850 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
851 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=4>Hit Points</th></tr>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
852 html_str += "<tr><th>Max:</th><td>"+self.xml.get('max')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
853 html_str += "<th>Current:</th><td>"+self.xml.get('current')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
854 html_str += "</tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
855 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
856
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
857 def get_max_hp( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
858 try: return eval( self.xml.get( 'max' ) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
859 except: return 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
860 def get_current_hp( self ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
861 try: return eval( self.xml.get( 'current' ) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
862 except: return 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
863
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
864 class d20pp(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
865 """ Node Handler for power points. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
866 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
867 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
868 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
869 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
870
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
871 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
872 wnd = outline_panel(parent,self,pp_panel,"Power Points")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
873 wnd.title = "Power Points"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
874 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
875
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
876 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
877 html_str = "<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=8>Power Points</th></tr>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
878 html_str += "<tr><th>Max:</th><td>"+self.xml.get('max1')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
879 html_str += "<th>Current:</th><td>"+self.xml.get('current1')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
880 html_str += "<th>Current Talents/day:</th><td>"+self.xml.get('free')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
881 html_str += "<th>Max Talents/day:</th><td>"+self.xml.get('maxfree')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
882 html_str += "</tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
883 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
884
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
885 def get_char_pp( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
886 pp = self.xml.get(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
887 return pp
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
888
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
889 def set_char_pp( self, attr, evl ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
890 pp = self.xml.set(attr, evl)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
891 return pp
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
892
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
893 class d20attacks(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
894 """ Node Handler for attacks. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
895 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
896 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
897 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
898 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
899 node_list = self.xml.findall('melee')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
900 self.melee = node_list[0]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
901 node_list = self.xml.findall('ranged')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
902 self.ranged = node_list[0]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
903 self.refresh_weapons()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
904
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
905 def refresh_weapons(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
906 self.weapons = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
907 tree = self.tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
908 icons = self.tree.icons
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
909 tree.CollapseAndReset(self.mytree_node)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
910 node_list = self.xml.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
911 for n in node_list:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
912 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
913 new_tree_node = tree.AppendItem(self.mytree_node,name,icons['sword'],icons['sword'])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
914 tree.SetPyData(new_tree_node,self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
915 self.weapons[name]=n
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
916
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
917 def get_attack_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
918 temp = self.melee
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
919 base = int(temp.get('base'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
920 base2 = int(temp.get('second'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
921 base3 = int(temp.get('third'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
922 base4 = int(temp.get('forth'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
923 base5 = int(temp.get('fifth'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
924 base6 = int(temp.get('sixth'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
925 misc = int(temp.get('misc'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
926 return (base, base2, base3, base4, base5, base6, misc)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
927
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
928 # Replace any 'S' and 'D' in an attack modifier and damage modifier with the
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
929 # strength bonus or dexterity bonus respectively.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
930 def process_mod_codes( self, attack, damage ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
931 str_mod = self.char_hander.child_handlers['abilities'].get_mod( 'Str' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
932 dex_mod = self.char_hander.child_handlers['abilities'].get_mod( 'Dex' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
933 str_re = re.compile('S')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
934 dex_re = re.compile('D')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
935 attack = str_re.sub( str( str_mod ), attack )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
936 attack = dex_re.sub( str( dex_mod ), attack )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
937 damage = str_re.sub( str( str_mod ), damage );
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
938 damage = dex_re.sub( str( dex_mod ), damage );
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
939 return (attack, damage)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
940
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
941 # Decompose a damage string (e.g. longsword +1 sneak attack "1d8+S+1+1d6")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
942 # into it's 4 seperate components <n>d<s>+<mods>+<extra dice>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
943 def decompose_damage( self, damage ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
944 m = re.match( r"(?P<n>\d+)d(?P<s>\d+)(?P<mods>(\s*(\+|-|/|\*)\s*(\d+|D|S)*)*)(?P<extra>(\s*(\+|-)\s*\d+d\d+)?)\s*$", damage )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
945 return (int(m.group('n')), int(m.group('s')), m.group('mods'), m.group('extra'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
946
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
947 def on_rclick(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
948 item = self.tree.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
949 name = self.tree.GetItemText(item)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
950 if item == self.mytree_node:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
951 d20_char_child.on_ldclick(self,evt)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
952 #self.frame.add_panel(self.get_design_panel(self.frame.note))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
953 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
954 # Weapon/attack specific attack modifier (e.g. "S+1" for a longsword+1).
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
955 attack_mod_str = self.weapons[name].get('mod')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
956
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
957 # Weapon/attack specific damage (e.g. "1d8+S+1" for a longsword+1).
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
958 damage_str = self.weapons[name].get('damage')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
959 (num_damage_dice, damage_die, damage_mods, extra_damage) = self.decompose_damage( damage_str )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
960
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
961 # Replace any 'S' and 'D' in attack_mod_str and damage_str with the
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
962 # strength bonus or dexterity bonus respectively.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
963 (attack_mod_str, damage_mods) = self.process_mod_codes( attack_mod_str, damage_mods )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
964
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
965 # Base attack bonuses for up to six attacks.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
966 bab_attributes = ['base', 'second', 'third', 'forth', 'fifth', 'sixth']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
967 bab = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
968 for b in bab_attributes: bab.append( int(self.melee.get( b )) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
969
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
970 # Misc. attack modifier to be applied to *all* attacks.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
971 misc_mod = int(self.melee.get( 'misc' ));
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
972
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
973 # Attack modifier (except BAB)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
974 attack_mod = misc_mod + eval( attack_mod_str )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
975
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
976 # Total damage mod (except extra dice)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
977 if damage_mods != '': damage_mod = eval( damage_mods )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
978 else: damage_mod = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
979
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
980 # Determine critical hit range and multiplier.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
981 critical_str = self.weapons[name].get( 'critical' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
982 m = re.match( r"(((?P<min>\d+)-)?\d+/)?x(?P<mult>\d+)", critical_str )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
983 crit_min = m.group( 'min' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
984 crit_mult = m.group( 'mult' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
985 if crit_min == None: crit_min = 20
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
986 else: crit_min = int( crit_min )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
987 if crit_mult == None: crit_mult = 2
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
988 else: crit_mult = int( crit_mult )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
989
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
990 # Simple matter to output all the attack/damage lines to the chat buffer.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
991 for i in range( 0, len( bab ) ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
992 if bab[i] > 0 or i == 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
993 attack_roll_str = '[1d20%+d]' % (bab[i] + attack_mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
994 attack_roll_parsed = self.chat.ParseDice( attack_roll_str )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
995 damage_roll_str = '[%dd%d%+d%s]' % (num_damage_dice, damage_die, damage_mod, extra_damage)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
996 damage_roll_parsed = self.chat.ParseDice( damage_roll_str )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
997 txt = '%s (%s): %s ===> Damage: %s' \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
998 % (name, bab_attributes[i], attack_roll_parsed, damage_roll_parsed)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
999 self.chat.Post( txt, True, True )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1000
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1001 # Check for a critical hit
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1002 d20_roll = int(re.match( r".*\[(\d+),.*", attack_roll_parsed ).group(1));
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1003 dmg = damage_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1004 if d20_roll >= crit_min:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1005 for j in range(1,crit_mult): dmg += '+%s' % damage_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1006 txt = 'Critical hit? [1d20%+d] ===> Damage: [%dd%d%+d%s]' \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1007 % (bab[i] + attack_mod, crit_mult*num_damage_dice, \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1008 damage_die, crit_mult*damage_mod, extra_damage)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1009 self.chat.ParsePost( txt, True, True )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1010
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1011 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1012 wnd = outline_panel(parent,self,attack_panel,"Attacks")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1013 wnd.title = "Attacks"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1014 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1015
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1016 def get_char_lvl( self, attr ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1017 return self.char_hander.get_char_lvl(attr)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1018
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1019 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1020 babs = self.get_attack_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1021 html_str = "<table width=100% border=1 ><tr ALIGN='center'><th BGCOLOR=#E9E9E9>Base Attack Bonus</th>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1022 html_str += '<td>%+d' % babs[0]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1023 for i in range(1,6):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1024 if babs[i] > 0: html_str += '/%+d' % babs[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1025 html_str += "</td></tr><tr ALIGN='center' ><th BGCOLOR=#E9E9E9>Misc. Attack Bonus</th>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1026 html_str += '<td>%+d</td></tr></table>' % babs[6]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1027
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1028 n_list = self.xml.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1029 for n in n_list:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1030 (attack_mod, damage_mod) = self.process_mod_codes( n.get( 'mod' ), \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1031 n.get( 'damage' ) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1032 attack_mod = eval( attack_mod )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1033 html_str += """<P><table width=100% border=1><tr BGCOLOR=#E9E9E9><th colspan=3>Weapon</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1034 <th>Attack</th><th >Damage</th></tr>""" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1035 + "<tr ALIGN='center'><td colspan=3>" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1036 + n.get('name') + "</td><td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1037 html_str += '%+d</td><td>%s</td></tr>' % (attack_mod, damage_mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1038 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Critical</th><th>Range</th><th>Weight</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1039 <th>Type</th><th>Size</th></tr>""" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1040 + "<tr ALIGN='center'><td>" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1041 + n.get( 'critical' ) + "</td><td>" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1042 + n.get( 'range' ) + "</td><td>" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1043 + n.get( 'weight' )+"</td><td>" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1044 + n.get( 'type' ) + "</td><td>" \
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1045 + n.get( 'size' ) + "</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1046 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1047
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1048 class d20armor(d20_char_child):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1049 """ Node Handler for ac. This handler will be
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1050 created by d20char_handler.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1051 """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1052 def __init__(self,xml,tree_node,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1053 d20_char_child.__init__(self,xml,tree_node,parent)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1054
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1055 def get_spell_failure(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1056 return self.get_total('spellfailure')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1057
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1058 def get_total_weight(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1059 return self.get_total('weight')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1060
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1061 def get_check_pen(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1062 return self.get_total('checkpenalty')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1063
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1064 def get_armor_class(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1065 ac_total = 10
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1066 ac_total += self.get_total('bonus')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1067 dex_mod = self.char_hander.child_handlers['abilities'].get_mod('Dex')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1068 max_dex = self.get_max_dex()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1069 if dex_mod < max_dex: ac_total += dex_mod
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1070 else: ac_total += max_dex
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1071 return ac_total
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1072
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1073 def get_max_dex(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1074 armor_list = self.xml.findall('armor')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1075 dex = 10
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1076 for a in armor_list:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1077 temp = int(a.get("maxdex"))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1078 if temp < dex: dex = temp
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1079 return dex
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1080
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1081 def get_total(self,attr):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1082 armor_list = self.xml.findall('armor')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1083 total = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1084 for a in armor_list: total += int(a.get(attr))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1085 return total
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1086
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1087 def get_design_panel(self,parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1088 wnd = outline_panel(parent,self,ac_panel,"Armor")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1089 wnd.title = "Armor"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1090 return wnd
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1091
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1092 def tohtml(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1093 html_str = """<table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th>AC</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1094 <th>Check Penalty</th><th >Spell Failure</th><th>Max Dex</th><th>Total Weight</th></tr>"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1095 html_str += "<tr ALIGN='center' ><td>"+str(self.get_armor_class())+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1096 html_str += "<td>"+str(self.get_check_pen())+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1097 html_str += "<td>"+str(self.get_spell_failure())+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1098 html_str += "<td>"+str(self.get_max_dex())+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1099 html_str += "<td>"+str(self.get_total_weight())+"</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1100 for n in self.xml:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1101 html_str += """<P><table width=100% border=1 ><tr BGCOLOR=#E9E9E9 ><th colspan=3>Armor</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1102 <th>Type</th><th >Bonus</th></tr>"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1103 html_str += "<tr ALIGN='center' ><td colspan=3>"+n.get('name')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1104 html_str += "<td>"+n.get('type')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1105 html_str += "<td>"+n.get('bonus')+"</td></tr>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1106 html_str += """<tr BGCOLOR=#E9E9E9 ><th>Check Penalty</th><th>Spell Failure</th>
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1107 <th>Max Dex</th><th>Speed</th><th>Weight</th></tr>"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1108 html_str += "<tr ALIGN='center'><td>"+n.get('checkpenalty')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1109 html_str += "<td>"+n.get('spellfailure')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1110 html_str += "<td>"+n.get('maxdex')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1111 html_str += "<td>"+n.get('speed')+"</td>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1112 html_str += "<td>"+n.get('weight')+"</td></tr></table>"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1113 return html_str
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1114
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1115
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1116 ########################
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1117 ## d20 char windows
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1118 ########################
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1119
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1120 class base_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1121 def __init__(self, parent):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1122 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1123
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1124 #self.build_ctrls()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1125 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1126
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1127 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1128 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1129 #self.splitter.SetDimensions(0,0,s[0],s[1])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1130
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1131 class outline_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1132 def __init__(self, parent, handler, wnd, txt,):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1133 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1134 self.panel = wnd(self,handler)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1135 self.outline = wx.StaticBox(self,-1,txt)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1136 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1137
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1138 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1139 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1140 self.panel.SetDimensions(20,20,s[0]-40,s[1]-40)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1141 self.outline.SetDimensions(5,5,s[0]-10,s[1]-10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1142
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1143 class char_panel(wx.ScrolledWindow):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1144 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1145 pname = handler.xml.set("name", 'TWO')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1146 wx.ScrolledWindow.__init__(self, parent, -1,style=wx.VSCROLL | wx.SUNKEN_BORDER )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1147 self.height = 1200
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1148 self.SetScrollbars(10, 10,80, self.height/10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1149 self.main_sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1150 self.panels = {}
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1151 keys = handler.child_handlers.keys()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1152 for k in keys: self.panels[k] = handler.child_handlers[k].get_design_panel(self, [k])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1153 self.sub_sizer = wx.BoxSizer(wx.VERTICAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1154 self.sub_sizer2 = wx.BoxSizer(wx.VERTICAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1155 self.sub_sizer.Add(self.panels['general'], 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1156 self.sub_sizer.Add(self.panels['abilities'], 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1157
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1158 self.sub_sizer.Add(self.panels['attacks'], 2, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1159 self.sub_sizer.Add(self.panels['ac'], 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1160 self.sub_sizer.Add(self.panels['spells'], 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1161
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1162 self.sub_sizer2.Add(self.panels['classes'], 2, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1163 self.sub_sizer2.Add(self.panels['hp'], 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1164 self.sub_sizer2.Add(self.panels['pp'], 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1165 self.sub_sizer2.Add(self.panels['saves'], 2, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1166
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1167 self.sub_sizer2.Add(self.panels['feats'], 2, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1168 self.sub_sizer2.Add(self.panels['powers'], 2, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1169 self.sub_sizer2.Add(self.panels['skills'], 3, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1170
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1171 self.main_sizer.Add(self.sub_sizer, 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1172 self.main_sizer.Add(self.sub_sizer2, 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1173 self.panels['abilities'].panel.char_wnd = self
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1174 self.SetSizer(self.main_sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1175 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1176
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1177
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1178 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1179 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1180 self.SetScrollbars(10, 10,s[0]/10, self.height/10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1181 dc = wx.ClientDC(self)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1182 x = dc.DeviceToLogicalX(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1183 y = dc.DeviceToLogicalY(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1184 self.main_sizer.SetDimension(x,y,s[0],self.height)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1185 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1186
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1187 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1188 self.panels['saves'].panel.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1189 self.panels['skills'].panel.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1190 self.panels['attacks'].panel.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1191 self.panels['powers'].panel.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1192 self.panels['spells'].panel.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1193
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1194 HOWTO_MAX = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1195
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1196 class howto_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1197 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1198 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1199 pname = handler.xml.set("name", 'How To')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1200 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1201 self.sizer.AddMany([ (wx.StaticText(self, -1,
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1202 handler.xml.find('howto').text),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1203 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1204 ])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1205 self.sizer.AddGrowableCol(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1206 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1207
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1208
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1209 HP_CUR = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1210 HP_MAX = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1211
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1212 class hp_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1213 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1214 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1215 pname = handler.xml.set("name", 'HitPoints')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1216 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1217 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1218 self.sizer.AddMany([ (wx.StaticText(self, -1, "HP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1219 (wx.TextCtrl(self, HP_CUR, self.xml.get('current')), 0, wx.EXPAND),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1220 (wx.StaticText(self, -1, "HP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1221 (wx.TextCtrl(self, HP_MAX, self.xml.get('max')), 0, wx.EXPAND),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1222 ])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1223 self.sizer.AddGrowableCol(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1224 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1225 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1226 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_MAX)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1227 self.Bind(wx.EVT_TEXT, self.on_text, id=HP_CUR)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1228
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1229 def on_text(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1230 id = evt.GetId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1231 if id == HP_CUR: self.xml.set('current',evt.GetString())
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1232 elif id == HP_MAX: self.xml.set('max',evt.GetString())
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1233
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1234 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1235 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1236 self.sizer.SetDimension(0,0,s[0],s[1])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1237
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1238 PP_CUR = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1239 PP_MAX = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1240 PP_FRE = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1241 PP_MFRE = wx.NewId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1242
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1243 class pp_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1244 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1245 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1246 pname = handler.xml.set("name", 'PowerPoints')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1247 self.sizer = wx.FlexGridSizer(2, 4, 2, 2) # rows, cols, hgap, vgap
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1248 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1249
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1250 self.sizer.AddMany([ (wx.StaticText(self, -1, "PP Current:"), 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1251 (wx.TextCtrl(self, PP_CUR, self.xml.get('current1')), 0, wx.EXPAND),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1252 (wx.StaticText(self, -1, "PP Max:"), 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1253 (wx.TextCtrl(self, PP_MAX, self.xml.get('max1')), 0, wx.EXPAND),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1254 (wx.StaticText(self, -1, "Current Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1255 (wx.TextCtrl(self, PP_FRE, self.xml.get('free')), 0, wx.EXPAND),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1256 (wx.StaticText(self, -1, "Max Free Talants per day:"), 0, wx.ALIGN_CENTER_VERTICAL),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1257 (wx.TextCtrl(self, PP_MFRE, self.xml.get('maxfree')), 0, wx.EXPAND),
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1258 ])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1259 self.sizer.AddGrowableCol(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1260 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1261 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1262 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MAX)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1263 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_CUR)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1264 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_FRE)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1265 self.Bind(wx.EVT_TEXT, self.on_text, id=PP_MFRE)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1266
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1267 def on_text(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1268 id = evt.GetId()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1269 if id == PP_CUR: self.xml.set('current1',evt.GetString())
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1270 elif id == PP_MAX: self.xml.set('max1',evt.GetString())
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1271 elif id == PP_FRE: self.xml.set('free',evt.GetString())
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1272 elif id == PP_MFRE: self.xml.set('maxfree',evt.GetString())
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1273
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1274 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1275 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1276 self.sizer.SetDimension(0,0,s[0],s[1])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1277
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1278
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1279 class gen_grid(wx.grid.Grid):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1280 """grid for gen info"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1281 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1282 pname = handler.xml.set("name", 'General')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1283 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1284 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1285 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1286 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1287 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1288 self.CreateGrid(len(n_list),2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1289 self.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1290 self.SetColLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1291 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1292 i = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1293 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1294
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1295 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1296 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1297 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1298 value = self.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1299 self.n_list[row].text = value
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1300 if row==0: self.handler.on_name_change(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1301
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1302 def refresh_row(self,rowi):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1303 self.SetCellValue(rowi,0,self.n_list[rowi].tag)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1304 self.SetReadOnly(rowi,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1305 self.SetCellValue(rowi,1,self.n_list[rowi].text)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1306
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1307 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1308 (w,h) = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1309 cols = self.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1310 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1311 for i in range(0,cols): self.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1312 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1313 self.Refresh()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1314
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1315 class inventory_grid(wx.grid.Grid):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1316 """grid for gen info"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1317 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1318 pname = handler.xml.set("name", 'Money and Inventory')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1319 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1320 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1321 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1322 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1323 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1324 self.CreateGrid(len(n_list),2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1325 self.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1326 self.SetColLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1327 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1328 i = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1329 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1330
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1331 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1332 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1333 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1334 value = self.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1335 self.n_list[row].text = value
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1336 if row==0: self.handler.on_name_change(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1337
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1338 def refresh_row(self,rowi):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1339 self.SetCellValue(rowi,0,self.n_list[rowi].tag)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1340 self.SetReadOnly(rowi,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1341 self.SetCellValue(rowi,1,self.n_list[rowi].text)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1342
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1343 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1344 (w,h) = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1345 cols = self.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1346 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1347 for i in range(0,cols): self.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1348 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1349 self.Refresh()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1350
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1351 class abil_grid(wx.grid.Grid):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1352 """grid for abilities"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1353 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1354 pname = handler.xml.set("name", 'Stats')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1355 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1356 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1357 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1358 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1359 stats = handler.xml.findall('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1360 self.CreateGrid(len(stats),3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1361 self.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1362 col_names = ['Ability','Score','Modifier']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1363 for i in range(len(col_names)): self.SetColLabelValue(i,col_names[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1364 self.stats = stats
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1365 i = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1366 for i in range(len(stats)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1367 self.char_wnd = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1368
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1369 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1370 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1371 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1372 value = self.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1373 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1374 int(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1375 self.stats[row].set('base',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1376 self.refresh_row(row)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1377 except: self.SetCellValue(row,col,"0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1378 if self.char_wnd: self.char_wnd.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1379
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1380 def refresh_row(self,rowi):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1381 s = self.stats[rowi]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1382 name = s.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1383 abbr = s.get('abbr')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1384 self.SetCellValue(rowi,0,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1385 self.SetReadOnly(rowi,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1386 self.SetCellValue(rowi,1,s.get('base'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1387 self.SetCellValue(rowi,2,str(self.handler.get_mod(abbr)))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1388 self.SetReadOnly(rowi,2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1389
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1390 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1391 (w,h) = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1392 cols = self.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1393 col_w = w/(cols+2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1394 self.SetColSize(0,col_w*3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1395 for i in range(1,cols): self.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1396 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1397 self.Refresh()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1398
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1399 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1400 for r in range(self.GetNumberRows()-1): self.refresh_row(r)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1401
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1402
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1403 class save_grid(wx.grid.Grid):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1404 """grid for saves"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1405 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1406 pname = handler.xml.set("name", 'Saves')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1407 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1408 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1409 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1410 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1411 saves = handler.xml.findall('save')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1412 self.stats = handler.char_hander.child_handlers['abilities']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1413 self.CreateGrid(len(saves),7)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1414 self.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1415 col_names = ['Save','Key','base','Abil','Magic','Misc','Total']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1416 for i in range(len(col_names)): self.SetColLabelValue(i,col_names[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1417 self.saves = saves
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1418 i = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1419 for i in range(len(saves)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1420
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1421 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1422 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1423 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1424 value = self.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1425 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1426 int(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1427 if col == 2: self.saves[row].set('base',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1428 elif col == 4: self.saves[row].set('magmod',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1429 elif col == 4: self.saves[row].set('miscmod',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1430 self.refresh_row(row)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1431 except: self.SetCellValue(row,col,"0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1432
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1433 def refresh_row(self,rowi):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1434 s = self.saves[rowi]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1435 name = s.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1436 self.SetCellValue(rowi,0,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1437 self.SetReadOnly(rowi,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1438 stat = s.get('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1439 self.SetCellValue(rowi,1,stat)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1440 self.SetReadOnly(rowi,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1441 self.SetCellValue(rowi,2,s.get('base'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1442 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat)))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1443 self.SetReadOnly(rowi,3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1444 self.SetCellValue(rowi,4,s.get('magmod'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1445 self.SetCellValue(rowi,5,s.get('miscmod'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1446 mod = str(self.handler.get_mod(name))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1447 self.SetCellValue(rowi,6,mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1448 self.SetReadOnly(rowi,6)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1449
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1450 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1451 (w,h) = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1452 cols = self.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1453 col_w = w/(cols+2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1454 self.SetColSize(0,col_w*3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1455 for i in range(1,cols): self.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1456 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1457 self.Refresh()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1458
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1459 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1460 for r in range(self.GetNumberRows()): self.refresh_row(r)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1461
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1462
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1463 class skill_grid(wx.grid.Grid):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1464 """ panel for skills """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1465 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1466 pname = handler.xml.set("name", 'Skills')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1467 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1468 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1469 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1470 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1471 skills = handler.xml.findall('skill')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1472 self.stats = handler.char_hander.child_handlers['abilities']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1473 self.CreateGrid(len(skills),6)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1474 self.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1475 col_names = ['Skill','Key','Rank','Abil','Misc','Total']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1476 for i in range(len(col_names)): self.SetColLabelValue(i,col_names[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1477 rowi = 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1478 self.skills = skills
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1479 for i in range(len(skills)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1480
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1481 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1482 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1483 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1484 value = self.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1485 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1486 int(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1487 if col == 2: self.skills[row].set('rank',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1488 elif col == 4: self.skills[row].set('misc',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1489 self.refresh_row(row)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1490 except: self.SetCellValue(row,col,"0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1491
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1492 def refresh_row(self,rowi):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1493 s = self.skills[rowi]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1494 name = s.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1495 self.SetCellValue(rowi,0,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1496 self.SetReadOnly(rowi,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1497 stat = s.get('stat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1498 self.SetCellValue(rowi,1,stat)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1499 self.SetReadOnly(rowi,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1500 self.SetCellValue(rowi,2,s.get('rank'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1501 self.SetCellValue(rowi,3,str(self.stats.get_mod(stat)))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1502 self.SetReadOnly(rowi,3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1503 self.SetCellValue(rowi,4,s.get('misc'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1504 mod = str(self.handler.get_mod(name))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1505 self.SetCellValue(rowi,5,mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1506 self.SetReadOnly(rowi,5)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1507
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1508 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1509 (w,h) = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1510 cols = self.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1511 col_w = w/(cols+2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1512 self.SetColSize(0,col_w*3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1513 for i in range(1,cols): self.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1514 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1515 self.Refresh()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1516
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1517 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1518 for r in range(self.GetNumberRows()): self.refresh_row(r)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1519
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1520
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1521 class feat_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1522 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1523 pname = handler.xml.set("name", 'Feats')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1524 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1525 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1526 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1527 sizer.Add(wx.Button(self, 10, "Remove Feat"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1528 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1529 sizer.Add(wx.Button(self, 20, "Add Feat"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1530 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1531 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1532 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1533 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1534
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1535 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1536 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1537 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1538 self.grid.CreateGrid(len(n_list),2,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1539 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1540 self.grid.SetColLabelValue(0,"Feat")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1541 self.grid.SetColLabelValue(1,"Type")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1542 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1543 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1544 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1545
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1546 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1547 feat = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1548 name = feat.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1549 type = feat.get('type')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1550 self.grid.SetCellValue(i,0,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1551 self.grid.SetReadOnly(i,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1552 self.grid.SetCellValue(i,1,type)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1553 self.grid.SetReadOnly(i,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1554
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1555 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1556 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1557 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1558 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1559 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1560 self.xml.removeChild(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1561
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1562 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1563 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1564 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20feats.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1565 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1566 f_list = self.temp_dom.findall('feat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1567 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1568 for f in f_list: opts.append(f.get('name'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1569 dlg = wx.SingleChoiceDialog(self,'Choose Feat','Feats',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1570 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1571 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1572 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1573 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1574 self.n_list = self.xml.findall('feat')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1575 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1576 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1577
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1578 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1579 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1580 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1581 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1582 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1583 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1584 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1585 for i in range(0,cols): self.grid.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1586
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1587 class spell_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1588 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1589 pname = handler.xml.set("name", 'Arcane Spells')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1590 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1591 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1592 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1593 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1594 sizer.Add(wx.Button(self, 10, "Remove Spell"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1595 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1596 sizer.Add(wx.Button(self, 20, "Add Spell"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1597 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1598 sizer.Add(wx.Button(self, 30, "Refresh Spells"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1599 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1600 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1601 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1602 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1603 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1604 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1605 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1606 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1607 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1608 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1609 self.grid.CreateGrid(len(n_list),4,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1610 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1611 self.grid.SetColLabelValue(0,"No.")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1612 self.grid.SetColLabelValue(1,"Lvl")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1613 self.grid.SetColLabelValue(2,"Spell")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1614 self.grid.SetColLabelValue(3,"Desc")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1615 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1616 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1617
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1618 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1619 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1620 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1621 value = self.grid.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1622 if col == 0: self.n_list[row].set('memrz',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1623
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1624 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1625 spell = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1626 memrz = spell.get('memrz')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1627 name = spell.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1628 type = spell.get('desc')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1629 level = spell.get('level')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1630 self.grid.SetCellValue(i,0,memrz)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1631 self.grid.SetCellValue(i,2,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1632 self.grid.SetReadOnly(i,2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1633 self.grid.SetCellValue(i,3,type)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1634 self.grid.SetReadOnly(i,3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1635 self.grid.SetCellValue(i,1,level)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1636 self.grid.SetReadOnly(i,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1637
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1638 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1639 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1640 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1641 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1642 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1643 self.xml.removeChild(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1644 self.handler.refresh_spells()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1645
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1646 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1647 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1648 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20spells.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1649 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1650 f_list = self.temp_dom.findall('spell')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1651 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1652 for f in f_list: opts.append("(" + f.get('level') + ")" + f.get('name'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1653 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1654 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1655 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1656 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1657 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1658 self.n_list = self.xml.findall('spell')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1659 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1660 self.handler.refresh_spells()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1661 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1662
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1663 def on_refresh_spells( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1664 f_list = self.xml.findall('spell')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1665 for spell in f_list: spell.set( 'used', '0' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1666
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1667 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1668 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1669 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1670 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1671 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1672 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1673 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1674 for i in range(0,cols): self.grid.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1675 self.grid.SetColSize(0,w * 0.10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1676 self.grid.SetColSize(1,w * 0.10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1677 self.grid.SetColSize(2,w * 0.30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1678 self.grid.SetColSize(3,w * 0.50)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1679
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1680 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1681 for i in range(len(self.n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1682
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1683 class divine_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1684 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1685 pname = handler.xml.set("name", 'Divine Spells')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1686 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1687 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1688 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1689 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1690 sizer.Add(wx.Button(self, 10, "Remove Spell"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1691 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1692 sizer.Add(wx.Button(self, 20, "Add Spell"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1693 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1694 sizer.Add(wx.Button(self, 30, "Refresh Spells"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1695 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1696 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1697 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1698 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1699 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1700 self.Bind(wx.EVT_BUTTON, self.on_refresh_spells, id=30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1701 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1702 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1703 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1704 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1705 self.grid.CreateGrid(len(n_list),4,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1706 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1707 self.grid.SetColLabelValue(0,"No.")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1708 self.grid.SetColLabelValue(1,"Lvl")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1709 self.grid.SetColLabelValue(2,"Spell")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1710 self.grid.SetColLabelValue(3,"Desc")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1711 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1712 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1713
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1714 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1715 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1716 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1717 value = self.grid.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1718 if col == 0: self.n_list[row].set('memrz',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1719
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1720
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1721 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1722 spell = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1723 memrz = spell.get('memrz')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1724 name = spell.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1725 type = spell.get('desc')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1726 level = spell.get('level')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1727 self.grid.SetCellValue(i,0,memrz)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1728 self.grid.SetCellValue(i,2,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1729 self.grid.SetReadOnly(i,2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1730 self.grid.SetCellValue(i,3,type)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1731 self.grid.SetReadOnly(i,3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1732 self.grid.SetCellValue(i,1,level)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1733 self.grid.SetReadOnly(i,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1734
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1735 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1736 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1737 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1738 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1739 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1740 self.xml.remove(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1741 self.handler.refresh_spells()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1742
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1743 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1744 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1745 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20divine.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1746 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1747 f_list = self.temp_dom.findall('gift')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1748 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1749 for f in f_list: opts.append("(" + f.get('level') + ")" + f.get('name'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1750 dlg = wx.SingleChoiceDialog(self,'Choose Spell','Spells',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1751 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1752 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1753 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1754 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1755 self.n_list = self.xml.findall('gift')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1756 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1757 self.handler.refresh_spells()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1758 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1759
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1760 def on_refresh_spells( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1761 f_list = self.xml.findall('gift')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1762 for spell in f_list: spell.set( 'used', '0' )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1763
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1764 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1765 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1766 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1767 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1768 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1769 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1770 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1771 for i in range(0,cols): self.grid.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1772 self.grid.SetColSize(0,w * 0.10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1773 self.grid.SetColSize(1,w * 0.10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1774 self.grid.SetColSize(2,w * 0.30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1775 self.grid.SetColSize(3,w * 0.50)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1776
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1777 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1778 for i in range(len(self.n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1779
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1780
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1781 class power_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1782 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1783 pname = handler.xml.set("name", 'Pionic Powers')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1784 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1785 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1786 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1787 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1788 sizer.Add(wx.Button(self, 10, "Remove Power"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1789 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1790 sizer.Add(wx.Button(self, 20, "Add Power"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1791 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1792 sizer.Add(wx.Button(self, 30, "Refresh Powers"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1793 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1794 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1795 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1796 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1797 self.Bind(wx.EVT_BUTTON, self.on_refresh_powers, id=30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1798 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1799 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1800 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1801 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1802 self.grid.CreateGrid(len(n_list),5,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1803 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1804 self.grid.SetColLabelValue(0,"PP")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1805 self.grid.SetColLabelValue(1,"Lvl")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1806 self.grid.SetColLabelValue(2,"Power")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1807 self.grid.SetColLabelValue(3,"Desc")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1808 self.grid.SetColLabelValue(4,"Type")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1809 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1810 self.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1811 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1812 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1813
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1814 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1815 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1816 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1817 value = self.grid.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1818
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1819 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1820 power = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1821 point = power.get('point')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1822 name = power.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1823 type = power.get('desc')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1824 test = power.get('test')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1825 level = power.get('level')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1826 self.grid.SetCellValue(i,0,point)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1827 self.grid.SetReadOnly(i,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1828 self.grid.SetCellValue(i,1,level)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1829 self.grid.SetReadOnly(i,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1830 self.grid.SetCellValue(i,2,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1831 self.grid.SetReadOnly(i,2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1832 self.grid.SetCellValue(i,3,type)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1833 self.grid.SetReadOnly(i,3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1834 self.grid.SetCellValue(i,4,test)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1835 self.grid.SetReadOnly(i,4)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1836
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1837 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1838 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1839 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1840 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1841 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1842 self.xml.removeChild(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1843 self.handler.refresh_powers()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1844
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1845 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1846 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1847 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20powers.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1848 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1849 f_list = self.temp_dom.findall('power')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1850 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1851 for f in f_list: opts.append("(" + f.get('level') + ") - " + f.get('name') + " - " + f.get('test'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1852 dlg = wx.SingleChoiceDialog(self,'Choose Power','Powers',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1853 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1854 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1855 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1856 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1857 self.n_list = self.xml.findall('power')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1858 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1859 self.handler.refresh_powers()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1860 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1861
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1862 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1863 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1864 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1865 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1866 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1867 self.xml.remove(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1868 self.n_list = self.xml.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1869 self.handler.refresh_weapons()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1870
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1871 def on_refresh_powers( self, evt ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1872 mfre = self.handler.get_char_pp('maxfree')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1873 mpp = self.handler.get_char_pp('max1')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1874 self.handler.set_char_pp( 'free', mfre )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1875 self.handler.set_char_pp( 'current1', mpp )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1876
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1877 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1878 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1879 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1880 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1881 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1882 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1883 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1884 for i in range(0,cols): self.grid.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1885 self.grid.SetColSize(0,w * 0.05)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1886 self.grid.SetColSize(1,w * 0.05)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1887 self.grid.SetColSize(2,w * 0.30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1888 self.grid.SetColSize(3,w * 0.30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1889 self.grid.SetColSize(4,w * 0.30)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1890
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1891 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1892 for i in range(len(self.n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1893
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1894 class attack_grid(wx.grid.Grid):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1895 """grid for attacks"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1896 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1897 pname = handler.xml.set("name", 'Melee')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1898 wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1899 self.parent = parent
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1900 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1901 self.babs = self.handler.melee
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1902 self.CreateGrid(1,7)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1903 self.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1904 col_names = ['base','base 2','base 3','base 4','base 5','base 6','misc']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1905 for i in range(len(col_names)): self.SetColLabelValue(i,col_names[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1906 self.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1907 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1908 self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1909
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1910 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1911 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1912 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1913 value = self.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1914 try: int(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1915 except:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1916 value = "0"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1917 self.SetCellValue( row, col, value )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1918 attribs = ['base','second','third','forth','fifth','sixth','misc']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1919 self.babs.set( attribs[col], value )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1920 self.parent.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1921
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1922 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1923 attack_mods = self.handler.get_attack_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1924 for i in range(0,7): self.SetCellValue( 0, i, str(attack_mods[i]) )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1925
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1926 def on_size(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1927 (w,h) = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1928 cols = self.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1929 col_w = w/cols
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1930 for i in range(0,cols): self.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1931 evt.Skip()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1932 self.Refresh()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1933
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1934 class weapon_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1935 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1936 pname = handler.xml.set("name", 'Weapons')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1937 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1938 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1939 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1940 sizer.Add(wx.Button(self, 10, "Remove Weapon"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1941 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1942 sizer.Add(wx.Button(self, 20, "Add Weapon"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1943 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1944 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1945 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1946 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1947 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1948 n_list = handler.xml.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1949 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1950 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1951 self.handler = handler
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1952 self.grid.CreateGrid(len(n_list),8,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1953 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1954 col_names = ['Name','damage','mod','critical','type','weight','range','size']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1955 for i in range(len(col_names)): self.grid.SetColLabelValue(i,col_names[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1956 self.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1957 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1958 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1959
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1960 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1961 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1962 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1963 value = self.grid.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1964 if col == 0:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1965 self.n_list[row].set('name',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1966 self.handler.refresh_weapons();
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1967 else: self.n_list[row].set(self.grid.GetColLabelValue(col),value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1968
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1969 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1970 n = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1971 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1972 mod = n.get('mod')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1973 ran = n.get('range')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1974 self.grid.SetCellValue(i,0,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1975 self.grid.SetCellValue(i,1,n.get('damage'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1976 self.grid.SetCellValue(i,2,mod)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1977 self.grid.SetCellValue(i,3,n.get('critical'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1978 self.grid.SetCellValue(i,4,n.get('type'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1979 self.grid.SetCellValue(i,5,n.get('weight'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1980 self.grid.SetCellValue(i,6,ran)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1981 self.grid.SetCellValue(i,7,n.get('size') )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1982
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1983 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1984 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1985 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1986 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1987 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1988 self.xml.remove(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1989 self.n_list = self.xml.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1990 self.handler.refresh_weapons()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1991
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1992 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1993 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1994 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20weapons.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1995 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1996 f_list = self.temp_dom.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1997 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1998 for f in f_list: opts.append(f.get('name'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
1999 dlg = wx.SingleChoiceDialog(self,'Choose Weapon','Weapon List',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2000 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2001 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2002 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2003 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2004 self.n_list = self.xml.findall('weapon')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2005 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2006 self.handler.refresh_weapons()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2007 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2008
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2009 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2010 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2011 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2012 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2013 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2014 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2015 col_w = w/(cols+1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2016 self.grid.SetColSize(0,col_w*2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2017 for i in range(1,cols): self.grid.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2018
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2019 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2020 for i in range(len(self.n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2021
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2022
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2023 class attack_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2024 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2025 pname = handler.xml.set("name", 'Melee')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2026 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2027
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2028 self.a_grid = attack_grid(self, handler)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2029 self.w_panel = weapon_panel(self, handler)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2030 self.sizer = wx.BoxSizer(wx.VERTICAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2031 self.sizer.Add(self.a_grid, 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2032 self.sizer.Add(self.w_panel, 2, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2033 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2034 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2035
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2036 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2037 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2038 self.sizer.SetDimension(0,0,s[0],s[1])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2039
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2040 def refresh_data(self):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2041 self.w_panel.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2042 self.a_grid.refresh_data()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2043
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2044
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2045 class ac_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2046 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2047 pname = handler.xml.set("name", 'Armor')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2048 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2049 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2050 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2051 sizer.Add(wx.Button(self, 10, "Remove Armor"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2052 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2053 sizer.Add(wx.Button(self, 20, "Add Armor"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2054 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2055 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2056 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2057 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2058 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2059 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2060 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2061 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2062 col_names = ['Armor','bonus','maxdex','cp','sf','weight','speed','type']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2063 self.grid.CreateGrid(len(n_list),len(col_names),1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2064 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2065 for i in range(len(col_names)): self.grid.SetColLabelValue(i,col_names[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2066 self.atts =['name','bonus','maxdex','checkpenalty','spellfailure','weight','speed','type']
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2067 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2068 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2069 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2070
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2071 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2072 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2073 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2074 value = self.grid.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2075 if col >= 1 and col <= 5:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2076 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2077 int(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2078 self.n_list[row].set(self.atts[col],value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2079 except: self.grid.SetCellValue(row,col,"0")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2080 else: self.n_list[row].set(self.atts[col],value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2081
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2082 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2083 n = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2084 for y in range(len(self.atts)):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2085 self.grid.SetCellValue(i,y,n.get(self.atts[y]))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2086
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2087 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2088 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2089 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2090 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2091 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2092 self.xml.remove(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2093
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2094 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2095 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2096 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20armor.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2097 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2098 f_list = self.temp_dom.findall('armor')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2099 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2100 for f in f_list: opts.append(f.get('name'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2101 dlg = wx.SingleChoiceDialog(self,'Choose Armor:','Armor List',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2102 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2103 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2104 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2105 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2106 self.n_list = self.xml.findall('armor')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2107 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2108 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2109
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2110 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2111 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2112 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2113 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2114 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2115 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2116 col_w = w/(cols+2)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2117 self.grid.SetColSize(0,col_w*3)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2118 for i in range(1,cols): self.grid.SetColSize(i,col_w)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2119
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2120
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2121 class class_panel(wx.Panel):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2122 def __init__(self, parent, handler):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2123 pname = handler.xml.set("name", 'Class')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2124 wx.Panel.__init__(self, parent, -1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2125 self.grid =wx.grid.Grid(self, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2126 sizer = wx.BoxSizer(wx.HORIZONTAL)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2127 sizer.Add(wx.Button(self, 10, "Remove Class"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2128 sizer.Add(wx.Size(10,10))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2129 sizer.Add(wx.Button(self, 20, "Add Class"), 1, wx.EXPAND)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2130 self.sizer = sizer
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2131 self.SetSizer(self.sizer)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2132 self.Bind(wx.EVT_SIZE, self.on_size)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2133 self.Bind(wx.EVT_BUTTON, self.on_remove, id=10)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2134 self.Bind(wx.EVT_BUTTON, self.on_add, id=20)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2135 self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2136
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2137 n_list = handler.xml[:]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2138 self.n_list = n_list
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2139 self.xml = handler.xml
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2140 self.grid.CreateGrid(len(n_list),2,1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2141 self.grid.SetRowLabelSize(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2142 self.grid.SetColLabelValue(0,"Class")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2143 self.grid.SetColLabelValue(1,"Level")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2144 for i in range(len(n_list)): self.refresh_row(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2145 self.temp_dom = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2146
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2147 def on_cell_change(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2148 row = evt.GetRow()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2149 col = evt.GetCol()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2150 value = self.grid.GetCellValue(row,col)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2151 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2152 int(value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2153 self.n_list[row].set('level',value)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2154 except: self.grid.SetCellValue(row,col,"1")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2155
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2156 def refresh_row(self,i):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2157 n = self.n_list[i]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2158 name = n.get('name')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2159 level = n.get('level')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2160 self.grid.SetCellValue(i,0,name)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2161 self.grid.SetReadOnly(i,0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2162 self.grid.SetCellValue(i,1,level)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2163
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2164 def on_remove(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2165 rows = self.grid.GetNumberRows()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2166 for i in range(rows):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2167 if self.grid.IsInSelection(i,0):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2168 self.grid.DeleteRows(i)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2169 self.xml.remove(self.n_list[i])
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2170
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2171 def on_add(self,evt):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2172 if not self.temp_dom:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2173 tree = parse(orpg.dirpath.dir_struct["d20"]+"d20classes.xml")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2174 self.temp_dom = tree.getroot()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2175 f_list = self.temp_dom.findall('class')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2176 opts = []
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2177 for f in f_list: opts.append(f.get('name'))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2178 dlg = wx.SingleChoiceDialog(self,'Choose Class','Classes',opts)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2179 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2180 i = dlg.GetSelection()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2181 new_node = self.xml.append(XML(tostring(f_list[i])))
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2182 self.grid.AppendRows(1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2183 self.n_list = self.xml.findall('class')
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2184 self.refresh_row(self.grid.GetNumberRows()-1)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2185 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2186
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2187 def on_size(self,event):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2188 s = self.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2189 self.grid.SetDimensions(0,0,s[0],s[1]-25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2190 self.sizer.SetDimension(0,s[1]-25,s[0],25)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2191 (w,h) = self.grid.GetClientSizeTuple()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2192 cols = self.grid.GetNumberCols()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2193 col_w = w/(cols)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 152
diff changeset
2194 for i in range(0,cols): self.grid.SetColSize(i,col_w)