Mercurial > traipse
comparison plugins/xxsimpleinit.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 97265586402b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 import os | |
2 import orpg.pluginhandler | |
3 from orpg.orpgCore import * | |
4 import wx | |
5 | |
6 class Plugin(orpg.pluginhandler.PluginHandler): | |
7 # Initialization subroutine. | |
8 # | |
9 # !self : instance of self | |
10 # !openrpg : instance of the the base openrpg control | |
11 def __init__(self, plugindb, parent): | |
12 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent) | |
13 self.orpgframe = open_rpg.get_component('frame') | |
14 | |
15 # The Following code should be edited to contain the proper information | |
16 self.name = 'Simple Init' | |
17 self.author = 'Dj Gilcrease' | |
18 self.help = 'This is a simplistic Init tool that does not relie on Chat message parsing' | |
19 | |
20 #You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled | |
21 #to set their proper values. | |
22 | |
23 def plugin_menu(self): | |
24 self.menu = wx.Menu() | |
25 | |
26 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'Show') | |
27 self.topframe.Bind(wx.EVT_MENU, self.on_init, self.toggle) | |
28 self.toggle.Check(True) | |
29 | |
30 | |
31 def plugin_enabled(self): | |
32 self.plugin_addcommand('/inittoggle', self.on_init, '- This will Show or Hide the Init window') | |
33 self.plugin_addcommand('/rollinit', self.rollInit, '- This will roll a new set of Inits', False) | |
34 self.plugin_addcommand('/startcombat', self.startInit, '- This will start the combat', False) | |
35 self.plugin_addcommand('/nextplayer', self.advanceInit, '- This will advance the Initiative to the next Player', False) | |
36 self.plugin_addcommand('/stopcombat', self.stopInit, '- This will end the combat', False) | |
37 self.plugin_addcommand('/pausecombat', self.pauseInit, '- This will pause the auto Advancer', False) | |
38 | |
39 self.InitSaves = self.plugindb.GetDict("xxsimpleinit", "InitSaves", {}) | |
40 self.frame = InitFrame(self) | |
41 self.frame.Show() | |
42 self.advanceTimer = wx.Timer(self.frame, wx.NewId()) | |
43 self.frame.Bind(wx.EVT_TIMER, self.advanceInit, self.advanceTimer) | |
44 self.buttonTimer = wx.Timer(self.frame, wx.NewId()) | |
45 self.frame.Bind(wx.EVT_TIMER, self.buttonCheck, self.buttonTimer) | |
46 self.buttonTimer.Start(250) | |
47 self.autoAdvancePaused = False | |
48 #self.PluginMenu() | |
49 | |
50 def plugin_disabled(self): | |
51 self.plugin_removecmd('/inittoggle') | |
52 self.plugin_removecmd('/rollinit') | |
53 self.plugin_removecmd('/startcombat') | |
54 self.plugin_removecmd('/nextplayer') | |
55 self.plugin_removecmd('/stopcombat') | |
56 self.plugin_removecmd('/pausecombat') | |
57 | |
58 self.advanceTimer.Stop() | |
59 del self.advanceTimer | |
60 | |
61 self.buttonTimer.Stop() | |
62 del self.buttonTimer | |
63 | |
64 try: | |
65 self.frame.Destroy() | |
66 except: | |
67 pass | |
68 | |
69 def on_init(self, cmdargs): | |
70 if self.frame.IsShown(): | |
71 self.toggle.Check(False) | |
72 self.frame.Hide() | |
73 else: | |
74 self.toggle.Check(True) | |
75 self.frame.Show() | |
76 print self.toggle.IsChecked() | |
77 | |
78 def startInit(self, evt=None): | |
79 if self.frame.initList.GetItemCount() == 0: | |
80 self.chat.InfoPost('You need to add some stuff to the Init list before you start') | |
81 return | |
82 | |
83 if not self.frame.startButton.IsEnabled(): | |
84 self.chat.InfoPost('Combat Round has already started! You must Stop the current combat to start a new one.') | |
85 return | |
86 | |
87 self.orpgframe.Freeze() | |
88 self.frame.Freeze() | |
89 self.frame.nextButton.Enable() | |
90 self.frame.stopButton.Enable() | |
91 self.frame.startButton.Disable() | |
92 self.frame.rollButton.Disable() | |
93 self.frame.autoAdvanceCheck.Disable() | |
94 self.frame.autoAdvanceList.Disable() | |
95 self.frame.autoAdvanceToggle.Enable() | |
96 self.frame.addButton.Disable() | |
97 self.frame.editButton.Disable() | |
98 self.frame.deleteButton.Disable() | |
99 self.frame.saveButton.Disable() | |
100 self.frame.loadButton.Disable() | |
101 self.frame.clearButton.Disable() | |
102 | |
103 self.frame.currentInit = -1 | |
104 self.round = 0 | |
105 | |
106 self.chat.Post('<font color="#00ff00" size="4"><b>============ START COMBAT ============</b></font>', True, True) | |
107 self.advanceInit() | |
108 self.frame.Thaw() | |
109 | |
110 if self.frame.autoAdvanceCheck.IsChecked(): | |
111 time = int(60000*int(self.frame.autoAdvanceList.GetStringSelection())) | |
112 self.advanceTimer.Start(time) | |
113 else: | |
114 self.frame.addButton.Enable() | |
115 self.frame.editButton.Enable() | |
116 self.frame.deleteButton.Enable() | |
117 | |
118 if self.frame.IsShown(): | |
119 wx.CallAfter(self.frame.SetFocus) | |
120 | |
121 wx.CallAfter(self.orpgframe.Thaw) | |
122 | |
123 def stopInit(self, evt=None): | |
124 if not self.frame.stopButton.IsEnabled(): | |
125 self.chat.InfoPost('Combat is already ended!') | |
126 return | |
127 | |
128 self.frame.Freeze() | |
129 self.frame.nextButton.Disable() | |
130 self.frame.stopButton.Disable() | |
131 self.frame.startButton.Enable() | |
132 self.frame.rollButton.Enable() | |
133 self.frame.autoAdvanceCheck.Enable() | |
134 self.frame.autoAdvanceList.Enable() | |
135 self.frame.autoAdvanceToggle.Disable() | |
136 self.frame.addButton.Enable() | |
137 self.frame.editButton.Enable() | |
138 self.frame.deleteButton.Enable() | |
139 self.frame.saveButton.Enable() | |
140 self.frame.loadButton.Enable() | |
141 self.frame.clearButton.Enable() | |
142 | |
143 for i in xrange(0, self.frame.initList.GetItemCount()): | |
144 self.frame.currentInit = i | |
145 if self.frame.currentInit.type == 'Effect': | |
146 self.frame.initList.DeleteItem(i) | |
147 | |
148 self.frame.currentInit = 0 | |
149 | |
150 if self.autoAdvancePaused and self.frame.autoAdvanceCheck.IsChecked(): | |
151 self.pauseInit('No Adv') | |
152 self.frame.Thaw() | |
153 | |
154 self.advanceTimer.Stop() | |
155 self.chat.Post('<font color="#ff0000" size="4"><b>============ END COMBAT ============</b></font>', True, True) | |
156 | |
157 def advanceInit(self, evt=None): | |
158 if not self.frame.nextButton.IsEnabled(): | |
159 self.chat.InfoPost('You must first Start combat inorder to advance the initiative turn!') | |
160 return | |
161 | |
162 self.frame.currentInit = self.frame.initIdx+1 | |
163 if self.frame.currentInit.type == 'Effect': | |
164 newDur = str(int(self.frame.currentInit.duration)-1) | |
165 self.frame.initList.SetStringItem(self.frame.initIdx, 2, newDur) | |
166 msg = '<br><table width="100%" border="1"><tr><td align="center"><center><u><b><font color="#ff0000" size="4">EFFECT NOTICE</font></b></u></center></td></tr>' | |
167 msg += '<tr><td align="center"><font color="#000000">' + self.frame.currentInit.name + ' has ' + newDur + ' rounds remaining</font></td></tr></table>' | |
168 self.chat.Post(msg, True, True) | |
169 wx.CallAfter(self.advanceInit) | |
170 else: | |
171 msg = '<br><table width="100%" border="1"><tr><td align="center"><center><u><font color="#ff0000" size="4"><b>' + self.frame.nextMessage.GetValue() + '</b></font></u></center></td></tr>' | |
172 msg += '<tr><td align="center"><b><font size="3"><font color="#ff0000">' + str(self.frame.initIdx+1) + ':</font> ' | |
173 msg += '<font color="#0000ff">(' + self.frame.currentInit.init + ')</font> ' | |
174 msg += '<font color="#000000">' + self.frame.currentInit.name + '</b></font></font></td></tr></table>' | |
175 self.chat.Post(msg, True, True) | |
176 | |
177 if self.frame.currentInit.type == 'Effect' and int(self.frame.currentInit.duration) <= 0: | |
178 self.frame.Freeze() | |
179 cidx = self.frame.initIdx | |
180 self.frame.initList.DeleteItem(cidx) | |
181 self.frame.currentInit = cidx | |
182 self.frame.Thaw() | |
183 | |
184 def pauseInit(self, evt=None): | |
185 self.frame.Freeze() | |
186 if not self.autoAdvancePaused: | |
187 self.frame.autoAdvanceToggle.SetLabel('Resume Auto Advance') | |
188 self.autoAdvancePaused = True | |
189 self.advanceTimer.Stop() | |
190 self.frame.nextButton.Disable() | |
191 self.frame.addButton.Enable() | |
192 self.frame.editButton.Enable() | |
193 self.frame.deleteButton.Enable() | |
194 else: | |
195 self.frame.autoAdvanceToggle.SetLabel('Pause Auto Advance') | |
196 self.frame.nextButton.Enable() | |
197 self.frame.addButton.Disable() | |
198 self.frame.editButton.Disable() | |
199 self.frame.deleteButton.Disable() | |
200 self.autoAdvancePaused = False | |
201 if evt != 'No Adv': | |
202 self.advanceInit() | |
203 self.advanceTimer.Start() | |
204 self.frame.Thaw() | |
205 | |
206 def newRound(self): | |
207 self.round += 1 | |
208 msg = '<br><hr><font color="#ff0000" size="4"><b>End of Round #' + str(self.round-1) + ', Starting Round #' + str(self.round) + '</b></font><hr>' | |
209 self.chat.Post(msg, True, True) | |
210 | |
211 def rollD20Init(self): | |
212 if not self.frame.rollButton.IsEnabled(): | |
213 self.chat.InfoPost("You cannot roll new Inits at this time") | |
214 return | |
215 self.orpgframe.Freeze() | |
216 self.frame.Freeze() | |
217 msg = '<br><font color="#0000ff" size="4"><b>============ START INIT LIST ============</b></font><br>' | |
218 msg += '<font color="#000000"><b>' | |
219 for i in xrange(0, self.frame.initList.GetItemCount()): | |
220 self.frame.currentInit = i | |
221 if self.frame.currentInit.manual == 'No': | |
222 initRoll = self.chat.ParseDice('[1d20' + self.frame.currentInit.initMod + ']') | |
223 | |
224 initRoll = initRoll.split('(') | |
225 initRoll = initRoll[1].replace(')','') | |
226 self.frame.initList.SetStringItem(i, 4, initRoll) | |
227 self.frame.initList.SetItemData(i, int(initRoll)) | |
228 else: | |
229 initRoll = self.frame.currentInit.init | |
230 | |
231 if self.frame.currentInit.type != 'Effect': | |
232 msg += '<br>' + self.frame.currentInit.name + ' = <font color="#ff0000">' + initRoll + '</font>' | |
233 | |
234 msg += '</b></font><br>' | |
235 | |
236 self.frame.initList.SortItems(self.frame.initSort) | |
237 msg += '<font color="#0000ff" size="4"><b>============ END INIT LIST ============</b></font>' | |
238 self.chat.Post(msg, True, True) | |
239 | |
240 self.frame.Thaw() | |
241 if self.frame.IsShown(): | |
242 wx.CallAfter(self.frame.SetFocus) | |
243 wx.CallAfter(self.orpgframe.Thaw) | |
244 | |
245 #Events | |
246 def rollInit(self, evt): | |
247 if self.frame.initRollType.GetStringSelection() == 'd20': | |
248 self.rollD20Init() | |
249 | |
250 def buttonCheck(self, evt): | |
251 if self.autoAdvancePaused: | |
252 return | |
253 if self.frame.initList.GetItemCount() == 0: | |
254 self.frame.Freeze() | |
255 self.advanceTimer.Stop() | |
256 self.frame.startButton.Disable() | |
257 self.frame.rollButton.Disable() | |
258 self.frame.nextButton.Disable() | |
259 self.frame.stopButton.Disable() | |
260 self.frame.editButton.Disable() | |
261 self.frame.deleteButton.Disable() | |
262 self.frame.saveButton.Disable() | |
263 self.frame.clearButton.Disable() | |
264 self.frame.Thaw() | |
265 elif not self.frame.stopButton.IsEnabled(): | |
266 self.frame.startButton.Enable() | |
267 self.frame.rollButton.Enable() | |
268 self.frame.editButton.Enable() | |
269 self.frame.deleteButton.Enable() | |
270 self.frame.saveButton.Enable() | |
271 self.frame.clearButton.Enable() | |
272 | |
273 if not self.frame.autoAdvanceCheck.IsChecked(): | |
274 self.frame.autoAdvanceToggle.Disable() | |
275 self.autoAdvancePaused = True | |
276 elif self.frame.autoAdvanceCheck.IsChecked() and self.frame.stopButton.IsEnabled(): | |
277 self.frame.autoAdvanceToggle.Enable() | |
278 | |
279 class InitFrame(wx.Frame): | |
280 def __init__(self, plugin): | |
281 self.plugin = plugin | |
282 self.toggle = plugin.toggle | |
283 self.log = open_rpg.get_component('log') | |
284 self.log.log("Enter InitFrame", ORPG_DEBUG) | |
285 | |
286 wx.Frame.__init__(self, None, wx.ID_ANY, title="Simple Init", style=wx.DEFAULT_FRAME_STYLE) | |
287 self.SetOwnBackgroundColour('#EFEFEF') | |
288 | |
289 self.dir_struct = open_rpg.get_component('dir_struct') | |
290 self.settings = open_rpg.get_component('settings') | |
291 self.xml = open_rpg.get_component('xml') | |
292 self.validate = open_rpg.get_component('validate') | |
293 | |
294 self.Freeze() | |
295 self.buildMenu() | |
296 self.buildButtons() | |
297 self.buildGUI() | |
298 wx.CallAfter(self.InitSetup) | |
299 | |
300 self.Bind(wx.EVT_CLOSE, self.onCloseWindow) | |
301 | |
302 self.log.log("Exit InitFrame", ORPG_DEBUG) | |
303 | |
304 def InitSetup(self): | |
305 self.chat = open_rpg.get_component('chat') | |
306 self.gametree = open_rpg.get_component('tree') | |
307 self.map = open_rpg.get_component('map') | |
308 self.session = open_rpg.get_component('session') | |
309 | |
310 self.initIdx = -1 | |
311 self.Thaw() | |
312 | |
313 def initSort(self, item1, item2): | |
314 if item1 == item2: | |
315 return 0 | |
316 elif item1 > item2: | |
317 return -1 | |
318 elif item1 < item2: | |
319 return 1 | |
320 | |
321 return 0 | |
322 | |
323 def onCloseWindow(self, evt): | |
324 self.Hide() | |
325 self.toggle.Check(False) | |
326 | |
327 def buildMenu(self): | |
328 self.log.log("Enter InitFrame->buildMenu(self)", ORPG_DEBUG) | |
329 | |
330 initmenu = wx.Menu() | |
331 | |
332 item = wx.MenuItem(initmenu, wx.ID_ANY, "Add\tInsert", "Add") | |
333 self.Bind(wx.EVT_MENU, self.OnMB_InitAdd, item) | |
334 initmenu.AppendItem(item) | |
335 | |
336 item = wx.MenuItem(initmenu, wx.ID_ANY, "Edit\tCtrl+E", "Edit") | |
337 self.Bind(wx.EVT_MENU, self.OnMB_InitEdit, item) | |
338 initmenu.AppendItem(item) | |
339 | |
340 item = wx.MenuItem(initmenu, wx.ID_ANY, "Delete\tCtrl+D", "Delete") | |
341 self.Bind(wx.EVT_MENU, self.OnMB_InitDelete, item) | |
342 initmenu.AppendItem(item) | |
343 | |
344 item = wx.MenuItem(initmenu, wx.ID_ANY, "Clear\tCtrl+C", "Clear") | |
345 self.Bind(wx.EVT_MENU, self.OnMB_InitClear, item) | |
346 initmenu.AppendItem(item) | |
347 | |
348 initmenu.AppendSeparator() | |
349 | |
350 item = wx.MenuItem(initmenu, wx.ID_ANY, "Next\tEnter", "Next") | |
351 self.Bind(wx.EVT_MENU, self.plugin.advanceInit, item) | |
352 initmenu.AppendItem(item) | |
353 | |
354 initmenu.AppendSeparator() | |
355 | |
356 item = wx.MenuItem(initmenu, wx.ID_ANY, "Save\tCtrl+S", "Save Current Init List") | |
357 self.Bind(wx.EVT_MENU, self.OnMB_InitSave, item) | |
358 initmenu.AppendItem(item) | |
359 | |
360 item = wx.MenuItem(initmenu, wx.ID_ANY, "Load", "Load New Init List") | |
361 self.Bind(wx.EVT_MENU, self.OnMB_InitLoad, item) | |
362 initmenu.AppendItem(item) | |
363 | |
364 menu = wx.MenuBar() | |
365 menu.Append(initmenu, "&Init") | |
366 | |
367 self.SetMenuBar(menu) | |
368 | |
369 self.log.log("Exit InitFrame->buildMenu(self)", ORPG_DEBUG) | |
370 | |
371 def buildButtons(self): | |
372 self.log.log("Enter InitFrame->buildButtons(self)", ORPG_DEBUG) | |
373 | |
374 self.autoAdvanceCheck = wx.CheckBox(self, wx.ID_ANY, "") | |
375 self.autoAdvanceCheck.SetValue(True) | |
376 self.autoAdvanceList = wx.Choice(self, wx.ID_ANY, choices=['1','2','3','4','5']) | |
377 self.autoAdvanceList.SetSelection(2) | |
378 self.autoAdvanceToggle = wx.Button(self, wx.ID_ANY, "Pause Auto Advance") | |
379 self.Bind(wx.EVT_BUTTON, self.plugin.pauseInit, self.autoAdvanceToggle) | |
380 self.autoAdvanceToggle.Disable() | |
381 | |
382 self.psizer = wx.BoxSizer(wx.HORIZONTAL) | |
383 self.psizer.Add(wx.StaticText(self, wx.ID_ANY, "Auto Advance"), 0, wx.ALIGN_CENTER|wx.ALL, 5) | |
384 self.psizer.Add(self.autoAdvanceCheck, 0, wx.ALIGN_CENTER|wx.ALL, 0) | |
385 self.psizer.Add(wx.StaticText(self, wx.ID_ANY, "Every"), 0, wx.ALIGN_CENTER|wx.ALL, 5) | |
386 self.psizer.Add(self.autoAdvanceList, 0, wx.ALIGN_CENTER|wx.ALL, 0) | |
387 self.psizer.Add(wx.StaticText(self, wx.ID_ANY, "Minutes"), 0, wx.ALIGN_CENTER|wx.ALL, 5) | |
388 self.psizer.Add(self.autoAdvanceToggle, 0, wx.ALIGN_CENTER|wx.ALL, 10) | |
389 | |
390 self.addButton = wx.Button(self, wx.ID_ANY, "Add") | |
391 self.Bind(wx.EVT_BUTTON, self.OnMB_InitAdd, self.addButton) | |
392 self.editButton = wx.Button(self, wx.ID_ANY, "Edit") | |
393 self.editButton.Disable() | |
394 self.Bind(wx.EVT_BUTTON, self.OnMB_InitEdit, self.editButton) | |
395 self.deleteButton = wx.Button(self, wx.ID_ANY, "Delete") | |
396 self.deleteButton.Disable() | |
397 self.Bind(wx.EVT_BUTTON, self.OnMB_InitDelete, self.deleteButton) | |
398 self.saveButton = wx.Button(self, wx.ID_ANY, "Save") | |
399 self.saveButton.Disable() | |
400 self.Bind(wx.EVT_BUTTON, self.OnMB_InitSave, self.saveButton) | |
401 self.loadButton = wx.Button(self, wx.ID_ANY, "Load") | |
402 self.Bind(wx.EVT_BUTTON, self.OnMB_InitLoad, self.loadButton) | |
403 self.clearButton = wx.Button(self, wx.ID_ANY, "Clear") | |
404 self.clearButton.Disable() | |
405 self.Bind(wx.EVT_BUTTON, self.OnMB_InitClear, self.clearButton) | |
406 | |
407 | |
408 self.esizer = wx.BoxSizer(wx.VERTICAL) | |
409 self.esizer.Add(self.addButton, 0, wx.EXPAND|wx.ALL, 2) | |
410 self.esizer.Add(self.editButton, 0, wx.EXPAND|wx.ALL, 3) | |
411 self.esizer.Add(self.deleteButton, 0, wx.EXPAND|wx.ALL, 2) | |
412 self.esizer.Add(self.saveButton, 0, wx.EXPAND|wx.ALL, 3) | |
413 self.esizer.Add(self.loadButton, 0, wx.EXPAND|wx.ALL, 2) | |
414 self.esizer.Add(self.clearButton, 0, wx.EXPAND|wx.ALL, 3) | |
415 | |
416 self.rollButton = wx.Button(self, wx.ID_ANY, "Roll New Inits") | |
417 self.Bind(wx.EVT_BUTTON, self.plugin.rollInit, self.rollButton) | |
418 self.startButton = wx.Button(self, wx.ID_ANY, "Start") | |
419 self.Bind(wx.EVT_BUTTON, self.plugin.startInit, self.startButton) | |
420 self.nextButton = wx.Button(self, wx.ID_ANY, "Next") | |
421 self.nextButton.Disable() | |
422 self.Bind(wx.EVT_BUTTON, self.plugin.advanceInit, self.nextButton) | |
423 self.stopButton = wx.Button(self, wx.ID_ANY, "Stop") | |
424 self.stopButton.Disable() | |
425 self.Bind(wx.EVT_BUTTON, self.plugin.stopInit, self.stopButton) | |
426 | |
427 self.asizer = wx.BoxSizer(wx.HORIZONTAL) | |
428 self.asizer.Add(self.rollButton, 0, wx.EXPAND|wx.ALL, 5) | |
429 self.asizer.Add(self.startButton, 0, wx.EXPAND|wx.ALL, 5) | |
430 self.asizer.Add(self.nextButton, 0, wx.EXPAND|wx.ALL, 5) | |
431 self.asizer.Add(self.stopButton, 0, wx.EXPAND|wx.ALL, 5) | |
432 | |
433 self.log.log("Exit InitFrame->buildButtons(self)", ORPG_DEBUG) | |
434 | |
435 def buildGUI(self): | |
436 self.log.log("Enter InitFrame->buildGUI(self)", ORPG_DEBUG) | |
437 | |
438 sizer = wx.GridBagSizer(hgap=1, vgap=1) | |
439 | |
440 self.initList = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) | |
441 self.initList.InsertColumn(0, "Name") | |
442 self.initList.InsertColumn(1, "Type") | |
443 self.initList.InsertColumn(2, "Duration") | |
444 self.initList.InsertColumn(3, "Init Mod") | |
445 self.initList.InsertColumn(4, "Init") | |
446 self.initList.InsertColumn(5, "Manualy Set") | |
447 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.selectInit, self.initList) | |
448 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.deselectInit, self.initList) | |
449 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_InitEdit, self.initList) | |
450 self.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.Test, self.initList) | |
451 | |
452 self.nextMessage = wx.TextCtrl(self, wx.ID_ANY, "UP NEXT FOR THE KILLING") | |
453 msgsizer = wx.BoxSizer(wx.HORIZONTAL) | |
454 msgsizer.Add(wx.StaticText(self, wx.ID_ANY, "Next Message"), 0, wx.ALIGN_CENTER|wx.ALL, 5) | |
455 msgsizer.Add(self.nextMessage, 1, wx.EXPAND|wx.ALL, 5) | |
456 | |
457 self.initRollType = wx.Choice(self, wx.ID_ANY, choices=['d20']) | |
458 self.initRollType.SetSelection(0) | |
459 | |
460 sizer.Add(self.psizer, (0,0), flag=wx.EXPAND) | |
461 sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Init Roll Type'), (0,1), flag=wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL) | |
462 sizer.Add(msgsizer, (1,0), flag=wx.EXPAND) | |
463 sizer.Add(self.initRollType, (1,1), flag=wx.ALIGN_CENTER) | |
464 sizer.Add(self.initList, (2,0), flag=wx.EXPAND) | |
465 sizer.Add(self.esizer, (2,1), flag=wx.EXPAND) | |
466 sizer.Add(self.asizer, (3,0), flag=wx.EXPAND) | |
467 sizer.AddGrowableCol(0) | |
468 sizer.AddGrowableRow(2) | |
469 | |
470 self.SetSizer(sizer) | |
471 self.SetAutoLayout(True) | |
472 self.Fit() | |
473 | |
474 self.log.log("Exit InitFrame->buildGUI(self)", ORPG_DEBUG) | |
475 | |
476 def updateInit(self, init, type): | |
477 reset = False | |
478 if not self.startButton.IsEnabled() and self.initList.GetItemCount() > 0: | |
479 reset = True | |
480 name = self.currentInit.name | |
481 | |
482 | |
483 self.Freeze() | |
484 | |
485 if type == 'Add': | |
486 i = self.initList.InsertStringItem(self.initList.GetItemCount(), init.name) | |
487 self.initList.SetStringItem(i, 1, init.type) | |
488 self.initList.SetStringItem(i, 2, init.duration) | |
489 self.initList.SetStringItem(i, 3, init.initMod) | |
490 self.initList.SetStringItem(i, 4, init.init) | |
491 self.initList.SetStringItem(i, 5, init.manual) | |
492 self.initList.SetItemData(i, init) | |
493 else: | |
494 self.initList.SetStringItem(self.initIdx, 0, init.name) | |
495 self.initList.SetStringItem(self.initIdx, 1, init.type) | |
496 self.initList.SetStringItem(self.initIdx, 2, init.duration) | |
497 self.initList.SetStringItem(self.initIdx, 3, init.initMod) | |
498 self.initList.SetStringItem(self.initIdx, 4, init.init) | |
499 self.initList.SetStringItem(self.initIdx, 5, init.manual) | |
500 self.initList.SetItemData(self.initIdx, init) | |
501 | |
502 self.initList.SortItems(self.initSort) | |
503 self.initList.SetColumnWidth(0, wx.LIST_AUTOSIZE) | |
504 self.initList.SetColumnWidth(1, wx.LIST_AUTOSIZE) | |
505 self.initList.SetColumnWidth(2, wx.LIST_AUTOSIZE) | |
506 self.initList.SetColumnWidth(3, wx.LIST_AUTOSIZE) | |
507 | |
508 if reset: | |
509 for i in xrange(0, self.initList.GetItemCount()): | |
510 self.currentInit = i | |
511 if self.currentInit.name == name and type == 'Add': | |
512 break | |
513 elif self.currentInit.name == name and type == 'Edit': | |
514 self.currentInit = self.initIdx-1 | |
515 break | |
516 | |
517 self.initList.Select(self.initIdx) | |
518 else: | |
519 self.currentInit = 0 | |
520 self.Thaw() | |
521 | |
522 #Events | |
523 def Test(self, evt): | |
524 pass | |
525 | |
526 def selectInit(self, evt): | |
527 self.currentInit = evt.GetIndex() | |
528 self.initList.SetItemState(self.initIdx, 0, wx.LIST_STATE_SELECTED) | |
529 | |
530 def deselectInit(self, evt): | |
531 #self.currentInit = -1 | |
532 evt.Skip() | |
533 | |
534 def OnMB_InitAdd(self, evt): | |
535 addeditwnd = AddEditWnd(self, Init('New'), 'Add') | |
536 addeditwnd.Show() | |
537 | |
538 def OnMB_InitEdit(self, evt): | |
539 addeditwnd = AddEditWnd(self, self.currentInit, 'Edit') | |
540 addeditwnd.Show() | |
541 | |
542 def OnMB_InitDelete(self, evt): | |
543 if self.initIdx != -1: | |
544 self.initList.DeleteItem(self.initIdx) | |
545 self.currentInit = 0 | |
546 | |
547 def OnMB_InitClear(self, evt): | |
548 self.initList.DeleteAllItems() | |
549 self.initIdx = -1 | |
550 | |
551 def OnMB_InitSave(self, evt): | |
552 dlg = wx.TextEntryDialog(self, "Please Name This Init List", "New Init List") | |
553 if dlg.ShowModal() == wx.ID_OK: | |
554 saveas = dlg.GetValue() | |
555 dlg.Destroy() | |
556 else: | |
557 dlg.Destroy() | |
558 return | |
559 | |
560 self.Freeze() | |
561 cidx = self.initIdx | |
562 self.plugin.InitSaves[saveas] = [] | |
563 for i in xrange(0, self.initList.GetItemCount()): | |
564 self.currentInit = i | |
565 cinit = {} | |
566 cinit['name'] = self.currentInit.name | |
567 cinit['type'] = self.currentInit.type | |
568 cinit['duration'] = self.currentInit.duration | |
569 cinit['initMod'] = self.currentInit.initMod | |
570 cinit['init'] = self.currentInit.init | |
571 cinit['manual'] = self.currentInit.manual | |
572 self.plugin.InitSaves[saveas].append(cinit) | |
573 | |
574 self.currentInit = cidx | |
575 self.Thaw() | |
576 | |
577 self.plugin.plugindb.SetDict("xxsimpleinit", "InitSaves", self.plugin.InitSaves) | |
578 | |
579 | |
580 def OnMB_InitLoad(self, evt): | |
581 dlg = wx.Dialog(self, wx.ID_ANY, "Load Init List") | |
582 sz = wx.BoxSizer(wx.HORIZONTAL) | |
583 sz.Add(wx.StaticText(dlg, wx.ID_ANY, 'Select the Init List to Load'), 0, wx.ALIGN_CENTER) | |
584 selectList = wx.Choice(dlg, wx.ID_ANY, choices=self.plugin.InitSaves.keys()) | |
585 selectList.SetSelection(0) | |
586 sz.Add(selectList, 0, wx.EXPAND) | |
587 sz.Add(wx.Button(dlg, wx.ID_OK, 'Load'), 0) | |
588 sz.Add(wx.Button(dlg, wx.ID_CANCEL, 'Cancel'), 0) | |
589 dlg.Show() | |
590 | |
591 dlg.SetSizer(sz) | |
592 dlg.SetAutoLayout(True) | |
593 dlg.Fit() | |
594 | |
595 if dlg.ShowModal() == wx.ID_OK: | |
596 load = selectList.GetStringSelection() | |
597 dlg.Destroy() | |
598 else: | |
599 dlg.Destroy() | |
600 return | |
601 | |
602 self.Freeze() | |
603 self.OnMB_InitClear(None) | |
604 for newInit in self.plugin.InitSaves[load]: | |
605 init = Init(newInit['name'], newInit['type'], newInit['duration'], newInit['initMod'], newInit['init'], newInit['manual']) | |
606 self.updateInit(init, 'Add') | |
607 del init | |
608 | |
609 self.initList.SortItems(self.initSort) | |
610 self.currentInit = 0 | |
611 self.Thaw() | |
612 | |
613 #Getter/Setter | |
614 def GetSelectedInit(self): | |
615 return Init(self.initList.GetItem(self.initIdx, 0).GetText(),\ | |
616 self.initList.GetItem(self.initIdx, 1).GetText(),\ | |
617 self.initList.GetItem(self.initIdx, 2).GetText(),\ | |
618 self.initList.GetItem(self.initIdx, 3).GetText(),\ | |
619 self.initList.GetItem(self.initIdx, 4).GetText(),\ | |
620 self.initList.GetItem(self.initIdx, 5).GetText()) | |
621 | |
622 def SetSelectedInit(self, idx): | |
623 for i in xrange(0, self.initList.GetItemCount()): | |
624 self.initList.SetItemBackgroundColour(i, (255,255,255)) | |
625 | |
626 if idx >= self.initList.GetItemCount(): | |
627 self.initIdx = 0 | |
628 self.plugin.newRound() | |
629 else: | |
630 self.initIdx = idx | |
631 | |
632 if self.initIdx != -1: | |
633 self.initList.SetItemBackgroundColour(self.initIdx, (0,255,0)) | |
634 | |
635 #Properties | |
636 currentInit = property(GetSelectedInit, SetSelectedInit) | |
637 | |
638 class Init: | |
639 def __init__(self, *args, **kwargs): | |
640 """__init__(self, name, type='Player', duration='0', initMod='+0', init='0', manual='No')""" | |
641 if kwargs.has_key('name'): | |
642 self.name = kwargs['name'] | |
643 else: | |
644 try: | |
645 self.name = args[0] | |
646 except: | |
647 print 'Exception: Invalid initilization of ' + __name__ + ' Message. Missing name' | |
648 | |
649 try: | |
650 self.type = args[1] | |
651 except: | |
652 if kwargs.has_key('type'): | |
653 self.type = kwargs['type'] | |
654 else: | |
655 self.type = 'Player' | |
656 | |
657 try: | |
658 self.duration = args[2] | |
659 except: | |
660 if kwargs.has_key('duration'): | |
661 self.duration = kwargs['duration'] | |
662 else: | |
663 self.duration = '0' | |
664 | |
665 try: | |
666 self.initMod = args[3] | |
667 except: | |
668 if kwargs.has_key('initMod'): | |
669 self.initMod = kwargs['initMod'] | |
670 else: | |
671 self.initMod = '0' | |
672 | |
673 try: | |
674 self.init = args[4] | |
675 except: | |
676 if kwargs.has_key('init'): | |
677 self.init = kwargs['init'] | |
678 else: | |
679 self.init = '0' | |
680 | |
681 try: | |
682 self.manual = args[5] | |
683 except: | |
684 if kwargs.has_key('manual'): | |
685 self.manual = kwargs['manual'] | |
686 else: | |
687 self.manual = 'No' | |
688 | |
689 def __int__(self): | |
690 return int(self.init) | |
691 | |
692 | |
693 class AddEditWnd(wx.Frame): | |
694 def __init__(self, parent, Init, edittype="Add"): | |
695 self.parent = parent | |
696 self.edittype = edittype | |
697 if edittype == 'Add': | |
698 wndTitle = 'Add New Initiative Member' | |
699 else: | |
700 wndTitle = 'Edit Initive Member' | |
701 | |
702 wx.Frame.__init__(self, parent, wx.ID_ANY, title=wndTitle, style=wx.DEFAULT_FRAME_STYLE|wx.STAY_ON_TOP) | |
703 #self.MakeModal(True) | |
704 self.SetOwnBackgroundColour('#EFEFEF') | |
705 | |
706 self.currentInit = Init | |
707 | |
708 self.Freeze() | |
709 self.buildGUI() | |
710 self.Thaw() | |
711 | |
712 def buildGUI(self): | |
713 sizer = wx.GridBagSizer(hgap=1, vgap=1) | |
714 sizer.SetEmptyCellSize((0,0)) | |
715 | |
716 self.stDuration = wx.StaticText(self, wx.ID_ANY, 'Duration') | |
717 self.stInitiative = wx.StaticText(self, wx.ID_ANY, 'Initiative') | |
718 | |
719 sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Name'), (0,0), flag=wx.ALIGN_BOTTOM) | |
720 sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Type'), (0,1), flag=wx.ALIGN_BOTTOM) | |
721 sizer.Add(self.stDuration, (0,2), flag=wx.ALIGN_BOTTOM) | |
722 sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Int Mod'), (0,3), flag=wx.ALIGN_BOTTOM) | |
723 sizer.Add(self.stInitiative, (0,4), flag=wx.ALIGN_BOTTOM) | |
724 sizer.Add(wx.StaticText(self, wx.ID_ANY, 'Manualy Set'), (0,5), flag=wx.ALIGN_BOTTOM) | |
725 | |
726 self.name = wx.TextCtrl(self, wx.ID_ANY) | |
727 self.type = wx.Choice(self, wx.ID_ANY, choices=['Player', 'NPC', 'Effect']) | |
728 self.type.SetSelection(0) | |
729 self.Bind(wx.EVT_CHOICE, self.typeSelect, self.type) | |
730 self.duration = wx.TextCtrl(self, wx.ID_ANY, '', size=(40,-1)) | |
731 self.duration.SetMaxLength(4) | |
732 self.duration.Bind(wx.EVT_CHAR, self.validateNumber) | |
733 self.initMod = wx.Choice(self, wx.ID_ANY, choices=['-20', '-19', '-18', '-17', '-16', '-15', '-14', '-13', '-12', '-11', '-10', '-9', '-8', '-7', '-6', '-5', '-4', '-3', '-2', '-1', '+0', '+1', '+2', '+3', '+4', '+5', '+6', '+7', '+8', '+9','+10', '+11', '+12', '+13', '+14', '+15', '+16', '+17', '+18', '+19', '+20']) | |
734 self.initMod.SetSelection(20) | |
735 self.initiative = wx.TextCtrl(self, wx.ID_ANY, '0', size=(40,-1)) | |
736 self.initiative.SetMaxLength(4) | |
737 self.initiative.Bind(wx.EVT_CHAR, self.validateNumber) | |
738 self.manual = wx.Choice(self, wx.ID_ANY, choices=['No', 'Yes']) | |
739 self.manual.SetSelection(0) | |
740 self.Bind(wx.EVT_CHOICE, self.manualSelect, self.manual) | |
741 | |
742 self.initiative.Hide() | |
743 self.stInitiative.Hide() | |
744 self.stDuration.Hide() | |
745 self.duration.Hide() | |
746 | |
747 if self.edittype == 'Edit': | |
748 self.name.SetValue(self.currentInit.name) | |
749 self.type.SetStringSelection(self.currentInit.type) | |
750 self.duration.SetValue(self.currentInit.duration) | |
751 self.initMod.SetStringSelection(self.currentInit.initMod) | |
752 self.initiative.SetValue(self.currentInit.init) | |
753 self.manual.SetStringSelection(self.currentInit.manual) | |
754 | |
755 self.manualSelect(None) | |
756 self.typeSelect(None) | |
757 | |
758 sizer.Add(self.name, (1,0), flag=wx.ALIGN_CENTER) | |
759 sizer.Add(self.type, (1,1), flag=wx.ALIGN_CENTER) | |
760 sizer.Add(self.duration, (1,2), flag=wx.ALIGN_CENTER) | |
761 sizer.Add(self.initMod, (1,3), flag=wx.ALIGN_CENTER) | |
762 sizer.Add(self.initiative, (1,4), flag=wx.ALIGN_CENTER) | |
763 sizer.Add(self.manual, (1,5), flag=wx.ALIGN_CENTER) | |
764 | |
765 self.okButton = wx.Button(self, wx.ID_OK, 'Ok') | |
766 self.cancelButton = wx.Button(self, wx.ID_CANCEL, 'Cancel') | |
767 | |
768 sizer.Add(self.okButton, (0,6), flag=wx.EXPAND) | |
769 sizer.Add(self.cancelButton, (1,6)) | |
770 self.Bind(wx.EVT_BUTTON, self.onOK, self.okButton) | |
771 self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelButton) | |
772 | |
773 self.SetSizer(sizer) | |
774 self.SetAutoLayout(True) | |
775 self.Fit() | |
776 | |
777 | |
778 #Events | |
779 def validateNumber(self, evt): | |
780 if evt.GetKeyCode() == wx.WXK_DELETE or evt.GetKeyCode() == wx.WXK_BACK or (evt.GetKeyCode() < 256 and chr(evt.GetKeyCode()) in string.digits): | |
781 evt.Skip() | |
782 else: | |
783 wx.Bell() | |
784 | |
785 def manualSelect(self, evt): | |
786 if self.manual.GetStringSelection() == 'Yes': | |
787 self.initiative.Show() | |
788 self.stInitiative.Show() | |
789 else: | |
790 self.initiative.Hide() | |
791 self.stInitiative.Hide() | |
792 | |
793 self.Fit() | |
794 | |
795 def typeSelect(self, evt): | |
796 if self.type.GetStringSelection() == 'Effect': | |
797 self.stDuration.Show() | |
798 self.duration.Show() | |
799 else: | |
800 self.stDuration.Hide() | |
801 self.duration.Hide() | |
802 | |
803 self.Fit() | |
804 | |
805 def onOK(self, evt): | |
806 self.currentInit.name = self.name.GetValue() | |
807 self.currentInit.type = self.type.GetStringSelection() | |
808 self.currentInit.duration = self.duration.GetValue() | |
809 self.currentInit.initMod = self.initMod.GetStringSelection() | |
810 self.currentInit.init = self.initiative.GetValue() | |
811 self.currentInit.manual = self.manual.GetStringSelection() | |
812 self.parent.updateInit(self.currentInit, self.edittype) | |
813 self.Close() | |
814 | |
815 def onCancel(self, evt): | |
816 self.Close() |