Rework mainOnly parameter into conditions

This commit is contained in:
DarkPhoenix
2019-08-19 12:37:52 +03:00
parent 8b2f9ce59d
commit 01bda70fef
5 changed files with 104 additions and 78 deletions

View File

@@ -83,19 +83,20 @@ class XDef:
class Input:
def __init__(self, handle, unit, label, iconID, defaultValue, defaultRange, mainOnly=False, mainTooltip=None, secondaryTooltip=None):
def __init__(self, handle, unit, label, iconID, defaultValue, defaultRange, mainTooltip=None, secondaryTooltip=None, conditions=()):
self.handle = handle
self.unit = unit
self.label = label
self.iconID = iconID
self.defaultValue = defaultValue
self.defaultRange = defaultRange
self.mainOnly = mainOnly
self.mainTooltip = mainTooltip
self.secondaryTooltip = secondaryTooltip
# Format: ((x condition, y condition), (x condition, y condition), ...)
self.conditions = tuple(conditions)
def __hash__(self):
return hash((self.handle, self.unit, self.label, self.iconID, self.defaultValue, self.defaultRange, self.mainOnly, self.mainTooltip, self.secondaryTooltip))
return hash((self.handle, self.unit, self.label, self.iconID, self.defaultValue, self.defaultRange, self.mainTooltip, self.secondaryTooltip, self.conditions))
def __eq__(self, other):
if not isinstance(other, Input):
@@ -107,6 +108,6 @@ class Input:
self.iconID == other.iconID,
self.defaultValue == other.defaultValue,
self.defaultRange == other.defaultRange,
self.mainOnly == other.mainOnly,
self.mainTooltip == other.mainTooltip,
self.secondaryTooltip == other.secondaryTooltip))
self.secondaryTooltip == other.secondaryTooltip,
self.conditions == other.conditions))

View File

@@ -35,8 +35,11 @@ class FitCapRegenGraph(FitGraph):
YDef(handle='capAmount', unit='GJ', label='Cap amount'),
YDef(handle='capRegen', unit='GJ/s', label='Cap regen')]
inputs = [
Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=120, defaultRange=(0, 300), mainOnly=True),
Input(handle='capAmount', unit='%', label='Cap amount', iconID=1668, defaultValue=25, defaultRange=(0, 100), mainOnly=True)]
Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=120, defaultRange=(0, 300), conditions=[
(('time', 's'), None)]),
Input(handle='capAmount', unit='%', label='Cap amount', iconID=1668, defaultValue=25, defaultRange=(0, 100), conditions=[
(('capAmount', 'GJ'), None),
(('capAmount', '%'), None)])]
srcExtraCols = ('CapAmount', 'CapTime')
# Calculation stuff

View File

@@ -63,7 +63,9 @@ class FitDamageStatsGraph(FitGraph):
Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=None, defaultRange=(0, 80), secondaryTooltip='When set, uses attacker\'s exact damage stats at a given time\nWhen not set, uses attacker\'s damage stats as shown in stats panel of main window'),
Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=None, defaultRange=(0, 100), mainTooltip='Distance between the attacker and the target, as seen in overview (surface-to-surface)', secondaryTooltip='Distance between the attacker and the target, as seen in overview (surface-to-surface)\nWhen set, places the target that far away from the attacker\nWhen not set, attacker\'s weapons always hit the target'),
Input(handle='tgtSpeed', unit='%', label='Target speed', iconID=1389, defaultValue=100, defaultRange=(0, 100)),
Input(handle='tgtSigRad', unit='%', label='Target signature', iconID=1390, defaultValue=100, defaultRange=(100, 200), mainOnly=True)]
Input(handle='tgtSigRad', unit='%', label='Target signature', iconID=1390, defaultValue=100, defaultRange=(100, 200), conditions=[
(('tgtSigRad', 'm'), None),
(('tgtSigRad', '%'), None)])]
srcVectorDef = VectorDef(lengthHandle='atkSpeed', lengthUnit='%', angleHandle='atkAngle', angleUnit='degrees', label='Attacker')
tgtVectorDef = VectorDef(lengthHandle='tgtSpeed', lengthUnit='%', angleHandle='tgtAngle', angleUnit='degrees', label='Target')
hasTargets = True

View File

@@ -31,8 +31,12 @@ class FitShieldRegenGraph(FitGraph):
internalName = 'shieldRegenGraph'
name = 'Shield Regeneration'
inputs = [
Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=120, defaultRange=(0, 300), mainOnly=True),
Input(handle='shieldAmount', unit='%', label='Shield amount', iconID=1384, defaultValue=25, defaultRange=(0, 100), mainOnly=True)]
Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=120, defaultRange=(0, 300), conditions=[
(('time', 's'), None)]),
Input(handle='shieldAmount', unit='%', label='Shield amount', iconID=1384, defaultValue=25, defaultRange=(0, 100), conditions=[
(('shieldAmount', 'EHP'), None),
(('shieldAmount', 'HP'), None),
(('shieldAmount', '%'), None)])]
srcExtraCols = ('ShieldAmount', 'ShieldTime')
usesHpEffectivity = True

View File

@@ -186,86 +186,102 @@ class GraphControlPanel(wx.Panel):
self._mainInputBox = None
self._miscInputBoxes.clear()
self._inputCheckboxes.clear()
# Update vectors
def handleVector(vectorDef, vector, handledHandles, mainInputHandle):
handledHandles.add(vectorDef.lengthHandle)
handledHandles.add(vectorDef.angleHandle)
try:
storedLength = self._storedConsts[(vectorDef.lengthHandle, vectorDef.lengthUnit)]
except KeyError:
pass
else:
vector.SetLength(storedLength / 100)
try:
storedAngle = self._storedConsts[(vectorDef.angleHandle, vectorDef.angleUnit)]
except KeyError:
pass
else:
vector.SetAngle(storedAngle)
vector.SetDirectionOnly(vectorDef.lengthHandle == mainInputHandle)
view = self.graphFrame.getView()
handledHandles = set()
if view.srcVectorDef is not None:
handleVector(view.srcVectorDef, self.srcVector, handledHandles, self.xType.mainInput[0])
self.__handleVector(view.srcVectorDef, self.srcVector, handledHandles, self.xType.mainInput[0])
if view.tgtVectorDef is not None:
handleVector(view.tgtVectorDef, self.tgtVector, handledHandles, self.xType.mainInput[0])
self.__handleVector(view.tgtVectorDef, self.tgtVector, handledHandles, self.xType.mainInput[0])
# Update inputs
def addInputField(inputDef, handledHandles, mainInput=False):
handledHandles.add(inputDef.handle)
fieldSizer = wx.BoxSizer(wx.HORIZONTAL)
tooltipText = (inputDef.mainTooltip if mainInput else inputDef.secondaryTooltip) or ''
if mainInput:
fieldTextBox = FloatRangeBox(self, self._storedRanges.get((inputDef.handle, inputDef.unit), inputDef.defaultRange))
fieldTextBox.Bind(wx.EVT_TEXT, self.OnMainInputChanged)
else:
fieldTextBox = FloatBox(self, self._storedConsts.get((inputDef.handle, inputDef.unit), inputDef.defaultValue))
fieldTextBox.Bind(wx.EVT_TEXT, self.OnNonMainInputChanged)
fieldTextBox.SetToolTip(wx.ToolTip(tooltipText))
fieldSizer.Add(fieldTextBox, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
fieldIcon = None
if inputDef.iconID is not None:
icon = BitmapLoader.getBitmap(inputDef.iconID, 'icons')
if icon is not None:
fieldIcon = wx.StaticBitmap(self)
fieldIcon.SetBitmap(icon)
fieldIcon.SetToolTip(wx.ToolTip(tooltipText))
fieldSizer.Add(fieldIcon, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3)
fieldLabel = wx.StaticText(self, wx.ID_ANY, self.formatLabel(inputDef))
fieldLabel.SetToolTip(wx.ToolTip(tooltipText))
fieldSizer.Add(fieldLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0)
self.inputsSizer.Add(fieldSizer, 0, wx.EXPAND | wx.BOTTOM, 5)
# Store info about added input box
inputBox = InputBox(handle=inputDef.handle, unit=inputDef.unit, textBox=fieldTextBox, icon=fieldIcon, label=fieldLabel)
if mainInput:
self._mainInputBox = inputBox
else:
self._miscInputBoxes.append(inputBox)
addInputField(view.inputMap[self.xType.mainInput], handledHandles, mainInput=True)
self.__addInputField(view.inputMap[self.xType.mainInput], handledHandles, mainInput=True)
for inputDef in view.inputs:
if inputDef.mainOnly:
continue
if inputDef.handle in handledHandles:
continue
addInputField(inputDef, handledHandles)
def addInputCheckbox(checkboxDef, handledHandles):
handledHandles.add(checkboxDef.handle)
fieldCheckbox = wx.CheckBox(self, wx.ID_ANY, checkboxDef.label, wx.DefaultPosition, wx.DefaultSize, 0)
fieldCheckbox.SetValue(self._storedConsts.get((checkboxDef.handle, None), checkboxDef.defaultValue))
fieldCheckbox.Bind(wx.EVT_CHECKBOX, self.OnNonMainInputChanged)
self.inputsSizer.Add(fieldCheckbox, 0, wx.BOTTOM, 5)
# Store info about added checkbox
checkbox = CheckBox(handle=checkboxDef.handle, checkBox=fieldCheckbox)
self._inputCheckboxes.append(checkbox)
self.__addInputField(inputDef, handledHandles)
# Add checkboxes
for checkboxDef in view.checkboxes:
if checkboxDef.handle in handledHandles:
continue
addInputCheckbox(checkboxDef, handledHandles)
self.__addInputCheckbox(checkboxDef, handledHandles)
def __handleVector(self, vectorDef, vector, handledHandles, mainInputHandle):
handledHandles.add(vectorDef.lengthHandle)
handledHandles.add(vectorDef.angleHandle)
try:
storedLength = self._storedConsts[(vectorDef.lengthHandle, vectorDef.lengthUnit)]
except KeyError:
pass
else:
vector.SetLength(storedLength / 100)
try:
storedAngle = self._storedConsts[(vectorDef.angleHandle, vectorDef.angleUnit)]
except KeyError:
pass
else:
vector.SetAngle(storedAngle)
vector.SetDirectionOnly(vectorDef.lengthHandle == mainInputHandle)
def __addInputField(self, inputDef, handledHandles, mainInput=False):
if not self.__checkInputConditions(inputDef):
return
handledHandles.add(inputDef.handle)
fieldSizer = wx.BoxSizer(wx.HORIZONTAL)
tooltipText = (inputDef.mainTooltip if mainInput else inputDef.secondaryTooltip) or ''
if mainInput:
fieldTextBox = FloatRangeBox(self, self._storedRanges.get((inputDef.handle, inputDef.unit), inputDef.defaultRange))
fieldTextBox.Bind(wx.EVT_TEXT, self.OnMainInputChanged)
else:
fieldTextBox = FloatBox(self, self._storedConsts.get((inputDef.handle, inputDef.unit), inputDef.defaultValue))
fieldTextBox.Bind(wx.EVT_TEXT, self.OnNonMainInputChanged)
fieldTextBox.SetToolTip(wx.ToolTip(tooltipText))
fieldSizer.Add(fieldTextBox, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
fieldIcon = None
if inputDef.iconID is not None:
icon = BitmapLoader.getBitmap(inputDef.iconID, 'icons')
if icon is not None:
fieldIcon = wx.StaticBitmap(self)
fieldIcon.SetBitmap(icon)
fieldIcon.SetToolTip(wx.ToolTip(tooltipText))
fieldSizer.Add(fieldIcon, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 3)
fieldLabel = wx.StaticText(self, wx.ID_ANY, self.formatLabel(inputDef))
fieldLabel.SetToolTip(wx.ToolTip(tooltipText))
fieldSizer.Add(fieldLabel, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 0)
self.inputsSizer.Add(fieldSizer, 0, wx.EXPAND | wx.BOTTOM, 5)
# Store info about added input box
inputBox = InputBox(handle=inputDef.handle, unit=inputDef.unit, textBox=fieldTextBox, icon=fieldIcon, label=fieldLabel)
if mainInput:
self._mainInputBox = inputBox
else:
self._miscInputBoxes.append(inputBox)
def __addInputCheckbox(self, checkboxDef, handledHandles):
handledHandles.add(checkboxDef.handle)
fieldCheckbox = wx.CheckBox(self, wx.ID_ANY, checkboxDef.label, wx.DefaultPosition, wx.DefaultSize, 0)
fieldCheckbox.SetValue(self._storedConsts.get((checkboxDef.handle, None), checkboxDef.defaultValue))
fieldCheckbox.Bind(wx.EVT_CHECKBOX, self.OnNonMainInputChanged)
self.inputsSizer.Add(fieldCheckbox, 0, wx.BOTTOM, 5)
# Store info about added checkbox
checkbox = CheckBox(handle=checkboxDef.handle, checkBox=fieldCheckbox)
self._inputCheckboxes.append(checkbox)
def __checkInputConditions(self, inputDef):
if not inputDef.conditions:
return True
selectedX = self.xType
selectedY = self.yType
for xCond, yCond in inputDef.conditions:
xMatch = True
yMatch = True
if xCond is not None:
xCondHandle, xCondUnit = xCond
xMatch = selectedX.handle == xCondHandle and selectedX.unit == xCondUnit
if yCond is not None:
yCondHandle, yCondUnit = yCond
yMatch = selectedY.handle == yCondHandle and selectedY.unit == yCondUnit
if xMatch and yMatch:
return True
return False
def refreshAxeLabels(self, restoreSelection=False):
view = self.graphFrame.getView()