Add: [ALAS] Hide custom settings if custom is not selected

This commit is contained in:
LmeSzinc 2023-12-18 21:46:19 +08:00
parent d1ded20872
commit 6b8aff93da
4 changed files with 81 additions and 0 deletions

View File

@ -768,6 +768,24 @@ class ConfigUpdater:
elif key == 'Rogue.RogueWorld.UseStamina' and value is True:
yield 'Rogue.RogueWorld.UseImmersifier', True
def iter_hidden_args(self, data) -> t.Iterator[str]:
"""
Args:
data (dict): config
Yields:
str: Arg path that should be hidden
"""
if deep_get(data, 'Rogue.RoguePath.PresetResonanceFilter') != 'custom':
yield 'Rogue.RoguePath.CustomResonanceFilter'
def get_hidden_args(self, data) -> t.Set[str]:
"""
Return a set of hidden args
"""
out = list(self.iter_hidden_args(data))
return set(out)
def read_file(self, config_name, is_template=False):
"""
Read and update config file.

View File

@ -106,6 +106,7 @@ class AlasGUI(Frame):
self.alas_name = ""
self.alas_mod = "alas"
self.alas_config = AzurLaneConfig("template")
self.alas_config_hidden = set()
self.initial()
@use_scope("aside", clear=True)
@ -236,6 +237,7 @@ class AlasGUI(Frame):
)
config = self.alas_config.read_file(self.alas_name)
self.alas_config_hidden = self.alas_config.get_hidden_args(config)
for group, arg_dict in deep_iter(self.ALAS_ARGS[task], depth=1):
if self.set_group(group, arg_dict, config, task):
self.set_navigator(group)
@ -291,6 +293,9 @@ class AlasGUI(Frame):
if o is not None:
# output will inherit current scope when created, override here
o.spec["scope"] = f"#pywebio-scope-group_{group_name}"
# Add hidden-arg
if f"{task}.{group_name}.{arg_name}" in self.alas_config_hidden:
o.style("display:none")
output_list.append(o)
if not output_list:
@ -507,6 +512,13 @@ class AlasGUI(Frame):
logger.warning(f"Invalid value {v} for key {k}, skip saving.")
self.pin_remove_invalid_mark(valid)
self.pin_set_invalid_mark(invalid)
new_hidden_args = config_updater.get_hidden_args(config)
for k in new_hidden_args - self.alas_config_hidden:
self.pin_set_hidden_arg(k, type_=deep_get(self.ALAS_ARGS, f"{k}.type"))
for k in self.alas_config_hidden - new_hidden_args:
self.pin_remove_hidden_arg(k, type_=deep_get(self.ALAS_ARGS, f"{k}.type"))
self.alas_config_hidden = new_hidden_args
if modified:
toast(
t("Gui.Toast.ConfigSaved"),

View File

@ -4,6 +4,7 @@ from pywebio.output import clear, put_html, put_scope, put_text, use_scope
from pywebio.session import defer_call, info, run_js
from module.webui.utils import Icon, WebIOTaskHandler, set_localstorage
from module.webui.widgets import type_to_html
class Base:
@ -167,3 +168,33 @@ class Frame(Base):
run_js(js)
# for key in keys:
# pin_update(key, valid_status=0)
@staticmethod
def pin_set_hidden_arg(key, type_) -> None:
"""
Hide arg
Args:
key: Path
type_: Type in _widget_type_to_func
"""
type_ = type_to_html(type_)
key = "_".join(key.split("."))
key = f"pywebio-scope-arg_container-{type_}-{key}"
# This aims to be a typo, don't correct it, leave it as it is
if type_ == 'textarea':
key = key.replace('container', 'contianer')
js = f"""$("#{key}").css("display","none");"""
if js:
run_js(js)
@staticmethod
def pin_remove_hidden_arg(key, type_) -> None:
type_ = type_to_html(type_)
key = "_".join(key.split("."))
key = f"pywebio-scope-arg_container-{type_}-{key}"
if type_ == 'textarea':
key = key.replace('container', 'contianer')
js = f"""$("#{key}").removeAttr('style');"""
if js:
run_js(js)

View File

@ -424,6 +424,7 @@ def put_arg_textarea(kwargs: T_Output_Kwargs) -> Output:
)
return put_scope(
# This aims to be a typo, don't correct it, leave it as it is
f"arg_contianer-textarea-{name}",
[
get_title_help(kwargs),
@ -507,6 +508,25 @@ def put_output(output_kwargs: T_Output_Kwargs) -> Optional[Output]:
return _widget_type_to_func[output_kwargs["widget_type"]](output_kwargs)
def type_to_html(type_: str) -> str:
"""
Args:
type_: Type defined in _widget_type_to_func and argument.yaml
Returns:
str: Html element name
"""
if type_ == "checkbox":
return "checkbox"
if type_ in ["input", "lock", "datetime"]:
return "input"
if type_ in ["select", "state"]:
return "select"
if type_ in ["textarea", "storage"]:
return "textarea"
return type_
def get_loading_style(shape: str, fill: bool) -> str:
if fill:
return f"--loading-{shape}-fill--"