slider based options done
This commit is contained in:
1 parent
87a1038546
commit
41c2addbdf
5 files changed
+34
-24
No files matched your search
+3
-3
@@ -79,14 +79,14 @@
|
||||
"opening_moves": 22.0
|
||||
},
|
||||
"ai:p:weighted": {
|
||||
"weaken_fac": 1.25,
|
||||
"pick_override": 1.0,
|
||||
"lower_bound": 0.001,
|
||||
"weaken_fac": 1.25
|
||||
"lower_bound": 0.001
|
||||
},
|
||||
"ai:p:pick": {
|
||||
"pick_override": 0.95,
|
||||
"pick_n": 5,
|
||||
"pick_frac": 0.33
|
||||
"pick_frac": 0.35
|
||||
},
|
||||
"ai:p:local": {
|
||||
"pick_override": 0.95,
|
||||
|
||||
@@ -64,10 +64,17 @@ AI_STRENGTH = { # not used
|
||||
}
|
||||
|
||||
AI_OPTION_VALUES = {
|
||||
"kyu_rank": [(k, f"{k}[strength:kyu]") for k in range(15, 0, -1)] + [(k, f"{1-k}[strength:dan]") for k in range(0, -3, -1)],
|
||||
"strength": [0.25,0.5,1,2,4],
|
||||
"opening_moves": range(0,51),
|
||||
"pick_override": [0,0.5,0.6,0.7,0.8,0.9,0.95,1],
|
||||
"lower_bound": [(v,f"{v:.2%}") for v in [0,0.0001,0.0005,0.001,0.005,0.01,0.05] ],
|
||||
"weaken_fac": [-2,-1,0.5,1,1.25,1.5,2,4]
|
||||
"kyu_rank": [(k, f"{k}[strength:kyu]") for k in range(15, 0, -1)]
|
||||
+ [(k, f"{1-k}[strength:dan]") for k in range(0, -3, -1)],
|
||||
"strength": [0.25, 0.5, 1, 2, 4],
|
||||
"opening_moves": range(0, 51),
|
||||
"pick_override": [0, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.95, 0.99, 1],
|
||||
"lower_bound": [(v, f"{v:.2%}") for v in [0, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05]],
|
||||
"weaken_fac": [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 4],
|
||||
"endgame": [x / 100 for x in range(10, 80, 5)],
|
||||
"pick_frac": [x / 100 for x in range(0, 101, 5)],
|
||||
"pick_n": range(0, 26),
|
||||
"stddev": [x / 2 for x in range(21)],
|
||||
"line_weight": range(0, 11),
|
||||
"threshold": [2, 2.5, 3, 3.5, 4, 4.5],
|
||||
}
|
||||
@@ -158,9 +158,9 @@ class QuickConfigGui(MDBoxLayout):
|
||||
Clock.schedule_once(self.build_and_set_properties, 0)
|
||||
|
||||
def collect_properties(self, widget) -> Dict:
|
||||
if isinstance(widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox,LabelledSelectionSlider)) and getattr(
|
||||
widget, "input_property", None
|
||||
):
|
||||
if isinstance(
|
||||
widget, (LabelledTextInput, LabelledSpinner, LabelledCheckBox, LabelledSelectionSlider)
|
||||
) and getattr(widget, "input_property", None):
|
||||
try:
|
||||
ret = {widget.input_property: widget.input_value}
|
||||
except Exception as e: # TODO : on widget?
|
||||
@@ -318,12 +318,12 @@ class ConfigAIPopup(QuickConfigGui):
|
||||
self.options_grid.clear_widgets()
|
||||
self.help_label.text = i18n._(strategy.replace("ai:", "aihelp:"))
|
||||
for k, v in sorted(mode_settings.items(), key=lambda kv: kv[0]):
|
||||
self.options_grid.add_widget(DescriptionLabel(text=k,size_hint_x=0.25))
|
||||
self.options_grid.add_widget(DescriptionLabel(text=k, size_hint_x=0.25))
|
||||
if k in AI_OPTION_VALUES:
|
||||
values = AI_OPTION_VALUES[k]
|
||||
if isinstance(values[0],Tuple): # with descriptions, possibly language-specific
|
||||
if isinstance(values[0], Tuple): # with descriptions, possibly language-specific
|
||||
fixed_values = [(v, re.sub(r"\[(.*?)\]", lambda m: i18n._(m[1]), l)) for v, l in values]
|
||||
else: # just numbers
|
||||
else: # just numbers
|
||||
fixed_values = [(v, str(v)) for v in values]
|
||||
widget = LabelledSelectionSlider(values=fixed_values, input_property=f"ai/{strategy}/{k}")
|
||||
widget.set_value(v)
|
||||
|
||||
@@ -9,7 +9,6 @@ from kivymd.uix.label import MDLabel
|
||||
from kivymd.uix.selectioncontrol import Thumb
|
||||
|
||||
|
||||
|
||||
class SelectionSlider(Widget):
|
||||
__events__ = ["on_select"]
|
||||
active = BooleanProperty(False)
|
||||
@@ -18,19 +17,24 @@ class SelectionSlider(Widget):
|
||||
index = NumericProperty(0) # selected index
|
||||
values = ListProperty([(0, "")]) # (value:numeric,label:string) pairs
|
||||
normalized_pos = NumericProperty(0) # slider relative pos from 0-1
|
||||
px_pos = NumericProperty(0) # actual px pos
|
||||
px_pos = NumericProperty(0) # actual px pos
|
||||
padding = NumericProperty("16sp")
|
||||
|
||||
track_color = ListProperty([1, 1, 1, 0.3])
|
||||
thumb_color = ListProperty([0.5, 0.5, 0.5, 1])
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.bind(size=self.set_index_and_positions,pos=self.set_index_and_positions,values=self.set_index_and_positions,index=self.set_index_and_positions)
|
||||
self.bind(
|
||||
size=self.set_index_and_positions,
|
||||
pos=self.set_index_and_positions,
|
||||
values=self.set_index_and_positions,
|
||||
index=self.set_index_and_positions,
|
||||
)
|
||||
|
||||
def set_index_and_positions(self, *_args):
|
||||
self.index = max(0, min(self.index, len(self.values) - 1))
|
||||
self.normalized_pos = self.index / (len(self.values)-1)
|
||||
self.normalized_pos = self.index / (len(self.values) - 1)
|
||||
self.px_pos = self.x + self.padding + self.normalized_pos * (self.width - 2 * self.padding)
|
||||
|
||||
@property
|
||||
@@ -41,7 +45,7 @@ class SelectionSlider(Widget):
|
||||
eq_value = sorted([(abs(v - set_value), i) for i, (v, l) in enumerate(self.values)])
|
||||
self.index = eq_value[0][1]
|
||||
|
||||
def set_from_pos(self,pos):
|
||||
def set_from_pos(self, pos):
|
||||
norm_value = (pos[0] - self.x - self.padding) / (self.width - 2 * self.padding)
|
||||
self.index = round(norm_value * (len(self.values) - 1))
|
||||
|
||||
@@ -71,7 +75,7 @@ class SelectionSlider(Widget):
|
||||
self.dispatch("on_select", self.value)
|
||||
return True
|
||||
|
||||
def on_select(self,value):
|
||||
def on_select(self, value):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -13,7 +13,6 @@
|
||||
|
||||
#:set LIGHTGREY [0.7,0.7,0.7,1]
|
||||
#:import BACKGROUND_COLOR katrain.gui.style.BACKGROUND_COLOR
|
||||
#:import LIGHTER_BACKGROUND_COLOR katrain.gui.style.LIGHTER_BACKGROUND_COLOR
|
||||
#:import LIGHTGREY katrain.gui.style.LIGHTGREY
|
||||
#:import TEXT_COLOR katrain.gui.style.TEXT_COLOR
|
||||
|
||||
@@ -377,7 +376,7 @@
|
||||
values: root.values
|
||||
on_select: textbox.text = str(slider.value)
|
||||
track_color: LIGHTGREY
|
||||
thumb_color: LIGHTER_BACKGROUND_COLOR
|
||||
thumb_color: 0.5, 0.6, 0.8, 1
|
||||
LabelledFloatInput:
|
||||
id: textbox
|
||||
|
||||
|
||||
Reference in new issue
Block a user