Mercurial > traipse_dev
comparison orpg/map/__init__.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 from threading import Lock | |
2 import mimetypes | |
3 import xml.dom.minidom as minidom | |
4 | |
5 import wx | |
6 | |
7 import orpg.dirpath | |
8 from orpg.orpgCore import * | |
9 from orpg.tools.rgbhex import RGBHex | |
10 import orpg.tools.ButtonPanel as BP | |
11 | |
12 from _canvas import MapCanvas | |
13 | |
14 class MapWnd(wx.Panel): | |
15 def __init__(self, parent, openrpg): | |
16 wx.Panel.__init__(self, parent, wx.ID_ANY) | |
17 self.openrpg = openrpg | |
18 self.log = self.openrpg.get_component("log") | |
19 self.xml = self.openrpg.get_component("xml") | |
20 self.dir_struct = self.openrpg.get_component("dir_struct") | |
21 self.validate = self.openrpg.get_component("validate") | |
22 self.settings = self.openrpg.get_component("settings") | |
23 | |
24 self.Freeze() | |
25 sizer = wx.GridBagSizer(hgap=1, vgap=1) | |
26 sizer.SetEmptyCellSize((0,0)) | |
27 | |
28 self.canvas = MapCanvas(self, self.openrpg) | |
29 sizer.Add(self.canvas, (0,0), flag=wx.EXPAND) | |
30 | |
31 self.gmToolBar = BP.ButtonPanel(self, wx.ID_ANY) | |
32 sizer.Add(self.gmToolBar, (1,0), flag=wx.EXPAND) | |
33 self.playerToolBar = BP.ButtonPanel(self, wx.ID_ANY) | |
34 sizer.Add(self.playerToolBar, (2,0), flag=wx.EXPAND) | |
35 | |
36 sizer.AddGrowableCol(0) | |
37 sizer.AddGrowableRow(0) | |
38 | |
39 self.SetSizer(sizer) | |
40 self.SetAutoLayout(True) | |
41 | |
42 self._CreateToolBar() | |
43 | |
44 self.Bind(wx.EVT_MOUSEWHEEL, self.canvas.OnZoom) | |
45 self.Bind(wx.EVT_KEY_DOWN, self.canvas.OnKey) | |
46 self.Bind(wx.EVT_KEY_UP, self.canvas.OnKey) | |
47 self.Layout() | |
48 self.Thaw() | |
49 | |
50 wx.CallAfter(self.PostLoad) | |
51 | |
52 #Public API | |
53 def PostLoad(self): | |
54 self.canvas.Clear() | |
55 #self.canvas.roleTimer.Start(100) | |
56 self.canvas.UpdateMap() | |
57 | |
58 #Events | |
59 | |
60 | |
61 #Private Methods | |
62 def _SetColorBtn(self, color, btn): | |
63 dc = wx.MemoryDC() | |
64 bmp = wx.EmptyBitmap(16, 16) | |
65 dc.SelectObject(bmp) | |
66 dc.SetBrush(wx.Brush(color)) | |
67 dc.DrawRectangle(0,0, 16, 16) | |
68 | |
69 del dc | |
70 | |
71 btn.SetBitmap(bmp) | |
72 | |
73 def _CreateToolBar(self): | |
74 self.exclusiveToolList = {} | |
75 | |
76 self.OpenBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'open.bmp', wx.BITMAP_TYPE_BMP), kind=wx.ITEM_NORMAL, shortHelp="Load New Map", longHelp="Load New Map") | |
77 self.gmToolBar.AddButton(self.OpenBtn) | |
78 | |
79 self.SaveBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'save.bmp', wx.BITMAP_TYPE_BMP), kind=wx.ITEM_NORMAL, shortHelp="Save Map", longHelp="Save Map") | |
80 self.gmToolBar.AddButton(self.SaveBtn) | |
81 | |
82 self.DefaultBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'defaultmap.png', wx.BITMAP_TYPE_PNG), kind=wx.ITEM_NORMAL, shortHelp="Load Default Map", longHelp="Load Default Map") | |
83 self.gmToolBar.AddButton(self.DefaultBtn) | |
84 self.Bind(wx.EVT_BUTTON, self.canvas.OnDefaultBtn, id=self.DefaultBtn.GetId()) | |
85 | |
86 self.MapPropsBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'compass.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_NORMAL, shortHelp="Map Properties", longHelp="Map Properties") | |
87 self.gmToolBar.AddButton(self.MapPropsBtn) | |
88 | |
89 | |
90 self.gmToolBar.AddSeparator() | |
91 | |
92 self.BGBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'img.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_NORMAL, shortHelp="Change Background", longHelp="Change Background") | |
93 self.gmToolBar.AddButton(self.BGBtn) | |
94 self.Bind(wx.EVT_BUTTON, self.canvas.OnBGBtn, id=self.BGBtn.GetId()) | |
95 | |
96 self.BGColorBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.EmptyBitmap(16,16), kind=wx.ITEM_NORMAL, shortHelp="Map Background Color", longHelp="Map Background Color") | |
97 self.gmToolBar.AddButton(self.BGColorBtn) | |
98 self._SetColorBtn(wx.GREEN, self.BGColorBtn) | |
99 self.Bind(wx.EVT_BUTTON, self.canvas.OnBGColorBtn, id=self.BGColorBtn.GetId()) | |
100 | |
101 self.TileAddBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'chess.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_NORMAL, shortHelp="Add Map Tile", longHelp="Add Map Tile") | |
102 self.gmToolBar.AddButton(self.TileAddBtn) | |
103 | |
104 self.TileMoveBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'crosshair.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_CHECK, shortHelp="Edit Tiles", longHelp="Edit Tiles") | |
105 self.gmToolBar.AddButton(self.TileMoveBtn) | |
106 self.exclusiveToolList[self.TileMoveBtn.GetId()] = self.TileMoveBtn | |
107 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.TileMoveBtn.GetId()) | |
108 | |
109 self.GridBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'grid.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_NORMAL, shortHelp="Set Grid", longHelp="Set Grid") | |
110 self.gmToolBar.AddButton(self.GridBtn) | |
111 | |
112 self.gmToolBar.AddSeparator() | |
113 | |
114 self.FogBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'fogon.png', wx.BITMAP_TYPE_PNG), kind=wx.ITEM_CHECK, shortHelp="Turn Fog On", longHelp="Turn Fog On") | |
115 self.gmToolBar.AddButton(self.FogBtn) | |
116 self.Bind(wx.EVT_BUTTON, self.canvas.OnFogBtn, id=self.FogBtn.GetId()) | |
117 | |
118 self.FogToolBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'showfog.png', wx.BITMAP_TYPE_PNG), kind=wx.ITEM_CHECK, shortHelp="Show Tool", longHelp="Show Tool") | |
119 self.gmToolBar.AddButton(self.FogToolBtn) | |
120 self.exclusiveToolList[self.FogToolBtn.GetId()] = self.FogToolBtn | |
121 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.FogToolBtn.GetId()) | |
122 menu = wx.Menu("Fog Tool") | |
123 item = wx.MenuItem(menu, 1, "Show", "Show") | |
124 self.Bind(wx.EVT_MENU, self.OnFogSelection, item) | |
125 menu.AppendItem(item) | |
126 item = wx.MenuItem(menu, 2, "Hide", "Hide") | |
127 self.Bind(wx.EVT_MENU, self.OnFogSelection, item) | |
128 menu.AppendItem(item) | |
129 self.currentFog = 'Show' | |
130 self.FogToolBtn.SetMenu(menu) | |
131 | |
132 self.FogColorBtn = BP.ButtonInfo(self.gmToolBar, wx.ID_ANY, wx.EmptyBitmap(16,16), kind=wx.ITEM_NORMAL, shortHelp="Fog Color", longHelp="Fog Color") | |
133 self.gmToolBar.AddButton(self.FogColorBtn) | |
134 self._SetColorBtn(wx.BLACK, self.FogColorBtn) | |
135 self.Bind(wx.EVT_BUTTON, self.canvas.OnFogColorBtn, id=self.FogColorBtn.GetId()) | |
136 | |
137 self.gmToolBar.AddSeparator() | |
138 | |
139 self.MiniPropsBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'questionhead.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_NORMAL, shortHelp="Miniture Properties", longHelp="Miniture Properties") | |
140 self.gmToolBar.AddButton(self.MiniPropsBtn) | |
141 | |
142 self.gmToolBar.DoLayout() | |
143 | |
144 self.SelectorBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'mouse.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_CHECK, shortHelp="Selection Tool", longHelp="Selection Tool") | |
145 self.playerToolBar.AddButton(self.SelectorBtn) | |
146 self.exclusiveToolList[self.SelectorBtn.GetId()] = self.SelectorBtn | |
147 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.SelectorBtn.GetId()) | |
148 | |
149 self.MeasureBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'tape.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_CHECK, shortHelp="Measure Tool", longHelp="Measure Tool") | |
150 self.playerToolBar.AddButton(self.MeasureBtn) | |
151 self.exclusiveToolList[self.MeasureBtn.GetId()] = self.MeasureBtn | |
152 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.MeasureBtn.GetId()) | |
153 | |
154 self.ColorBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.EmptyBitmap(16,16), kind=wx.ITEM_NORMAL, shortHelp="Select a Color", longHelp="Select a Color") | |
155 self.playerToolBar.AddButton(self.ColorBtn) | |
156 self._SetColorBtn(wx.BLACK, self.ColorBtn) | |
157 self.Bind(wx.EVT_BUTTON, self.canvas.OnColorBtn, id=self.ColorBtn.GetId()) | |
158 | |
159 self.DrawBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'draw.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_CHECK, shortHelp="Freehand Line Tool", longHelp="Freehand Line Tool") | |
160 self.playerToolBar.AddButton(self.DrawBtn) | |
161 self.exclusiveToolList[self.DrawBtn.GetId()] = self.DrawBtn | |
162 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.DrawBtn.GetId()) | |
163 menu = wx.Menu("Line Tool") | |
164 item = wx.MenuItem(menu, 3, "Free Draw", "Free Draw") | |
165 self.Bind(wx.EVT_MENU, self.OnLineSelection, item) | |
166 menu.AppendItem(item) | |
167 item = wx.MenuItem(menu, 4, "Poly Draw", "Poly Draw") | |
168 self.Bind(wx.EVT_MENU, self.OnLineSelection, item) | |
169 menu.AppendItem(item) | |
170 self.currentLine = 'Free' | |
171 self.DrawBtn.SetMenu(menu) | |
172 | |
173 self.AddTextBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'text.png', wx.BITMAP_TYPE_PNG), kind=wx.ITEM_CHECK, shortHelp="Add Text Tool", longHelp="Add Text Tool") | |
174 self.playerToolBar.AddButton(self.AddTextBtn) | |
175 self.exclusiveToolList[self.AddTextBtn.GetId()] = self.AddTextBtn | |
176 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.AddTextBtn.GetId()) | |
177 | |
178 self.AddShapeBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'circle.png', wx.BITMAP_TYPE_PNG), kind=wx.ITEM_CHECK, shortHelp="Add Shape Tool", longHelp="Add Shape Tool") | |
179 self.playerToolBar.AddButton(self.AddShapeBtn) | |
180 self.exclusiveToolList[self.AddShapeBtn.GetId()] = self.AddShapeBtn | |
181 self.Bind(wx.EVT_BUTTON, self.canvas.OnExlusiveBtn, id=self.AddShapeBtn.GetId()) | |
182 menu = wx.Menu("Shape Tool") | |
183 item = wx.MenuItem(menu, 5, "Circle", "Circle") | |
184 self.Bind(wx.EVT_MENU, self.OnShapeSelection, item) | |
185 menu.AppendItem(item) | |
186 item = wx.MenuItem(menu, 6, "Rectangle", "Rectangle") | |
187 self.Bind(wx.EVT_MENU, self.OnShapeSelection, item) | |
188 menu.AppendItem(item) | |
189 item = wx.MenuItem(menu, 7, "Arc", "Arc") | |
190 self.Bind(wx.EVT_MENU, self.OnShapeSelection, item) | |
191 menu.AppendItem(item) | |
192 self.currentShape = 'Circle' | |
193 self.AddShapeBtn.SetMenu(menu) | |
194 | |
195 self.LineWidth = wx.Choice(self.playerToolBar, wx.ID_ANY, choices=["1","2","3","4","5","6","7","8","9","10"]) | |
196 self.LineWidth.SetSelection(0) | |
197 self.playerToolBar.AddControl(self.LineWidth) | |
198 | |
199 self.playerToolBar.AddSeparator() | |
200 | |
201 self.MiniBtn = BP.ButtonInfo(self.playerToolBar, wx.ID_ANY, wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'player.gif', wx.BITMAP_TYPE_GIF), kind=wx.ITEM_NORMAL, shortHelp="Add Mini", longHelp="Add Mini") | |
202 self.playerToolBar.AddButton(self.MiniBtn) | |
203 | |
204 self.playerToolBar.DoLayout() | |
205 | |
206 def OnShapeSelection(self, event): | |
207 id = event.GetId() | |
208 if id == 5: | |
209 self.currentShape = 'Circle' | |
210 self.AddShapeBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'circle.png', wx.BITMAP_TYPE_PNG) | |
211 elif id == 6: | |
212 self.currentShape = 'Rectangle' | |
213 self.AddShapeBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'rectangle.png', wx.BITMAP_TYPE_PNG) | |
214 elif id == 7: | |
215 self.currentShape = 'Arc' | |
216 self.AddShapeBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'arc.png', wx.BITMAP_TYPE_PNG) | |
217 | |
218 def OnLineSelection(self, event): | |
219 id = event.GetId() | |
220 if id == 3: | |
221 self.currentLine = 'Free' | |
222 self.DrawBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'draw.gif', wx.BITMAP_TYPE_GIF) | |
223 self.DrawBtn.SetShortHelp("Freehand Line Tool") | |
224 self.DrawBtn.SetLongHelp("Freehand Line Tool") | |
225 elif id == 4: | |
226 self.currentLine = 'Poly' | |
227 self.DrawBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'dash.png', wx.BITMAP_TYPE_PNG) | |
228 self.DrawBtn.SetShortHelp("Poly Line Tool") | |
229 self.DrawBtn.SetLongHelp("Poly Line Tool") | |
230 | |
231 def OnFogSelection(self, event): | |
232 id = event.GetId() | |
233 if id == 1: | |
234 self.currentFog = 'Show' | |
235 self.FogToolBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'showfog.png', wx.BITMAP_TYPE_PNG) | |
236 self.FogToolBtn.SetShortHelp("Show Fog Tool") | |
237 self.FogToolBtn.SetLongHelp("Show Fog Tool") | |
238 elif id == 2: | |
239 self.currentFog = 'Hide' | |
240 self.FogToolBtn.Bitmap = wx.Bitmap(orpg.dirpath.dir_struct["icon"] + 'hidefog.png', wx.BITMAP_TYPE_PNG) | |
241 self.FogToolBtn.SetShortHelp("Hide Fog Tool") | |
242 self.FogToolBtn.SetLongHelp("Hide Fog Tool") | |
243 | |
244 ### Test Stuff | |
245 class BlankFrame(wx.Frame): | |
246 def __init__(self, openrpg): | |
247 wx.Frame.__init__(self, None, title="New Map Test Window", size=(740,480)) | |
248 | |
249 self.map = MapWnd(self, openrpg) | |
250 self.basesizer = wx.BoxSizer(wx.VERTICAL) | |
251 self.basesizer.Add(self.map, 1, wx.EXPAND) | |
252 | |
253 self.SetSizer(self.basesizer) | |
254 self.SetAutoLayout(True) | |
255 #self.Fit() | |
256 | |
257 | |
258 class BlankApp(wx.App): | |
259 def OnInit(self): | |
260 self.frame = BlankFrame() | |
261 self.frame.Show() | |
262 self.SetTopWindow(self.frame) | |
263 | |
264 | |
265 return True | |
266 | |
267 if __name__ == "__main__": | |
268 app = BlankApp(0) | |
269 app.MainLoop() |