public void OnConnectButtonClick()
        {
            PhiClient client = PhiClient.instance;

            client.SetServerAddress(enteredAddress);
            client.TryConnect();
        }
Beispiel #2
0
        public PhiClient(string address)
        {
            this.address   = address;
            this.realmData = new RealmData();

            PhiClient.instance = this;
        }
Beispiel #3
0
        public override void DoWindowContents(Rect inRect)
        {
            base.DoWindowContents(inRect);

            PhiClient phi = PhiClient.instance;

            ListContainer mainList = new ListContainer();

            mainList.spaceBetween = ListContainer.SPACE;

            mainList.Add(new TextWidget("Realm", GameFont.Medium, TextAnchor.MiddleCenter));

            ListContainer rowBodyContainer = new ListContainer(new List <Displayable>()
            {
                DoChat(),
                new WidthContainer(DoBodyRightBar(), STATUS_AREA_WIDTH)
            }, ListFlow.ROW);

            rowBodyContainer.spaceBetween = ListContainer.SPACE;

            mainList.Add(rowBodyContainer);
            mainList.Add(new HeightContainer(DoFooter(), 30f));

            mainList.Draw(inRect);
        }
Beispiel #4
0
        public PhiInitializer()
        {
            string address = GetServerAddress();

            PhiClient client = new PhiClient(address);

            client.TryConnect();
        }
        public override void PostClose()
        {
            base.PostClose();

            PhiClient client = PhiClient.instance;

            client.OnUsable -= OnUsableCallback;
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public Displayable DoConnectedContent()
        {
            PhiClient     client   = PhiClient.instance;
            ListContainer mainCont = new ListContainer();

            mainCont.spaceBetween = ListContainer.SPACE;

            /**
             * Changing your nickname
             */
            ListContainer changeNickCont = new ListContainer(ListFlow.ROW);

            changeNickCont.spaceBetween = ListContainer.SPACE;
            mainCont.Add(new HeightContainer(changeNickCont, 30f));

            changeNickCont.Add(new TextFieldWidget(wantedNickname, (s) => wantedNickname = OnWantedNicknameChange(s)));
            changeNickCont.Add(new WidthContainer(new ButtonWidget("Change nickname", OnChangeNicknameClick), 140f));

            /**
             * Preferences list
             */
            UserPreferences pref      = client.currentUser.preferences;
            ListContainer   twoColumn = new ListContainer(ListFlow.ROW);

            twoColumn.spaceBetween = ListContainer.SPACE;
            mainCont.Add(twoColumn);

            ListContainer firstColumn = new ListContainer();

            twoColumn.Add(firstColumn);

            firstColumn.Add(new CheckboxLabeledWidget("Allow receiving items", pref.receiveItems, (b) =>
            {
                pref.receiveItems = b;
                client.UpdatePreferences();
            }));

            firstColumn.Add(new CheckboxLabeledWidget("Allow receiving colonists (EXPERIMENTAL)", pref.receiveColonists, (b) =>
            {
                pref.receiveColonists = b;
                client.UpdatePreferences();
            }));

            firstColumn.Add(new CheckboxLabeledWidget("Allow receiving animals (EXPERIMENTAL)", pref.receiveAnimals, (b) =>
            {
                pref.receiveAnimals = b;
                client.UpdatePreferences();
            }));

            // Just to take spaces while the column is empty
            ListContainer secondColumn = new ListContainer();

            twoColumn.Add(secondColumn);

            return(mainCont);
        }
Beispiel #8
0
        public void OnUserClick(User user)
        {
            PhiClient phiClient = PhiClient.instance;

            // We open a trade window with this user
            if (user != phiClient.currentUser || true)
            {
                Find.WindowStack.Add(new UserGiveWindow(user));
            }
        }
Beispiel #9
0
        public void OnUserClick(User user)
        {
            PhiClient phiClient = PhiClient.instance;

            if (user != phiClient.currentUser || true)
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                options.Add(new FloatMenuOption("Ship items", () => { OnShipItemsOptionClick(user); }));
                options.Add(new FloatMenuOption("Send colonist", () => { OnSendColonistOptionClick(user); }));

                Find.WindowStack.Add(new FloatMenu(options));
            }
        }
Beispiel #10
0
        public PhiInitializer()
        {
            PhiClient client = new PhiClient();

            client.TryConnect();

            // We use this as an entry to the main thread of the game.
            // Since the whole network layer receives messages in a different thread
            // than the game thread, we use this to resynchronize the whole thing.
            GameObject obj = new GameObject("Phi helper objects");

            obj.AddComponent <PhiComponent>();
        }
Beispiel #11
0
        public override void PreOpen()
        {
            base.PreOpen();

            PhiClient client = PhiClient.instance;

            this.enteredAddress = client.serverAddress;

            if (client.IsUsable())
            {
                OnUsableCallback();
            }
            client.OnUsable += OnUsableCallback;
        }
Beispiel #12
0
        public void OnShipItemsOptionClick(User user)
        {
            PhiClient phiClient = PhiClient.instance;

            // We open a trade window with this user
            if (user.preferences.receiveItems)
            {
                Find.WindowStack.Add(new UserGiveWindow(user));
            }
            else
            {
                Messages.Message(user.name + " does not accept items", MessageSound.RejectInput);
            }
        }
Beispiel #13
0
        public void OnSendColonistOptionClick(User user)
        {
            PhiClient phiClient = PhiClient.instance;

            // We open a trade window with this user
            if (user.preferences.receiveColonists)
            {
                Find.WindowStack.Add(new UserSendColonistWindow(user));
            }
            else
            {
                Messages.Message(user.name + " does not accept colonists", MessageTypeDefOf.RejectInput);
            }
        }
Beispiel #14
0
        private Displayable DoChat()
        {
            PhiClient phi = PhiClient.instance;

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

            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; }));
        }
Beispiel #15
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);
        }
Beispiel #16
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);
        }
Beispiel #17
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();
            }
        }
Beispiel #18
0
        public void OnColonistClick(Pawn pawn)
        {
            PhiClient client = PhiClient.instance;

            client.SendPawn(user, pawn);
        }
Beispiel #19
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);
                }
            }
        }
Beispiel #20
0
 // Token: 0x06000003 RID: 3 RVA: 0x000020BD File Offset: 0x000002BD
 public PhiClient()
 {
     instance      = this;
     serverAddress = GetServerAddress();
 }
Beispiel #21
0
 public PhiClient()
 {
     PhiClient.instance = this;
     this.serverAddress = this.GetServerAddress();
 }
Beispiel #22
0
        public void OnAnimalClick(Pawn pawn)
        {
            PhiClient client = PhiClient.instance;

            client.SendAnimal(user, pawn);
        }