示例#1
0
        private Displayable DoBodyRightBar()
        {
            PhiClient phi = PhiClient.instance;

            ListContainer cont = new ListContainer();

            cont.spaceBetween = ListContainer.SPACE;

            string status = "Status: ";

            switch (phi.client.state)
            {
            case WebSocketState.Open:
                status += "Connected";
                break;

            case WebSocketState.Closed:
                status += "Disconnected";
                break;

            case WebSocketState.Connecting:
                status += "Connecting";
                break;

            case WebSocketState.Closing:
                status += "Disconnecting";
                break;
            }
            cont.Add(new TextWidget(status));

            cont.Add(new HeightContainer(new ButtonWidget("Configuration", () => { OnConfigurationClick(); }), 30f));

            cont.Add(new Container(new TextFieldWidget(filterName, (s) => {
                filterName = s;
            }), 150f, 30f));

            if (phi.IsUsable())
            {
                ListContainer usersList = new ListContainer();
                foreach (User user in phi.realmData.users.Where((u) => u.connected))
                {
                    if (filterName != "")
                    {
                        if (ContainsStringIgnoreCase(user.name, filterName))
                        {
                            usersList.Add(new ButtonWidget(user.name, () => { OnUserClick(user); }, false));
                        }
                    }
                    else
                    {
                        usersList.Add(new ButtonWidget(user.name, () => { OnUserClick(user); }, false));
                    }
                }

                cont.Add(new ScrollContainer(usersList, userScrollPosition, (v) => { userScrollPosition = v; }));
            }
            return(cont);
        }
示例#2
0
        public override void PreOpen()
        {
            base.PreOpen();

            PhiClient client = PhiClient.instance;

            this.enteredAddress = client.serverAddress;

            if (client.IsUsable())
            {
                OnUsableCallback();
            }
            client.OnUsable += OnUsableCallback;
        }
示例#3
0
        public override void DoWindowContents(Rect inRect)
        {
            PhiClient client = PhiClient.instance;

            ListContainer cont = new ListContainer();

            cont.spaceBetween = ListContainer.SPACE;
            cont.Add(new HeightContainer(DoHeader(), 30f));

            if (client.IsUsable())
            {
                cont.Add(DoConnectedContent());
            }

            cont.Draw(inRect);
        }
示例#4
0
        private Displayable DoChat()
        {
            PhiClient phi = PhiClient.instance;

            var cont = new ListContainer(ListFlow.COLUMN, ListDirection.OPPOSITE);

            if (phi.IsUsable())
            {
                foreach (ChatMessage c in phi.realmData.chat.Reverse <ChatMessage>().Take(30))
                {
                    int idx = phi.realmData.users.LastIndexOf(c.user);
                    cont.Add(new ButtonWidget(phi.realmData.users[idx].name + ": " + c.message, () => { OnUserClick(phi.realmData.users[idx]); }, false));
                }
            }

            return(new ScrollContainer(cont, chatScroll, (v) => { chatScroll = v; }));
        }
示例#5
0
        public Displayable DoHeader()
        {
            PhiClient     client = PhiClient.instance;
            ListContainer cont   = new ListContainer(ListFlow.ROW);

            cont.spaceBetween = ListContainer.SPACE;

            if (client.IsUsable())
            {
                cont.Add(new TextWidget("Connected to " + client.serverAddress, GameFont.Small, TextAnchor.MiddleLeft));
                cont.Add(new WidthContainer(new ButtonWidget("Disconnect", () => { OnDisconnectButtonClick(); }), 140f));
            }
            else
            {
                cont.Add(new TextFieldWidget(enteredAddress, (s) => { enteredAddress = s; }));
                cont.Add(new WidthContainer(new ButtonWidget("Connect", () => { OnConnectButtonClick(); }), 140f));
            }

            return(cont);
        }
示例#6
0
        private void DrawChat(Rect rect)
        {
            PhiClient phiClient    = PhiClient.instance;
            Rect      messagesArea = rect.TopPartPixels(rect.height - CHAT_INPUT_HEIGHT).ContractedBy(CHAT_MARGIN);
            Rect      inputArea    = rect.BottomPartPixels(CHAT_INPUT_HEIGHT);

            /**
             * Drawing the messages
             */
            if (phiClient.IsUsable())
            {
                List <ChatMessage> messages = PhiClient.instance.realmData.chat;

                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.UpperLeft;

                // We fill the chat by the bottom, inverting the order of messages
                Rect messageSlot = messagesArea.BottomPart(0);
                foreach (ChatMessage message in messages.AsEnumerable().Reverse())
                {
                    string entry = message.user.name + ": " + message.message;

                    float height = Text.CalcHeight(entry, messageSlot.width);
                    messageSlot.y     -= height;
                    messageSlot.height = height;
                    Widgets.Label(messageSlot, entry);
                }
            }

            /**
             * Drawing the chat input TextField and Button
             */
            Rect textFieldArea  = inputArea.LeftPartPixels(inputArea.width - CHAT_INPUT_SEND_BUTTON_WIDTH);
            Rect sendButtonArea = inputArea.RightPartPixels(CHAT_INPUT_SEND_BUTTON_WIDTH);

            messageToSend = Widgets.TextField(textFieldArea, messageToSend);
            if (Widgets.ButtonText(sendButtonArea, "Send", true, true))
            {
                this.OnSendClick();
            }
        }
示例#7
0
        private void DrawStatus(Rect rect)
        {
            PhiClient phiClient = PhiClient.instance;

            /**
             * Drawing the status of the connection
             */
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;
            string status = "Status: ";

            switch (phiClient.client.state)
            {
            case WebSocketState.Open:
                status += "Connected";
                break;

            case WebSocketState.Closed:
                status += "Disconnected";
                break;

            case WebSocketState.Connecting:
                status += "Connecting";
                break;

            case WebSocketState.Closing:
                status += "Disconnecting";
                break;
            }

            float textHeight = Text.CalcHeight(status, rect.width);

            Widgets.Label(rect, status);
            rect = rect.BottomPartPixels(rect.height - textHeight);

            /**
             * Drawing the reconnection button
             */
            if (!phiClient.IsConnected())
            {
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.UpperLeft;

                Rect reconnectButtonArea = rect.TopPartPixels(40);

                if (Widgets.ButtonText(reconnectButtonArea, "Reconnect", true, true))
                {
                    this.OnReconnectClick();
                }

                rect = rect.BottomPartPixels(rect.height - reconnectButtonArea.height);
            }

            /**
             * Drawing the list of users
             */
            if (phiClient.IsUsable())
            {
                // Ordering the list according to connected status
                List <User> users = phiClient.realmData.users.OrderBy(u => u.connected).ToList();

                foreach (User user in users)
                {
                    string line = user.name;
                    if (user.connected)
                    {
                        line = "• " + line;
                    }
                    textHeight = Text.CalcHeight(line, rect.width);

                    // We check if we have not run out of space
                    if (rect.height < textHeight)
                    {
                        break;
                    }

                    Rect buttonArea = rect.TopPartPixels(textHeight);
                    if (Widgets.ButtonText(buttonArea, line, false))
                    {
                        this.OnUserClick(user);
                    }

                    rect = rect.BottomPartPixels(rect.height - buttonArea.height);
                }
            }
        }