comparison orpg/mapper/map_prop_dialog.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 78407d627cba
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/map_prop_dialog.py
21 # Author: OpenRPG
22 # Maintainer:
23 # Version:
24 # $Id: map_prop_dialog.py,v 1.16 2006/11/04 21:24:21 digitalxero Exp $
25 #
26 # Description:
27 #
28 __version__ = "$Id: map_prop_dialog.py,v 1.16 2006/11/04 21:24:21 digitalxero Exp $"
29
30 from orpg.orpg_windows import *
31 from background import *
32 from grid import *
33 from miniatures import *
34 from whiteboard import *
35
36 ##-----------------------------
37 ## map prop dialog
38 ##-----------------------------
39
40 CTRL_WIDTH = wx.NewId()
41 CTRL_HEIGHT = wx.NewId()
42 CTRL_BG_COLOR = wx.NewId()
43 CTRL_BG_COLOR_VALUE = wx.NewId()
44 CTRL_TEXTURE = wx.NewId()
45 CTRL_TEXTURE_PATH = wx.NewId()
46 CTRL_IMAGE = wx.NewId()
47 CTRL_IMAGE_PATH = wx.NewId()
48 CTRL_GRID = wx.NewId()
49 CTRL_GRID_SNAP = wx.NewId()
50 CTRL_GRID_COLOR = wx.NewId()
51 CTRL_GRID_MODE_RECT = wx.NewId()
52 CTRL_GRID_MODE_HEX = wx.NewId()
53 CTRL_GRID_LINE_NONE = wx.NewId()
54 CTRL_GRID_LINE_DOTTED = wx.NewId()
55 CTRL_GRID_LINE_SOLID = wx.NewId()
56
57 class general_map_prop_dialog(wx.Dialog):
58 def __init__(self,parent,size,bg_layer,grid_layer):
59 wx.Dialog.__init__(self,parent,-1,"General Map Properties",wx.DefaultPosition,wx.Size(425,405))
60 self.size = size
61 self.bg_layer = bg_layer
62 self.grid_layer = grid_layer
63 #build controls
64 self.ctrls = { CTRL_WIDTH : wx.TextCtrl(self, CTRL_WIDTH, str(size[0])),
65 CTRL_HEIGHT : wx.TextCtrl(self, CTRL_HEIGHT, str(size[1])),
66 CTRL_BG_COLOR : wx.RadioButton(self, CTRL_BG_COLOR, "Color", style=wx.RB_GROUP),
67 CTRL_BG_COLOR_VALUE : wx.Button(self, CTRL_BG_COLOR_VALUE, "Color"),
68 CTRL_TEXTURE : wx.RadioButton(self, CTRL_TEXTURE, "Texture"),
69 CTRL_TEXTURE_PATH: wx.TextCtrl(self, CTRL_TEXTURE_PATH,"http://"),
70 CTRL_IMAGE : wx.RadioButton(self, CTRL_IMAGE, "Image"),
71 CTRL_IMAGE_PATH :wx.TextCtrl(self, CTRL_IMAGE_PATH,"http://"),
72 CTRL_GRID : wx.TextCtrl(self, CTRL_GRID),
73 CTRL_GRID_SNAP : wx.CheckBox(self, CTRL_GRID_SNAP, " Snap to grid"),
74 CTRL_GRID_COLOR : wx.Button(self, CTRL_GRID_COLOR, "Grid Color"),
75 CTRL_GRID_MODE_RECT : wx.RadioButton(self, CTRL_GRID_MODE_RECT, "Rectangular", style=wx.RB_GROUP),
76 CTRL_GRID_MODE_HEX : wx.RadioButton(self, CTRL_GRID_MODE_HEX, "Hexagonal"),
77 CTRL_GRID_LINE_NONE : wx.RadioButton(self, CTRL_GRID_LINE_NONE, "No Lines", style=wx.RB_GROUP),
78 CTRL_GRID_LINE_DOTTED : wx.RadioButton(self, CTRL_GRID_LINE_DOTTED, "Dotted Lines"),
79 CTRL_GRID_LINE_SOLID : wx.RadioButton(self, CTRL_GRID_LINE_SOLID, "Solid Lines")
80 }
81 # set values of bg controls
82 self.ctrls[CTRL_BG_COLOR].SetValue(False)
83 self.ctrls[CTRL_TEXTURE].SetValue(False)
84 self.ctrls[CTRL_IMAGE].SetValue(False)
85
86 # Begin ted's changes for map bg persistency.
87 if bg_layer.bg_color != None:
88 self.ctrls[CTRL_BG_COLOR_VALUE].SetBackgroundColour(bg_layer.bg_color)
89 if bg_layer.img_path != None:
90 self.ctrls[CTRL_TEXTURE_PATH].SetValue(bg_layer.img_path)
91 self.ctrls[CTRL_IMAGE_PATH].SetValue(bg_layer.img_path)
92 # End ted's changes
93
94 if bg_layer.type == BG_COLOR:
95 self.ctrls[CTRL_BG_COLOR].SetValue(True)
96 # self.ctrls[CTRL_BG_COLOR_VALUE].SetBackgroundColour(bg_layer.bg_color)
97 elif bg_layer.type == BG_TEXTURE:
98 self.ctrls[CTRL_TEXTURE].SetValue(True)
99 # self.ctrls[CTRL_TEXTURE_PATH].SetValue(bg_layer.img_path)
100 elif bg_layer.type == BG_IMAGE:
101 self.ctrls[CTRL_WIDTH].Enable(False)
102 self.ctrls[CTRL_HEIGHT].Enable(False)
103 self.ctrls[CTRL_IMAGE].SetValue(True)
104 # self.ctrls[CTRL_IMAGE_PATH].SetValue(bg_layer.img_path)
105
106 # set grid layer control values
107 self.ctrls[CTRL_GRID].SetValue(str(grid_layer.unit_size))
108 self.ctrls[CTRL_GRID_SNAP].SetValue(grid_layer.snap)
109 self.ctrls[CTRL_GRID_COLOR].SetBackgroundColour(grid_layer.color)
110 self.ctrls[CTRL_GRID_MODE_RECT].SetValue(grid_layer.mode == GRID_RECTANGLE)
111 self.ctrls[CTRL_GRID_MODE_HEX].SetValue(grid_layer.mode == GRID_HEXAGON)
112 self.ctrls[CTRL_GRID_LINE_NONE].SetValue(grid_layer.line == LINE_NONE)
113 self.ctrls[CTRL_GRID_LINE_DOTTED].SetValue(grid_layer.line == LINE_DOTTED)
114 self.ctrls[CTRL_GRID_LINE_SOLID].SetValue(grid_layer.line == LINE_SOLID)
115
116 #create sizers
117 sizers = {}
118 sizers['main'] = wx.BoxSizer(wx.VERTICAL)
119
120 #size
121 sizers['size'] = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Size"), wx.HORIZONTAL)
122 sizers['size'].Add(wx.StaticText(self, -1, "Width: "), 0, wx.ALIGN_CENTER)
123 sizers['size'].Add(self.ctrls[CTRL_WIDTH], 0, wx.ALIGN_CENTER)
124 sizers['size'].Add(wx.Size(20,25))
125 sizers['size'].Add(wx.StaticText(self, -1, "Height: "), 0, wx.ALIGN_CENTER)
126 sizers['size'].Add(self.ctrls[CTRL_HEIGHT], 0, wx.ALIGN_CENTER)
127
128 #bg
129 sizers['bg'] = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Background"), wx.HORIZONTAL)
130 sizers['bg_layout'] = wx.FlexGridSizer(3, 2,10,10)
131 sizers['bg_layout'].AddMany([(self.ctrls[CTRL_BG_COLOR],0,wx.EXPAND),
132 (self.ctrls[CTRL_BG_COLOR_VALUE],1,wx.EXPAND),
133 (self.ctrls[CTRL_TEXTURE],0,wx.EXPAND),
134 (self.ctrls[CTRL_TEXTURE_PATH],1,wx.EXPAND),
135 (self.ctrls[CTRL_IMAGE],0,wx.EXPAND),
136 (self.ctrls[CTRL_IMAGE_PATH],1,wx.EXPAND)
137 ])
138 sizers['bg_layout'].AddGrowableCol(1)
139 sizers['bg'].Add(sizers['bg_layout'], 0, wx.EXPAND)
140
141 #grid
142 sizers['grid'] = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Grid"), wx.HORIZONTAL)
143 sizers['grid_layout'] = wx.FlexGridSizer(2, 3,10,10)
144 sizers['grid_layout'].AddMany([(wx.StaticText(self, -1, "Pixels per Square: "),2,wx.ALIGN_CENTER),
145 (self.ctrls[CTRL_GRID],1,wx.EXPAND),
146 (self.ctrls[CTRL_GRID_COLOR],1,wx.EXPAND),
147 (self.ctrls[CTRL_GRID_SNAP],2,wx.EXPAND),
148 (self.ctrls[CTRL_GRID_MODE_RECT],1,wx.EXPAND),
149 (self.ctrls[CTRL_GRID_MODE_HEX],1,wx.EXPAND),
150 (self.ctrls[CTRL_GRID_LINE_NONE],1,wx.EXPAND),
151 (self.ctrls[CTRL_GRID_LINE_DOTTED],1,wx.EXPAND),
152 (self.ctrls[CTRL_GRID_LINE_SOLID],1,wx.EXPAND)
153 ])
154 sizers['grid'].Add(sizers['grid_layout'], 0, wx.EXPAND)
155
156 # buttons
157 sizers['but'] = wx.BoxSizer(wx.HORIZONTAL)
158 sizers['but'].Add(wx.Button(self, wx.ID_OK, "Apply"), 1, wx.EXPAND)
159 sizers['but'].Add(wx.Size(10,10))
160 sizers['but'].Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.EXPAND)
161 self.sizers = sizers
162
163 #main sizer
164 self.sizers['main'].Add(sizers['size'],1, wx.EXPAND)
165 self.sizers['main'].Add(sizers['bg'], 1, wx.EXPAND)
166 self.sizers['main'].Add(sizers['grid'], 1, wx.EXPAND)
167 self.sizers['main'].Add(sizers['but'], 0, wx.EXPAND)
168 self.SetSizer(self.sizers['main'])
169 self.SetAutoLayout(True)
170 self.Fit()
171
172 #event handlers
173 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
174 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_BG_COLOR)
175 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_TEXTURE)
176 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_IMAGE)
177 self.Bind(wx.EVT_BUTTON, self.on_click, id=CTRL_BG_COLOR_VALUE)
178 self.Bind(wx.EVT_BUTTON, self.on_click, id=CTRL_GRID_COLOR)
179 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_MODE_RECT)
180 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_MODE_HEX)
181 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_LINE_NONE)
182 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_LINE_DOTTED)
183 self.Bind(wx.EVT_RADIOBUTTON, self.on_click, id=CTRL_GRID_LINE_SOLID)
184
185 def on_click(self,evt):
186 id = evt.GetId()
187 if id == CTRL_BG_COLOR or id == CTRL_TEXTURE:
188 self.ctrls[CTRL_WIDTH].Enable(True)
189 self.ctrls[CTRL_HEIGHT].Enable(True)
190 elif id == CTRL_IMAGE:
191 self.ctrls[CTRL_WIDTH].Enable(False)
192 self.ctrls[CTRL_HEIGHT].Enable(False)
193 elif id == CTRL_BG_COLOR_VALUE:
194 data = wx.ColourData()
195 data.SetChooseFull(True)
196 dlg = wx.ColourDialog(self, data)
197 if dlg.ShowModal() == wx.ID_OK:
198 data = dlg.GetColourData()
199 self.ctrls[CTRL_BG_COLOR_VALUE].SetBackgroundColour(data.GetColour())
200 dlg.Destroy()
201 elif id == CTRL_GRID_COLOR:
202 data = wx.ColourData()
203 data.SetChooseFull(True)
204 dlg = wx.ColourDialog(self, data)
205 if dlg.ShowModal() == wx.ID_OK:
206 data = dlg.GetColourData()
207 self.ctrls[CTRL_GRID_COLOR].SetBackgroundColour(data.GetColour())
208 dlg.Destroy()
209 def on_ok(self,evt):
210 try:
211 self.size = (int(self.ctrls[CTRL_WIDTH].GetValue()),int(self.ctrls[CTRL_HEIGHT].GetValue()))
212 except:
213 pass
214 # dlg = wx.MessageDialog(frame, 'Invalid Size',"Error")
215 # dlg.ShowModal()
216 # dlg.Destroy()
217 if self.ctrls[CTRL_BG_COLOR].GetValue() == True:
218 self.bg_layer.set_color(self.ctrls[CTRL_BG_COLOR_VALUE].GetBackgroundColour())
219 elif self.ctrls[CTRL_TEXTURE].GetValue() == True:
220 self.bg_layer.set_texture(self.ctrls[CTRL_TEXTURE_PATH].GetValue())
221 elif self.ctrls[CTRL_IMAGE].GetValue() == True:
222 self.size = self.bg_layer.set_image(self.ctrls[CTRL_IMAGE_PATH].GetValue(),self.grid_layer.mapscale)
223 else:
224 self.bg_layer.clear()
225 if self.ctrls[CTRL_GRID_MODE_RECT].GetValue() == True:
226 grid_mode = GRID_RECTANGLE
227 else:
228 grid_mode = GRID_HEXAGON
229 if self.ctrls[CTRL_GRID_LINE_NONE].GetValue() == True:
230 grid_line = LINE_NONE
231 elif self.ctrls[CTRL_GRID_LINE_DOTTED].GetValue() == True:
232 grid_line = LINE_DOTTED
233 else:
234 grid_line = LINE_SOLID
235 self.grid_layer.set_grid(int(self.ctrls[CTRL_GRID].GetValue()),
236 self.ctrls[CTRL_GRID_SNAP].GetValue(),
237 self.ctrls[CTRL_GRID_COLOR].GetBackgroundColour(),
238 grid_mode,
239 grid_line)
240 self.EndModal(wx.ID_OK)