NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

settings.py (8657B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\text\settings.py
      2 from carbonui import fontconst
      3 from clientsettings.setting import CharSettingBool
      4 font_shadow_enabled_setting = CharSettingBool(settings_key='global_font_shadow_enabled', default_value=True)
      5 
      6 class FontSizeOption(object):
      7     SMALL = 1
      8     MEDIUM = 2
      9     LARGE = 3
     10     EXTRA_SMALL = 4
     11     EXTRA_LARGE = 5
     12 
     13 
     14 def get_font_size_setting():
     15     return settings.public.ui.Get('clientFontSize', get_default_font_size_setting(session.languageID))
     16 
     17 
     18 def set_font_size_setting(value):
     19     current_value = settings.public.ui.Get('clientFontSize')
     20     if current_value != value:
     21         settings.public.ui.Set('clientFontSize', value)
     22         _notify_font_size_changed()
     23 
     24 
     25 def _notify_font_size_changed():
     26     update_font_size_factor()
     27     sm.ScatterEvent('OnFontSizeChanged')
     28 
     29 
     30 def update_font_size_factor():
     31     fontconst.fontSizeFactor = get_font_size_factor()
     32 
     33 
     34 def get_font_size_factor():
     35     setting = get_font_size_setting()
     36     if setting == FontSizeOption.EXTRA_LARGE:
     37         return 1.3
     38     elif setting == FontSizeOption.LARGE:
     39         return 1.2
     40     elif setting == FontSizeOption.MEDIUM:
     41         return 1.1
     42     else:
     43         return 1.0
     44 
     45 
     46 def get_font_size_for_preset(font_size_preset):
     47     selected_font_size_option = get_font_size_setting()
     48     font_sizes_by_setting = _get_font_sizes_by_setting()
     49     font_sizes = font_sizes_by_setting.get(selected_font_size_option)
     50     if font_sizes is None:
     51         font_sizes = font_sizes_by_setting[FontSizeOption.MEDIUM]
     52     return font_sizes[font_size_preset]
     53 
     54 
     55 def check_convert_font_size(fontsize):
     56     if fontsize < 0:
     57         return get_font_size_for_preset(fontsize)
     58     else:
     59         return fontsize
     60 
     61 
     62 _is_new_font_size_options_enabled = None
     63 NEW_FONT_SIZE_OPTIONS_ENABLED_KEY = 'pathfinder-new-font-size-options-available'
     64 NEW_FONT_SIZE_OPTIONS_ENABLED_DEFAULT = False
     65 
     66 def _update_new_font_size_options_enabled(evaluate_flag):
     67     global _is_new_font_size_options_enabled
     68     new_value = evaluate_flag()
     69     if _is_new_font_size_options_enabled != new_value:
     70         _is_new_font_size_options_enabled = new_value
     71         _handle_font_size_setting_feature_flag_changed()
     72 
     73 
     74 def is_new_font_size_options_enabled():
     75     if _is_new_font_size_options_enabled is None:
     76         from featuremanagement.client.flag import flag_bool
     77         flag_bool(key=NEW_FONT_SIZE_OPTIONS_ENABLED_KEY, default_value=NEW_FONT_SIZE_OPTIONS_ENABLED_DEFAULT, callback=_update_new_font_size_options_enabled)
     78     return _is_new_font_size_options_enabled
     79 
     80 
     81 def _get_font_sizes_by_setting():
     82     if is_new_font_size_options_enabled():
     83         return _NEW_FONT_SIZES_BY_SETTING
     84     else:
     85         return _OLD_FONT_SIZES_BY_SETTING
     86 
     87 
     88 _OLD_FONT_SIZES_BY_SETTING = {FontSizeOption.SMALL: {fontconst.EVE_SMALL_FONTSIZE: 10,
     89                         fontconst.EVE_MEDIUM_FONTSIZE: 12,
     90                         fontconst.EVE_LARGE_FONTSIZE: 14,
     91                         fontconst.EVE_XLARGE_FONTSIZE: 17,
     92                         fontconst.EVE_DETAIL_FONTSIZE: 10,
     93                         fontconst.EVE_BODY_FONTSIZE: 12,
     94                         fontconst.EVE_HEADER_FONTSIZE: 16,
     95                         fontconst.EVE_HEADLINE_FONTSIZE: 22,
     96                         fontconst.EVE_DISPLAY_FONTSIZE: 39},
     97  FontSizeOption.MEDIUM: {fontconst.EVE_SMALL_FONTSIZE: 11,
     98                          fontconst.EVE_MEDIUM_FONTSIZE: 13,
     99                          fontconst.EVE_LARGE_FONTSIZE: 15,
    100                          fontconst.EVE_XLARGE_FONTSIZE: 18,
    101                          fontconst.EVE_DETAIL_FONTSIZE: 11,
    102                          fontconst.EVE_BODY_FONTSIZE: 13,
    103                          fontconst.EVE_HEADER_FONTSIZE: 17,
    104                          fontconst.EVE_HEADLINE_FONTSIZE: 23,
    105                          fontconst.EVE_DISPLAY_FONTSIZE: 40},
    106  FontSizeOption.LARGE: {fontconst.EVE_SMALL_FONTSIZE: 12,
    107                         fontconst.EVE_MEDIUM_FONTSIZE: 14,
    108                         fontconst.EVE_LARGE_FONTSIZE: 16,
    109                         fontconst.EVE_XLARGE_FONTSIZE: 19,
    110                         fontconst.EVE_DETAIL_FONTSIZE: 12,
    111                         fontconst.EVE_BODY_FONTSIZE: 14,
    112                         fontconst.EVE_HEADER_FONTSIZE: 18,
    113                         fontconst.EVE_HEADLINE_FONTSIZE: 24,
    114                         fontconst.EVE_DISPLAY_FONTSIZE: 41}}
    115 _NEW_FONT_SIZES_BY_SETTING = {FontSizeOption.EXTRA_SMALL: {fontconst.EVE_SMALL_FONTSIZE: 10,
    116                               fontconst.EVE_MEDIUM_FONTSIZE: 12,
    117                               fontconst.EVE_LARGE_FONTSIZE: 14,
    118                               fontconst.EVE_XLARGE_FONTSIZE: 17,
    119                               fontconst.EVE_DETAIL_FONTSIZE: 10,
    120                               fontconst.EVE_BODY_FONTSIZE: 12,
    121                               fontconst.EVE_HEADER_FONTSIZE: 16,
    122                               fontconst.EVE_HEADLINE_FONTSIZE: 22,
    123                               fontconst.EVE_DISPLAY_FONTSIZE: 38},
    124  FontSizeOption.SMALL: {fontconst.EVE_SMALL_FONTSIZE: 11,
    125                         fontconst.EVE_MEDIUM_FONTSIZE: 13,
    126                         fontconst.EVE_LARGE_FONTSIZE: 15,
    127                         fontconst.EVE_XLARGE_FONTSIZE: 18,
    128                         fontconst.EVE_DETAIL_FONTSIZE: 10,
    129                         fontconst.EVE_BODY_FONTSIZE: 12,
    130                         fontconst.EVE_HEADER_FONTSIZE: 16,
    131                         fontconst.EVE_HEADLINE_FONTSIZE: 22,
    132                         fontconst.EVE_DISPLAY_FONTSIZE: 39},
    133  FontSizeOption.MEDIUM: {fontconst.EVE_SMALL_FONTSIZE: 12,
    134                          fontconst.EVE_MEDIUM_FONTSIZE: 14,
    135                          fontconst.EVE_LARGE_FONTSIZE: 16,
    136                          fontconst.EVE_XLARGE_FONTSIZE: 19,
    137                          fontconst.EVE_DETAIL_FONTSIZE: 12,
    138                          fontconst.EVE_BODY_FONTSIZE: 14,
    139                          fontconst.EVE_HEADER_FONTSIZE: 18,
    140                          fontconst.EVE_HEADLINE_FONTSIZE: 24,
    141                          fontconst.EVE_DISPLAY_FONTSIZE: 40},
    142  FontSizeOption.LARGE: {fontconst.EVE_SMALL_FONTSIZE: 13,
    143                         fontconst.EVE_MEDIUM_FONTSIZE: 15,
    144                         fontconst.EVE_LARGE_FONTSIZE: 17,
    145                         fontconst.EVE_XLARGE_FONTSIZE: 20,
    146                         fontconst.EVE_DETAIL_FONTSIZE: 13,
    147                         fontconst.EVE_BODY_FONTSIZE: 15,
    148                         fontconst.EVE_HEADER_FONTSIZE: 19,
    149                         fontconst.EVE_HEADLINE_FONTSIZE: 25,
    150                         fontconst.EVE_DISPLAY_FONTSIZE: 41},
    151  FontSizeOption.EXTRA_LARGE: {fontconst.EVE_SMALL_FONTSIZE: 14,
    152                               fontconst.EVE_MEDIUM_FONTSIZE: 16,
    153                               fontconst.EVE_LARGE_FONTSIZE: 18,
    154                               fontconst.EVE_XLARGE_FONTSIZE: 21,
    155                               fontconst.EVE_DETAIL_FONTSIZE: 14,
    156                               fontconst.EVE_BODY_FONTSIZE: 16,
    157                               fontconst.EVE_HEADER_FONTSIZE: 20,
    158                               fontconst.EVE_HEADLINE_FONTSIZE: 26,
    159                               fontconst.EVE_DISPLAY_FONTSIZE: 42}}
    160 
    161 def _handle_font_size_setting_feature_flag_changed():
    162     if not is_new_font_size_options_enabled():
    163         migration_map = {FontSizeOption.EXTRA_SMALL: FontSizeOption.SMALL,
    164          FontSizeOption.EXTRA_LARGE: FontSizeOption.LARGE}
    165         current_value = get_font_size_setting()
    166         if current_value in migration_map:
    167             set_font_size_setting(migration_map[current_value])
    168         else:
    169             _notify_font_size_changed()
    170     else:
    171         _notify_font_size_changed()
    172 
    173 
    174 DEFAULT_FONT_SIZE_BY_LANGUAGE_ID = {'ko': FontSizeOption.LARGE,
    175  'zh': FontSizeOption.LARGE,
    176  'ja': FontSizeOption.LARGE}
    177 
    178 def get_default_font_size_setting(language_id):
    179     return DEFAULT_FONT_SIZE_BY_LANGUAGE_ID.get(language_id.lower(), FontSizeOption.MEDIUM)
    180 
    181 
    182 def migrate_existing_font_size_settings_down_one_size(user_id, char_id):
    183     migration_flag = '__migrate_existing_font_size_settings_down_one_size__'
    184     if settings.public.ui.Get(migration_flag, False):
    185         return
    186     current_value = settings.public.ui.Get('clientFontSize', None)
    187     default_value = get_default_font_size_setting(session.languageID)
    188     new_font_size_option_by_old = {FontSizeOption.SMALL: FontSizeOption.EXTRA_SMALL,
    189      FontSizeOption.MEDIUM: FontSizeOption.SMALL,
    190      FontSizeOption.LARGE: FontSizeOption.MEDIUM}
    191     new_value = new_font_size_option_by_old.get(current_value, default_value)
    192     set_font_size_setting(new_value)
    193     settings.public.ui.Set(migration_flag, True)