comparison orpg/mapper/fog.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-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 (Stable) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Wed, 03 Feb 2010 22:16:49 -0600
parents 51428d30c59e
children d02e9197c066
comparison
equal deleted inserted replaced
27:51428d30c59e 28:ff154cf3350c
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)
87 self.fogregion = wx.Region() 86 self.fogregion = wx.Region()
88 self.fogregion.Clear() 87 self.fogregion.Clear()
89 self.fog_bmp = None 88 self.fog_bmp = None
90 self.width = 0 89 self.width = 0
91 self.height = 0 90 self.height = 0
105 self.add_area("none") 104 self.add_area("none")
106 self.fog_bmp = None 105 self.fog_bmp = None
107 106
108 def resize(self, size): 107 def resize(self, size):
109 try: 108 try:
110 if self.width == size[0] and self.height == size[1]: 109 if self.width == size[0] and self.height == size[1]: return
111 return
112 self.recompute_fog() 110 self.recompute_fog()
113 except: pass 111 except: pass
114 112
115 def recompute_fog(self): 113 def recompute_fog(self):
116 if not self.use_fog: 114 if not self.use_fog:
117 return 115 return
118 size = self.canvas.size 116 size = self.canvas.size
119 self.width = size[0]/COURSE+1 117 self.width = size[0]
120 self.height = size[1]/COURSE+1 118 self.height = size[1]
121 self.fog_bmp = wx.EmptyBitmap(self.width+2,self.height+2) 119 self.fog_bmp = wx.EmptyBitmap(self.width,self.height)
122 self.fill_fog() 120 self.fill_fog()
123 121
124 def fill_fog(self): 122 def fill_fog(self):
125 if not self.use_fog: 123 if not self.use_fog: return
126 return 124 mdc = wx.MemoryDC()
127 if "__WXGTK__" in wx.PlatformInfo: 125 mdc.SelectObject(self.fog_bmp)
128 mdc = wx.MemoryDC() 126 mdc.SetPen(wx.TRANSPARENT_PEN)
129 mdc.SelectObject(self.fog_bmp) 127 if (self.canvas.frame.session.role == "GM"): color = self.color
130 mdc.SetPen(wx.TRANSPARENT_PEN) 128 else: color = wx.BLACK
131 if (self.canvas.frame.session.role == "GM"): color = self.color 129 self.last_role = self.canvas.frame.session.role
132 else: color = wx.BLACK 130 mdc.SetBrush(wx.Brush(color,wx.SOLID))
133 self.last_role = self.canvas.frame.session.role 131 mdc.DestroyClippingRegion()
134 mdc.SetBrush(wx.Brush(color,wx.SOLID)) 132 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
135 mdc.DestroyClippingRegion() 133 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
134 if self.fogregion.GetBox().GetWidth()>0:
135 mdc.SetClippingRegionAsRegion(self.fogregion)
136 mdc.DrawRectangle(0, 0, self.width+2, self.height+2) 136 mdc.DrawRectangle(0, 0, self.width+2, self.height+2)
137 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID)) 137 mdc.SelectObject(wx.NullBitmap)
138 if self.fogregion.GetBox().GetWidth()>0: 138 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 139
144 def layerDraw(self, dc, topleft, size): 140 def layerDraw(self, dc, topleft, size):
145 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog: 141 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog: return
146 return
147 if self.last_role != self.canvas.frame.session.role: self.fill_fog() 142 if self.last_role != self.canvas.frame.session.role: self.fill_fog()
148 if "__WXGTK__" not in wx.PlatformInfo: 143 mdc = wx.MemoryDC()
149 gc = wx.GraphicsContext.Create(dc) 144 mdc.SelectObject(self.fog_bmp)
150 gc.SetBrush(wx.Brush(wx.BLACK)) 145 dc.Blit(0, 0, self.canvas.size[0], self.canvas.size[1], mdc, 0, 0, wx.AND)
151 if (self.canvas.frame.session.role == "GM"): 146 mdc.SelectObject(wx.NullBitmap)
152 gc.SetBrush(wx.Brush(self.color)) 147 del mdc
153 rgn = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2)
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 148
185 def createregn2(self, polyline, mode, show): 149 def createregn2(self, polyline, mode, show):
186 regn = self.scanConvert(polyline) 150 regn = self.scanConvert(polyline)
187 area = "" 151 area = ""
188 for i in polyline: 152 for i in polyline:
189 if (area != ""): 153 if (area != ""): area += ";"
190 area += ";"
191 area += str(i.X) + "," + str(i.Y) 154 area += str(i.X) + "," + str(i.Y)
192 if mode == 'new': 155 if mode == 'new':
193 if self.fogregion.IsEmpty(): 156 if self.fogregion.IsEmpty(): self.fogregion = regn
194 self.fogregion = regn
195 else: self.fogregion.UnionRegion(regn) 157 else: self.fogregion.UnionRegion(regn)
196 self.add_area(area, show) 158 self.add_area(area, show)
197 else: 159 else:
198 if not self.fogregion.IsEmpty(): 160 if not self.fogregion.IsEmpty(): self.fogregion.SubtractRegion(regn)
199 self.fogregion.SubtractRegion(regn)
200 else: 161 else:
201 self.fogregion = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) 162 self.fogregion = wx.Region(0, 0, self.canvas.size[0], self.canvas.size[1])
202 self.fogregion.SubtractRegion(regn) 163 self.fogregion.SubtractRegion(regn)
203 self.del_area(area, show) 164 self.del_area(area, show)
204 165
205 def createregn(self, polyline, mode, show="Yes"): 166 def createregn(self, polyline, mode, show="Yes"):
206 if not self.use_fog and mode == 'del': 167 if not self.use_fog and mode == 'del':
213 def scanConvert(self, polypt): 174 def scanConvert(self, polypt):
214 regn = wx.Region() 175 regn = wx.Region()
215 regn.Clear() 176 regn.Clear()
216 list = IRegion().scan_Convert(polypt) 177 list = IRegion().scan_Convert(polypt)
217 for i in list: 178 for i in list:
218 if regn.IsEmpty(): 179 if regn.IsEmpty(): regn = wx.Region(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE)
219 if "__WXGTK__" not in wx.PlatformInfo: regn = wx.Region(i.left*COURSE, i.y*COURSE, 180 else: regn.Union(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE)
220 i.right*COURSE+1-i.left*COURSE, 1*COURSE)
221 else: regn = wx.Region(i.left, i.y, i.right+1-i.left, 1)
222 else:
223 if "__WXGTK__" not in wx.PlatformInfo: regn.Union(i.left*COURSE, i.y*COURSE,
224 i.right*COURSE+1-i.left*COURSE, 1*COURSE)
225 else: regn.Union(i.left, i.y, i.right+1-i.left, 1)
226 return regn 181 return regn
227 182
228 def add_area(self, area="", show="Yes"): 183 def add_area(self, area="", show="Yes"):
229 poly = FogArea(area, self.log) 184 poly = FogArea(area, self.log)
230 xml_str = "<map><fog>" 185 xml_str = "<map><fog>"
238 xml_str += poly.toxml("del") 193 xml_str += poly.toxml("del")
239 xml_str += "</fog></map>" 194 xml_str += "</fog></map>"
240 if show == "Yes": self.canvas.frame.session.send(xml_str) 195 if show == "Yes": self.canvas.frame.session.send(xml_str)
241 196
242 def layerToXML(self, action="update"): 197 def layerToXML(self, action="update"):
243 if not self.use_fog: 198 if not self.use_fog: return ""
244 return ""
245 fog_string = "" 199 fog_string = ""
246 ri = wx.RegionIterator(self.fogregion) 200 ri = wx.RegionIterator(self.fogregion)
247 if not (ri.HaveRects()): fog_string = FogArea("all", self.log).toxml("del") 201 if not (ri.HaveRects()): fog_string = FogArea("all", self.log).toxml("del")
248 while ri.HaveRects(): 202 while ri.HaveRects():
249 if "__WXGTK__" not in wx.PlatformInfo: 203 x1 = ri.GetX()/COURSE
250 x1 = ri.GetX()/COURSE 204 x2 = x1+(ri.GetW()/COURSE)-1
251 x2 = x1+(ri.GetW()/COURSE)-1 205 y1 = ri.GetY()/COURSE
252 y1 = ri.GetY()/COURSE 206 y2 = y1+(ri.GetH()/COURSE)-1
253 y2 = y1+(ri.GetH()/COURSE)-1
254 else:
255 x1 = ri.GetX()
256 x2 = x1+ri.GetW()-1
257 y1 = ri.GetY()
258 y2 = y1+ri.GetH()-1
259 poly = FogArea(str(x1) + "," + str(y1) + ";" + 207 poly = FogArea(str(x1) + "," + str(y1) + ";" +
260 str(x2) + "," + str(y1) + ";" + 208 str(x2) + "," + str(y1) + ";" +
261 str(x2) + "," + str(y2) + ";" + 209 str(x2) + "," + str(y2) + ";" +
262 str(x1) + "," + str(y2), self.log) 210 str(x1) + "," + str(y2), self.log)
263 fog_string += poly.toxml(action) 211 fog_string += poly.toxml(action)
266 s = "<fog" 214 s = "<fog"
267 s += ">" 215 s += ">"
268 s += fog_string 216 s += fog_string
269 s += "</fog>" 217 s += "</fog>"
270 return s 218 return s
271 else: 219 else: return ""
272 return ""
273 220
274 def layerTakeDOM(self, xml_dom): 221 def layerTakeDOM(self, xml_dom):
275 try: 222 try:
276 if not self.use_fog: 223 if not self.use_fog:
277 self.use_fog = True 224 self.use_fog = True