comparison orpg/mapper/fog_handler.py @ 19:78407d627cba traipse_dev

Beginning of Code Clean-up. Some code untested, may break!
author sirebral
date Sat, 25 Jul 2009 17:24:40 -0500
parents 0b8b7e3ed78d
children 072ffc1d466f
comparison
equal deleted inserted replaced
18:67b900deb35c 19:78407d627cba
46 foglayer = self.canvas.layers['fog'] 46 foglayer = self.canvas.layers['fog']
47 base_layer_handler.build_ctrls(self) 47 base_layer_handler.build_ctrls(self)
48 self.f_type_radio = {} 48 self.f_type_radio = {}
49 self.fogshow = wx.RadioButton(self, wx.ID_ANY, "Show", style=wx.RB_GROUP) 49 self.fogshow = wx.RadioButton(self, wx.ID_ANY, "Show", style=wx.RB_GROUP)
50 self.foghide = wx.RadioButton(self, wx.ID_ANY, "Hide") 50 self.foghide = wx.RadioButton(self, wx.ID_ANY, "Hide")
51
52 #self.sizer.Add(self.foghide)
53 #self.sizer.Add(self.fogshow)
54
55 self.sizer.Add(self.foghide, 0, wx.ALIGN_CENTER) 51 self.sizer.Add(self.foghide, 0, wx.ALIGN_CENTER)
56 self.sizer.Add(self.fogshow, 0, wx.ALIGN_CENTER) 52 self.sizer.Add(self.fogshow, 0, wx.ALIGN_CENTER)
57
58 self.sizer.Add(wx.Size(20,25),1) 53 self.sizer.Add(wx.Size(20,25),1)
59
60 54
61 def build_menu(self,label = "fog"): 55 def build_menu(self,label = "fog"):
62 base_layer_handler.build_menu(self,label) 56 base_layer_handler.build_menu(self,label)
63 self.main_menu.AppendSeparator() 57 self.main_menu.AppendSeparator()
64
65 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Hide All", "Hide All") 58 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Hide All", "Hide All")
66 self.canvas.Bind(wx.EVT_MENU, self.on_hideall, item) 59 self.canvas.Bind(wx.EVT_MENU, self.on_hideall, item)
67 self.main_menu.AppendItem(item) 60 self.main_menu.AppendItem(item)
68
69 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Fog Mask", "Fog Mask") 61 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Fog Mask", "Fog Mask")
70 self.canvas.Bind(wx.EVT_MENU, self.on_color, item) 62 self.canvas.Bind(wx.EVT_MENU, self.on_color, item)
71 self.main_menu.AppendItem(item) 63 self.main_menu.AppendItem(item)
72
73 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Remove Fog Layer", "Remove Fog Layer") 64 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Remove Fog Layer", "Remove Fog Layer")
74 self.canvas.Bind(wx.EVT_MENU, self.on_remove, item) 65 self.canvas.Bind(wx.EVT_MENU, self.on_remove, item)
75 self.main_menu.AppendItem(item) 66 self.main_menu.AppendItem(item)
76
77 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Pen Color", "Pen Color") 67 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Pen Color", "Pen Color")
78 self.canvas.Bind(wx.EVT_MENU, self.on_pen_color, item) 68 self.canvas.Bind(wx.EVT_MENU, self.on_pen_color, item)
79 self.main_menu.AppendItem(item) 69 self.main_menu.AppendItem(item)
80
81
82
83 70
84 def on_remove(self,evt): 71 def on_remove(self,evt):
85 session=self.canvas.frame.session 72 session=self.canvas.frame.session
86 if (session.my_role() != session.ROLE_GM): 73 if (session.my_role() != session.ROLE_GM):
87 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") 74 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature")
139 126
140 def update_info(self): 127 def update_info(self):
141 foglayer = self.canvas.layers['fog'] 128 foglayer = self.canvas.layers['fog']
142 pass 129 pass
143 130
144
145 def on_motion(self, evt): 131 def on_motion(self, evt):
146 scale = self.canvas.layers['grid'].mapscale 132 scale = self.canvas.layers['grid'].mapscale
147 dc = wx.ClientDC(self.canvas) 133 dc = wx.ClientDC(self.canvas)
148 dc.SetUserScale(scale, scale) 134 dc.SetUserScale(scale, scale)
149 self.canvas.PrepareDC(dc) 135 self.canvas.PrepareDC(dc)
173 if self.drawing == True: 159 if self.drawing == True:
174 session=self.canvas.frame.session 160 session=self.canvas.frame.session
175 if (session.my_role() != session.ROLE_GM): 161 if (session.my_role() != session.ROLE_GM):
176 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") 162 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature")
177 else: 163 else:
178 # This code sets the mode to either new or del depending on the action to function with the updated createregen code. 164 # This code sets the mode to either new or del
165 # depending on the action to function with the updated createregen code.
179 if (self.fogshow.GetValue() == 1): 166 if (self.fogshow.GetValue() == 1):
180 showmode = 'new' 167 showmode = 'new'
181 else: 168 else:
182 showmode = 'del' 169 showmode = 'del'
183 scale = self.canvas.layers['grid'].mapscale 170 scale = self.canvas.layers['grid'].mapscale
185 self.canvas.PrepareDC(dc) 172 self.canvas.PrepareDC(dc)
186 dc.SetUserScale(scale,scale) 173 dc.SetUserScale(scale,scale)
187 pen= wx.Pen(self.pencolor) 174 pen= wx.Pen(self.pencolor)
188 pen.SetWidth(COURSE/2+1) 175 pen.SetWidth(COURSE/2+1)
189 dc.SetPen(pen) 176 dc.SetPen(pen)
190 dc.DrawLine(self.last.x*scale*COURSE,self.last.y*scale*COURSE,self.line[0].X*scale*COURSE,self.line[0].Y*scale*COURSE) 177 dc.DrawLine(self.last.x*scale*COURSE,self.last.y*scale*COURSE,
178 self.line[0].X*scale*COURSE,self.line[0].Y*scale*COURSE)
191 dc.SetPen(wx.NullPen) 179 dc.SetPen(wx.NullPen)
192 wx.BeginBusyCursor() 180 wx.BeginBusyCursor()
193 # This prevents the divide by zero error by not even sending the line to be proccessed if it contains less then 3 points 181 # This prevents the divide by zero error by not even
182 # sending the line to be proccessed if it contains less then 3 points
194 if (len(self.line)>1): 183 if (len(self.line)>1):
195 self.canvas.layers['fog'].createregn(self.line, showmode) 184 self.canvas.layers['fog'].createregn(self.line, showmode)
196 else: 185 else:
197 #print "Error Divide by zero, ignoring this section" 186 #print "Error Divide by zero, ignoring this section"
198 pass 187 pass