comparison orpg/mapper/fog.py @ 118:217fb049bd00 alpha

Traipse Alpha 'OpenRPG' {091028-00} 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: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! 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. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} 00: Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree
author sirebral
date Wed, 28 Oct 2009 14:24:54 -0500
parents f38df4bf9715
children 54446a995007 e842a5f1b775
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
80 class fog_layer(layer_base): 80 class fog_layer(layer_base):
81 def __init__(self, canvas): 81 def __init__(self, canvas):
82 self.canvas = canvas 82 self.canvas = canvas
83 self.log = component.get('log') 83 self.log = component.get('log')
84 layer_base.__init__(self) 84 layer_base.__init__(self)
85 self.color = wx.Color(128,128,128) 85 self.color = wx.Color(128, 128, 128)
86 if "__WXGTK__" not in wx.PlatformInfo: self.color = wx.Color(128,128,128, 128) 86 #if "__WXGTK__" not in wx.PlatformInfo: self.color = wx.Color(128,128,128, 128)
87 self.fogregion = wx.Region() 87 self.fogregion = wx.Region()
88 self.fogregion.Clear() 88 self.fogregion.Clear()
89 self.fog_bmp = None 89 self.fog_bmp = None
90 self.width = 0 90 self.width = 0
91 self.height = 0 91 self.height = 0
114 114
115 def recompute_fog(self): 115 def recompute_fog(self):
116 if not self.use_fog: 116 if not self.use_fog:
117 return 117 return
118 size = self.canvas.size 118 size = self.canvas.size
119 self.width = size[0]/COURSE+1 119 self.width = size[0]
120 self.height = size[1]/COURSE+1 120 self.height = size[1]
121 self.fog_bmp = wx.EmptyBitmap(self.width+2,self.height+2) 121 self.fog_bmp = wx.EmptyBitmap(self.width,self.height)
122 self.fill_fog() 122 self.fill_fog()
123 123
124 def fill_fog(self): 124 def fill_fog(self):
125 if not self.use_fog: 125 if not self.use_fog:
126 return 126 return
127 if "__WXGTK__" in wx.PlatformInfo: 127 mdc = wx.MemoryDC()
128 mdc = wx.MemoryDC() 128 mdc.SelectObject(self.fog_bmp)
129 mdc.SelectObject(self.fog_bmp) 129 mdc.SetPen(wx.TRANSPARENT_PEN)
130 mdc.SetPen(wx.TRANSPARENT_PEN) 130 if (self.canvas.frame.session.role == "GM"): color = self.color
131 if (self.canvas.frame.session.role == "GM"): color = self.color 131 else: color = wx.BLACK
132 else: color = wx.BLACK 132 self.last_role = self.canvas.frame.session.role
133 self.last_role = self.canvas.frame.session.role 133 mdc.SetBrush(wx.Brush(color,wx.SOLID))
134 mdc.SetBrush(wx.Brush(color,wx.SOLID)) 134 mdc.DestroyClippingRegion()
135 mdc.DestroyClippingRegion() 135 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
136 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
137 if self.fogregion.GetBox().GetWidth()>0:
138 mdc.SetClippingRegionAsRegion(self.fogregion)
136 mdc.DrawRectangle(0, 0, self.width+2, self.height+2) 139 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
137 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID)) 140 mdc.SelectObject(wx.NullBitmap)
138 if self.fogregion.GetBox().GetWidth()>0: 141 del mdc
139 mdc.SetClippingRegionAsRegion(self.fogregion)
140 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
141 mdc.SelectObject(wx.NullBitmap)
142 del mdc
143 142
144 def layerDraw(self, dc, topleft, size): 143 def layerDraw(self, dc, topleft, size):
145 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog: 144 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog:
146 return 145 return
147 if self.last_role != self.canvas.frame.session.role: self.fill_fog() 146 if self.last_role != self.canvas.frame.session.role: self.fill_fog()
148 if "__WXGTK__" not in wx.PlatformInfo: 147
149 gc = wx.GraphicsContext.Create(dc) 148 mdc = wx.MemoryDC()
150 gc.SetBrush(wx.Brush(wx.BLACK)) 149 mdc.SelectObject(self.fog_bmp)
151 if (self.canvas.frame.session.role == "GM"): 150 dc.Blit(0, 0, self.canvas.size[0], self.canvas.size[1], mdc, 0, 0, wx.AND)
152 gc.SetBrush(wx.Brush(self.color)) 151 mdc.SelectObject(wx.NullBitmap)
153 rgn = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) 152 del mdc
154 if not self.fogregion.IsEmpty(): rgn.SubtractRegion(self.fogregion)
155 gc.ClipRegion(rgn)
156 gc.DrawRectangle(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2)
157 else:
158 sc = dc.GetUserScale()
159 bmp = wx.EmptyBitmap(size[0],size[1])
160 mdc = wx.MemoryDC()
161 mdc.BeginDrawing()
162 mdc.SelectObject(bmp)
163 mdc.SetPen(wx.TRANSPARENT_PEN)
164 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
165 mdc.DrawRectangle(0,0,size[0],size[1])
166 srct = [int(topleft[0]/(sc[0]*COURSE)), int(topleft[1]/(sc[1]*COURSE))]
167 srcsz = [int((int(size[0]/COURSE+1)*COURSE)/(sc[0]*COURSE))+2,
168 int((int(size[1]/COURSE+1)*COURSE)/(sc[1]*COURSE))+2]
169 if (srct[0]+srcsz[0] > self.width): srcsz[0] = self.width-srct[0]
170 if (srct[1]+srcsz[1] > self.height): srcsz[1] = self.height-srct[1]
171 img = wx.ImageFromBitmap(self.fog_bmp).GetSubImage(wx.Rect(srct[0], srct[1], srcsz[0], srcsz[1]))
172 img.Rescale(srcsz[0]*COURSE*sc[0], srcsz[1]*COURSE*sc[1])
173 fog = wx.BitmapFromImage(img)
174 mdc.SetDeviceOrigin(-topleft[0], -topleft[1])
175 mdc.DrawBitmap(fog, srct[0]*COURSE*sc[0], srct[1]*COURSE*sc[1])
176 mdc.SetDeviceOrigin(0,0)
177 mdc.SetUserScale(1,1)
178 mdc.EndDrawing()
179 dc.SetUserScale(1,1)
180 dc.Blit(topleft[0], topleft[1], size[0], size[1], mdc,0,0,wx.AND)
181 dc.SetUserScale(sc[0],sc[1])
182 mdc.SelectObject(wx.NullBitmap)
183 del mdc
184 153
185 def createregn2(self, polyline, mode, show): 154 def createregn2(self, polyline, mode, show):
186 regn = self.scanConvert(polyline) 155 regn = self.scanConvert(polyline)
187 area = "" 156 area = ""
188 for i in polyline: 157 for i in polyline:
196 self.add_area(area, show) 165 self.add_area(area, show)
197 else: 166 else:
198 if not self.fogregion.IsEmpty(): 167 if not self.fogregion.IsEmpty():
199 self.fogregion.SubtractRegion(regn) 168 self.fogregion.SubtractRegion(regn)
200 else: 169 else:
201 self.fogregion = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) 170 self.fogregion = wx.Region(0, 0, self.canvas.size[0], self.canvas.size[1])
202 self.fogregion.SubtractRegion(regn) 171 self.fogregion.SubtractRegion(regn)
203 self.del_area(area, show) 172 self.del_area(area, show)
204 173
205 def createregn(self, polyline, mode, show="Yes"): 174 def createregn(self, polyline, mode, show="Yes"):
206 if not self.use_fog and mode == 'del': 175 if not self.use_fog and mode == 'del':
214 regn = wx.Region() 183 regn = wx.Region()
215 regn.Clear() 184 regn.Clear()
216 list = IRegion().scan_Convert(polypt) 185 list = IRegion().scan_Convert(polypt)
217 for i in list: 186 for i in list:
218 if regn.IsEmpty(): 187 if regn.IsEmpty():
219 if "__WXGTK__" not in wx.PlatformInfo: regn = wx.Region(i.left*COURSE, i.y*COURSE, 188 #if "__WXGTK__" not in wx.PlatformInfo:
220 i.right*COURSE+1-i.left*COURSE, 1*COURSE) 189 regn = wx.Region(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE)
221 else: regn = wx.Region(i.left, i.y, i.right+1-i.left, 1) 190 #else: regn = wx.Region(i.left, i.y, i.right+1-i.left, 1)
222 else: 191 else:
223 if "__WXGTK__" not in wx.PlatformInfo: regn.Union(i.left*COURSE, i.y*COURSE, 192 #if "__WXGTK__" not in wx.PlatformInfo:
224 i.right*COURSE+1-i.left*COURSE, 1*COURSE) 193 regn.Union(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE)
225 else: regn.Union(i.left, i.y, i.right+1-i.left, 1) 194 #else: regn.Union(i.left, i.y, i.right+1-i.left, 1)
226 return regn 195 return regn
227 196
228 def add_area(self, area="", show="Yes"): 197 def add_area(self, area="", show="Yes"):
229 poly = FogArea(area, self.log) 198 poly = FogArea(area, self.log)
230 xml_str = "<map><fog>" 199 xml_str = "<map><fog>"
244 return "" 213 return ""
245 fog_string = "" 214 fog_string = ""
246 ri = wx.RegionIterator(self.fogregion) 215 ri = wx.RegionIterator(self.fogregion)
247 if not (ri.HaveRects()): fog_string = FogArea("all", self.log).toxml("del") 216 if not (ri.HaveRects()): fog_string = FogArea("all", self.log).toxml("del")
248 while ri.HaveRects(): 217 while ri.HaveRects():
249 if "__WXGTK__" not in wx.PlatformInfo: 218 #if "__WXGTK__" not in wx.PlatformInfo:
250 x1 = ri.GetX()/COURSE 219 x1 = ri.GetX()/COURSE
251 x2 = x1+(ri.GetW()/COURSE)-1 220 x2 = x1+(ri.GetW()/COURSE)-1
252 y1 = ri.GetY()/COURSE 221 y1 = ri.GetY()/COURSE
253 y2 = y1+(ri.GetH()/COURSE)-1 222 y2 = y1+(ri.GetH()/COURSE)-1
254 else: 223 #else:
255 x1 = ri.GetX() 224 # x1 = ri.GetX()
256 x2 = x1+ri.GetW()-1 225 # x2 = x1+ri.GetW()-1
257 y1 = ri.GetY() 226 # y1 = ri.GetY()
258 y2 = y1+ri.GetH()-1 227 # y2 = y1+ri.GetH()-1
259 poly = FogArea(str(x1) + "," + str(y1) + ";" + 228 poly = FogArea(str(x1) + "," + str(y1) + ";" +
260 str(x2) + "," + str(y1) + ";" + 229 str(x2) + "," + str(y1) + ";" +
261 str(x2) + "," + str(y2) + ";" + 230 str(x2) + "," + str(y2) + ";" +
262 str(x1) + "," + str(y2), self.log) 231 str(x1) + "," + str(y2), self.log)
263 fog_string += poly.toxml(action) 232 fog_string += poly.toxml(action)