Пример #1
0
        public override double ServerUpdateIntervalSeconds => double.MaxValue; // never

        protected override void ServerInitialize(ServerInitializeData data)
        {
            if (data.IsFirstTimeInit)
            {
                data.PrivateState.Members = new NetworkSyncList <string>();
                data.PrivateState.ServerPartyChatHolder = ChatSystem.ServerCreateChatRoom(
                    new ChatRoomParty(party: data.GameObject));
            }

            PartySystem.ServerRegisterParty(data.GameObject);
        }
        private static void ShowInvitationDialog(string inviterName)
        {
            var text = string.Format(InvitationMessageFormat, inviterName);

            if (PartySystem.ClientGetCurrentPartyMembers().Count > 1)
            {
                // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                text += "[br]" + InvitationMessageYouWillLeaveYourParty;
            }

            DialogWindow.ShowDialog(
                title: PartyInvitationTitle,
                text: text,
                okText: CoreStrings.Button_Accept,
                okAction: () => PartySystem.ClientInvitationAccept(inviterName),
                cancelText: CoreStrings.Button_Deny,
                cancelAction: () => PartySystem.ClientInvitationDecline(inviterName),
                focusOnCancelButton: true,
                closeByEscapeKey: false);
        }
        private static void InvitationsCollectionChangedHandler(object sender, NotifyCollectionChangedEventArgs e)
        {
            string inviterName;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                inviterName = (string)e.NewItems[0];
                ShowNotification(inviterName);
                break;
            }

            case NotifyCollectionChangedAction.Remove:
            {
                inviterName = (string)e.OldItems[0];
                if (NotificationsFromInviteeDictionary.TryGetValue(inviterName, out var weakReference) &&
                    weakReference.TryGetTarget(out var control))
                {
                    control.Hide(quick: true);
                }

                NotificationsFromInviteeDictionary.Remove(inviterName);
                break;
            }

            case NotifyCollectionChangedAction.Reset:
            {
                // hide all current notifications
                foreach (var notificationControl in NotificationsFromInviteeDictionary)
                {
                    var weakReference = notificationControl.Value;
                    if (weakReference.TryGetTarget(out var control))
                    {
                        control.Hide(quick: true);
                    }
                }

                NotificationsFromInviteeDictionary.Clear();

                // display new notifications
                foreach (var name in PartySystem.ClientCurrentInvitationsFromCharacters)
                {
                    ShowNotification(name);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            void ShowNotification(string name)
            {
                if (ClientChatBlockList.IsBlocked(name))
                {
                    // don't display invitations from blocked players
                    return;
                }

                var control = NotificationSystem.ClientShowNotification(
                    title: PartyInvitationTitle,
                    message: string.Format(InvitationMessageFormat, name),
                    onClick: () => ShowInvitationDialog(name),
                    autoHide: false,
                    icon: IconPartyInvitation);

                control.CallbackOnRightClickHide = () => PartySystem.ClientInvitationDecline(name);

                NotificationsFromInviteeDictionary.Add(
                    name,
                    new WeakReference <HudNotificationControl>(control));
            }
        }