105
|
1 import os
|
|
2 import sys
|
|
3 import orpg.pluginhandler
|
|
4 from orpg.mapper.map import *
|
|
5 from orpg.orpgCore import component
|
|
6 import wx
|
|
7
|
|
8 from orpg.mapper.images import ImageHandler
|
|
9 from orpg.mapper.whiteboard_handler import *
|
|
10 from orpg.mapper.background_handler import *
|
|
11 from orpg.mapper.grid_handler import *
|
|
12 from orpg.mapper.map_handler import *
|
|
13 from orpg.mapper.fog_handler import *
|
|
14
|
|
15 from bcg.token_handler import *
|
|
16 from bcg.tokens import *
|
|
17
|
|
18
|
|
19 class Plugin(orpg.pluginhandler.PluginHandler):
|
|
20 # Initialization subroutine.
|
|
21 #
|
|
22 # !self : instance of self
|
|
23 # !openrpg : instance of the the base openrpg control
|
|
24 def __init__(self, plugindb, parent):
|
|
25 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
|
|
26
|
|
27 # The Following code should be edited to contain the proper information
|
|
28 self.name = 'Board / Card Game'
|
|
29 self.author = 'Tyler Starke (Prof. Ebral)'
|
|
30 self.help = 'Start Here'
|
|
31 self.parent = parent
|
|
32 #You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled
|
|
33 #to set their proper values.
|
|
34 self.sample_variable = {}
|
|
35
|
|
36 self.canvas = component.get('map').canvas ## Obtain MapCanvas
|
|
37
|
|
38 def plugin_enabled(self):
|
|
39 tabs = component.get('map_tabs')
|
|
40 layers = component.get('map_layers')
|
|
41 map_wnd = component.get('map_wnd')
|
|
42 pages = tabs.GetPageCount()
|
|
43 self.layers = []
|
|
44 while pages:
|
|
45 pages -= 1
|
|
46 if tabs.GetPageText(pages) != 'Background':
|
|
47 if tabs.GetPageText(pages) != 'Whiteboard':
|
|
48 tabs.RemovePage(pages)
|
|
49 #tabs.InsertPage(2, layers[0], 'Tiles') # Removed for testing.
|
|
50 map_wnd.handlers[6]=(token_handler(tabs, -1, map_wnd.canvas))
|
|
51 tabs.InsertPage(3, map_wnd.handlers[6], 'Tokens')
|
|
52
|
|
53 ## Re Direct MapCanvas OnPaint event.
|
|
54 self.canvas.Disconnect(-1, -1, wx.wxEVT_PAINT)
|
|
55 self.canvas.Bind(wx.EVT_PAINT, self.on_paint)
|
|
56
|
|
57 ## Add to MapCanvas proccessImages
|
|
58 self.canvas.Bind(wx.EVT_TIMER, self.processImages, self.canvas.image_timer)
|
|
59
|
|
60 ## Create Token Layer
|
|
61 self.canvas.layers['token'] = token_layer(self.canvas)
|
|
62 #self.canvas.layers['tiles'] = tile_layer(self.canvas) #Not ready.
|
|
63
|
|
64 ### Define Grid / Background
|
|
65 self.canvas.layers['grid'].snap = False
|
|
66 self.canvas.layers['grid'].line = 0
|
|
67 #self.canvas.layers['bg'].set_texture(component.get('cherrypy')+'Textures/versa_anigre.jpg')
|
|
68 pass
|
|
69
|
|
70 def processImages(self, evt=None):
|
|
71 self.session = component.get("session")
|
|
72 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'):
|
|
73 cidx = self.canvas.parent.get_tab_index("Tiles")
|
|
74 self.canvas.parent.tabs.EnableTab(cidx, False)
|
|
75 cidx = self.canvas.parent.get_tab_index("Tokens")
|
|
76 self.canvas.parent.tabs.EnableTab(cidx, False)
|
|
77 else:
|
|
78 cidx = self.canvas.parent.get_tab_index("Tiles")
|
|
79 self.canvas.parent.tabs.EnableTab(cidx, True)
|
|
80 cidx = self.canvas.parent.get_tab_index("Tokens")
|
|
81 self.canvas.parent.tabs.EnableTab(cidx, True)
|
|
82 if not self.canvas.cacheSizeSet:
|
|
83 self.canvas.cacheSizeSet = True
|
|
84 cacheSize = component.get('settings').get_setting("ImageCacheSize")
|
|
85 if len(cacheSize): self.canvas.cacheSize = int(cacheSize)
|
|
86 else: pass
|
|
87 if not ImageHandler.Queue.empty():
|
|
88 (path, image_type, imageId) = ImageHandler.Queue.get()
|
|
89 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap()
|
|
90 try:
|
|
91 # Now, apply the image to the proper object
|
|
92 if image_type == "miniature":
|
|
93 min = self.canvas.layers['miniatures'].get_miniature_by_id(imageId)
|
|
94 min.set_bmp(img)
|
|
95 elif image_type == "background" or image_type == "texture":
|
|
96 self.canvas.layers['bg'].bg_bmp = img
|
|
97 if image_type == "background": self.canvas.set_size([img.GetWidth(), img.GetHeight()])
|
|
98 elif image_type == "token":
|
|
99 min = self.canvas.layers['token'].get_token_by_id(imageId)
|
|
100 min.set_bmp(img)
|
|
101 except: pass
|
|
102
|
|
103 def on_paint(self, evt):
|
|
104 if self.canvas.layers.has_key('token') == False: self.canvas.layers['token'] = token_layer(self.canvas)
|
|
105 print 'BCG onpaint'
|
|
106 scale = self.canvas.layers['grid'].mapscale
|
|
107 scrollsize = self.canvas.GetScrollPixelsPerUnit()
|
|
108 clientsize = self.canvas.GetClientSize()
|
|
109 topleft1 = self.canvas.GetViewStart()
|
|
110 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]]
|
|
111 if (clientsize[0] > 1) and (clientsize[1] > 1):
|
|
112 dc = wx.MemoryDC()
|
|
113 bmp = wx.EmptyBitmap(clientsize[0]+1, clientsize[1]+1)
|
|
114 dc.SelectObject(bmp)
|
|
115 dc.SetPen(wx.TRANSPARENT_PEN)
|
|
116 dc.SetBrush(wx.Brush(self.canvas.GetBackgroundColour(), wx.SOLID))
|
|
117 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1)
|
|
118 dc.SetDeviceOrigin(-topleft[0], -topleft[1])
|
|
119 dc.SetUserScale(scale, scale)
|
|
120 self.canvas.layers['bg'].layerDraw(dc, scale, topleft, clientsize)
|
|
121 self.canvas.layers['grid'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale],
|
|
122 [clientsize[0]/scale, clientsize[1]/scale])
|
|
123
|
|
124
|
|
125 self.canvas.layers['token'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale],
|
|
126 [clientsize[0]/scale, clientsize[1]/scale])
|
|
127
|
|
128
|
|
129 self.canvas.layers['whiteboard'].layerDraw(dc)
|
|
130 self.canvas.layers['fog'].layerDraw(dc, topleft, clientsize)
|
|
131 dc.SetPen(wx.NullPen)
|
|
132 dc.SetBrush(wx.NullBrush)
|
|
133 dc.SelectObject(wx.NullBitmap)
|
|
134 del dc
|
|
135 wdc = self.canvas.preppaint()
|
|
136 wdc.DrawBitmap(bmp, topleft[0], topleft[1])
|
|
137 if settings.get_setting("AlwaysShowMapScale") == "1":
|
|
138 self.canvas.showmapscale(wdc)
|
|
139 try: evt.Skip()
|
|
140 except: pass
|
|
141
|
|
142 def plugin_disabled(self):
|
|
143 tabs = component.get('map_tabs')
|
|
144 map_wnd = component.get('map_wnd')
|
|
145 pages = tabs.GetPageCount()
|
|
146 while pages:
|
|
147 pages -= 1
|
|
148 if tabs.GetPageText(pages) != 'Background':
|
|
149 if tabs.GetPageText(pages) != 'Whiteboard':
|
|
150 tabs.RemovePage(pages)
|
|
151 layers = component.get('map_layers')
|
|
152 tabs.InsertPage(1, layers[1],"Grid")
|
|
153 tabs.InsertPage(2, layers[2],"Miniatures")
|
|
154 tabs.InsertPage(4, layers[4],"Fog")
|
|
155 tabs.InsertPage(5, layers[5],"General")
|
|
156 map_wnd.current_layer = 2
|
|
157 map_wnd.tabs.SetSelection(map_wnd.current_layer)
|
|
158
|
|
159 ## Re Connect original MapCanvas OnPaint event.
|
|
160 self.canvas.Disconnect(-1, -1, wx.wxEVT_PAINT)
|
|
161 self.canvas.Bind(wx.EVT_PAINT, self.canvas.on_paint)
|
|
162
|
|
163 ## Disconnect new proccessImages addition
|
|
164 self.canvas.Disconnect(-1, -1, wx.wxEVT_TIMER)
|
|
165 self.canvas.Bind(wx.EVT_TIMER, self.canvas.processImages, self.canvas.image_timer)
|
|
166
|
|
167 self.canvas.layers['grid'].snap = True
|
|
168 self.canvas.layers['grid'].line = 1
|
|
169
|
|
170 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
|
|
171 #such as closing windows created by the plugin
|
|
172 #self.plugin_removecmd('/test')
|
|
173 #self.plugin_removecmd('/example')
|
|
174
|
|
175 #This is the command to delete a message handler
|
|
176 #self.plugin_delete_msg_handler('xxblank')
|
|
177
|
|
178 #This is how you should destroy a frame when the plugin is disabled
|
|
179 #This same method should be used in close_module as well
|
|
180 try:
|
|
181 self.frame.Destroy()
|
|
182 except:
|
|
183 pass
|
|
184
|
|
185 def on_test(self, cmdargs):
|
|
186 #this is just an example function for a command you create.
|
|
187 # cmdargs contains everything you typed after the command
|
|
188 # so if you typed /test this is a test, cmdargs = this is a test
|
|
189 # args are the individual arguments split. For the above example
|
|
190 # args[0] = this , args[1] = is , args[2] = a , args[3] = test
|
|
191 self.plugin_send_msg(cmdargs, '<xxblank>' + cmdargs + '</xxblank>')
|
|
192 args = cmdargs.split(None,-1)
|
|
193 msg = 'cmdargs = %s' % (cmdargs)
|
|
194 self.chat.InfoPost(msg)
|
|
195
|
|
196 if len(args) == 0:
|
|
197 self.chat.InfoPost("You have no args")
|
|
198 else:
|
|
199 i = 0
|
|
200 for n in args:
|
|
201 msg = 'args[' + str(i) + '] = ' + n
|
|
202 self.chat.InfoPost(msg)
|
|
203 i += 1
|
|
204
|
|
205 def on_xml_recive(self,id, data,xml_dom):
|
|
206 self.chat.InfoPost(self.name + ":: Message recived<br />" + data.replace("<","<").replace(">",">") +'<br />From id:' + str(id))
|
|
207
|
|
208 def pre_parse(self, text):
|
|
209 #This is called just before a message is parsed by openrpg
|
|
210 return text
|
|
211
|
|
212 def send_msg(self, text, send):
|
|
213 #This is called when a message is about to be sent out.
|
|
214 #It covers all messages sent by the user, before they have been formatted.
|
|
215 #If send is set to 0, the message will not be sent out to other
|
|
216 #users, but it will still be posted to the user's chat normally.
|
|
217 #Otherwise, send defaults to 1. (The message is sent as normal)
|
|
218 return text, send
|
|
219
|
|
220 def plugin_incoming_msg(self, text, type, name, player):
|
|
221 #This is called whenever a message from someone else is received, no matter
|
|
222 #what type of message it is.
|
|
223 #The text variable is the text of the message. If the type is a regular
|
|
224 #message, it is already formatted. Otherwise, it's not.
|
|
225 #The type variable is an integer which tells you the type: 1=chat, 2=whisper
|
|
226 #3=emote, 4=info, and 5=system.
|
|
227 #The name variable is the name of the player who sent you the message.
|
|
228 #The player variable contains lots of info about the player sending the
|
|
229 #message, including name, ID#, and currently-set role.
|
|
230 #Uncomment the following line to see the format for the player variable.
|
|
231 #print player
|
|
232 return text, type, name
|
|
233
|
|
234 def post_msg(self, text, myself):
|
|
235 #This is called whenever a message from anyone is about to be posted
|
|
236 #to chat; it doesn't affect the copy of the message that gets sent to others
|
|
237 #Be careful; system and info messages trigger this too.
|
|
238 return text
|
|
239
|
|
240 def refresh_counter(self):
|
|
241 #This is called once per second. That's all you need to know.
|
|
242 pass
|