Allow to use floats in damage pattern editor
This commit is contained in:
30
eos/db/migrations/upgrade33.py
Normal file
30
eos/db/migrations/upgrade33.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Migration 33
|
||||
|
||||
Allow use of floats in damage pattern values
|
||||
"""
|
||||
|
||||
tmpTable = """
|
||||
CREATE TABLE "damagePatternsTemp" (
|
||||
"ID" INTEGER NOT NULL,
|
||||
"name" VARCHAR,
|
||||
"emAmount" FLOAT,
|
||||
"thermalAmount" FLOAT,
|
||||
"kineticAmount" FLOAT,
|
||||
"explosiveAmount" FLOAT,
|
||||
"ownerID" INTEGER,
|
||||
"created" DATETIME,
|
||||
"modified" DATETIME,
|
||||
PRIMARY KEY ("ID"),
|
||||
FOREIGN KEY("ownerID") REFERENCES users ("ID")
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
def upgrade(saveddata_engine):
|
||||
saveddata_engine.execute(tmpTable)
|
||||
saveddata_engine.execute(
|
||||
'INSERT INTO damagePatternsTemp (ID, name, emAmount, thermalAmount, kineticAmount, explosiveAmount, ownerID, created, modified) '
|
||||
'SELECT ID, name, emAmount, thermalAmount, kineticAmount, explosiveAmount, ownerID, created, modified FROM damagePatterns')
|
||||
saveddata_engine.execute('DROP TABLE damagePatterns')
|
||||
saveddata_engine.execute('ALTER TABLE damagePatternsTemp RENAME TO damagePatterns')
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with eos. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ===============================================================================
|
||||
|
||||
from sqlalchemy import Table, Column, Integer, ForeignKey, String, DateTime
|
||||
from sqlalchemy import Table, Column, Integer, Float, ForeignKey, String, DateTime
|
||||
from sqlalchemy.orm import mapper
|
||||
import datetime
|
||||
|
||||
@@ -27,10 +27,10 @@ from eos.saveddata.damagePattern import DamagePattern
|
||||
damagePatterns_table = Table("damagePatterns", saveddata_meta,
|
||||
Column("ID", Integer, primary_key=True),
|
||||
Column("name", String),
|
||||
Column("emAmount", Integer),
|
||||
Column("thermalAmount", Integer),
|
||||
Column("kineticAmount", Integer),
|
||||
Column("explosiveAmount", Integer),
|
||||
Column("emAmount", Float),
|
||||
Column("thermalAmount", Float),
|
||||
Column("kineticAmount", Float),
|
||||
Column("explosiveAmount", Float),
|
||||
Column("ownerID", ForeignKey("users.ID"), nullable=True),
|
||||
Column("created", DateTime, nullable=True, default=datetime.datetime.now),
|
||||
Column("modified", DateTime, nullable=True, onupdate=datetime.datetime.now)
|
||||
|
||||
@@ -20,25 +20,24 @@
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
from logbook import Logger
|
||||
# noinspection PyPackageRequirements
|
||||
from wx.lib.intctrl import IntCtrl
|
||||
|
||||
from gui.auxFrame import AuxiliaryFrame
|
||||
from gui.bitmap_loader import BitmapLoader
|
||||
from gui.builtinViews.entityEditor import BaseValidator, EntityEditor
|
||||
from gui.utils.clipboard import fromClipboard, toClipboard
|
||||
from gui.utils.inputs import FloatBox
|
||||
from service.damagePattern import DamagePattern, ImportError
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class DmgPatternTextValidor(BaseValidator):
|
||||
class DmgPatternNameValidator(BaseValidator):
|
||||
def __init__(self):
|
||||
BaseValidator.__init__(self)
|
||||
|
||||
def Clone(self):
|
||||
return DmgPatternTextValidor()
|
||||
return DmgPatternNameValidator()
|
||||
|
||||
def Validate(self, win):
|
||||
entityEditor = win.parent
|
||||
@@ -62,7 +61,7 @@ class DmgPatternTextValidor(BaseValidator):
|
||||
class DmgPatternEntityEditor(EntityEditor):
|
||||
def __init__(self, parent):
|
||||
EntityEditor.__init__(self, parent, "Damage Profile")
|
||||
self.SetEditorValidator(DmgPatternTextValidor)
|
||||
self.SetEditorValidator(DmgPatternNameValidator)
|
||||
|
||||
def getEntitiesFromContext(self):
|
||||
sDP = DamagePattern.getInstance()
|
||||
@@ -134,18 +133,16 @@ class DmgPatternEditor(AuxiliaryFrame):
|
||||
border = 5
|
||||
|
||||
# set text edit
|
||||
setattr(self, "%sEdit" % type_, IntCtrl(self, wx.ID_ANY, 0, wx.DefaultPosition, defSize))
|
||||
setattr(self, "%sPerc" % type_, wx.StaticText(self, wx.ID_ANY, "0%"))
|
||||
editObj = getattr(self, "%sEdit" % type_)
|
||||
editBox = FloatBox(parent=self, id=wx.ID_ANY, value=0, pos=wx.DefaultPosition, size=defSize)
|
||||
percLabel = wx.StaticText(self, wx.ID_ANY, "0%")
|
||||
setattr(self, "%sEdit" % type_, editBox)
|
||||
setattr(self, "%sPerc" % type_, percLabel)
|
||||
|
||||
dmgeditSizer.Add(bmp, 0, style, border)
|
||||
dmgeditSizer.Add(editObj, 0, wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
dmgeditSizer.Add(getattr(self, "%sPerc" % type_), 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
dmgeditSizer.Add(editBox, 0, wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
dmgeditSizer.Add(percLabel, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
|
||||
editObj.Bind(wx.EVT_TEXT, self.ValuesUpdated)
|
||||
editObj.SetLimited(True)
|
||||
editObj.SetMin(0)
|
||||
editObj.SetMax(2000000)
|
||||
editBox.Bind(wx.EVT_TEXT, self.OnFieldChanged)
|
||||
|
||||
contentSizer.Add(dmgeditSizer, 1, wx.EXPAND | wx.ALL, 5)
|
||||
self.slfooter = wx.StaticLine(self)
|
||||
@@ -196,17 +193,17 @@ class DmgPatternEditor(AuxiliaryFrame):
|
||||
|
||||
self.patternChanged()
|
||||
|
||||
def ValuesUpdated(self, event=None):
|
||||
def OnFieldChanged(self, event=None):
|
||||
if self.block:
|
||||
return
|
||||
|
||||
p = self.entityEditor.getActiveEntity()
|
||||
total = sum([getattr(self, "%sEdit" % attr).GetValue() for attr in self.DAMAGE_TYPES])
|
||||
total = sum([getattr(self, "%sEdit" % attr).GetValueFloat() for attr in self.DAMAGE_TYPES])
|
||||
for type_ in self.DAMAGE_TYPES:
|
||||
editObj = getattr(self, "%sEdit" % type_)
|
||||
percObj = getattr(self, "%sPerc" % type_)
|
||||
setattr(p, "%sAmount" % type_, editObj.GetValue())
|
||||
percObj.SetLabel("%.1f%%" % (float(editObj.GetValue()) * 100 / total if total > 0 else 0))
|
||||
editBox = getattr(self, "%sEdit" % type_)
|
||||
percLabel = getattr(self, "%sPerc" % type_)
|
||||
setattr(p, "%sAmount" % type_, editBox.GetValueFloat())
|
||||
percLabel.SetLabel("%.1f%%" % (float(editBox.GetValueFloat()) * 100 / total if total > 0 else 0))
|
||||
|
||||
self.totSizer.Layout()
|
||||
|
||||
@@ -245,10 +242,10 @@ class DmgPatternEditor(AuxiliaryFrame):
|
||||
for field in self.DAMAGE_TYPES:
|
||||
edit = getattr(self, "%sEdit" % field)
|
||||
amount = int(round(getattr(p, "%sAmount" % field)))
|
||||
edit.SetValue(amount)
|
||||
edit.ChangeValueFloat(amount)
|
||||
|
||||
self.block = False
|
||||
self.ValuesUpdated()
|
||||
self.OnFieldChanged()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user