annotate plugins/bcg/tokens.py @ 105:2f2bebe9c77f alpha

Traipse Alpha 'OpenRPG' {091006-03} 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: 00: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! 01: Forgot the default_server_bookmarks.xml; added. 02: Bookmarks working with no errors now! Sweet! 03: Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code.
author sirebral
date Tue, 06 Oct 2009 22:16:34 -0500
parents
children
rev   line source
105
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
2 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
4 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
8 # (at your option) any later version.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
9 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
14 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
18 # --
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
19 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
20 # File: mapper/tokens.py
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
21 # Author: Chris Davis
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
22 # Maintainer:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
23 # Version:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
24 # $Id: tokens.py,v 1.46 2007/12/07 20:39:50 digitalxero Exp $
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
25 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
26 # Description: This file contains some of the basic definitions for the chat
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
27 # utilities in the orpg project.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
28 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
29 __version__ = "$Id: tokens.py,v 1.46 2007/12/07 20:39:50 digitalxero Exp $"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
30
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
31 from orpg.mapper.base import *
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
32 import thread
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
33 import time
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
34 import urllib
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
35 import os.path
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
36
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
37 from orpg.tools.orpg_settings import settings
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
38
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
39 MIN_STICKY_BACK = -0XFFFFFF
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
40 MIN_STICKY_FRONT = 0xFFFFFF
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
41
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
42 ##----------------------------------------
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
43 ## token object
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
44 ##----------------------------------------
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
45
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
46 FACE_NONE = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
47 FACE_NORTH = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
48 FACE_NORTHEAST = 2
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
49 FACE_EAST = 3
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
50 FACE_SOUTHEAST = 4
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
51 FACE_SOUTH = 5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
52 FACE_SOUTHWEST = 6
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
53 FACE_WEST = 7
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
54 FACE_NORTHWEST = 8
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
55 SNAPTO_ALIGN_CENTER = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
56 SNAPTO_ALIGN_TL = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
57
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
58 def cmp_zorder(first,second):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
59 f = first.zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
60 s = second.zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
61 if f == None: f = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
62 if s == None: s = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
63 if f == s: value = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
64 elif f < s: value = -1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
65 else: value = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
66 return value
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
67
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
68 class BmpToken:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
69 def __init__(self, id,path, bmp, pos=cmpPoint(0,0),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
70 heading=FACE_NONE, rotate=0, label="",
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
71 locked=False, hide=False, snap_to_align=SNAPTO_ALIGN_CENTER,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
72 zorder=0, width=0, height=0, log=None, local=False, localPath='', localTime=-1):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
73 self.heading = heading
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
74 self.rotate = rotate
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
75 self.label = label
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
76 self.path = path
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
77 self.bmp = bmp
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
78 self.pos = pos
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
79 self.selected = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
80 self.locked = locked
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
81 self.snap_to_align = snap_to_align
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
82 self.hide = hide
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
83 self.id = id
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
84 self.zorder = zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
85 self.left = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
86 self.local = local
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
87 self.localPath = localPath
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
88 self.localTime = localTime
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
89 if not width: self.width = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
90 else: self.width = width
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
91 if not height: self.height = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
92 else: self.height = height
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
93 self.right = bmp.GetWidth()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
94 self.top = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
95 self.bottom = bmp.GetHeight()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
96 self.isUpdated = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
97 self.gray = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
98 self.drawn = {}
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
99
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
100 def __del__(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
101 del self.bmp
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
102 self.bmp = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
103
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
104 def set_bmp(self, bmp):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
105 self.bmp = bmp
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
106
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
107 def set_min_props(self, heading=FACE_NONE, rotate=0, label="", locked=False, hide=False, width=0, height=0):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
108 self.heading = heading
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
109 self.rotate = rotate
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
110 self.label = label
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
111 if locked: self.locked = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
112 else: self.locked = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
113 if hide: self.hide = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
114 else: self.hide = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
115 self.width = int(width)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
116 self.height = int(height)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
117 self.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
118
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
119 def hit_test(self, pt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
120 rect = self.get_rect()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
121 result = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
122 result = rect.InsideXY(pt.x, pt.y)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
123 return result
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
124
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
125 def get_rect(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
126 ret = wx.Rect(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
127 return ret
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
128
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
129 def draw(self, dc, mini_layer, op=wx.COPY):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
130 if isinstance(self.bmp, tuple):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
131 self.bmp = wx.ImageFromMime(self.bmp[1], self.bmp[2]).ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
132 if self.bmp != None and self.bmp.Ok():
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
133 # check if hidden and GM: we outline the mini in grey (little bit smaller than the actual size)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
134 # and write the label in the center of the mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
135 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
136 # set the width and height of the image
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
137 if self.width and self.height:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
138 tmp_image = self.bmp.ConvertToImage()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
139 tmp_image.Rescale(int(self.width), int(self.height))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
140 tmp_image.ConvertAlphaToMask()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
141 self.bmp = tmp_image.ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
142 mask = wx.Mask(self.bmp, wx.Colour(tmp_image.GetMaskRed(),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
143 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue()))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
144 self.bmp.SetMask(mask)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
145 del tmp_image
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
146 del mask
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
147 self.left = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
148 self.right = self.bmp.GetWidth()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
149 self.top = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
150 self.bottom = self.bmp.GetHeight()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
151 # grey outline
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
152 graypen = wx.Pen("gray", 1, wx.DOT)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
153 dc.SetPen(graypen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
154 dc.SetBrush(wx.TRANSPARENT_BRUSH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
155 #if width or height < 20 then offset = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
156 if self.bmp.GetWidth() <= 20: xoffset = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
157 else: xoffset = 5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
158 if self.bmp.GetHeight() <= 20: yoffset = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
159 else: yoffset = 5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
160 dc.DrawRectangle(self.pos.x + xoffset,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
161 self.pos.y + yoffset, self.bmp.GetWidth() - (xoffset * 2),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
162 self.bmp.GetHeight() - (yoffset * 2))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
163 dc.SetBrush(wx.NullBrush)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
164 dc.SetPen(wx.NullPen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
165 ## draw label in the center of the mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
166 label = mini_layer.get_mini_label(self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
167 if len(label):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
168 dc.SetTextForeground(wx.RED)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
169 (textWidth,textHeight) = dc.GetTextExtent(label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
170 x = self.pos.x +((self.bmp.GetWidth() - textWidth) /2) - 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
171 y = self.pos.y + (self.bmp.GetHeight() / 2)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
172 dc.SetPen(wx.GREY_PEN)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
173 dc.SetBrush(wx.LIGHT_GREY_BRUSH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
174 dc.DrawRectangle(x, y, textWidth+2, textHeight+2)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
175 if (textWidth+2 > self.right):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
176 self.right += int((textWidth+2-self.right)/2)+1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
177 self.left -= int((textWidth+2-self.right)/2)+1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
178 self.bottom = y+textHeight+2-self.pos.y
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
179 dc.SetPen(wx.NullPen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
180 dc.SetBrush(wx.NullBrush)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
181 dc.DrawText(label, x+1, y+1)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
182
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
183 #selected outline
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
184 if self.selected:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
185 dc.SetPen(wx.RED_PEN)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
186 dc.SetBrush(wx.TRANSPARENT_BRUSH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
187 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
188 dc.SetBrush(wx.NullBrush)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
189 dc.SetPen(wx.NullPen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
190 return True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
191 elif self.hide: return True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
192
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
193 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
194 # set the width and height of the image
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
195 bmp = self.bmp
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
196 if self.width and self.height:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
197 tmp_image = self.bmp.ConvertToImage()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
198 tmp_image.Rescale(int(self.width), int(self.height))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
199 tmp_image.ConvertAlphaToMask()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
200 self.bmp = tmp_image.ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
201 mask = wx.Mask(self.bmp, wx.Colour(tmp_image.GetMaskRed(),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
202 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue()))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
203 self.bmp.SetMask(mask)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
204 if self.gray:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
205 tmp_image = tmp_image.ConvertToGreyscale()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
206 bmp = tmp_image.ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
207 else: bmp = self.bmp
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
208
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
209 if self.rotate != 0:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
210 x = bmp.GetWidth(); print x
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
211 y = bmp.GetHeight(); print y
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
212 img = bmp.ConvertToImage()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
213 img = img.Rotate(self.rotate, (3, 80), True)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
214 img.ConvertAlphaToMask()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
215
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
216 bmp = img.ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
217 mask = wx.Mask(bmp, wx.Colour(img.GetMaskRed(),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
218 img.GetMaskGreen(), img.GetMaskBlue()))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
219 bmp.SetMask(mask)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
220
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
221 dc.DrawBitmap(bmp, self.pos.x, self.pos.y, True)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
222 component.get('drawn')[bmp] = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
223 self.left = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
224 self.right = self.bmp.GetWidth()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
225 self.top = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
226 self.bottom = self.bmp.GetHeight()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
227
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
228 # Draw the heading if needed
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
229 if self.heading:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
230 x_adjust = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
231 y_adjust = 4
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
232 x_half = self.bmp.GetWidth()/2
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
233 y_half = self.bmp.GetHeight()/2
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
234 x_quarter = self.bmp.GetWidth()/4
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
235 y_quarter = self.bmp.GetHeight()/4
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
236 x_3quarter = x_quarter*3
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
237 y_3quarter = y_quarter*3
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
238 x_full = self.bmp.GetWidth()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
239 y_full = self.bmp.GetHeight()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
240 x_center = self.pos.x + x_half
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
241 y_center = self.pos.y + y_half
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
242 # Remember, the pen/brush must be a different color than the
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
243 # facing marker!!!! We'll use black/cyan for starters.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
244 # Also notice that we will draw the heading on top of the
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
245 # larger facing marker.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
246 dc.SetPen(wx.BLACK_PEN)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
247 dc.SetBrush(wx.CYAN_BRUSH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
248 triangle = []
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
249
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
250 # Figure out which direction to draw the marker!!
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
251 if self.heading == FACE_NORTH:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
252 triangle.append(cmpPoint(x_center - x_quarter, y_center - y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
253 triangle.append(cmpPoint(x_center, y_center - y_3quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
254 triangle.append(cmpPoint(x_center + x_quarter, y_center - y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
255 elif self.heading == FACE_SOUTH:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
256 triangle.append(cmpPoint(x_center - x_quarter, y_center + y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
257 triangle.append(cmpPoint(x_center, y_center + y_3quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
258 triangle.append(cmpPoint(x_center + x_quarter, y_center + y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
259 elif self.heading == FACE_NORTHEAST:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
260 triangle.append(cmpPoint(x_center + x_quarter, y_center - y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
261 triangle.append(cmpPoint(x_center + x_3quarter, y_center - y_3quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
262 triangle.append(cmpPoint(x_center + x_half, y_center - y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
263 elif self.heading == FACE_EAST:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
264 triangle.append(cmpPoint(x_center + x_half, y_center - y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
265 triangle.append(cmpPoint(x_center + x_3quarter, y_center ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
266 triangle.append(cmpPoint(x_center + x_half, y_center + y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
267 elif self.heading == FACE_SOUTHEAST:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
268 triangle.append(cmpPoint(x_center + x_half, y_center + y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
269 triangle.append(cmpPoint(x_center + x_3quarter, y_center + y_3quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
270 triangle.append(cmpPoint(x_center + x_quarter, y_center + y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
271 elif self.heading == FACE_SOUTHWEST:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
272 triangle.append(cmpPoint(x_center - x_quarter, y_center + y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
273 triangle.append(cmpPoint(x_center - x_3quarter, y_center + y_3quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
274 triangle.append(cmpPoint(x_center - x_half, y_center + y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
275 elif self.heading == FACE_WEST:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
276 triangle.append(cmpPoint(x_center - x_half, y_center + y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
277 triangle.append(cmpPoint(x_center - x_3quarter, y_center ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
278 triangle.append(cmpPoint(x_center - x_half, y_center - y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
279 elif self.heading == FACE_NORTHWEST:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
280 triangle.append(cmpPoint(x_center - x_half, y_center - y_quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
281 triangle.append(cmpPoint(x_center - x_3quarter, y_center - y_3quarter ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
282 triangle.append(cmpPoint(x_center - x_quarter, y_center - y_half ))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
283 dc.DrawPolygon(triangle)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
284 dc.SetBrush(wx.NullBrush)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
285 dc.SetPen(wx.NullPen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
286 #selected outline
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
287 if self.selected:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
288 dc.SetPen(wx.RED_PEN)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
289 dc.SetBrush(wx.TRANSPARENT_BRUSH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
290 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
291 dc.SetBrush(wx.NullBrush)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
292 dc.SetPen(wx.NullPen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
293 # draw label
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
294 label = mini_layer.get_mini_label(self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
295 if len(label):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
296 dc.SetTextForeground(wx.RED)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
297 (textWidth,textHeight) = dc.GetTextExtent(label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
298 x = self.pos.x +((self.bmp.GetWidth() - textWidth) /2) - 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
299 y = self.pos.y + self.bmp.GetHeight() + 6
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
300 dc.SetPen(wx.WHITE_PEN)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
301 dc.SetBrush(wx.WHITE_BRUSH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
302 dc.DrawRectangle(x,y,textWidth+2,textHeight+2)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
303 if (textWidth+2 > self.right):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
304 self.right += int((textWidth+2-self.right)/2)+1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
305 self.left -= int((textWidth+2-self.right)/2)+1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
306 self.bottom = y+textHeight+2-self.pos.y
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
307 dc.SetPen(wx.NullPen)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
308 dc.SetBrush(wx.NullBrush)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
309 dc.DrawText(label,x+1,y+1)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
310 self.top-=5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
311 self.bottom+=5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
312 self.left-=5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
313 self.right+=5
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
314 return True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
315 else: return False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
316
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
317 def toxml(self, action="update"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
318 if action == "del":
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
319 xml_str = "<token action='del' id='" + self.id + "'/>"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
320 return xml_str
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
321 xml_str = "<token"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
322 xml_str += " action='" + action + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
323 xml_str += " label='" + self.label + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
324 xml_str+= " id='" + self.id + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
325 if self.pos != None:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
326 xml_str += " posx='" + str(self.pos.x) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
327 xml_str += " posy='" + str(self.pos.y) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
328 if self.heading != None: xml_str += " heading='" + str(self.heading) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
329 if self.rotate != None: xml_str += " rotate='" + str(self.rotate) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
330 if self.path != None: xml_str += " path='" + urllib.quote(self.path).replace('%3A', ':') + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
331 if self.locked: xml_str += " locked='1'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
332 else: xml_str += " locked='0'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
333 if self.hide: xml_str += " hide='1'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
334 else: xml_str += " hide='0'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
335 if self.snap_to_align != None: xml_str += " align='" + str(self.snap_to_align) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
336 if self.id != None: xml_str += " zorder='" + str(self.zorder) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
337 if self.width != None: xml_str += " width='" + str(self.width) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
338 if self.height != None: xml_str += " height='" + str(self.height) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
339 if self.local:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
340 xml_str += ' local="' + str(self.local) + '"'
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
341 xml_str += ' localPath="' + str(urllib.quote(self.localPath).replace('%3A', ':')) + '"'
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
342 xml_str += ' localTime="' + str(self.localTime) + '"'
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
343 xml_str += " />"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
344 if (action == "update" and self.isUpdated) or action == "new":
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
345 self.isUpdated = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
346 return xml_str
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
347 else: return ''
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
348
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
349 def takedom(self, xml_dom):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
350 self.id = xml_dom.getAttribute("id")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
351 if xml_dom.hasAttribute("posx"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
352 self.pos.x = int(xml_dom.getAttribute("posx"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
353 if xml_dom.hasAttribute("posy"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
354 self.pos.y = int(xml_dom.getAttribute("posy"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
355 if xml_dom.hasAttribute("heading"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
356 self.heading = int(xml_dom.getAttribute("heading"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
357 if xml_dom.hasAttribute("rotate"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
358 self.rotate = int(xml_dom.getAttribute("rotate"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
359 if xml_dom.hasAttribute("path"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
360 self.path = urllib.unquote(xml_dom.getAttribute("path"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
361 self.set_bmp(ImageHandler.load(self.path, 'token', self.id))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
362 if xml_dom.hasAttribute("locked"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
363 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
364 else: self.locked = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
365 if xml_dom.hasAttribute("hide"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
366 if xml_dom.getAttribute("hide") == '1' or xml_dom.getAttribute("hide") == 'True': self.hide = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
367 else: self.hide = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
368 if xml_dom.hasAttribute("label"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
369 self.label = xml_dom.getAttribute("label")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
370 if xml_dom.hasAttribute("zorder"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
371 self.zorder = int(xml_dom.getAttribute("zorder"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
372 if xml_dom.hasAttribute("align"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
373 if xml_dom.getAttribute("align") == '1' or xml_dom.getAttribute("align") == 'True': self.snap_to_align = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
374 else: self.snap_to_align = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
375 if xml_dom.hasAttribute("width"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
376 self.width = int(xml_dom.getAttribute("width"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
377 if xml_dom.hasAttribute("height"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
378 self.height = int(xml_dom.getAttribute("height"))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
379
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
380 ##-----------------------------
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
381 ## token layer
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
382 ##-----------------------------
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
383 class token_layer(layer_base):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
384 def __init__(self, canvas):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
385 self.canvas = canvas
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
386 layer_base.__init__(self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
387 self.id = -1 #added.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
388 self.tokens = []
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
389 self.serial_number = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
390
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
391 self.drawn = {}
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
392 component.add('drawn', self.drawn)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
393 # Set the font of the labels to be the same as the chat window
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
394 # only smaller.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
395 font_size = int(settings.get_setting('defaultfontsize'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
396 if (font_size >= 10): font_size -= 2
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
397 self.label_font = wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
398 False, settings.get_setting('defaultfont'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
399
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
400 def next_serial(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
401 self.serial_number += 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
402 return self.serial_number
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
403
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
404 def get_next_highest_z(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
405 z = len(self.tokens)+1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
406 return z
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
407
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
408 def cleanly_collapse_zorder(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
409 # lock the zorder stuff
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
410 sorted_tokens = self.tokens[:]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
411 sorted_tokens.sort(cmp_zorder)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
412 i = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
413 for mini in sorted_tokens:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
414 mini.zorder = i
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
415 i = i + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
416 # unlock the zorder stuff
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
417
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
418 def collapse_zorder(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
419 # lock the zorder stuff
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
420 sorted_tokens = self.tokens[:]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
421 sorted_tokens.sort(cmp_zorder)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
422 i = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
423 for mini in sorted_tokens:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
424 if (mini.zorder != MIN_STICKY_BACK) and (mini.zorder != MIN_STICKY_FRONT): mini.zorder = i
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
425 else: pass
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
426 i = i + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
427 # unlock the zorder stuff
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
428
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
429 def rollback_serial(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
430 self.serial_number -= 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
431
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
432 def add_token(self, id, path, pos=cmpPoint(0,0), label="", heading=FACE_NONE,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
433 rotate=0, width=0, height=0, local=False, localPath='', localTime=-1):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
434 bmp = ImageHandler.load(path, 'token', id)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
435 if bmp:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
436 mini = BmpToken(id, path, bmp, pos, heading, rotate, label,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
437 zorder=self. get_next_highest_z(), width=width,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
438 height=height, local=local, localPath=localPath, localTime=localTime)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
439 self.tokens.append(mini)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
440 self.drawn[mini.bmp] = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
441 xml_str = "<map><tokens>"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
442 xml_str += mini.toxml("new")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
443 xml_str += "</tokens></map>"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
444 component.get('session').send(xml_str)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
445
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
446 def get_token_by_id(self, id):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
447 for mini in self.tokens:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
448 if str(mini.id) == str(id):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
449 return mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
450 return None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
451
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
452 def del_token(self, min):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
453 xml_str = "<map><tokens>"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
454 xml_str += min.toxml("del")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
455 xml_str += "</tokens></map>"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
456 self.canvas.frame.session.send(xml_str)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
457 self.tokens.remove(min)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
458 del min
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
459 self.collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
460
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
461 def del_all_tokens(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
462 while len(self.tokens):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
463 min = self.tokens.pop()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
464 del min
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
465 self.collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
466
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
467 def layerDraw(self, dc, topleft, size):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
468 dc.SetFont(self.label_font)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
469 sorted_tokens = self.tokens[:]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
470 sorted_tokens.sort(cmp_zorder)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
471 for m in sorted_tokens:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
472 if (m.pos.x>topleft[0]-m.right and
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
473 m.pos.y>topleft[1]-m.bottom and
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
474 m.pos.x<topleft[0]+size[0]-m.left and
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
475 m.pos.y<topleft[1]+size[1]-m.top):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
476 """
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
477 if self.drawn.has_key(m.bmp):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
478 if self.drawn[m.bmp] == True:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
479 dc2 = wx.MemoryDC()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
480 img = m.bmp.ConvertToImage()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
481 bmp = img.ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
482
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
483 dc2.SelectObject(bmp)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
484 dc.Blit(m.pos.x, m.pos.y, img.GetHeight(), img.GetWidth(), dc2, 0, 0, wx.COPY, True, 0, 0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
485 del dc2
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
486
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
487 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
488 """
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
489 m.draw(dc, self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
490
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
491 def find_token(self, pt, only_unlocked=False):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
492 min_list = []
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
493 for m in self.tokens:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
494 if m.hit_test(pt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
495 if m.hide and self.canvas.frame.session.my_role() != self.canvas.frame.session.ROLE_GM: continue
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
496 if only_unlocked and not m.locked: min_list.append(m)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
497 elif not only_unlocked and m.locked: min_list.append(m)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
498 else: continue
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
499 if len(min_list) > 0:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
500 return min_list
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
501 else: return None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
502
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
503 def layerToXML(self, action="update"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
504 """ format """
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
505 minis_string = ""
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
506 if self.tokens:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
507 for m in self.tokens: minis_string += m.toxml(action)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
508 if minis_string != '':
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
509 s = "<tokens"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
510 s += " serial='" + str(self.serial_number) + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
511 s += ">"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
512 s += minis_string
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
513 s += "</tokens>"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
514 return s
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
515 else: return ""
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
516
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
517 def layerTakeDOM(self, xml_dom):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
518 if xml_dom.hasAttribute('serial'):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
519 self.serial_number = int(xml_dom.getAttribute('serial'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
520 children = xml_dom._get_childNodes()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
521 for c in children:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
522 action = c.getAttribute("action")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
523 id = c.getAttribute('id')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
524 if action == "del":
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
525 mini = self.get_token_by_id(id)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
526 if mini:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
527 self.tokens.remove(mini)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
528 del mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
529 elif action == "new":
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
530 pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy')))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
531 path = urllib.unquote(c.getAttribute('path'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
532 label = c.getAttribute('label')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
533 height = width = heading = rotate = snap_to_align = zorder = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
534 locked = hide = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
535 if c.hasAttribute('height'): height = int(c.getAttribute('height'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
536 if c.hasAttribute('width'): width = int(c.getAttribute('width'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
537 if c.getAttribute('locked') == 'True' or c.getAttribute('locked') == '1': locked = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
538 if c.getAttribute('hide') == 'True' or c.getAttribute('hide') == '1': hide = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
539 if c.getAttribute('heading'): heading = int(c.getAttribute('heading'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
540 if c.hasAttribute('rotate'): rotate = int(c.getAttribute('rotate'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
541 if c.hasAttribute('align'): snap_to_align = int(c.getAttribute('align'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
542 if c.getAttribute('zorder'): zorder = int(c.getAttribute('zorder'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
543 min = BmpToken(id, path, ImageHandler.load(path, 'token', id), pos, heading,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
544 rotate, label, locked, hide, snap_to_align, zorder, width, height)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
545 self.tokens.append(min)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
546 if c.hasAttribute('local') and c.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(c.getAttribute('localPath'))):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
547 localPath = urllib.unquote(c.getAttribute('localPath'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
548 local = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
549 localTime = float(c.getAttribute('localTime'))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
550 if localTime-time.time() <= 144000:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
551 file = open(localPath, "rb")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
552 imgdata = file.read()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
553 file.close()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
554 filename = os.path.split(localPath)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
555 (imgtype,j) = mimetypes.guess_type(filename[1])
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
556 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype})
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
557 thread.start_new_thread(self.upload, (postdata, localPath, True))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
558 # collapse the zorder. If the client behaved well, then nothing should change.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
559 # Otherwise, this will ensure that there's some kind of z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
560 self.collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
561 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
562 mini = self.get_token_by_id(id)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
563 if mini: mini.takedom(c)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
564
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
565 def upload(self, postdata, filename, modify=False, pos=cmpPoint(0,0)):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
566 self.lock.acquire()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
567 url = settings.get_setting('ImageServerBaseURL')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
568 file = urllib.urlopen(url, postdata)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
569 recvdata = file.read()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
570 file.close()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
571 try:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
572 xml_dom = minidom.parseString(recvdata)._get_documentElement()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
573 if xml_dom.nodeName == 'path':
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
574 path = xml_dom.getAttribute('url')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
575 path = urllib.unquote(path)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
576 if not modify:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
577 start = path.rfind("/") + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
578 if self.canvas.parent.layer_handlers[2].auto_label: min_label = path[start:len(path)-4]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
579 else: min_label = ""
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
580 id = 'mini-' + self.canvas.frame.session.get_next_id()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
581 self.add_token(id, path, pos=pos, label=min_label, local=True,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
582 localPath=filename, localTime=time.time())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
583 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
584 self.tokens[len(self.tokens)-1].local = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
585 self.tokens[len(self.tokens)-1].localPath = filename
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
586 self.tokens[len(self.tokens)-1].localTime = time.time()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
587 self.tokens[len(self.tokens)-1].path = path
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
588 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
589 print xml_dom.getAttribute('msg')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
590 except Exception, e:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
591 print e
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
592 print recvdata
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
593 urllib.urlcleanup()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
594 self.lock.release()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
595 ####################################################################
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
596 ## helper function
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
597
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
598 def get_mini_label(self, mini):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
599 # override this to change the label displayed under each mini (and the label on hidden minis)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
600 return mini.label