theme.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """庭院菜单主题。原地更新共享规则,保持导航图持有的对象引用有效。"""
  2. from copy import deepcopy
  3. from tasks.Component.Costume.config import ThemeType
  4. from tasks.Component.CostumeTheme.assets import CostumeThemeAssets
  5. from tasks.GameUi.assets import GameUiAssets
  6. _THEME_NAMES = (
  7. 'I_MAIN_SCROLL_CLOSE',
  8. 'I_MAIN_GOTO_COLLECTION', 'I_MAIN_GOTO_TRAVEL',
  9. 'I_MAIN_GOTO_TEAM', 'I_MAIN_GOTO_GUILD', 'I_MAIN_GOTO_MALL',
  10. 'I_MAIN_GOTO_DAILY', 'I_MAIN_GOTO_FRIENDS', 'I_MAIN_GOTO_ONMYODO',
  11. 'I_MAIN_GOTO_SHIKIGAMI_RECORDS',
  12. )
  13. # Capture pristine defaults before any task can select a menu theme.
  14. _DEFAULT_RULES = {name: deepcopy(getattr(GameUiAssets, name)) for name in _THEME_NAMES}
  15. _THEME_RULES = {
  16. ThemeType.COSTUME_THEME_DEFAULT: _DEFAULT_RULES,
  17. ThemeType.COSTUME_THEME_XINYU_MINGXIAO: {
  18. # Entry icons use the shared GameUi defaults, not theme-specific copies.
  19. **_DEFAULT_RULES,
  20. 'I_MAIN_SCROLL_CLOSE': CostumeThemeAssets.I_MAIN_SCROLL_CLOSE_2,
  21. },
  22. }
  23. def apply_theme(theme_type: ThemeType) -> None:
  24. rules = _THEME_RULES[theme_type]
  25. for name, source in rules.items():
  26. target = getattr(GameUiAssets, name)
  27. # Reset cached image/name/features and match state as well as file/ROI.
  28. # Do NOT replace the object: page transitions retain references to it.
  29. target.__dict__.clear()
  30. target.__dict__.update(deepcopy(source.__dict__))