From 07dacb887608aefe347a5479c1c9294521fb9c4d Mon Sep 17 00:00:00 2001 From: bridge Date: Sun, 1 Feb 2026 12:26:43 +0800 Subject: [PATCH] feat: enhance hidden domains serialization and UI representation - Updated `serialize_active_domains` to include both active and inactive hidden domains, adding an `is_open` property for each domain. - Modified `StatusBar` and `StatusWidget` components to reflect the new domain state, displaying appropriate labels and colors based on the activation status. - Adjusted localization files for English and Chinese to align with the updated hidden domain features. --- src/server/main.py | 42 ++++++++++++++-------- web/src/components/layout/StatusBar.vue | 9 +++-- web/src/components/layout/StatusWidget.vue | 12 +++++-- web/src/locales/en-US.json | 5 ++- web/src/locales/zh-CN.json | 5 ++- web/src/types/core.ts | 1 + 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/server/main.py b/src/server/main.py index c499a35..945b672 100644 --- a/src/server/main.py +++ b/src/server/main.py @@ -173,26 +173,40 @@ manager = ConnectionManager() def serialize_active_domains(world: World) -> List[dict]: - """序列化当前开启的秘境列表""" + """序列化所有秘境列表(包括开启和未开启的)""" domains_data = [] if not world or not world.gathering_manager: return [] + # 找到 HiddenDomain 实例 + hidden_domain_gathering = None for gathering in world.gathering_manager.gatherings: - # Check by class name to avoid circular imports if gathering.__class__.__name__ == "HiddenDomain": - # Accessing _active_domains safely - active_domains = getattr(gathering, "_active_domains", []) - for d in active_domains: - domains_data.append({ - "id": d.id, - "name": d.name, - "desc": d.desc, - # Use str() to trigger Realm.__str__ which returns translated text - "max_realm": str(d.max_realm), - "danger_prob": d.danger_prob, - "drop_prob": d.drop_prob - }) + hidden_domain_gathering = gathering + break + + if hidden_domain_gathering: + # 获取所有配置(假设 _load_configs 开销不大,或者已缓存) + # 这里为了确保获取最新状态,重新加载配置 + # 注意:访问受保护方法 _load_configs + all_configs = hidden_domain_gathering._load_configs() + + # 获取当前开启的 ID 集合 + active_ids = {d.id for d in hidden_domain_gathering._active_domains} + + for d in all_configs: + is_open = d.id in active_ids + + domains_data.append({ + "id": d.id, + "name": d.name, + "desc": d.desc, + "max_realm": str(d.max_realm), + "danger_prob": d.danger_prob, + "drop_prob": d.drop_prob, + "is_open": is_open + }) + return domains_data def serialize_events_for_client(events: List[Event]) -> List[dict]: diff --git a/web/src/components/layout/StatusBar.vue b/web/src/components/layout/StatusBar.vue index 4b4870f..cecd422 100644 --- a/web/src/components/layout/StatusBar.vue +++ b/web/src/components/layout/StatusBar.vue @@ -19,14 +19,13 @@ const phenomenonColor = computed(() => { }) const domainLabel = computed(() => { - const count = store.activeDomains.length; - return count > 0 - ? t('game.status_bar.hidden_domain.label_active', { count }) - : t('game.status_bar.hidden_domain.label'); + return t('game.status_bar.hidden_domain.label'); }); const domainColor = computed(() => { - return store.activeDomains.length > 0 ? '#fa8c16' : '#666'; // 有秘境时亮橙色,否则灰色 + // 如果有任意一个秘境是开启状态,则亮色 + const anyOpen = store.activeDomains.some(d => d.is_open); + return anyOpen ? '#fa8c16' : '#666'; // 有开启亮橙色,全关闭灰色 }); function getRarityColor(rarity: string) { diff --git a/web/src/components/layout/StatusWidget.vue b/web/src/components/layout/StatusWidget.vue index a6f93da..6f7498c 100644 --- a/web/src/components/layout/StatusWidget.vue +++ b/web/src/components/layout/StatusWidget.vue @@ -52,9 +52,13 @@ const emit = defineEmits(['trigger-click']) -
+
- {{ item.name }} +
+ {{ item.name }} + 未开启 + 开启中 +
{{ item.max_realm }} @@ -92,9 +96,13 @@ const emit = defineEmits(['trigger-click']) } .domain-item { padding: 4px 0; } +.domain-item.is-closed { opacity: 0.5; filter: grayscale(0.8); } + .d-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; } +.d-title-group { display: flex; align-items: center; gap: 8px; } .d-name { font-weight: bold; color: #fadb14; font-size: 14px; } .d-tag { font-size: 10px; height: 18px; line-height: 18px; } +.d-status { font-size: 10px; height: 18px; line-height: 18px; padding: 0 4px; } .d-desc { font-size: 12px; color: #aaa; margin-bottom: 8px; line-height: 1.4; } .d-stats { display: flex; gap: 12px; font-size: 12px; color: #888; } .empty-state { padding: 20px; } diff --git a/web/src/locales/en-US.json b/web/src/locales/en-US.json index 342f0d8..853b3af 100644 --- a/web/src/locales/en-US.json +++ b/web/src/locales/en-US.json @@ -233,9 +233,8 @@ "author_github": "Github", "hidden_domain": { "label": "[Hidden Domain]", - "label_active": "[Domain Opened: {count}]", - "title": "Opened Hidden Domains", - "empty": "No hidden domains currently open", + "title": "Hidden Domains List", + "empty": "No hidden domains data", "danger": "Danger", "drop": "Fortune" } diff --git a/web/src/locales/zh-CN.json b/web/src/locales/zh-CN.json index d980783..cbaf6b4 100644 --- a/web/src/locales/zh-CN.json +++ b/web/src/locales/zh-CN.json @@ -233,9 +233,8 @@ "author_github": "Github仓库", "hidden_domain": { "label": "[秘境]", - "label_active": "[秘境开启: {count}]", - "title": "当前开启秘境", - "empty": "当前暂无秘境开启", + "title": "秘境列表", + "empty": "暂无秘境数据", "danger": "凶险", "drop": "机缘" } diff --git a/web/src/types/core.ts b/web/src/types/core.ts index bc52e9b..2cf050e 100644 --- a/web/src/types/core.ts +++ b/web/src/types/core.ts @@ -193,6 +193,7 @@ export interface HiddenDomainInfo { max_realm: string; // 限制境界 danger_prob: number; // 凶险度 (0.0 - 1.0) drop_prob: number; // 机缘度 (0.0 - 1.0) + is_open: boolean; // 是否开启 } // --- 事件 (Events) ---