Пример #1
0
 private void MaxPlayersBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     MaxPlayersBox.Text = new String(MaxPlayersBox.Text.Where(Char.IsDigit).ToArray());
     if (MaxPlayersBox.Text.Length > 3)
     {
         MaxPlayersBox.Text = MaxPlayersBox.Text.Substring(0, 3);
     }
     if (String.IsNullOrEmpty(MaxPlayersBox.Text))
     {
         setError(MaxPlayersBox, "Field is required.");
     }
     else
     {
         int count = int.Parse(MaxPlayersBox.Text);
         if (count > 15)
         {
             setError(MaxPlayersBox, "Can't be more than 15 players.");
         }
         else if (count < 2)
         {
             setError(MaxPlayersBox, "Can't be less than 2 players.");
         }
         else
         {
             Validation.ClearInvalid(MaxPlayersBox.GetBindingExpression(TextBox.TextProperty));
         }
     }
 }
Пример #2
0
        private void SaveBTN_Click(object sender, RoutedEventArgs e)
        {
            disableAllButtonsAndText();
            startLoadingAnim();
            bool allFine = true;

            if (String.IsNullOrEmpty(RoomNameBox.Text))
            {
                setError(RoomNameBox, "Field is required.");
                allFine = false;
            }
            else
            {
                Validation.ClearInvalid(RoomNameBox.GetBindingExpression(TextBox.TextProperty));
            }
            MaxPlayersBox.Text = new String(MaxPlayersBox.Text.Where(Char.IsDigit).ToArray());
            if (MaxPlayersBox.Text.Length > 3)
            {
                MaxPlayersBox.Text = MaxPlayersBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(MaxPlayersBox.Text))
            {
                setError(MaxPlayersBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(MaxPlayersBox.Text);
                if (count > 15)
                {
                    setError(MaxPlayersBox, "Can't be more than 15 players.");
                    allFine = false;
                }
                else if (count < 2)
                {
                    setError(MaxPlayersBox, "Can't be less than 2 players.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(MaxPlayersBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            SecondsBox.Text = new String(SecondsBox.Text.Where(Char.IsDigit).ToArray());
            if (SecondsBox.Text.Length > 3)
            {
                SecondsBox.Text = SecondsBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(SecondsBox.Text))
            {
                setError(SecondsBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(SecondsBox.Text);
                if (count > 100)
                {
                    setError(SecondsBox, "Can't be more than 100 seconds.");
                    allFine = false;
                }
                else if (count < 10)
                {
                    setError(SecondsBox, "Can't be less than 10 seconds.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(SecondsBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            QuestionsBox.Text = new String(QuestionsBox.Text.Where(Char.IsDigit).ToArray());
            if (QuestionsBox.Text.Length > 3)
            {
                QuestionsBox.Text = QuestionsBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(QuestionsBox.Text))
            {
                setError(QuestionsBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(QuestionsBox.Text);
                if (count > 20)
                {
                    setError(QuestionsBox, "Can't be more than 20 questions.");
                    allFine = false;
                }
                else if (count < 2)
                {
                    setError(QuestionsBox, "Can't be less than 2 questions.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(QuestionsBox.GetBindingExpression(TextBox.TextProperty));
                }
            }

            if (allFine)
            {
                EditRoomRequest editRoomRequest = new EditRoomRequest();
                editRoomRequest.answerTimeout = int.Parse(SecondsBox.Text);
                editRoomRequest.questionCount = int.Parse(QuestionsBox.Text);
                editRoomRequest.maxUsers      = int.Parse(MaxPlayersBox.Text);
                editRoomRequest.roomName      = RoomNameBox.Text;
                app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(editRoomRequest, Constants.EDIT_ROOM_REQUEST)).ContinueWith(task =>
                {
                    ResponseInfo response             = task.Result;
                    EditRoomResponse editRoomResponse = JsonDeserializer.deserializeResponse <EditRoomResponse>(response.buffer);
                    switch (editRoomResponse.status)
                    {
                    case Constants.EDIT_ROOM_SUCCESS:
                        GetRoomDetailsRequest getRoomDetailsRequest = new GetRoomDetailsRequest();
                        getRoomDetailsRequest.roomId = 0;
                        app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(getRoomDetailsRequest, Constants.GET_ROOM_DETAILS_REQUEST)).ContinueWith(task1 =>
                        {
                            ResponseInfo response1 = task1.Result;
                            GetRoomDetailsResponse getRoomDetailsResponse = JsonDeserializer.deserializeResponse <GetRoomDetailsResponse>(response1.buffer);
                            updateRoomTexts(getRoomDetailsResponse);
                            MyMessageQueue.Enqueue("Saved successfully!");
                            enableAllButtonsAndText();
                            stopLoadingAnim();
                        });
                        break;

                    case Constants.EDIT_ROOM_NOT_EXIST:
                        thr.Abort();
                        MyMessageQueue.Enqueue("Room not exist anymore.");
                        this.Dispatcher.Invoke(() =>
                        {
                            NavigationService ns = NavigationService.GetNavigationService(this);
                            ns.Navigate(new Uri("Menu.xaml", UriKind.Relative));
                        });
                        break;
                    }
                });
            }
            else
            {
                enableAllButtonsAndText();
                stopLoadingAnim();
            }
        }
Пример #3
0
        private void CreateBTN_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(btn, true);
            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetValue(btn, -1);
            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndicatorVisible(btn, true);
            btn.IsEnabled = false;
            bool allFine = true;

            MaxPlayersBox.Text = new String(MaxPlayersBox.Text.Where(Char.IsDigit).ToArray());
            if (MaxPlayersBox.Text.Length > 3)
            {
                MaxPlayersBox.Text = MaxPlayersBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(MaxPlayersBox.Text))
            {
                setError(MaxPlayersBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(MaxPlayersBox.Text);
                if (count > 15)
                {
                    setError(MaxPlayersBox, "Can't be more than 15 players.");
                    allFine = false;
                }
                else if (count < 2)
                {
                    setError(MaxPlayersBox, "Can't be less than 2 players.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(MaxPlayersBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            QuestionsBox.Text = new String(QuestionsBox.Text.Where(Char.IsDigit).ToArray());
            if (QuestionsBox.Text.Length > 3)
            {
                QuestionsBox.Text = QuestionsBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(QuestionsBox.Text))
            {
                setError(QuestionsBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(QuestionsBox.Text);
                if (count > 20)
                {
                    setError(QuestionsBox, "Can't be more than 20 questions.");
                    allFine = false;
                }
                else if (count < 2)
                {
                    setError(QuestionsBox, "Can't be less than 2 questions.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(QuestionsBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            SecondsBox.Text = new String(SecondsBox.Text.Where(Char.IsDigit).ToArray());
            if (SecondsBox.Text.Length > 3)
            {
                SecondsBox.Text = SecondsBox.Text.Substring(0, 3);
            }
            if (String.IsNullOrEmpty(SecondsBox.Text))
            {
                setError(SecondsBox, "Field is required.");
                allFine = false;
            }
            else
            {
                int count = int.Parse(SecondsBox.Text);
                if (count > 100)
                {
                    setError(SecondsBox, "Can't be more than 100 seconds.");
                    allFine = false;
                }
                else if (count < 10)
                {
                    setError(SecondsBox, "Can't be less than 10 seconds.");
                    allFine = false;
                }
                else
                {
                    Validation.ClearInvalid(SecondsBox.GetBindingExpression(TextBox.TextProperty));
                }
            }
            if (String.IsNullOrEmpty(RoomNameBox.Text))
            {
                setError(RoomNameBox, "Field is required.");
                allFine = false;
            }
            else
            {
                Validation.ClearInvalid(RoomNameBox.GetBindingExpression(TextBox.TextProperty));
            }
            if (allFine)
            {
                CreateRoomRequest createRoomRequest = new CreateRoomRequest();
                createRoomRequest.answerTimeout = int.Parse(SecondsBox.Text);
                createRoomRequest.maxUsers      = int.Parse(MaxPlayersBox.Text);
                createRoomRequest.questionCount = int.Parse(QuestionsBox.Text);
                createRoomRequest.roomName      = RoomNameBox.Text;
                app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(createRoomRequest, Constants.CREATE_ROOM_REQUEST_CODE)).ContinueWith(task =>
                {
                    ResponseInfo response = task.Result;
                    CreateRoomResponse createRoomResponse = JsonDeserializer.deserializeResponse <CreateRoomResponse>(response.buffer);
                    switch (createRoomResponse.status)
                    {
                    case Constants.CREATE_ROOM_SUCCESS:
                        MyMessageQueue.Enqueue("Room Created Successfully!");
                        this.Dispatcher.Invoke(() =>
                        {
                            app.admin            = true;
                            NavigationService ns = NavigationService.GetNavigationService(this);
                            ns.Navigate(new Uri("RoomLobby.xaml", UriKind.Relative));
                        });
                        break;

                    case Constants.CREATE_ROOM_MAXIMUM_ROOMS_IN_SERVER:
                        MyMessageQueue.Enqueue("Max rooms reached.\nTry again later.");
                        break;
                    }
                    this.Dispatcher.Invoke(() =>
                    {
                        ButtonProgressAssist.SetIsIndeterminate(btn, false);
                        ButtonProgressAssist.SetIsIndicatorVisible(btn, false);
                        btn.IsEnabled = true;
                    });
                });
            }
            else
            {
                ButtonProgressAssist.SetIsIndeterminate(btn, false);
                ButtonProgressAssist.SetIsIndicatorVisible(btn, false);
                btn.IsEnabled = true;
            }
        }