comparison orpg/mapper/grid_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 0b8b7e3ed78d
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 #
2 # openrpg-dev@lists.sourceforge.net
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 # --
18 #
19 # File: orpg/mapper/grid_handler.py
20 # Author: OpenRPG Team
21 # Maintainer:
22 # Version:
23 # $Id: grid_handler.py,v 1.20 2007/04/03 00:14:35 digitalxero Exp $
24 #
25 # Description: grid layer handler
26 #
27 __version__ = "$Id: grid_handler.py,v 1.20 2007/04/03 00:14:35 digitalxero Exp $"
28
29 from grid import *
30 from base_handler import *
31
32 class grid_handler(base_layer_handler):
33 def __init__(self, parent, id, canvas):
34 base_layer_handler.__init__(self, parent, id, canvas)
35
36 def build_ctrls(self):
37 base_layer_handler.build_ctrls(self)
38 self.line_type = wx.Choice(self, wx.ID_ANY, choices = ["No Lines", "Dotted Lines", "Solid Lines" ])
39 self.grid_mode = wx.Choice(self, wx.ID_ANY, choices = ["Rectangular", "Hexagonal","Isometric"])
40 self.grid_snap = wx.CheckBox(self, wx.ID_ANY, " Snap")
41 self.grid_size = wx.TextCtrl(self, wx.ID_ANY, size=(32,-1) )
42 self.grid_ratio = wx.TextCtrl(self, wx.ID_ANY, size=(32,-1) )
43 self.color_button = wx.Button(self, wx.ID_ANY, "Color", style=wx.BU_EXACTFIT)
44 self.apply_button = wx.Button(self, wx.ID_OK, "Apply", style=wx.BU_EXACTFIT)
45 self.color_button.SetBackgroundColour(wx.BLACK)
46 self.color_button.SetForegroundColour(wx.WHITE)
47 self.sizer.Add(wx.StaticText(self, -1, "Size: "), 0, wx.ALIGN_CENTER|wx.ALL, 3)
48 self.sizer.Add(self.grid_size, 0, wx.EXPAND|wx.ALL, 2)
49 self.sizer.Add(wx.StaticText(self, -1, "Ratio: "), 0, wx.ALIGN_CENTER|wx.ALL, 3)
50 self.sizer.Add(self.grid_ratio, 0, wx.EXPAND|wx.ALL, 2)
51 self.sizer.Add(self.line_type, 0, wx.EXPAND|wx.ALL, 3)
52 self.sizer.Add(self.grid_mode, 0, wx.EXPAND|wx.ALL, 2)
53 self.sizer.Add(self.grid_snap, 0, wx.EXPAND|wx.ALL, 3)
54 self.sizer.Add(self.color_button, 0, wx.EXPAND|wx.ALL, 2)
55 self.sizer.Add(self.apply_button, 0, wx.EXPAND|wx.ALL, 3)
56 self.sizer.Add(wx.Size(20,25),1)
57 self.Bind(wx.EVT_BUTTON, self.on_bg_color, self.color_button)
58 self.Bind(wx.EVT_BUTTON, self.on_apply, self.apply_button)
59 self.update_info()
60
61 def update_info(self):
62 layer = self.canvas.layers['grid']
63 self.grid_size.SetValue(str(layer.get_unit_size()))
64 self.grid_ratio.SetValue(str(layer.get_iso_ratio()))
65 self.grid_mode.SetSelection(layer.get_mode())
66 self.line_type.SetSelection(layer.get_line_type())
67 self.color_button.SetBackgroundColour(layer.get_color())
68 self.grid_snap.SetValue(layer.is_snap())
69 layer.isUpdated = True
70
71 def build_menu(self,label = "Grid"):
72 base_layer_handler.build_menu(self,label)
73
74 def on_bg_color(self,evt):
75 data = wx.ColourData()
76 data.SetChooseFull(True)
77 dlg = wx.ColourDialog(self.canvas, data)
78 if dlg.ShowModal() == wx.ID_OK:
79 data = dlg.GetColourData()
80 color = data.GetColour()
81 self.color_button.SetBackgroundColour(color)
82 dlg.Destroy()
83
84 def on_apply(self, evt):
85 session=self.canvas.frame.session
86 if (session.my_role() != session.ROLE_GM):
87 open_rpg.get_component("chat").InfoPost("You must be a GM to use this feature")
88 return
89
90 self.canvas.layers['grid'].set_grid(int(self.grid_size.GetValue()),self.grid_snap.GetValue(),
91 self.color_button.GetBackgroundColour(),self.grid_mode.GetSelection(),self.line_type.GetSelection(),float(self.grid_ratio.GetValue()))
92 self.update_info()
93 self.canvas.send_map_data()
94 self.canvas.Refresh()