Mercurial > traipse_dev
comparison plugins/xxgsc.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 | 24d59375aac9 b633f4c64aae |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 import os | |
2 from orpg.orpg_wx import * | |
3 import random | |
4 import orpg.pluginhandler | |
5 | |
6 | |
7 ID_ROLL = wx.NewId() | |
8 | |
9 class Plugin(orpg.pluginhandler.PluginHandler): | |
10 # Initialization subroutine. | |
11 # | |
12 # !self : instance of self | |
13 # !chat : instance of the chat window to write to | |
14 def __init__(self, plugindb, parent): | |
15 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent) | |
16 | |
17 self.name = 'Game Status Controller' | |
18 self.author = 'Woody, updated by mDuo13' | |
19 self.help = 'This plugin lets you quickly and easily manage a status that includes \n' | |
20 self.help += 'your HP and AC for AD&D 2nd Edition. Type /gsc to open up the manager\n' | |
21 self.help += 'window, and from there just change the values as necessary and the changes\n' | |
22 self.help += 'will be reflected in your status. To revert to your regular status, close\n' | |
23 self.help += 'the GSC window.' | |
24 | |
25 self.frame = None | |
26 | |
27 def plugin_enabled(self): | |
28 self.plugin_addcommand('/gsc', self.on_gsc, '- The GSC command') | |
29 self.frame = RollerFrame(None, -1, "Game Status Ctrl (GSC)", self) | |
30 self.frame.Hide() | |
31 | |
32 item = wx.MenuItem(self.menu, wx.ID_ANY, "GSC Window", "GSC Window", wx.ITEM_CHECK) | |
33 self.topframe.Bind(wx.EVT_MENU, self._toggleWindow, item) | |
34 self.menu.AppendItem(item) | |
35 | |
36 def plugin_disabled(self): | |
37 self.plugin_removecmd('/gsc') | |
38 try: | |
39 self.frame.TimeToQuit(1) | |
40 except: | |
41 pass | |
42 | |
43 def on_gsc(self, cmdargs): | |
44 item = self.menu.FindItemById(self.menu.FindItem("GSC Window")) | |
45 item.Check(True) | |
46 self.frame.Show() | |
47 self.frame.Raise() | |
48 | |
49 #Events | |
50 def _toggleWindow(self, evt): | |
51 id = evt.GetId() | |
52 item = self.menu.FindItemById(id) | |
53 if self.frame.IsShown(): | |
54 self.frame.Hide() | |
55 item.Check(False) | |
56 else: | |
57 self.frame.Show() | |
58 item.Check(True) | |
59 | |
60 | |
61 class RollerFrame(wx.Frame): | |
62 def __init__(self, parent, ID, title, plugin): | |
63 wx.Frame.__init__(self, parent, ID, title, | |
64 wx.DefaultPosition, wx.Size(200, 70)) | |
65 | |
66 self.settings = plugin.settings | |
67 self.session = plugin.session | |
68 self.plugin = plugin | |
69 | |
70 self.panel = wx.Panel(self,-1) | |
71 menu = wx.Menu() | |
72 menu.AppendSeparator() | |
73 menu.Append(wx.ID_EXIT, "&Close", "Close this window") | |
74 menuBar = wx.MenuBar() | |
75 menuBar.Append(menu, "&File"); | |
76 self.SetMenuBar(menuBar) | |
77 | |
78 self.old_idle = self.settings.get_setting('IdleStatusAlias') | |
79 | |
80 wx.StaticText(self.panel, -1, "AC:", wx.Point(0, 5)) | |
81 self.ac = wx.SpinCtrl(self.panel, ID_ROLL, "", wx.Point(18, 0), wx.Size(45, -1), min = -100, max = 100, initial = 10) | |
82 self.ac.SetValue(10) | |
83 | |
84 wx.StaticText(self.panel, -1, "/", wx.Point(136, 5)) | |
85 self.max_hp = wx.SpinCtrl(self.panel, ID_ROLL, "", wx.Point(144, 0), wx.Size(48, -1), min = -999, max = 999, initial = 10) | |
86 self.max_hp.SetValue(10) | |
87 | |
88 wx.StaticText(self.panel, -1, "HP:", wx.Point(65, 5)) | |
89 self.hp = wx.SpinCtrl(self.panel, ID_ROLL, "", wx.Point(83, 0), wx.Size(48, -1), min = -999, max = 999, initial = 10) | |
90 self.hp.SetValue(10) | |
91 | |
92 self.Bind(wx.EVT_SPINCTRL, self.SetStatus, id=ID_ROLL) | |
93 self.Bind(wx.EVT_TEXT, self.SetStatus, id=ID_ROLL) | |
94 self.Bind(wx.EVT_MENU, self.TimeToQuit, id=wx.ID_EXIT) | |
95 self.Bind(wx.EVT_CLOSE, self._close) | |
96 self.SetStatus(None) | |
97 | |
98 def SetStatus(self, evt): | |
99 new_status = "AC: " + str(self.ac.GetValue()) + " HP: " + str(self.hp.GetValue()) + "/" + str(self.max_hp.GetValue()) | |
100 self.settings.set_setting('IdleStatusAlias',new_status) | |
101 self.session.set_text_status(new_status) | |
102 | |
103 def TimeToQuit(self, event): | |
104 self.settings.set_setting('IdleStatusAlias',self.old_idle) | |
105 self.session.set_text_status(self.old_idle) | |
106 self.frame = None | |
107 self.Destroy() | |
108 | |
109 def _close(self, evt): | |
110 self.Hide() | |
111 item = self.plugin.menu.FindItemById(self.plugin.menu.FindItem("GSC Window")) | |
112 item.Check(False) |