forked from xiangwang25/whale-town-front-v2
feat: add in-game social test lab
This commit is contained in:
@@ -8,7 +8,7 @@ extends Control
|
||||
# ============================================================================
|
||||
|
||||
const HUD_MARGIN: Vector2 = Vector2(16, 16)
|
||||
const SHORTCUT_BAR_SIZE: Vector2 = Vector2(406, 86)
|
||||
const SHORTCUT_BAR_SIZE: Vector2 = Vector2(476, 86)
|
||||
const PLAYER_PROFILE_BUTTON_SIZE: Vector2 = Vector2(210, 78)
|
||||
const PLAYER_AVATAR_SIZE: Vector2 = Vector2(58, 58)
|
||||
const HUD_SEPARATION: int = 18
|
||||
@@ -26,6 +26,8 @@ var _avatarPanel: PanelContainer
|
||||
var _walletRefreshTimer: Timer
|
||||
var _taskShortcutButton: Button
|
||||
var _taskRewardBadge: Label
|
||||
var _shortcutRow: HBoxContainer
|
||||
var _adminShortcutButton: Button
|
||||
|
||||
var _currentUsername: String = "玩家"
|
||||
var _walletBalance: int = 0
|
||||
@@ -39,6 +41,7 @@ func _ready() -> void:
|
||||
_subscribe_to_events()
|
||||
_load_current_user()
|
||||
_refresh_wallet()
|
||||
call_deferred("_refresh_admin_shortcut")
|
||||
|
||||
func _exit_tree() -> void:
|
||||
var eventSystem := _get_event_system()
|
||||
@@ -94,6 +97,7 @@ func _build_shortcut_bar() -> PanelContainer:
|
||||
panel.add_child(margin)
|
||||
|
||||
var row := HBoxContainer.new()
|
||||
_shortcutRow = row
|
||||
row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
row.add_theme_constant_override("separation", 8)
|
||||
margin.add_child(row)
|
||||
@@ -121,6 +125,7 @@ func _build_shortcut_bar() -> PanelContainer:
|
||||
row.add_child(_create_shortcut_button("friends", "好友", _on_friends_pressed))
|
||||
row.add_child(_create_shortcut_button("activity", "通知", _on_notifications_pressed))
|
||||
row.add_child(_create_shortcut_button("settings", "设置", _on_settings_pressed))
|
||||
_refresh_admin_shortcut()
|
||||
|
||||
return panel
|
||||
|
||||
@@ -296,9 +301,11 @@ func _on_auth_state_changed(isAuthenticated: bool, user: Dictionary) -> void:
|
||||
if not isAuthenticated:
|
||||
_set_username("玩家")
|
||||
_reset_wallet()
|
||||
_refresh_admin_shortcut()
|
||||
return
|
||||
_apply_auth_user_payload({"user": user})
|
||||
_refresh_wallet()
|
||||
_refresh_admin_shortcut()
|
||||
|
||||
func _apply_auth_user_payload(data: Dictionary) -> void:
|
||||
var userVariant: Variant = data.get("user", {})
|
||||
@@ -306,11 +313,13 @@ func _apply_auth_user_payload(data: Dictionary) -> void:
|
||||
var username := str((userVariant as Dictionary).get("username", "")).strip_edges()
|
||||
if not username.is_empty():
|
||||
_set_username(username)
|
||||
_refresh_admin_shortcut()
|
||||
|
||||
func _on_auth_logout(_data: Variant = null) -> void:
|
||||
_set_username("玩家")
|
||||
_reset_wallet()
|
||||
_on_task_board_changed({})
|
||||
_refresh_admin_shortcut()
|
||||
|
||||
func _on_task_board_changed(board: Dictionary) -> void:
|
||||
if not is_instance_valid(_taskShortcutButton):
|
||||
@@ -482,6 +491,35 @@ func _on_avatar_pressed() -> void:
|
||||
if eventSystem != null:
|
||||
eventSystem.call("emit_event", EventNames.HUD_SETTINGS_REQUESTED, {})
|
||||
|
||||
func _on_admin_test_lab_pressed() -> void:
|
||||
var eventSystem := _get_event_system()
|
||||
if eventSystem != null:
|
||||
eventSystem.call("emit_event", EventNames.HUD_ADMIN_TEST_LAB_REQUESTED, {})
|
||||
|
||||
func _refresh_admin_shortcut() -> void:
|
||||
if not is_instance_valid(_shortcutRow):
|
||||
return
|
||||
var shouldShow: bool = _is_current_user_admin()
|
||||
if shouldShow and not is_instance_valid(_adminShortcutButton):
|
||||
_adminShortcutButton = _create_shortcut_button("admin", "管理", _on_admin_test_lab_pressed)
|
||||
_adminShortcutButton.tooltip_text = "管理员测试实验室"
|
||||
_shortcutRow.add_child(_adminShortcutButton)
|
||||
elif not shouldShow and is_instance_valid(_adminShortcutButton):
|
||||
_adminShortcutButton.queue_free()
|
||||
_adminShortcutButton = null
|
||||
|
||||
func _is_current_user_admin() -> bool:
|
||||
var authManager := get_node_or_null("/root/AuthManager")
|
||||
if authManager == null or not authManager.has_method("is_authenticated") or not bool(authManager.call("is_authenticated")):
|
||||
return false
|
||||
if not authManager.has_method("get_current_user"):
|
||||
return false
|
||||
var userVariant: Variant = authManager.call("get_current_user")
|
||||
if not (userVariant is Dictionary):
|
||||
return false
|
||||
var user: Dictionary = userVariant as Dictionary
|
||||
return int(user.get("role", 0)) == 9
|
||||
|
||||
func _emit_status_message(message: String) -> void:
|
||||
var eventSystem := _get_event_system()
|
||||
if eventSystem != null:
|
||||
|
||||
Reference in New Issue
Block a user