annotate plugins/bcg/token_handler.py @ 137:54446a995007 alpha

Traipse Alpha 'OpenRPG' {091018-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! **New Gametree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Wed, 18 Nov 2009 19:57:52 -0600
parents 2f2bebe9c77f
children
rev   line source
105
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
2 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
4 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
8 # (at your option) any later version.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
9 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
14 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
18 # --
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
19 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
20 # File: mapper/whiteboard_hander.py
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
21 # Author: OpenRPG Team
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
22 # Maintainer:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
23 # Version:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
24 # $Id: token_handler.py,v 1.43 2007/12/07 20:39:50 digitalxero Exp $
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
25 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
26 # Description: Token layer handler; derived from token Layer handler
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
27 #
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
28 __version__ = "$Id: token_handler.py,v 1.43 2007/12/07 20:39:50 madmathlabs Exp $"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
29
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
30 from orpg.mapper.base_handler import *
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
31 from tok_dialogs import *
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
32 import thread
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
33 import time
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
34 import mimetypes
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
35 import urllib
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
36 import xml.dom.minidom as minidom
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
37 import wx
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
38
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
39 ## rewrite Grid
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
40 from orpg.mapper.grid import GRID_RECTANGLE
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
41 from orpg.mapper.grid import GRID_HEXAGON
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
42 from orpg.mapper.grid import GRID_ISOMETRIC
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
43 import os
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
44
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
45 from orpg.tools.orpg_settings import settings
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
46
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
47 ## Jesus H! No Face, rotate!
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
48 TOK_ROT_LEFT = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
49 ROT_LEFT_45 = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
50 LABEL_TOOL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
51 LAYER_TOOL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
52 TOK_LIST_TOOL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
53 TOK_TOOL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
54 TOK_URL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
55 SERIAL_TOOL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
56 TOK_MOVE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
57 TOK_REMOVE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
58 TOK_PROP_DLG = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
59 TOK_FACING_NONE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
60 TOK_FACING_MATCH = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
61 TOK_FACING_EAST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
62 TOK_FACING_WEST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
63 TOK_FACING_NORTH = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
64 TOK_FACING_SOUTH = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
65 TOK_FACING_NORTHEAST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
66 TOK_FACING_SOUTHEAST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
67 TOK_FACING_SOUTHWEST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
68 TOK_FACING_NORTHWEST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
69 TOK_HEADING_NONE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
70 TOK_HEADING_MATCH = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
71 TOK_HEADING_EAST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
72 TOK_HEADING_WEST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
73 TOK_HEADING_NORTH = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
74 TOK_HEADING_SOUTH = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
75 TOK_HEADING_NORTHEAST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
76 TOK_HEADING_SOUTHEAST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
77 TOK_HEADING_SOUTHWEST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
78 TOK_HEADING_NORTHWEST = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
79 TOK_HEADING_SUBMENU = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
80 TOK_FACING_SUBMENU = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
81 TOK_ALIGN_SUBMENU = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
82 TOK_ALIGN_GRID_CENTER = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
83 TOK_ALIGN_GRID_TL = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
84 TOK_TITLE_HACK = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
85 TOK_TO_GAMETREE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
86 TOK_BACK_ONE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
87 TOK_FORWARD_ONE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
88 TOK_TO_BACK = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
89 TOK_TO_FRONT = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
90 TOK_LOCK_BACK = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
91 TOK_LOCK_FRONT = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
92 TOK_FRONTBACK_UNLOCK = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
93 TOK_ZORDER_SUBMENU = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
94 TOK_SHOW_HIDE = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
95 TOK_LOCK_UNLOCK = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
96 MAP_REFRESH_MINI_URLS = wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
97
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
98 class myFileDropTarget(wx.FileDropTarget):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
99 def __init__(self, handler):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
100 wx.FileDropTarget.__init__(self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
101 self.m_handler = handler
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
102 def OnDropFiles(self, x, y, filenames):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
103 self.m_handler.on_drop_files(x, y, filenames)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
104
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
105 class token_handler(base_layer_handler):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
106
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
107 def __init__(self, parent, id, canvas):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
108 self.sel_min = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
109 self.auto_label = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
110 self.use_serial = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
111 self.auto_label_cb = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
112 self.canvas = canvas
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
113 self.settings = settings
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
114 self.mini_rclick_menu_extra_items = {}
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
115 self.background_rclick_menu_extra_items = {}
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
116 base_layer_handler.__init__(self, parent, id, canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
117 # id is the index of the last good menu choice or 'None'
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
118 # if the last menu was left without making a choice
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
119 # should be -1 at other times to prevent events overlapping
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
120 self.lastMenuChoice = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
121 self.drag_mini = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
122 self.tooltip_delay_miliseconds = 500
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
123 self.tooltip_timer = wx.CallLater(self.tooltip_delay_miliseconds, self.on_tooltip_timer)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
124 self.tooltip_timer.Stop()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
125 dt = myFileDropTarget(self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
126 self.canvas.SetDropTarget(dt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
127 #wxInitAllImageHandlers()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
128
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
129 def build_ctrls(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
130 base_layer_handler.build_ctrls(self)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
131 # add controls in reverse order! (unless you want them after the default tools)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
132 self.auto_label_cb = wx.CheckBox(self, wx.ID_ANY, ' Auto Label ', (-1,-1),(-1,-1))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
133 self.auto_label_cb.SetValue(self.auto_label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
134 self.min_url = wx.ComboBox(self, wx.ID_ANY, "http://", style=wx.CB_DROPDOWN | wx.CB_SORT)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
135 self.localBrowse = wx.Button(self, wx.ID_ANY, 'Browse', style=wx.BU_EXACTFIT)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
136 minilist = createMaskedButton( self, dir_struct["icon"]+'questionhead.gif', 'Edit token properties', wx.ID_ANY)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
137 miniadd = wx.Button(self, wx.ID_OK, "Add Token", style=wx.BU_EXACTFIT)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
138 self.sizer.Add(self.auto_label_cb,0,wx.ALIGN_CENTER)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
139 self.sizer.Add((6, 0))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
140 self.sizer.Add(self.min_url, 1, wx.ALIGN_CENTER)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
141 self.sizer.Add((6, 0))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
142 self.sizer.Add(miniadd, 0, wx.ALIGN_CENTER)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
143 self.sizer.Add((6, 0))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
144 self.sizer.Add(self.localBrowse, 0, wx.ALIGN_CENTER)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
145 self.sizer.Add((6, 0))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
146 self.sizer.Add(minilist, 0, wx.ALIGN_CENTER)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
147 self.Bind(wx.EVT_BUTTON, self.on_min_list, minilist)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
148 self.Bind(wx.EVT_BUTTON, self.on_token, miniadd)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
149 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
150 self.Bind(wx.EVT_CHECKBOX, self.on_label, self.auto_label_cb)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
151
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
152 def on_browse(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
153 if not self.role_is_gm_or_player(): return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
154 dlg = wx.FileDialog(None, "Select a Token to load", dir_struct["user"]+'webfiles/',
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
155 wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
156 if not dlg.ShowModal() == wx.ID_OK:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
157 dlg.Destroy()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
158 return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
159 file = open(dlg.GetPath(), "rb")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
160 imgdata = file.read()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
161 file.close()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
162 filename = dlg.GetFilename()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
163 (imgtype,j) = mimetypes.guess_type(filename)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
164 postdata = urllib.urlencode({'filename':filename, 'imgdata':imgdata, 'imgtype':imgtype})
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
165
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
166 ## Removal of Remote Server?
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
167 if self.settings.get_setting('LocalorRemote') == 'Remote':
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
168 # make the new mini appear in top left of current viewable map
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
169 dc = wx.ClientDC(self.canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
170 self.canvas.PrepareDC(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
171 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
172 x = dc.DeviceToLogicalX(0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
173 y = dc.DeviceToLogicalY(0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
174 thread.start_new_thread(self.canvas.layers['token'].upload,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
175 (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)})
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
176 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
177 try: min_url = component.get("cherrypy") + filename
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
178 except: return #chat.InfoPost('CherryPy is not started!')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
179 min_url = dlg.GetDirectory().replace(dir_struct["user"]+'webfiles' + os.sep,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
180 component.get("cherrypy")) + '/' + filename
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
181 # build url
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
182 if min_url == "" or min_url == "http://": return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
183 if min_url[:7] != "http://": min_url = "http://" + min_url
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
184 # make label
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
185 if self.auto_label and min_url[-4:-3] == '.':
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
186 start = min_url.rfind("/") + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
187 min_label = min_url[start:len(min_url)-4]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
188 if self.use_serial: min_label = '%s %d' % ( min_label, self.canvas.layers['token'].next_serial() )
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
189 else: min_label = ""
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
190 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
191 try:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
192 id = 'mini-' + self.canvas.frame.session.get_next_id()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
193 # make the new mini appear in top left of current viewable map
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
194 dc = wx.ClientDC(self.canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
195 self.canvas.PrepareDC(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
196 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
197 x = dc.DeviceToLogicalX(0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
198 y = dc.DeviceToLogicalY(0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
199 self.canvas.layers['token'].add_token(id, min_url, pos=cmpPoint(x,y), label=min_label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
200 except:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
201 # When there is an exception here, we should be decrementing the serial_number for reuse!!
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
202 unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
203 dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
204 dlg.ShowModal()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
205 dlg.Destroy()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
206 self.canvas.layers['token'].rollback_serial()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
207 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
208 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
209
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
210
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
211 def build_menu(self,label = "Token"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
212 ## Menu Changes: Rotate
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
213 ## Menu into Component
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
214 ## Remove To GameTree option
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
215 base_layer_handler.build_menu(self,label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
216 self.main_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
217 self.main_menu.Append(LABEL_TOOL,"&Auto label","",1)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
218 self.main_menu.Check(LABEL_TOOL,self.auto_label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
219 self.main_menu.Append(SERIAL_TOOL,"&Number minis","",1)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
220 self.main_menu.Check(SERIAL_TOOL, self.use_serial)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
221 self.main_menu.Append(MAP_REFRESH_MINI_URLS,"&Refresh tokens") # Add the menu item
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
222 self.main_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
223 self.main_menu.Append(TOK_MOVE, "Move")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
224 self.canvas.Bind(wx.EVT_MENU, self.on_map_board_menu_item, id=MAP_REFRESH_MINI_URLS) # Set the handler
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
225 self.canvas.Bind(wx.EVT_MENU, self.on_label, id=LABEL_TOOL)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
226 self.canvas.Bind(wx.EVT_MENU, self.on_serial, id=SERIAL_TOOL)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
227 # build token menu
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
228 self.min_menu = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
229 # Rectangles and hexagons require slightly different menus because of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
230 # facing and heading possibilities.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
231
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
232 rot_left = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
233 rot_left_45 = rot_left.Append(-1, '45*')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
234 self.canvas.Bind(wx.EVT_MENU, self.rot_left_45, rot_left_45)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
235 rot_right = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
236
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
237 rot_right_45 = rot_right.Append(-1, '45*')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
238 self.canvas.Bind(wx.EVT_MENU, self.rot_right_45, rot_right_45)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
239 ## Replace with Rotate. Left - Right, 45 - 90 degress.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
240 """
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
241 face_menu = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
242 face_menu.Append(TOK_FACING_NONE,"&None")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
243 face_menu.Append(TOK_FACING_NORTH,"&North")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
244 face_menu.Append(TOK_FACING_NORTHEAST,"Northeast")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
245 face_menu.Append(TOK_FACING_EAST,"East")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
246 face_menu.Append(TOK_FACING_SOUTHEAST,"Southeast")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
247 face_menu.Append(TOK_FACING_SOUTH,"&South")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
248 face_menu.Append(TOK_FACING_SOUTHWEST,"Southwest")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
249 face_menu.Append(TOK_FACING_WEST,"West")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
250 face_menu.Append(TOK_FACING_NORTHWEST,"Northwest")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
251 """
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
252 ###
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
253
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
254 heading_menu = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
255 heading_menu.Append(TOK_HEADING_NONE,"&None")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
256 heading_menu.Append(TOK_HEADING_NORTH,"&North")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
257 heading_menu.Append(TOK_HEADING_NORTHEAST,"Northeast")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
258 heading_menu.Append(TOK_HEADING_EAST,"East")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
259 heading_menu.Append(TOK_HEADING_SOUTHEAST,"Southeast")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
260 heading_menu.Append(TOK_HEADING_SOUTH,"&South")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
261 heading_menu.Append(TOK_HEADING_SOUTHWEST,"Southwest")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
262 heading_menu.Append(TOK_HEADING_WEST,"West")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
263 heading_menu.Append(TOK_HEADING_NORTHWEST,"Northwest")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
264
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
265 align_menu = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
266 align_menu.Append(TOK_ALIGN_GRID_CENTER,"&Center")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
267 align_menu.Append(TOK_ALIGN_GRID_TL,"&Top-Left")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
268 # This is a hack to simulate a menu title, due to problem in Linux
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
269 if wx.Platform == '__WXMSW__': self.min_menu.SetTitle(label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
270 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
271 self.min_menu.Append(TOK_TITLE_HACK,label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
272 self.min_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
273 self.min_menu.Append(TOK_SHOW_HIDE,"Show / Hide")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
274 self.min_menu.Append(TOK_LOCK_UNLOCK, "Lock / Unlock")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
275 self.min_menu.Append(TOK_REMOVE,"&Remove")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
276
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
277 ##Remove
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
278 #self.min_menu.Append(TOK_TO_GAMETREE,"To &Gametree")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
279 ###
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
280
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
281 self.min_menu.AppendMenu(TOK_HEADING_SUBMENU,"Set &Heading",heading_menu)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
282
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
283 ##Remove
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
284 self.min_menu.AppendMenu(TOK_ROT_LEFT,"&Rotate Left",rot_left)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
285 self.min_menu.AppendMenu(wx.ID_ANY,"&Rotate Right",rot_right)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
286 ###
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
287
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
288 self.min_menu.AppendMenu(TOK_ALIGN_SUBMENU,"Snap-to &Alignment",align_menu)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
289 self.min_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
290 zorder_menu = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
291 zorder_menu.Append(TOK_BACK_ONE,"Back one")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
292 zorder_menu.Append(TOK_FORWARD_ONE,"Forward one")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
293 zorder_menu.Append(TOK_TO_BACK,"To back")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
294 zorder_menu.Append(TOK_TO_FRONT,"To front")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
295 zorder_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
296 zorder_menu.Append(TOK_LOCK_BACK,"Lock to back")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
297 zorder_menu.Append(TOK_LOCK_FRONT,"Lock to front")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
298 zorder_menu.Append(TOK_FRONTBACK_UNLOCK,"Unlock Front/Back")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
299 self.min_menu.AppendMenu(TOK_ZORDER_SUBMENU, "Token Z-Order",zorder_menu)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
300 #self.min_menu.Append(TOK_LOCK,"&Lock")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
301 self.min_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
302 self.min_menu.Append(TOK_PROP_DLG,"&Properties")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
303
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
304
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
305 #self.min_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
306 #self.min_menu.Append(TOK_MOVE, "Move")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
307
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
308 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_MOVE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
309 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_SHOW_HIDE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
310 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_LOCK_UNLOCK)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
311 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_REMOVE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
312
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
313 ##Remove
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
314 #self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_TO_GAMETREE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
315 ###
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
316
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
317 #self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_LOCK)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
318 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_PROP_DLG)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
319
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
320 ##Remove
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
321 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_NONE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
322 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_EAST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
323 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_WEST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
324 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_NORTH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
325 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_SOUTH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
326 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_NORTHEAST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
327 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_SOUTHEAST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
328 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_SOUTHWEST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
329 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FACING_NORTHWEST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
330 ###
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
331
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
332 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_NONE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
333 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_EAST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
334 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_WEST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
335 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_NORTH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
336 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_SOUTH)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
337 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_NORTHEAST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
338 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_SOUTHEAST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
339 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_SOUTHWEST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
340 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_HEADING_NORTHWEST)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
341 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_ALIGN_GRID_CENTER)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
342 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_ALIGN_GRID_TL)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
343 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_BACK_ONE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
344 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FORWARD_ONE)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
345 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_TO_BACK)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
346 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_TO_FRONT)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
347 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_LOCK_BACK)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
348 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_LOCK_FRONT)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
349 self.canvas.Bind(wx.EVT_MENU, self.on_min_menu_item, id=TOK_FRONTBACK_UNLOCK)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
350 ######### add plugin added menu items #########
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
351 if len(self.mini_rclick_menu_extra_items)>0:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
352 self.min_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
353 for item in self.mini_rclick_menu_extra_items.items(): self.min_menu.Append(item[1], item[0])
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
354 if len(self.background_rclick_menu_extra_items)>0:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
355 self.main_menu.AppendSeparator()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
356 for item in self.background_rclick_menu_extra_items.items():
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
357 self.main_menu.Append(item[1], item[0])
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
358
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
359 def do_min_menu(self,pos):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
360 self.canvas.PopupMenu(self.min_menu,pos)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
361
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
362 def rot_left_45(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
363 #self.sel_rmin.rotate += 0.785
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
364 self.sel_rmin.rotate += 1.046
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
365 #component.get('drawn')[self.sel_rmin] = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
366
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
367 def rot_right_45(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
368 #self.sel_rmin.rotate -= 0.785
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
369 self.sel_rmin.rotate -= 1.046
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
370
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
371 def do_min_select_menu(self, min_list, pos):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
372 # to prevent another event being processed
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
373 self.lastMenuChoice = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
374 self.min_select_menu = wx.Menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
375 self.min_select_menu.SetTitle("Select Token")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
376 loop_count = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
377 try:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
378 for m in min_list:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
379 # Either use the token label for the selection list
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
380 if m.label: self.min_select_menu.Append(loop_count, m.label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
381 # Or use part of the images filename as an identifier
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
382 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
383 string_split = string.split(m.path,"/",)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
384 last_string = string_split[len(string_split)-1]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
385 self.min_select_menu.Append(loop_count, 'Unlabeled - ' + last_string[:len(last_string)-4])
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
386 self.canvas.Bind(wx.EVT_MENU, self.min_selected, id=loop_count)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
387 loop_count += 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
388 self.canvas.PopupMenu(self.min_select_menu,pos)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
389 except: pass
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
390
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
391 def min_selected(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
392 # this is the callback function for the menu that is used to choose
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
393 # between minis when you right click, left click or left double click
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
394 # on a stack of two or more
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
395 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
396 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
397 self.lastMenuChoice = evt.GetId()-1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
398
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
399 def on_min_menu_item(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
400 id = evt.GetId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
401 if id == TOK_MOVE:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
402 if self.sel_min:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
403 self.moveSelectedMini(self.last_rclick_pos)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
404 self.deselectAndRefresh()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
405 return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
406 elif id == TOK_REMOVE: self.canvas.layers['token'].del_token(self.sel_rmin)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
407
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
408 ##Remove
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
409 elif id == TOK_TO_GAMETREE:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
410 min_xml = self.sel_rmin.toxml(action="new")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
411 node_begin = "<nodehandler module='map_token_nodehandler' class='map_token_handler' name='"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
412 if self.sel_rmin.label: node_begin += self.sel_rmin.label + "'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
413 else: node_begin += "Unnamed token'"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
414 node_begin += ">"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
415 gametree = component.get('tree')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
416 node_xml = node_begin + min_xml + '</nodehandler>'
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
417 #print "Sending this XML to insert_xml:" + node_xml
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
418 gametree.insert_xml(str(node_xml))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
419
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
420 elif id == TOK_SHOW_HIDE:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
421 if self.sel_rmin.hide: self.sel_rmin.hide = 0
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
422 else: self.sel_rmin.hide = 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
423 elif id == TOK_LOCK_UNLOCK:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
424 if self.sel_rmin.locked: self.sel_rmin.locked = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
425 else: self.sel_rmin.locked = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
426 if self.sel_rmin == self.sel_min:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
427 # when we lock / unlock the selected mini make sure it isn't still selected
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
428 # or it might easily get moved by accident and be hard to move back
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
429 self.sel_min.selected = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
430 self.sel_min.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
431 self.sel_min = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
432 recycle_bin = {TOK_HEADING_NONE: FACE_NONE, TOK_HEADING_NORTH: FACE_NORTH,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
433 TOK_HEADING_NORTHWEST: FACE_NORTHWEST, TOK_HEADING_NORTHEAST: FACE_NORTHEAST,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
434 TOK_HEADING_EAST: FACE_EAST, TOK_HEADING_SOUTHEAST: FACE_SOUTHEAST, TOK_HEADING_SOUTHWEST: FACE_SOUTHWEST,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
435 TOK_HEADING_SOUTH: FACE_SOUTH, TOK_HEADING_WEST: FACE_WEST}
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
436 if recycle_bin.has_key(id):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
437 self.sel_rmin.heading = recycle_bin[id]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
438 del recycle_bin
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
439 recycle_bin = {TOK_FACING_NONE: FACE_NONE, TOK_FACING_NORTH: FACE_NORTH,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
440 TOK_FACING_NORTHWEST: FACE_NORTHWEST, TOK_FACING_NORTHEAST: FACE_NORTHEAST,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
441 TOK_FACING_EAST: FACE_EAST, TOK_FACING_SOUTHEAST: FACE_SOUTHEAST, TOK_FACING_SOUTHWEST: FACE_SOUTHWEST,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
442 TOK_FACING_SOUTH: FACE_SOUTH, TOK_FACING_WEST: FACE_WEST}
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
443 if recycle_bin.has_key(id):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
444 self.sel_rmin.face = recycle_bin[id]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
445 del recycle_bin
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
446 elif id == TOK_ALIGN_GRID_CENTER: self.sel_rmin.snap_to_align = SNAPTO_ALIGN_CENTER
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
447 elif id == TOK_ALIGN_GRID_TL: self.sel_rmin.snap_to_align = SNAPTO_ALIGN_TL
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
448 elif id == TOK_PROP_DLG:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
449 old_lock_value = self.sel_rmin.locked
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
450 dlg = min_edit_dialog(self.canvas.frame.GetParent(),self.sel_rmin)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
451 if dlg.ShowModal() == wx.ID_OK:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
452 if self.sel_rmin == self.sel_min and self.sel_rmin.locked != old_lock_value:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
453 # when we lock / unlock the selected mini make sure it isn't still selected
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
454 # or it might easily get moved by accident and be hard to move back
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
455 self.sel_min.selected = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
456 self.sel_min.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
457 self.sel_min = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
458 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
459 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
460 return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
461
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
462 elif id == TOK_BACK_ONE:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
463 # This assumes that we always start out with a z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
464 # that starts at 0 and goes up to the number of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
465 # minis - 1. If this isn't the case, then execute
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
466 # a self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
467 # before getting the oldz to test
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
468 # Save the selected minis current z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
469 oldz = self.sel_rmin.zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
470 # Make sure the mini isn't sticky front or back
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
471 if (oldz != TOK_STICKY_BACK) and (oldz != TOK_STICKY_FRONT):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
472 ## print "old z-order = " + str(oldz)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
473 self.sel_rmin.zorder -= 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
474 # Re-collapse to normalize
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
475 # Note: only one update (with the final values) will be sent
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
476 self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
477
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
478 elif id == TOK_FORWARD_ONE:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
479 # This assumes that we always start out with a z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
480 # that starts at 0 and goes up to the number of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
481 # minis - 1. If this isn't the case, then execute
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
482 # a self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
483 # before getting the oldz to test
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
484 # Save the selected minis current z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
485 oldz = self.sel_rmin.zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
486 ## print "old z-order = " + str(oldz)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
487 self.sel_rmin.zorder += 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
488
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
489 # Re-collapse to normalize
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
490 # Note: only one update (with the final values) will be sent
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
491 self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
492
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
493 elif id == TOK_TO_FRONT:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
494 # This assumes that we always start out with a z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
495 # that starts at 0 and goes up to the number of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
496 # minis - 1. If this isn't the case, then execute
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
497 # a self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
498 # before getting the oldz to test
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
499 # Save the selected minis current z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
500 oldz = self.sel_rmin.zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
501
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
502 # Make sure the mini isn't sticky front or back
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
503 if (oldz != TOK_STICKY_BACK) and (oldz != TOK_STICKY_FRONT):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
504 ## print "old z-order = " + str(oldz)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
505 # The new z-order will be one more than the last index
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
506 newz = len(self.canvas.layers['token'].token)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
507 ## print "new z-order = " + str(newz)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
508 self.sel_rmin.zorder = newz
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
509 # Re-collapse to normalize
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
510 # Note: only one update (with the final values) will be sent
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
511 self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
512
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
513 elif id == TOK_TO_BACK:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
514 # This assumes that we always start out with a z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
515 # that starts at 0 and goes up to the number of
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
516 # minis - 1. If this isn't the case, then execute
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
517 # a self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
518 # before getting the oldz to test
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
519 # Save the selected minis current z-order
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
520 oldz = self.sel_rmin.zorder
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
521 # Make sure the mini isn't sticky front or back
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
522 if (oldz != TOK_STICKY_BACK) and (oldz != TOK_STICKY_FRONT):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
523 ## print "old z-order = " + str(oldz)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
524
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
525 # Since 0 is the lowest in a normalized order, be one less
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
526 newz = -1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
527 ## print "new z-order = " + str(newz)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
528 self.sel_rmin.zorder = newz
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
529 # Re-collapse to normalize
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
530 # Note: only one update (with the final values) will be sent
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
531 self.canvas.layers['token'].collapse_zorder()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
532
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
533 elif id == TOK_FRONTBACK_UNLOCK:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
534 #print "Unlocked/ unstickified..."
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
535 if self.sel_rmin.zorder == TOK_STICKY_BACK: self.sel_rmin.zorder = TOK_STICKY_BACK + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
536 elif self.sel_rmin.zorder == TOK_STICKY_FRONT: self.sel_rmin.zorder = TOK_STICKY_FRONT - 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
537 elif id == TOK_LOCK_BACK: self.sel_rmin.zorder = TOK_STICKY_BACK
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
538 elif id == TOK_LOCK_FRONT: self.sel_rmin.zorder = TOK_STICKY_FRONT
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
539 # Pretty much, we always want to refresh when we go through here
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
540 # This helps us remove the redundant self.Refresh() on EVERY menu event
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
541 # that we process above.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
542 self.sel_rmin.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
543 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
544 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
545
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
546 def on_token(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
547 session = self.canvas.frame.session
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
548 if (session.my_role() != session.ROLE_GM) and (session.my_role() != session.ROLE_PLAYER) and (session.use_roles()):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
549 self.infoPost("You must be either a player or GM to use the token Layer")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
550 return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
551 min_url = self.min_url.GetValue()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
552 # build url
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
553 if min_url == "" or min_url == "http://": return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
554 if min_url[:7] != "http://" : min_url = "http://" + min_url
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
555 # make label
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
556 if self.auto_label and min_url[-4:-3] == '.':
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
557 start = min_url.rfind("/") + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
558 min_label = min_url[start:len(min_url)-4]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
559 if self.use_serial:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
560 min_label = '%s %d' % ( min_label, self.canvas.layers['token'].next_serial() )
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
561 else: min_label = ""
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
562 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
563 try:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
564 id = 'mini-' + self.canvas.frame.session.get_next_id()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
565 # make the new mini appear in top left of current viewable map
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
566 dc = wx.ClientDC(self.canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
567 self.canvas.PrepareDC(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
568 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
569 x = dc.DeviceToLogicalX(0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
570 y = dc.DeviceToLogicalY(0)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
571 self.canvas.layers['token'].add_token(id, min_url, pos=cmpPoint(x,y), label=min_label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
572 except:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
573 # When there is an exception here, we should be decrementing the serial_number for reuse!!
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
574 unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n"
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
575 #print unablemsg
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
576 dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
577 dlg.ShowModal()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
578 dlg.Destroy()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
579 self.canvas.layers['token'].rollback_serial()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
580 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
581 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
582 #except Exception, e:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
583 #wx.MessageBox(str(e),"token Error")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
584
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
585 def on_label(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
586 self.auto_label = not self.auto_label
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
587 self.auto_label_cb.SetValue(self.auto_label)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
588 #self.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
589 #self.Refresh()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
590
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
591 def on_min_list(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
592 session = self.canvas.frame.session
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
593 if (session.my_role() != session.ROLE_GM):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
594 self.infoPost("You must be a GM to use this feature")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
595 return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
596 #d = min_list_panel(self.frame.GetParent(),self.canvas.layers,"token list")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
597 d = min_list_panel(self.canvas.frame,self.canvas.layers,"token list")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
598 if d.ShowModal() == wx.ID_OK: d.Destroy()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
599 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
600
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
601 def on_serial(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
602 self.use_serial = not self.use_serial
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
603
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
604 def on_map_board_menu_item(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
605 id = evt.GetId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
606 if id == MAP_REFRESH_MINI_URLS: # Note: this doesn't change the mini, so no need to update the map
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
607 for mini in self.canvas.layers['token'].tokens: # For all minis
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
608 mini.set_bmp(ImageHandler.load(mini.path, 'token', mini.id)) # Reload their bmp member
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
609 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
610
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
611 ####################################################################
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
612 ## old functions, changed an awful lot
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
613
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
614 def on_left_down(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
615 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
616 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
617 if mini:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
618 deselecting_selected_mini = (mini == self.sel_min) #clicked on the selected mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
619 self.deselectAndRefresh()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
620 self.drag_mini = mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
621 if deselecting_selected_mini: return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
622 self.sel_min = mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
623 self.sel_min.selected = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
624 self.canvas.Refresh()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
625 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
626 self.drag_mini = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
627 pos = self.getLogicalPosition(evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
628 self.moveSelectedMini(pos)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
629 self.deselectAndRefresh()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
630
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
631 def on_right_down(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
632 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
633 self.last_rclick_pos = self.getLogicalPosition(evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
634 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
635 if mini:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
636 self.sel_rmin = mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
637 if self.sel_min: self.min_menu.Enable(TOK_MOVE, True)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
638 else: self.min_menu.Enable(TOK_MOVE, False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
639 self.prepare_mini_rclick_menu(evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
640 self.do_min_menu(evt.GetPosition())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
641 else:# pass it on
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
642 if self.sel_min: self.main_menu.Enable(TOK_MOVE, True)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
643 else: self.main_menu.Enable(TOK_MOVE, False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
644 self.prepare_background_rclick_menu(evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
645 base_layer_handler.on_right_down(self, evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
646
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
647 ####################################################################
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
648 ## new functions
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
649
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
650 def on_drop_files(self, x, y, filepaths):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
651 # currently we ignore multiple files
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
652 filepath = filepaths[0]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
653 start1 = filepath.rfind("\\") + 1 # check for both slashes in path to be on the safe side
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
654 start2 = filepath.rfind("/") + 1
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
655 if start1 < start2: start1 = start2
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
656 filename = filepath[start1:]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
657 pos = filename.rfind('.')
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
658 ext = filename[pos:].lower()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
659 #ext = filename[-4:].lower()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
660 if(ext != ".bmp" and ext != ".gif" and ext != ".jpg" and ext != ".jpeg" and ext != ".png"):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
661 self.infoPost("Supported file extensions are: *.bmp, *.gif, *.jpg, *.jpeg, *.png")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
662 return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
663 file = open(filepath, "rb")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
664 imgdata = file.read()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
665 file.close()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
666 dc = wx.ClientDC(self.canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
667 self.canvas.PrepareDC(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
668 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
669 x = dc.DeviceToLogicalX(x)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
670 y = dc.DeviceToLogicalY(y)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
671 (imgtype,j) = mimetypes.guess_type(filename)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
672 postdata = urllib.urlencode({'filename':filename, 'imgdata':imgdata, 'imgtype':imgtype})
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
673 thread.start_new_thread(self.canvas.layers['token'].upload, (postdata, filepath), {'pos':cmpPoint(x,y)})
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
674
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
675 def on_tooltip_timer(self, *args):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
676 pos = args[0]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
677 dc = wx.ClientDC(self.canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
678 self.canvas.PrepareDC(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
679 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
680 pos = wx.Point(dc.DeviceToLogicalX(pos.x), dc.DeviceToLogicalY(pos.y))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
681 mini_list = self.getMiniListOrSelectedMini(pos)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
682 if len(mini_list) > 0:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
683 print mini_list
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
684 tooltip = self.get_mini_tooltip(mini_list); print tooltip
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
685 self.canvas.SetToolTipString(tooltip)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
686 else: self.canvas.SetToolTipString("")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
687
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
688 def on_motion(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
689 if evt.Dragging() and evt.LeftIsDown():
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
690 if self.canvas.drag is None and self.drag_mini is not None:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
691 drag_bmp = self.drag_mini.bmp
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
692 if self.drag_mini.width and self.drag_mini.height:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
693 tmp_image = drag_bmp.ConvertToImage()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
694 tmp_image.Rescale(int(self.drag_mini.width * self.canvas.layers['grid'].mapscale),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
695 int(self.drag_mini.height * self.canvas.layers['grid'].mapscale))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
696 tmp_image.ConvertAlphaToMask()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
697
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
698 ### Should show rotated image when dragging.
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
699 if self.drag_mini.rotate != 0 :
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
700 tmp_image = tmp_image.Rotate(self.drag_mini.rotate,
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
701 (self.drag_mini.width/2, self.drag_mini.height/2))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
702
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
703 drag_bmp = tmp_image.ConvertToBitmap()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
704 mask = wx.Mask(drag_bmp, wx.Colour(tmp_image.GetMaskRed(),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
705 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue()))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
706 drag_bmp.SetMask(mask)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
707 tmp_image = tmp_image.ConvertToGreyscale()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
708 self.drag_mini.gray = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
709 self.drag_mini.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
710 def refresh():
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
711 self.canvas.drag.Hide()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
712 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
713 wx.CallAfter(refresh)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
714 self.canvas.drag = wx.DragImage(drag_bmp)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
715 self.drag_offset = self.getLogicalPosition(evt)- self.drag_mini.pos
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
716 self.canvas.drag.BeginDrag((int(self.drag_offset.x * self.canvas.layers['grid'].mapscale),
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
717 int(self.drag_offset.y * self.canvas.layers['grid'].mapscale)), self.canvas, False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
718 elif self.canvas.drag is not None:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
719 self.canvas.drag.Move(evt.GetPosition())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
720 self.canvas.drag.Show()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
721 # reset tool tip timer
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
722 self.canvas.SetToolTipString("")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
723 self.tooltip_timer.Restart(self.tooltip_delay_miliseconds, evt.GetPosition())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
724
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
725 def on_left_up(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
726 if self.canvas.drag:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
727 self.canvas.drag.Hide()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
728 self.canvas.drag.EndDrag()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
729 self.canvas.drag = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
730 pos = self.getLogicalPosition(evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
731 pos = pos - self.drag_offset
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
732 if self.canvas.layers['grid'].snap:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
733 nudge = int(self.canvas.layers['grid'].unit_size/2)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
734 if self.canvas.layers['grid'].mode != GRID_ISOMETRIC:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
735 if self.drag_mini.snap_to_align == SNAPTO_ALIGN_CENTER:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
736 pos = pos + (int(self.drag_mini.bmp.GetWidth()/2),int(self.drag_mini.bmp.GetHeight()/2))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
737 else: pos = pos + (nudge, nudge)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
738 else:# GRID_ISOMETRIC
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
739 if self.drag_mini.snap_to_align == SNAPTO_ALIGN_CENTER:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
740 pos = pos + (int(self.drag_mini.bmp.GetWidth()/2), self.drag_mini.bmp.GetHeight())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
741 else: pass # no nudge for the isomorphic / top-left
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
742 self.sel_min = self.drag_mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
743 # check to see if the mouse is inside the window still
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
744 w = self.canvas.GetClientSizeTuple() # this is the window size, minus any scrollbars
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
745 p = evt.GetPosition() # compare the window size, w with the non-logical position
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
746 c = self.canvas.size # this is the grid size, compare with the logical position, pos
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
747 # both are [width, height]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
748 if p.x>=0 and pos.x<c[0] and p.x<w[0] and p.y>=0 and pos.y<c[1] and p.y<w[1]:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
749 self.moveSelectedMini(pos)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
750 self.sel_min.gray = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
751 self.sel_min.selected = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
752 self.sel_min.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
753 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
754 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
755 self.sel_min = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
756 self.drag_mini = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
757
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
758 def on_left_dclick(self,evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
759 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
760 mini = self.find_mini(evt, evt.CmdDown() and self.role_is_gm())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
761 if mini: self.on_mini_dclick(evt, mini)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
762 else: base_layer_handler.on_left_dclick(self, evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
763
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
764
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
765 ####################################################################
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
766 ## hook functions (although with python you can override any of the functions)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
767
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
768 def prepare_mini_rclick_menu(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
769 # override the entire right-click on a mini menu
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
770 pass
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
771
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
772 def prepare_background_rclick_menu(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
773 # override the entire right-click on the map menu
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
774 pass
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
775
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
776 def get_mini_tooltip(self, mini_list):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
777 # override to create a tooltip
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
778 return ""
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
779
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
780 def on_mini_dclick(self, evt, mini):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
781 # do something after the mini was left double clicked
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
782 pass
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
783
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
784 ####################################################################
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
785 ## easy way to add a single menu item
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
786
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
787 def set_mini_rclick_menu_item(self, label, callback_function):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
788 # remember you might want to call these at the end of your callback function:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
789 # mini_handler.sel_rmin.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
790 # canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
791 # canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
792 if callback_function == None: del self.mini_rclick_menu_extra_items[label]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
793 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
794 if not self.mini_rclick_menu_extra_items.has_key(label):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
795 self.mini_rclick_menu_extra_items[label]=wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
796 menu_id = self.mini_rclick_menu_extra_items[label]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
797 self.canvas.Bind(wx.EVT_MENU, callback_function, id=menu_id)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
798 self.build_menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
799
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
800 def set_background_rclick_menu_item(self, label, callback_function):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
801 if callback_function == None: del self.background_rclick_menu_extra_items[label]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
802 else:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
803 if not self.background_rclick_menu_extra_items.has_key(label):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
804 self.background_rclick_menu_extra_items[label]=wx.NewId()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
805 menu_id = self.background_rclick_menu_extra_items[label]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
806 self.canvas.Bind(wx.EVT_MENU, callback_function, id=menu_id)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
807 self.build_menu()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
808
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
809
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
810 ####################################################################
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
811 ## helper functions
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
812
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
813 def infoPost(self, message):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
814 component.get("chat").InfoPost(message)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
815
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
816 def role_is_gm_or_player(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
817 session = self.canvas.frame.session
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
818 if (session.my_role() <> session.ROLE_GM) and (session.my_role() <> session.ROLE_PLAYER) and (session.use_roles()):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
819 self.infoPost("You must be either a player or GM to use the token Layer")
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
820 return False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
821 return True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
822
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
823 def role_is_gm(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
824 session = self.canvas.frame.session
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
825 if (session.my_role() <> session.ROLE_GM) and (session.use_roles()): return False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
826 return True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
827
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
828 def alreadyDealingWithMenu(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
829 return self.lastMenuChoice is not None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
830
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
831 def getLastMenuChoice(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
832 choice = self.lastMenuChoice
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
833 self.lastMenuChoice = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
834 return choice
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
835
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
836 def getLogicalPosition(self, evt):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
837 dc = wx.ClientDC(self.canvas)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
838 self.canvas.PrepareDC(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
839 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
840 pos = evt.GetLogicalPosition(dc)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
841 return pos
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
842
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
843 def getMiniListOrSelectedMini(self, pos, include_locked=False):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
844 if self.sel_min and self.sel_min.hit_test(pos):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
845 # clicked on the selected mini - assume that is the intended target
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
846 # and don't give a choice of it and any other minis stacked with it
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
847 mini_list = []
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
848 mini_list.append(self.sel_min)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
849 return mini_list
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
850 mini_list = self.canvas.layers['token'].find_token(pos, (not include_locked))
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
851 if mini_list: return mini_list
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
852 mini_list = []
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
853 return mini_list
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
854
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
855 def deselectAndRefresh(self):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
856 if self.sel_min:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
857 self.sel_min.selected = False
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
858 self.sel_min.isUpdated = True
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
859 self.canvas.Refresh(False)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
860 self.canvas.send_map_data()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
861 self.sel_min = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
862
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
863 def moveSelectedMini(self, pos):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
864 if self.sel_min: self.moveMini(pos, self.sel_min)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
865
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
866 def moveMini(self, pos, mini):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
867 grid = self.canvas.layers['grid']
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
868 mini.pos = grid.get_snapped_to_pos(pos, mini.snap_to_align, mini.bmp.GetWidth(), mini.bmp.GetHeight())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
869
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
870 def find_mini(self, evt, include_locked):
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
871 if not self.role_is_gm_or_player() or self.alreadyDealingWithMenu(): return
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
872 pos = self.getLogicalPosition(evt)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
873 mini_list = self.getMiniListOrSelectedMini(pos, include_locked)
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
874 mini = None
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
875 if len(mini_list) > 1:
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
876 try: self.do_min_select_menu(mini_list, evt.GetPosition())
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
877 except: pass
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
878 choice = self.getLastMenuChoice()
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
879 if choice == None: return None # left menu without making a choice, eg by clicking outside menu
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
880 mini = mini_list[choice]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
881 elif len(mini_list) == 1: mini = mini_list[0]
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
882 return mini
2f2bebe9c77f Traipse Alpha 'OpenRPG' {091006-03}
sirebral
parents:
diff changeset
883