annotate orpg/gametree/nodehandlers/d20.py @ 217:c719a07cd28d beta

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