Merge branch 'master' into attrGroup
# Conflicts: # eos/gamedata.py # eve.db # gui/builtinItemStatsViews/itemAttributes.py
This commit is contained in:
@@ -46,17 +46,17 @@ class AttributeSlider(wx.Panel):
|
||||
# Slider which abstracts users values from internal values (because the built in slider does not deal with floats
|
||||
# and the like), based on http://wxpython-users.wxwidgets.narkive.com/ekgBzA7u/anyone-ever-thought-of-a-floating-point-slider
|
||||
|
||||
def __init__(self, parent, baseValue, minMod, maxMod, inverse=False, id=-1):
|
||||
def __init__(self, parent, baseValue, minValue, maxValue, inverse=False, id=-1):
|
||||
wx.Panel.__init__(self, parent, id=id)
|
||||
|
||||
self.parent = parent
|
||||
|
||||
self.inverse = inverse
|
||||
|
||||
self.base_value = baseValue
|
||||
|
||||
self.UserMinValue = minMod
|
||||
self.UserMaxValue = maxMod
|
||||
self.UserMinValue = minValue
|
||||
self.UserMaxValue = maxValue
|
||||
|
||||
self.inverse = inverse
|
||||
|
||||
# The internal slider basically represents the percentage towards the end of the range. It has to be normalized
|
||||
# in this way, otherwise when we start off with a base, if the range is skewed to one side, the base value won't
|
||||
@@ -65,12 +65,12 @@ class AttributeSlider(wx.Panel):
|
||||
|
||||
# Additionally, since we want the slider to be accurate to 3 decimal places, we need to blow out the two ends here
|
||||
# (if we have a slider that needs to land on 66.66% towards the right, it will actually be converted to 66%. Se we need it to support 6,666)
|
||||
#
|
||||
# self.SliderMinValue = -100
|
||||
# self.SliderMaxValue = 100
|
||||
# self.SliderValue = 0
|
||||
|
||||
self.SliderMinValue = -100
|
||||
self.SliderMaxValue = 100
|
||||
self.SliderValue = 0
|
||||
|
||||
range = [(self.UserMinValue * self.base_value), (self.UserMaxValue * self.base_value)]
|
||||
range = [self.UserMinValue, self.UserMaxValue]
|
||||
|
||||
self.ctrl = wx.SpinCtrlDouble(self, min=min(range), max=max(range))
|
||||
self.ctrl.SetDigits(3)
|
||||
@@ -92,19 +92,12 @@ class AttributeSlider(wx.Panel):
|
||||
evt.Skip()
|
||||
|
||||
def SetValue(self, value, post_event=True):
|
||||
# todo: check this against values that might be 2.5x and whatnot
|
||||
mod = value / self.base_value
|
||||
self.ctrl.SetValue(value)
|
||||
slider_percentage = 0
|
||||
if mod < 1:
|
||||
modEnd = self.UserMinValue
|
||||
slider_percentage = (1 - mod) / (1 - modEnd) * -100
|
||||
elif mod > 1:
|
||||
modEnd = self.UserMaxValue
|
||||
slider_percentage = ((mod - 1) / (modEnd - 1)) * 100
|
||||
# print(slider_percentage)
|
||||
if self.inverse:
|
||||
slider_percentage *= -1
|
||||
invert_factor = -1 if self.inverse else 1
|
||||
if value >= self.base_value:
|
||||
slider_percentage = (value - self.base_value) / (self.UserMaxValue - self.base_value) * 100 * invert_factor
|
||||
else:
|
||||
slider_percentage = (value - self.base_value) / (self.base_value - self.UserMinValue) * 100 * invert_factor
|
||||
self.slider.SetValue(slider_percentage)
|
||||
if post_event:
|
||||
wx.PostEvent(self, ValueChanged(self, None, value, None, slider_percentage))
|
||||
|
||||
@@ -7,7 +7,7 @@ import wx.lib.agw.hypertreelist
|
||||
from gui.builtinItemStatsViews.helpers import AutoListCtrl
|
||||
|
||||
from gui.bitmap_loader import BitmapLoader
|
||||
from gui.utils.numberFormatter import formatAmount
|
||||
from gui.utils.numberFormatter import formatAmount, roundDec
|
||||
from enum import IntEnum
|
||||
from gui.builtinItemStatsViews.attributeGrouping import *
|
||||
|
||||
@@ -294,14 +294,14 @@ class ItemParams(wx.Panel):
|
||||
if self.toggleView != 1:
|
||||
valueUnit = str(value)
|
||||
elif info and info.unit:
|
||||
valueUnit = self.FormatValue(*info.unit.TranslateValue(value))
|
||||
valueUnit = self.FormatValue(*info.unit.PreformatValue(value))
|
||||
else:
|
||||
valueUnit = formatAmount(value, 3, 0, 0)
|
||||
|
||||
if self.toggleView != 1:
|
||||
valueUnitDefault = str(valueDefault)
|
||||
elif info and info.unit:
|
||||
valueUnitDefault = self.FormatValue(*info.unit.TranslateValue(valueDefault))
|
||||
valueUnitDefault = self.FormatValue(*info.unit.PreformatValue(valueDefault))
|
||||
else:
|
||||
valueUnitDefault = formatAmount(valueDefault, 3, 0, 0)
|
||||
|
||||
@@ -314,11 +314,13 @@ class ItemParams(wx.Panel):
|
||||
# self.paramList.SetItemImage(index, attrIcon, which=wx.TreeItemIcon_Normal)
|
||||
|
||||
@staticmethod
|
||||
def FormatValue(value, unit):
|
||||
def FormatValue(value, unit, rounding='prec', digits=3):
|
||||
"""Formats a value / unit combination into a string
|
||||
@todo: move this to a more central location, since this is also used in the item mutator panel"""
|
||||
if isinstance(value, (int, float)):
|
||||
fvalue = formatAmount(value, 3, 0, 0)
|
||||
if isinstance(value, (int, float)) and rounding == 'prec':
|
||||
fvalue = formatAmount(value, digits, 0, 0)
|
||||
elif isinstance(value, (int, float)) and rounding == 'dec':
|
||||
fvalue = roundDec(value, digits)
|
||||
else:
|
||||
fvalue = value
|
||||
return "%s %s" % (fvalue, unit)
|
||||
|
||||
@@ -30,17 +30,9 @@ class ItemMutator(wx.Panel):
|
||||
self.event_mapping = {}
|
||||
|
||||
for m in sorted(stuff.mutators.values(), key=lambda x: x.attribute.displayName):
|
||||
baseValueFormated = m.attribute.unit.TranslateValue(m.baseValue)[0]
|
||||
valueFormated = m.attribute.unit.TranslateValue(m.value)[0]
|
||||
slider = AttributeSlider(self, baseValueFormated, m.minMod, m.maxMod, not m.highIsGood)
|
||||
slider.SetValue(valueFormated, False)
|
||||
slider.Bind(EVT_VALUE_CHANGED, self.changeMutatedValue)
|
||||
self.event_mapping[slider] = m
|
||||
headingSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
# create array for the two ranges
|
||||
min_t = [round(m.minValue, 3), m.minMod, None]
|
||||
max_t = [round(m.maxValue, 3), m.maxMod, None]
|
||||
min_t = [m.minValue, m.minMod, None]
|
||||
max_t = [m.maxValue, m.maxMod, None]
|
||||
|
||||
# Then we need to determine if it's better than original, which will be the color
|
||||
min_t[2] = min_t[1] < 1 if not m.highIsGood else 1 < min_t[1]
|
||||
@@ -56,14 +48,8 @@ class ItemMutator(wx.Panel):
|
||||
worse_range = max_t
|
||||
else:
|
||||
worse_range = min_t
|
||||
#
|
||||
# print("{}: \nHigh is good: {}".format(m.attribute.displayName, m.attribute.highIsGood))
|
||||
# print("Value {}".format(m.baseValue))
|
||||
#
|
||||
# print(min_t)
|
||||
# print(max_t)
|
||||
# print(better_range)
|
||||
# print(worse_range)
|
||||
|
||||
headingSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
font = parent.GetFont()
|
||||
font.SetWeight(wx.BOLD)
|
||||
@@ -75,19 +61,30 @@ class ItemMutator(wx.Panel):
|
||||
|
||||
headingSizer.Add(displayName, 3, wx.ALL | wx.EXPAND, 0)
|
||||
|
||||
range_low = wx.StaticText(self, wx.ID_ANY, ItemParams.FormatValue(*m.attribute.unit.TranslateValue(worse_range[0])))
|
||||
range_low.SetForegroundColour(self.goodColor if worse_range[2] else self.badColor)
|
||||
worst_val = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(worse_range[0]), rounding='dec')
|
||||
worst_text = wx.StaticText(self, wx.ID_ANY, worst_val)
|
||||
worst_text.SetForegroundColour(self.goodColor if worse_range[2] else self.badColor)
|
||||
|
||||
range_high = wx.StaticText(self, wx.ID_ANY, ItemParams.FormatValue(*m.attribute.unit.TranslateValue(better_range[0])))
|
||||
range_high.SetForegroundColour(self.goodColor if better_range[2] else self.badColor)
|
||||
best_val = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(better_range[0]), rounding='dec')
|
||||
best_text = wx.StaticText(self, wx.ID_ANY, best_val)
|
||||
best_text.SetForegroundColour(self.goodColor if better_range[2] else self.badColor)
|
||||
|
||||
headingSizer.Add(range_low, 0, wx.ALL | wx.EXPAND, 0)
|
||||
headingSizer.Add(worst_text, 0, wx.ALL | wx.EXPAND, 0)
|
||||
headingSizer.Add(wx.StaticText(self, wx.ID_ANY, " ─ "), 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 5)
|
||||
headingSizer.Add(range_high, 0, wx.RIGHT | wx.EXPAND, 10)
|
||||
headingSizer.Add(best_text, 0, wx.RIGHT | wx.EXPAND, 10)
|
||||
|
||||
mainSizer.Add(headingSizer, 0, wx.ALL | wx.EXPAND, 5)
|
||||
|
||||
slider = AttributeSlider(parent=self,
|
||||
baseValue=m.attribute.unit.SimplifyValue(m.baseValue),
|
||||
minValue=m.attribute.unit.SimplifyValue(min_t[0]),
|
||||
maxValue=m.attribute.unit.SimplifyValue(max_t[0]),
|
||||
inverse=better_range is min_t)
|
||||
slider.SetValue(m.attribute.unit.SimplifyValue(m.value), False)
|
||||
slider.Bind(EVT_VALUE_CHANGED, self.changeMutatedValue)
|
||||
self.event_mapping[slider] = m
|
||||
mainSizer.Add(slider, 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 10)
|
||||
|
||||
mainSizer.Add(wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL), 0, wx.ALL | wx.EXPAND, 5)
|
||||
|
||||
mainSizer.AddStretchSpacer()
|
||||
@@ -132,7 +129,7 @@ class ItemMutator(wx.Panel):
|
||||
|
||||
for slider, m in self.event_mapping.items():
|
||||
value = sFit.changeMutatedValue(m, m.baseValue)
|
||||
value = m.attribute.unit.TranslateValue(value)[0]
|
||||
value = m.attribute.unit.SimplifyValue(value)
|
||||
slider.SetValue(value)
|
||||
|
||||
evt.Skip()
|
||||
@@ -143,7 +140,7 @@ class ItemMutator(wx.Panel):
|
||||
for slider, m in self.event_mapping.items():
|
||||
value = random.uniform(m.minValue, m.maxValue)
|
||||
value = sFit.changeMutatedValue(m, value)
|
||||
value = m.attribute.unit.TranslateValue(value)[0]
|
||||
value = m.attribute.unit.SimplifyValue(value)
|
||||
slider.SetValue(value)
|
||||
|
||||
evt.Skip()
|
||||
|
||||
Reference in New Issue
Block a user