Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/map_miniature_nodehandler.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | c54768cffbd4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: map_miniature_nodehandler.py | |
21 # Author: Andrew Bennett | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: map_miniature_nodehandler.py,v 1.17 2007/12/07 20:39:48 digitalxero Exp $ | |
25 # | |
26 # Description: nodehandler for miniature images | |
27 # | |
28 | |
29 #from nodehandlers.core import * | |
30 from core import * | |
31 from orpg.gametree import * | |
32 from orpg.mapper.miniatures_msg import mini_msg | |
33 from orpg.mapper.images import ImageHandler | |
34 import urllib | |
35 | |
36 | |
37 class map_miniature_handler(node_handler): | |
38 | |
39 """ A node handler for miniatures | |
40 <nodehandler name='Elf-1' module='map_miniature_nodehandler' class='map_miniature_handler' > | |
41 <miniature id='' label='Elf-1' posx='' posy='' path='' ... /> | |
42 </nodehandler > | |
43 """ | |
44 | |
45 | |
46 def __init__(self,xml_dom,tree_node): | |
47 node_handler.__init__(self,xml_dom,tree_node) | |
48 self.mapper = open_rpg.get_component("map") | |
49 self.session = open_rpg.get_component("session") | |
50 self.miniature_dom = self.master_dom.getElementsByTagName("miniature") | |
51 if self.miniature_dom: | |
52 self.miniature_dom = self.miniature_dom[0] # convert to scalar | |
53 | |
54 def get_scaled_bitmap(self,x,y): | |
55 my_mini_msg = mini_msg() | |
56 my_mini_msg.init_from_dom(self.miniature_dom) | |
57 bmp = None | |
58 path = my_mini_msg.get_prop("path") | |
59 | |
60 if path: | |
61 path = urllib.unquote(path) | |
62 if ImageHandler.Cache.has_key(path): | |
63 bmp = ImageHandler.Cache[path] | |
64 else: | |
65 #bmp = ImageHandler.directLoad(path, 'miniature', id) | |
66 bmp = ImageHandler.directLoad(path)# Old Code TaS. | |
67 | |
68 if bmp: | |
69 img = wx.ImageFromMime(ImageHandler.Cache[path][1], ImageHandler.Cache[path][2]) | |
70 #img = wx.ImageFromBitmap(bmp) | |
71 scaled_img = img.Scale(x,y) | |
72 scaled_bmp = scaled_img.ConvertToBitmap() | |
73 scratch = scaled_img.ConvertToBitmap() | |
74 memDC = wx.MemoryDC() | |
75 memDC.BeginDrawing() | |
76 memDC.SelectObject(scaled_bmp) | |
77 memDC.SetBrush(wx.WHITE_BRUSH) | |
78 memDC.SetPen(wx.WHITE_PEN) | |
79 memDC.DrawRectangle(0,0,x,y) | |
80 memDC.SetPen(wx.NullPen) | |
81 memDC.SetBrush(wx.NullBrush) | |
82 memDC.DrawBitmap(scratch,0,0,1) | |
83 memDC.SelectObject(wx.NullBitmap) | |
84 memDC.EndDrawing() | |
85 del memDC | |
86 return scaled_bmp | |
87 | |
88 def map_aware(self): | |
89 return 1 | |
90 | |
91 def get_miniature_XML(self): | |
92 my_mini_msg = mini_msg() | |
93 my_mini_msg.init_from_dom(self.miniature_dom) | |
94 my_mini_msg.init_prop("id",self.session.get_next_id()) | |
95 label = self.master_dom.getAttribute("name") | |
96 my_mini_msg.init_prop("label",label) | |
97 new_xml = my_mini_msg.get_all_xml() | |
98 return new_xml | |
99 | |
100 def get_to_map_XML(self): | |
101 new_xml = self.get_miniature_XML() | |
102 new_xml = str("<map action='update'><miniatures>" + new_xml + "</miniatures></map>") | |
103 return new_xml | |
104 | |
105 def on_send_to_map(self,evt): | |
106 if isinstance(evt, wx.MouseEvent) and evt.LeftUp():# as opposed to a menu event | |
107 dc = wx.ClientDC(self.mapper.canvas) | |
108 self.mapper.canvas.PrepareDC(dc) | |
109 grid = self.mapper.canvas.layers['grid'] | |
110 dc.SetUserScale(grid.mapscale, grid.mapscale) | |
111 pos = evt.GetLogicalPosition(dc) | |
112 try: | |
113 align = int(self.miniature_dom.getAttribute("align")) | |
114 width = int(self.miniature_dom.getAttribute("width")) | |
115 height = int(self.miniature_dom.getAttribute("height")) | |
116 pos = grid.get_snapped_to_pos(pos, align, width, height) | |
117 except: | |
118 pass | |
119 self.miniature_dom.setAttribute("posx", str(pos.x)) | |
120 self.miniature_dom.setAttribute("posy", str(pos.y)) | |
121 new_xml = self.get_to_map_XML() | |
122 if (self.session.my_role() != self.session.ROLE_GM) and (self.session.my_role() != self.session.ROLE_PLAYER): | |
123 open_rpg.get_component("chat").InfoPost("You must be either a player or GM to use the miniature Layer") | |
124 return | |
125 | |
126 if new_xml: | |
127 self.mapper.new_data(new_xml) | |
128 self.session.send(new_xml) | |
129 else: | |
130 print "problem converting old mini xml to new mini xml" | |
131 | |
132 def about(self): | |
133 return "Miniature node by Andrew Bennett" | |
134 | |
135 def tohtml(self): | |
136 html_str = "<table><tr><td>" | |
137 html_str += "<center><img src='" + self.miniature_dom.getAttribute("path") + "'>" | |
138 html_str += "</center></td></tr>\n" | |
139 html_str += "<tr><td><center>" + self.master_dom.getAttribute("name") + "</center></td></tr></table>" | |
140 return html_str |