Mercurial > traipse
comparison orpg/mapper/fog_handler.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 5df1340bda13 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: mapper/fog_handler.py | |
21 # Author: Mark Tarrabain | |
22 # | |
23 # Description: Handler for fog layer | |
24 # | |
25 | |
26 from fog import * | |
27 from base_handler import * | |
28 from region import * | |
29 | |
30 #CTRL_REVEAL = wx.NewId() | |
31 #CTRL_HIDE = wx.NewId() | |
32 #CTRL_REMOVE = wx.NewId() | |
33 #CTRL_SHOWALL = wx.NewId() | |
34 #CTRL_HIDEALL = wx.NewId() | |
35 #CTRL_COLOR = wx.NewId() | |
36 #CTRL_PEN = wx.NewId() | |
37 | |
38 class fog_handler(base_layer_handler): | |
39 def __init__(self, parent, id, canvas): | |
40 self.showmode = 1 | |
41 self.drawing = False | |
42 self.pencolor=wx.WHITE | |
43 base_layer_handler.__init__(self, parent, id, canvas) | |
44 | |
45 def build_ctrls(self): | |
46 foglayer = self.canvas.layers['fog'] | |
47 base_layer_handler.build_ctrls(self) | |
48 self.f_type_radio = {} | |
49 self.fogshow = wx.RadioButton(self, wx.ID_ANY, "Show", style=wx.RB_GROUP) | |
50 self.foghide = wx.RadioButton(self, wx.ID_ANY, "Hide") | |
51 | |
52 self.sizer.Add(self.foghide) | |
53 self.sizer.Add(self.fogshow) | |
54 self.sizer.Add(wx.Size(20,25),1) | |
55 | |
56 | |
57 def build_menu(self,label = "fog"): | |
58 base_layer_handler.build_menu(self,label) | |
59 self.main_menu.AppendSeparator() | |
60 | |
61 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Hide All", "Hide All") | |
62 self.canvas.Bind(wx.EVT_MENU, self.on_hideall, item) | |
63 self.main_menu.AppendItem(item) | |
64 | |
65 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Fog Mask", "Fog Mask") | |
66 self.canvas.Bind(wx.EVT_MENU, self.on_color, item) | |
67 self.main_menu.AppendItem(item) | |
68 | |
69 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Remove Fog Layer", "Remove Fog Layer") | |
70 self.canvas.Bind(wx.EVT_MENU, self.on_remove, item) | |
71 self.main_menu.AppendItem(item) | |
72 | |
73 item = wx.MenuItem(self.main_menu, wx.ID_ANY, "&Pen Color", "Pen Color") | |
74 self.canvas.Bind(wx.EVT_MENU, self.on_pen_color, item) | |
75 self.main_menu.AppendItem(item) | |
76 | |
77 | |
78 | |
79 | |
80 def on_remove(self,evt): | |
81 session=self.canvas.frame.session | |
82 if (session.my_role() != session.ROLE_GM): | |
83 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | |
84 return | |
85 self.canvas.layers['fog'].remove_fog() | |
86 self.canvas.Refresh(False) | |
87 | |
88 def on_showall(self,evt): | |
89 session=self.canvas.frame.session | |
90 if (session.my_role() != session.ROLE_GM): | |
91 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | |
92 return | |
93 foglayer = self.canvas.layers['fog'] | |
94 foglayer.showall() | |
95 self.canvas.Refresh(False) | |
96 | |
97 def on_pen_color(self,evt): | |
98 data = wx.ColourData() | |
99 data.SetChooseFull(True) | |
100 data.SetColour(self.pencolor) | |
101 dlg = wx.ColourDialog(self.canvas, data) | |
102 if dlg.ShowModal() == wx.ID_OK: | |
103 data = dlg.GetColourData() | |
104 color = data.GetColour() | |
105 self.pencolor=color | |
106 dlg.Destroy() | |
107 | |
108 def on_hideall(self,evt): | |
109 session=self.canvas.frame.session | |
110 if (session.my_role() != session.ROLE_GM): | |
111 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | |
112 return | |
113 foglayer=self.canvas.layers['fog'] | |
114 foglayer.clear() | |
115 self.canvas.Refresh(False) | |
116 | |
117 def on_color(self,evt): | |
118 session=self.canvas.frame.session | |
119 if (session.my_role() != session.ROLE_GM): | |
120 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | |
121 return | |
122 data = wx.ColourData() | |
123 data.SetChooseFull(True) | |
124 data.SetColour(self.canvas.layers['fog'].color) | |
125 dlg = wx.ColourDialog(self.canvas, data) | |
126 if dlg.ShowModal() == wx.ID_OK: | |
127 data = dlg.GetColourData() | |
128 color = data.GetColour() | |
129 if "__WXGTK__" not in wx.PlatformInfo: | |
130 color = wx.Color(color.Red(), color.Green(), color.Blue(), 128) | |
131 self.canvas.layers['fog'].color = color | |
132 dlg.Destroy() | |
133 self.canvas.layers['fog'].fill_fog() | |
134 self.canvas.Refresh(False) | |
135 | |
136 def update_info(self): | |
137 foglayer = self.canvas.layers['fog'] | |
138 pass | |
139 | |
140 | |
141 def on_motion(self, evt): | |
142 scale = self.canvas.layers['grid'].mapscale | |
143 dc = wx.ClientDC(self.canvas) | |
144 dc.SetUserScale(scale, scale) | |
145 self.canvas.PrepareDC(dc) | |
146 pos = evt.GetLogicalPosition(dc) | |
147 pos.x /= COURSE | |
148 pos.y /= COURSE | |
149 pos.x /= scale | |
150 pos.y /= scale | |
151 | |
152 if evt.m_leftDown: | |
153 if not self.drawing: | |
154 self.line = [] | |
155 self.line.append(IPoint().make(pos.x, pos.y)) | |
156 elif pos.x != self.last.x or pos.y != self.last.y: | |
157 pen= wx.Pen(self.pencolor) | |
158 pen.SetWidth(COURSE/2+1) | |
159 dc.SetPen(pen) | |
160 multi = scale*COURSE | |
161 dc.DrawLine(self.last.x*multi, self.last.y*multi, pos.x*multi, pos.y*multi) | |
162 dc.SetPen(wx.NullPen) | |
163 self.line.append(IPoint().make(pos.x, pos.y)) | |
164 self.last = pos | |
165 self.drawing = True | |
166 del dc | |
167 | |
168 def on_left_up(self,evt): | |
169 if self.drawing == True: | |
170 session=self.canvas.frame.session | |
171 if (session.my_role() != session.ROLE_GM): | |
172 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature") | |
173 else: | |
174 # This code sets the mode to either new or del depending on the action to function with the updated createregen code. | |
175 if (self.fogshow.GetValue() == 1): | |
176 showmode = 'new' | |
177 else: | |
178 showmode = 'del' | |
179 scale = self.canvas.layers['grid'].mapscale | |
180 dc = wx.ClientDC(self.canvas) | |
181 self.canvas.PrepareDC(dc) | |
182 dc.SetUserScale(scale,scale) | |
183 pen= wx.Pen(self.pencolor) | |
184 pen.SetWidth(COURSE/2+1) | |
185 dc.SetPen(pen) | |
186 dc.DrawLine(self.last.x*scale*COURSE,self.last.y*scale*COURSE,self.line[0].X*scale*COURSE,self.line[0].Y*scale*COURSE) | |
187 dc.SetPen(wx.NullPen) | |
188 wx.BeginBusyCursor() | |
189 # This prevents the divide by zero error by not even sending the line to be proccessed if it contains less then 3 points | |
190 if (len(self.line)>1): | |
191 self.canvas.layers['fog'].createregn(self.line, showmode) | |
192 else: | |
193 #print "Error Divide by zero, ignoring this section" | |
194 pass | |
195 wx.EndBusyCursor() | |
196 del dc | |
197 self.canvas.Refresh(False) | |
198 self.drawing = False |