Mercurial > openrpg
changeset 515:52dcb3fed083
continuing develoment of plugin. added a delete all button, allow bonuses to be added to nodes that are not integers but simple arithmetic (eg includes min/max or if..else)
author | david@goon |
---|---|
date | Wed, 10 Feb 2010 20:39:17 -0600 |
parents | 52c273953722 |
children | e8816dc7c8bb |
files | plugins/xxbonuses.py |
diffstat | 1 files changed, 30 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/xxbonuses.py Wed Feb 10 20:35:53 2010 -0600 +++ b/plugins/xxbonuses.py Wed Feb 10 20:39:17 2010 -0600 @@ -6,7 +6,7 @@ from orpg.mapper.base_handler import base_layer_handler import wx import types -from orpg.gametree.nodehandlers.core import is_integer +from orpg.chat.chatwnd import compiled_simple_arithmetic_regex from orpg.chat.commands import command_args_parser from orpg.gametree.nodehandlers.core import node_handler @@ -52,8 +52,8 @@ # overrides the existing chat method def my_handle_adding_bonuses(self, value, handler): - if is_integer(value): - newint = int(value) + if compiled_simple_arithmetic_regex.match(value): + newint = eval(value) fullpath, v, namespace_name, namespace_path = open_rpg.get_component('tree').get_path_data(handler.mytree_node) if namespace_name: key = (namespace_name, namespace_path) @@ -155,12 +155,12 @@ if handler is None: open_rpg.get_component("chat").InfoPost("Second parameter must reference a node.") return - value = handler.get_value() - try: - value = int(value) - except: - open_rpg.get_component("chat").InfoPost("Value of node must be an integer.") - return +## value = handler.get_value() +## try: +## value = int(value) +## except: +## open_rpg.get_component("chat").InfoPost("Value of node must be an integer.") +## return if 'type' in key_values: bonus_type = key_values['type'] else: @@ -229,12 +229,12 @@ if handler is None: chat.InfoPost("Path parameters must be indexed nodes.") return - value = handler.get_value() - try: - value = int(value) - except: - chat.InfoPost("Value of node to receive bonus must be an integer.") - return +## value = handler.get_value() +## try: +## value = int(value) +## except: +## chat.InfoPost("Value of node to receive bonus must be an integer.") +## return fullpath, v, n, namespace_path = open_rpg.get_component('tree').get_path_data(handler.mytree_node) if namespace_name: path = namespace_path @@ -251,7 +251,8 @@ LIST_CTRL = wx.NewId() -BUT_ADD = wx.NewId() +BUT_DEL = wx.NewId() +BUT_DEL_ALL = wx.NewId() class BonusFrame(wx.Frame): def __init__(self): @@ -275,10 +276,12 @@ self.effects.append(effect) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.listbox, 1, wx.EXPAND) - sizer.Add(wx.Button(self, BUT_ADD, "Delete"), 0, wx.EXPAND) + sizer.Add(wx.Button(self, BUT_DEL, "Delete"), 0, wx.EXPAND) + sizer.Add(wx.Button(self, BUT_DEL_ALL, "Delete All"), 0, wx.EXPAND) self.SetSizer(sizer) #self.SetAutoLayout(True) - self.Bind(wx.EVT_BUTTON, self.on_delete, id=BUT_ADD) + self.Bind(wx.EVT_BUTTON, self.on_delete, id=BUT_DEL) + self.Bind(wx.EVT_BUTTON, self.on_delete_all, id=BUT_DEL_ALL) def on_delete(self, evt): index = self.listbox.GetFocusedItem() @@ -287,3 +290,12 @@ open_rpg.get_component("chat").delete_effect(effect) self.effects[index:index+1] = [] self.listbox.DeleteItem(index) + + def on_delete_all(self, evt): + dlg = wx.MessageDialog(self, "Are you sure you want to delete all bonuses and effects?","Delete All",wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) + if dlg.ShowModal() != wx.ID_YES: + return + open_rpg.get_component("chat").effects = [] + open_rpg.get_component("chat").bonus_map = {} + self.effects = [] + self.listbox.DeleteAllItems()