annotate orpg/mapper/fog.py @ 228:24769389a7ba alpha

Traipse Alpha 'OpenRPG' {100612-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 (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 04:38:29 -0500
parents 06f10429eedc
children
rev   line source
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
2 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
4 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
8 # (at your option) any later version.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
9 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
14 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
18 # --
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
19 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
20 # File: mapper/fog.py
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
21 # Author: OpenRPG Team
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
22 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
23 # Description: Maintenance of data structures required for FoW
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
24 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
25
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
26 import sys
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
27 from base import *
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
28 from random import Random
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
29 from region import *
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
30 from xml.etree.ElementTree import Element, tostring
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
31 import traceback
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
32 COURSE = 10
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
33
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
34 class FogArea:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
35 def __init__(self, outline, log):
83
f38df4bf9715 Traipse Alpha 'OpenRPG' {090909-00}
sirebral
parents: 71
diff changeset
36 self.log = log
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
37 self.outline = outline
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
38
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
39 def set_fog_props(self, str):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
40 self.outline = str
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
41
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
42 def points_to_elements(self, points=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
43 result = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
44 if points == None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
45 return result
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 20
diff changeset
46
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
47 for pairs in string.split( points, ';' ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
48 pair = string.split( pairs, ',' )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
49 p = Element( "point" )
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
50 p.set( "x", pair[0] )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
51 p.set( "y", pair[1] )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
52 result.append( p )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
53 return result
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
54
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
55 def toxml(self, action="update"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
56 xml_str = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
57 localOutline = self.outline
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
58 if localOutline != None and localOutline != "all" and localOutline != "none":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
59 localOutline = "points"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
60 elem = Element( "poly" )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
61 if action == "del":
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
62 elem.set( "action", action )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
63 elem.set( "outline", localOutline )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
64 if localOutline == 'points':
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
65 foglist = self.points_to_elements( self.outline )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
66 for p in foglist: elem.append( p )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
67 return tostring(elem)
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
68 elem.set( "action", action )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
69 if localOutline != None:
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
70 elem.set( "outline", localOutline )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
71 if localOutline == 'points':
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
72 foglist = self.points_to_elements( self.outline )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
73 for p in foglist: elem.append( p )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
74 #xml_str = elem.toxml()
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
75 return tostring(elem)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
76
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
77 class fog_layer(layer_base):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
78 def __init__(self, canvas):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
79 self.canvas = canvas
83
f38df4bf9715 Traipse Alpha 'OpenRPG' {090909-00}
sirebral
parents: 71
diff changeset
80 self.log = component.get('log')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
81 layer_base.__init__(self)
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
82 self.color = wx.Color(128, 128, 128)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
83 self.fogregion = wx.Region()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
84 self.fogregion.Clear()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
85 self.fog_bmp = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
86 self.width = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
87 self.height = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
88 self.use_fog = False
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
89 self.last_role = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
90
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
91 def clear(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
92 self.fogregion.Clear()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
93 self.use_fog = True
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
94 self.del_area("all")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
95 self.recompute_fog()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
96
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
97 def remove_fog(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
98 self.fogregion.Clear()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
99 self.use_fog = False
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
100 self.del_area("all")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
101 self.add_area("none")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
102 self.fog_bmp = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
103
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
104 def resize(self, size):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
105 try:
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
106 if self.width == size[0] and self.height == size[1]: return
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
107 self.recompute_fog()
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
108 except: pass
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
109
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
110 def recompute_fog(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
111 if not self.use_fog:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
112 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
113 size = self.canvas.size
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
114 self.width = size[0]
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
115 self.height = size[1]
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
116 self.fog_bmp = wx.EmptyBitmap(self.width,self.height)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
117 self.fill_fog()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
118
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
119 def fill_fog(self):
139
8e07c1a2c69b Traipse Alpha 'OpenRPG' {091123-00}
sirebral
parents: 137
diff changeset
120 if not self.use_fog: return
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
121 mdc = wx.MemoryDC()
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
122 mdc.SelectObject(self.fog_bmp)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
123 mdc.SetPen(wx.TRANSPARENT_PEN)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
124 if (self.canvas.frame.session.role == "GM"): color = self.color
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
125 else: color = wx.BLACK
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
126 self.last_role = self.canvas.frame.session.role
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
127 mdc.SetBrush(wx.Brush(color,wx.SOLID))
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
128 mdc.DestroyClippingRegion()
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
129 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
130 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
131 if self.fogregion.GetBox().GetWidth()>0:
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
132 mdc.SetClippingRegionAsRegion(self.fogregion)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
133 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
134 mdc.SelectObject(wx.NullBitmap)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
135 del mdc
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
136
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
137 def layerDraw(self, dc, topleft, size):
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
138 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog: return
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
139 if self.last_role != self.canvas.frame.session.role: self.fill_fog()
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
140 mdc = wx.MemoryDC()
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
141 mdc.SelectObject(self.fog_bmp)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
142 dc.Blit(0, 0, self.canvas.size[0], self.canvas.size[1], mdc, 0, 0, wx.AND)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
143 mdc.SelectObject(wx.NullBitmap)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
144 del mdc
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
145
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
146 def createregn2(self, polyline, mode, show):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
147 regn = self.scanConvert(polyline)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
148 area = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
149 for i in polyline:
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
150 if (area != ""): area += ";"
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
151 area += str(i.X) + "," + str(i.Y)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
152 if mode == 'new':
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
153 if self.fogregion.IsEmpty(): self.fogregion = regn
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
154 else: self.fogregion.UnionRegion(regn)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
155 self.add_area(area, show)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
156 else:
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
157 if not self.fogregion.IsEmpty(): self.fogregion.SubtractRegion(regn)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
158 else:
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
159 self.fogregion = wx.Region(0, 0, self.canvas.size[0], self.canvas.size[1])
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
160 self.fogregion.SubtractRegion(regn)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
161 self.del_area(area, show)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
162
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
163 def createregn(self, polyline, mode, show="Yes"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
164 if not self.use_fog and mode == 'del':
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
165 self.clear()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
166 self.canvas.Refresh(False)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
167 if self.use_fog:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
168 self.createregn2(polyline, mode, show)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
169 self.fill_fog()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
170
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
171 def scanConvert(self, polypt):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
172 regn = wx.Region()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
173 regn.Clear()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
174 list = IRegion().scan_Convert(polypt)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
175 for i in list:
139
8e07c1a2c69b Traipse Alpha 'OpenRPG' {091123-00}
sirebral
parents: 137
diff changeset
176 if regn.IsEmpty(): regn = wx.Region(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE)
8e07c1a2c69b Traipse Alpha 'OpenRPG' {091123-00}
sirebral
parents: 137
diff changeset
177 else: regn.Union(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
178 return regn
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
179
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
180 def add_area(self, area="", show="Yes"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
181 poly = FogArea(area, self.log)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
182 xml_str = "<map><fog>"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
183 xml_str += poly.toxml("new")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
184 xml_str += "</fog></map>"
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
185 if show == "Yes": self.canvas.frame.session.send(xml_str)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
186
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
187 def del_area(self, area="", show="Yes"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
188 poly = FogArea(area, self.log)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
189 xml_str = "<map><fog>"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
190 xml_str += poly.toxml("del")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
191 xml_str += "</fog></map>"
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
192 if show == "Yes": self.canvas.frame.session.send(xml_str)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
193
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
194 def layerToXML(self, action="update"):
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
195 if not self.use_fog: return ""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
196 fog_string = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
197 ri = wx.RegionIterator(self.fogregion)
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
198 if not (ri.HaveRects()): fog_string = FogArea("all", self.log).toxml("del")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
199 while ri.HaveRects():
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
200 x1 = ri.GetX()/COURSE
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
201 x2 = x1+(ri.GetW()/COURSE)-1
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
202 y1 = ri.GetY()/COURSE
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 83
diff changeset
203 y2 = y1+(ri.GetH()/COURSE)-1
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
204 poly = FogArea(str(x1) + "," + str(y1) + ";" +
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
205 str(x2) + "," + str(y1) + ";" +
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
206 str(x2) + "," + str(y2) + ";" +
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
207 str(x1) + "," + str(y2), self.log)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
208 fog_string += poly.toxml(action)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
209 ri.Next()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
210 if fog_string:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
211 s = "<fog"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
212 s += ">"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
213 s += fog_string
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
214 s += "</fog>"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
215 return s
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 139
diff changeset
216 else: return ""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
217
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
218 def layerTakeDOM(self, xml_dom):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
219 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
220 if not self.use_fog:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
221 self.use_fog = True
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
222 self.recompute_fog()
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
223 serial = xml_dom.get('serial')
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
224 if serial != None: self.serial_number = int(serial)
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
225 children = xml_dom.getchildren()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
226 for l in children:
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
227 action = l.get("action")
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
228 outline = l.get("outline")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
229 if (outline == "all"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
230 polyline = [IPoint().make(0,0), IPoint().make(self.width-1, 0),
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
231 IPoint().make(self.width-1, self.height-1),
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
232 IPoint().make(0, self.height-1)]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
233 elif (outline == "none"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
234 polyline = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
235 self.use_fog = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
236 self.fog_bmp = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
237 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
238 polyline = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
239 lastx = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
240 lasty = None
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
241 list = l.getchildren()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
242 for point in list:
228
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
243 x = point.get( "x" )
24769389a7ba Traipse Alpha 'OpenRPG' {100612-01}
sirebral
parents: 151
diff changeset
244 y = point.get( "y" )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
245 if (x != lastx or y != lasty):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
246 polyline.append(IPoint().make(int(x), int(y)))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
247 lastx = x
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
248 lasty = y
20
072ffc1d466f 2nd attempt. Still untested.
sirebral
parents: 19
diff changeset
249 if (len(polyline) > 1): self.createregn2(polyline, action, "No")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
250 self.fill_fog()
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 20
diff changeset
251 except: pass