// load cards to GUI private void loadCardsToGUI(List <Models.Card> Cards, int index) { for (int i = index; i < index + 10; i++) { if (i < Cards.Count) { try { listGuiImages[i - index].Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}{2}/{3}.jpg", AppDomain.CurrentDomain.BaseDirectory, cardsPath, Cards[i].Set, Cards[i].Name), UriKind.Absolute)); if (listGuiCardButtons[i - index].Visibility == Visibility.Hidden) { listGuiCardButtons[i - index].Visibility = Visibility.Visible; } } catch (Exception ex) { logger.Log(ex.ToString()); listGuiImages[i - index].Source = null; listGuiCardButtons[i - index].Visibility = Visibility.Hidden; } } else { listGuiImages[i - index].Source = null; listGuiCardButtons[i - index].Visibility = Visibility.Hidden; } } }
// zoomed in image public void cardImage_MouseRightButtonDown(object sender, MouseEventArgs e) { Image img = (Image)sender; try { zoomedImage.Source = img.Source; } catch (Exception ex) { logger.Log(ex.ToString()); } Point location = ((Button)(img.Parent)).TranslatePoint(new Point(0, 0), grdParent); if (location.X + zoomedImage.Width > parent.Width - 100) { location.X -= zoomedImage.Width + 15; } else { location.X += 75; } if (location.Y + zoomedImage.Height > parent.Height) { location.Y -= zoomedImage.Height - 90; } zoomedImage.Margin = new Thickness(location.X, location.Y, 0, 0); zoomedImage.Visibility = Visibility.Visible; }
public void setCard(Models.CardWithGameProperties card) { Card = card; try { if (Card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, cardBackPath), UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}{2}/{3}.jpg", AppDomain.CurrentDomain.BaseDirectory, cardsPath, Card.Set, Card.Name), UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } }
// zoomed in image private void cardImage_MouseRightButtonDown(object sender, MouseEventArgs e) { Image img = (Image)sender; int index = Int32.Parse(img.Name.Substring(9)); try { zoomedImage.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/Cards/" + ctrl.filteredCollection[ctrl.currentIndex + index - 1].Name + ".png", UriKind.Absolute)); } catch (Exception ex) { logger.Log(ex.ToString()); } Point location = listGuiImages[index - 1].TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0)); zoomedImage.Margin = new Thickness(location.X + 127, location.Y, 0, 0); zoomedImage.Visibility = Visibility.Visible; }
public CardGUIModel(Models.CardWithGameProperties Card_, GUIPages.GUIGameRoom parent_, Thickness margin, Visibility visibility) { logger = new Log.Logger(); Card = Card_; parent = parent_; // Border Border = new Border(); Border.Width = 73; Border.Height = 100; Border.VerticalAlignment = VerticalAlignment.Top; Border.HorizontalAlignment = HorizontalAlignment.Left; Border.Margin = margin; Border.BorderThickness = new Thickness(5); Border.BorderBrush = Brushes.Transparent; Border.Visibility = visibility; // Button Btn = new Button(); Btn.Style = parent.FindResource("cardButtonStyle") as Style; Btn.Cursor = System.Windows.Input.Cursors.Hand; Btn.Click += cardButton_Click; Border.Child = Btn; // Image Image = new Image(); try { if (Card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/GUI/CardBack.png", UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/Cards/" + Card.Name + ".png", UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } Image.Stretch = Stretch.UniformToFill; Image.MouseRightButtonUp += parent.cardImage_MouseRightButtonUp; Image.MouseRightButtonDown += parent.cardImage_MouseRightButtonDown; Btn.Content = Image; }
public SimpleCardGUIModel(Models.Card card, int width = 75, int height = 104) { logger = new Log.Logger(); // Border Border = new Border(); Border.Width = width; Border.Height = height; Border.VerticalAlignment = VerticalAlignment.Top; Border.HorizontalAlignment = HorizontalAlignment.Left; Border.Margin = new Thickness(0); Border.BorderThickness = new Thickness(5); Border.BorderBrush = Brushes.Transparent; // Image Image = new Image(); try { if (card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, cardBackPath), UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}{2}/{3}.jpg", AppDomain.CurrentDomain.BaseDirectory, cardsPath, card.Set, card.Name), UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } Image.Stretch = Stretch.UniformToFill; Border.Child = Image; }
public SelectGUI_CardGUIModel(CardGUIModel cardGUI, GUIWindows.GUISelect parent_, Thickness margin) { logger = new Log.Logger(); this.cardGUI = cardGUI; parent = parent_; // Border Border = new Border(); Border.Width = 73; Border.Height = 100; Border.HorizontalAlignment = HorizontalAlignment.Left; Border.Margin = margin; Border.BorderThickness = new Thickness(5); Border.BorderBrush = Brushes.Transparent; TranslateTransform t = new TranslateTransform(0, 0); Border.RenderTransform = t; Border.Visibility = Visibility.Visible; // Button Btn = new Button(); Btn.Style = parent.FindResource("cardButtonStyle") as Style; Btn.Cursor = System.Windows.Input.Cursors.Hand; Btn.Click += Btn_Click; Border.Child = Btn; // Image Image = new Image(); try { if (cardGUI.Card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/GUI/CardBack.png", UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/Cards/" + cardGUI.Card.Name + ".png", UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } Image.Stretch = Stretch.UniformToFill; Btn.Content = Image; }
// scans the storage of specified socket and tries to retrieve a complete received message public Models.Message getWholeMessage(Socket socket) { int index; Models.Message obMessage = null; index = getIndexOfSocketStorage(socket); if (index != -1) { int beginIndex = storage[index].Storage.IndexOf(BEGIN_MESSAGE_DELIMITER); int endIndex = storage[index].Storage.IndexOf(END_MESSAGE_DELIMITER); string message; if (endIndex >= 0 && beginIndex >= 0 && endIndex < beginIndex) { storage[index].Storage = storage[index].Storage.Substring(beginIndex); beginIndex = storage[index].Storage.IndexOf(BEGIN_MESSAGE_DELIMITER); endIndex = storage[index].Storage.IndexOf(END_MESSAGE_DELIMITER); } if (endIndex >= 0 && beginIndex >= 0) { message = storage[index].Storage.Substring(beginIndex + BEGIN_MESSAGE_DELIMITER.Length, endIndex - (beginIndex + BEGIN_MESSAGE_DELIMITER.Length)); try { obMessage = Models.Message.Deserialize(message); } catch (Exception ex) { obMessage = null; logger.Log(ex.Message); } if (endIndex + END_MESSAGE_DELIMITER.Length == storage[index].Storage.Length) { storage[index].Storage = ""; } else { storage[index].Storage = storage[index].Storage.Substring(endIndex + END_MESSAGE_DELIMITER.Length); } } } return(obMessage); }
public void setCard(Models.CardWithGameProperties card) { Card = card; try { if (Card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/GUI/CardBack.png", UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/Cards/" + Card.Name + ".png", UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } }
public void messageProcessor(List <Models.Message> messageList) { foreach (Models.Message message in messageList) { try { if (message.Type == "ClientMessage") { Models.ClientMessage cm = message.Value.ToObject <Models.ClientMessage>(); // parse Message to ClientMessage clientCommandProcessor(cm); } else if (message.Type == "GameMessage") { Models.GameMessage gm = message.Value.ToObject <Models.GameMessage>(); // parse Message to GameMessage gameCommandProcessor(gm); } } catch (Exception ex) { logger.Log(ex.ToString()); } } }
private void init(Card card, Window parent, Thickness margin, bool clickable, int shieldNumber = -1) { logger = new Log.Logger(); Card = card; this.parent = parent; // Border Border = new Border(); Border.Width = 75; Border.Height = 100; Border.HorizontalAlignment = HorizontalAlignment.Left; Border.Margin = margin; Border.BorderThickness = new Thickness(5); Border.BorderBrush = Brushes.Transparent; TranslateTransform t = new TranslateTransform(0, 0); Border.RenderTransform = t; Border.Visibility = Visibility.Visible; // Grid Grd = new Grid(); // Button Btn = new Button(); Btn.Style = parent.FindResource("cardButtonStyle") as Style; Btn.Cursor = System.Windows.Input.Cursors.Hand; if (clickable) { Btn.Click += Btn_Click; } Border.Child = Grd; // Image Image = new Image(); try { if (card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, cardBackPath), UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}{2}/{3}.jpg", AppDomain.CurrentDomain.BaseDirectory, cardsPath, card.Set, card.Name), UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } Image.Stretch = Stretch.UniformToFill; Btn.Content = Image; Grd.Children.Add(Btn); if (shieldNumber != -1) { // Textblock TxtBlock = new TextBlock(); TxtBlock.Text = shieldNumber.ToString(); TxtBlock.FontSize = 15; TxtBlock.Foreground = Brushes.White; TxtBlock.FontWeight = FontWeights.Bold; TxtBlock.HorizontalAlignment = HorizontalAlignment.Left; TxtBlock.VerticalAlignment = VerticalAlignment.Top; TxtBlock.Margin = new Thickness(10, 5, 0, 0); Grd.Children.Add(TxtBlock); } }
public GameRoomGUIModel(GameRoom room, string myNickName, GUIPages.GUILobbyRoom parent_) { logger = new Log.Logger(); Parent = parent_; ID = room.RoomID; if (myNickName == room.Owner) { OwnRoom = true; } else { OwnRoom = false; } guestNickName = room.Guest; ColumnDefinition cd = new ColumnDefinition(); BrushConverter bc = new BrushConverter(); // Border Border = new Border(); Border.Height = 100; Border.Margin = new Thickness(10); Border.CornerRadius = new CornerRadius(20); Border.Background = Brushes.Black; Border.Opacity = 0.8; Border.BorderThickness = new Thickness(2); Border.BorderBrush = Brushes.LightGray; // GRID cd.Width = GridLength.Auto; grid.ColumnDefinitions.Add(cd); cd = new ColumnDefinition(); cd.Width = new GridLength(1, GridUnitType.Star); grid.ColumnDefinitions.Add(cd); cd = new ColumnDefinition(); cd.Width = GridLength.Auto; grid.ColumnDefinitions.Add(cd); // PLAYER1 BORDER borderForP1.CornerRadius = new CornerRadius(10); borderForP1.Background = Brushes.Gold; borderForP1.Margin = new Thickness(25, 23, 0, 23); borderForP1.Padding = new Thickness(5, 0, 5, 0); borderForP1.BorderBrush = Brushes.White; borderForP1.BorderThickness = new Thickness(2); // PLAYER1 LABEL labelForP1.Content = room.Owner; labelForP1.FontSize = 25; labelForP1.Foreground = Brushes.Black; labelForP1.VerticalAlignment = VerticalAlignment.Center; labelForP1.FontWeight = FontWeights.Bold; borderForP1.Child = labelForP1; // IMAGE try { VSimage.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Images/GUI/VS.png", UriKind.Absolute)); } catch (Exception) { logger.Log("Couldn't load 'versus image' in game room " + ID); } VSimage.Width = 60; VSimage.Margin = new Thickness(25, 0, 25, 0); // PLAYER2 BORDER borderForP2.CornerRadius = new CornerRadius(10); borderForP2.HorizontalAlignment = HorizontalAlignment.Left; borderForP2.Background = Brushes.Gold; borderForP2.Margin = new Thickness(0, 23, 20, 23); borderForP2.Padding = new Thickness(5, 0, 5, 0); borderForP2.BorderBrush = Brushes.White; borderForP2.BorderThickness = new Thickness(2); // PLAYER2 LABEL labelForP2.Content = room.Guest; labelForP2.FontSize = 25; labelForP2.Foreground = Brushes.Black; labelForP2.VerticalAlignment = VerticalAlignment.Center; labelForP2.FontWeight = FontWeights.Bold; borderForP2.Child = labelForP2; dp.Children.Add(borderForP1); dp.Children.Add(VSimage); dp.Children.Add(borderForP2); grid.Children.Add(dp); // STATE stateLabel.Content = room.State; stateLabel.FontSize = 23; stateLabel.Foreground = Brushes.White; stateLabel.HorizontalAlignment = HorizontalAlignment.Center; stateLabel.VerticalAlignment = VerticalAlignment.Center; stateLabel.FontWeight = FontWeights.Bold; grid.Children.Add(stateLabel); Grid.SetColumn(stateLabel, 1); // mainButton Style style = Parent.FindResource("buttonStyle") as Style; mainButton.Style = style; mainButton.HorizontalAlignment = HorizontalAlignment.Right; mainButton.VerticalAlignment = VerticalAlignment.Top; mainButton.Cursor = System.Windows.Input.Cursors.Hand; mainButton.Background = Brushes.Black; mainButton.Foreground = Brushes.White; mainButton.FontSize = 20; mainButton.Margin = new Thickness(10, 10, 10, 0); mainButton.Width = 110; mainButton.Click += btnMain_Click; // if it's your room then you can close it if (OwnRoom) { mainButton.Content = "Close"; mainButtonIsJoin = false; } else { // if it's not your room then you can join it if it's free, otherwise you can't do anything mainButton.Content = "Join"; mainButtonIsJoin = true; if (room.Guest != "*") { mainButton.IsEnabled = false; } } // readyButton readyButton.Style = style; readyButton.HorizontalAlignment = HorizontalAlignment.Right; readyButton.VerticalAlignment = VerticalAlignment.Bottom; readyButton.Cursor = System.Windows.Input.Cursors.Hand; readyButton.Background = Brushes.Black; readyButton.Foreground = Brushes.White; readyButton.FontSize = 20; readyButton.Margin = new Thickness(10, 0, 10, 10); readyButton.Width = 110; readyButton.Content = "Ready"; readyButton.IsEnabled = false; readyButton.Click += btnReady_Click; grid.Children.Add(mainButton); grid.Children.Add(readyButton); Grid.SetColumn(mainButton, 2); Grid.SetColumn(readyButton, 2); Border.Child = grid; }
public CardGUIModel(Models.CardWithGameProperties Card_, GUIPages.GUIGameRoom parent_, Thickness margin, Visibility visibility, int shieldNumber = -1) { logger = new Log.Logger(); Card = Card_; parent = parent_; ShieldNumber = shieldNumber; // Border Border = new Border(); Border.Width = 75; Border.Height = 100; Border.VerticalAlignment = VerticalAlignment.Top; Border.HorizontalAlignment = HorizontalAlignment.Left; Border.Margin = margin; Border.BorderThickness = new Thickness(5); Border.BorderBrush = Brushes.Transparent; Border.Visibility = visibility; //Grid Grd = new Grid(); // Button Btn = new Button(); Btn.Style = parent.FindResource("cardButtonStyle") as Style; Btn.Cursor = System.Windows.Input.Cursors.Hand; Btn.Click += cardButton_Click; Border.Child = Grd; // Image Image = new Image(); try { if (Card == null) { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, cardBackPath), UriKind.Absolute)); } else { Image.Source = new System.Windows.Media.Imaging.BitmapImage( new Uri( string.Format("{0}{1}{2}/{3}.jpg", AppDomain.CurrentDomain.BaseDirectory, cardsPath, Card.Set, Card.Name), UriKind.Absolute)); } } catch (Exception ex) { logger.Log(ex.ToString()); } Image.Stretch = Stretch.UniformToFill; Image.MouseRightButtonUp += parent.cardImage_MouseRightButtonUp; Image.MouseRightButtonDown += parent.cardImage_MouseRightButtonDown; Btn.Content = Image; Grd.Children.Add(Btn); if (shieldNumber != -1) { // Textblock TxtBlock = new TextBlock(); TxtBlock.Text = shieldNumber.ToString(); TxtBlock.FontSize = 15; TxtBlock.Foreground = Brushes.White; TxtBlock.FontWeight = FontWeights.Bold; TxtBlock.HorizontalAlignment = HorizontalAlignment.Left; TxtBlock.VerticalAlignment = VerticalAlignment.Top; TxtBlock.Margin = new Thickness(10, 5, 0, 0); Grd.Children.Add(TxtBlock); } }