public CardPanelControl(Pile p, Action<CardButton> f) { panel = new CardPanel(() => { var b = new CardButton(new FML(clickedCallback, f)); b.setHeight(150); return b; }, new LayoutArgs(false, false)); panel.Size = new Size(300, 150); panel.BackColor = Color.Navy; p.addObserver(panel); window = GUI.showWindow(panel); }
private void clickedCallback(CardButton b) { Card c = b.Card; waiter.signal(c); }
public void addArrows(CardButton f, IEnumerable<Target> ts) { foreach (Target t in ts) { Observable o; if (t.isCard) { o = t.card; } else if (t.isPlayer) { o = t.player; } else { throw new Exception(); } foreach (var v in o.getObservers()) { if (v is CardButton) { addArrow(f, v as CardButton); } else if (v is PlayerPanel) { addArrow(f, (v as PlayerPanel).playerPortrait); } else { throw new Exception(); } } } }
public DeckEditorPanel() { BackColor = Color.Beige; currentSortingColor = Colour.GREY; int currentPage = 0; int cardsPerPage = 8; sortedIds = new List<Card>(); myDeckIsHard = new Pile(new Card[] { }); p = new CardPanel(new Func<CardButton>(() => new CardButton()), new LayoutArgs(true, true)); myDeckIsHard.addObserver(p); ids = ((CardId[])Enum.GetValues(typeof (CardId))).Select(id => new Card(id)) .Where(c => c.rarity != Rarity.Token) .OrderBy(card => card.colour) .ToArray(); cardInfo = new CardInfoPanel(); cardInfo.BackColor = BackColor; Controls.Add(cardInfo); cardSlot = new CardButton[8]; cardCount = new Label(); int nrOfCards = ids.Length; cards = new CardButton[nrOfCards]; for (int i = 0; i < nrOfCards; i++) { cards[i] = new CardButton(ids[i].cardId); sortedIds.Add(ids[i]); } for (int i = 0; i < cardsPerPage; i++) { int i0 = i; cardSlot[i] = cards[i]; cardSlot[i].Size = new Size(200,300); Controls.Add(cardSlot[i]); cardSlot[i].MouseDown += (_, __) => { if (__.Button == MouseButtons.Left) addToDeck(cards[i0].Card.cardId); else if (__.Button == MouseButtons.Right) removeFromDeck(cards[i0].Card.cardId); }; cardSlot[i].MouseHover += (_, __) => { cardInfo.showCard(cardSlot[i0].Card); }; } scrollLeftButton = new Button(); scrollRightButton = new Button(); scrollLeftButton.Image = ImageLoader.getStepImage("arrowLeft", new Size(60, 60)); scrollRightButton.Image = ImageLoader.getStepImage("arrowRight", new Size(60, 60)); //todo: you need to double press if you scroll one way then the other. scrollLeftButton.MouseDown += (_, __) => { if (currentPage > 0) currentPage--; int cardSlotNr = cardsPerPage-1; for (int i = currentPage*cardsPerPage+cardsPerPage-1; i > currentPage*cardsPerPage-1; i--) { cardSlot[cardSlotNr].Visible = true; cardSlot[cardSlotNr].notifyObserver(new Card(sortedIds[i].cardId), null); cardSlotNr--; } Console.WriteLine(currentPage); }; scrollRightButton.MouseDown += (_, __) => { //this if doesn't even make sense, but it just werks. todo if (currentPage * cardsPerPage - cardsPerPage < sortedIds.Count - cardsPerPage * 2) currentPage++; int cardSlotNr = 0; for (int i = currentPage * cardsPerPage - cardsPerPage; i < currentPage * cardsPerPage; i++) { if (i < sortedIds.Count - cardsPerPage) { cardSlot[cardSlotNr].Visible = true; cardSlot[cardSlotNr].notifyObserver(new Card(sortedIds[i + cardsPerPage].cardId), null); } else cardSlot[cardSlotNr].Visible = false; cardSlotNr++; } }; backToMainMenuButton = new Button(); backToMainMenuButton.Size = new Size(120, 40); backToMainMenuButton.Text = "back to main menu"; backToMainMenuButton.MouseDown += (_, __) => { GUI.transitionToMainMenu(); }; Controls.Add(scrollLeftButton); Controls.Add(scrollRightButton); noDeckName = new Label(); noDeckName.Text = "Every deck needs a name."; noDeckName.Visible = false; noDeckName.Size = new Size(250, 25); noDeckName.BackColor = Color.Red; loadButton = new Button(); loadButton.Image = ImageLoader.getStepImage("load", new Size(60, 60)); loadButton.Size = loadButton.Image.Size; loadButton.MouseDown += (_, __) => { loadDeckFromFile((s) => loadIntoEditor(loadDeck(s))); }; saveButton = new Button(); saveButton.Image = ImageLoader.getStepImage("save", new Size(60, 60)); saveButton.Size = saveButton.Image.Size; saveButton.MouseDown += (_, __) => { if (tb.Text != "") saveDeck(); else { noDeckName.Visible = true; } }; sortButtons = new Button[6]; //todo use images or something, instead of solid colors Color[] colors = new Color[6] {Color.White, Color.Blue, Color.Black, Color.Red, Color.Green, Color.Gray}; for(int i = 0; i < sortButtons.Count(); i++) { //todo ask seba why i0 is needed int i0 = i; sortButtons[i] = new Button(); sortButtons[i].Tag = (Colour)i; sortButtons[i].BackColor = colors[i]; sortButtons[i].Location = new Point(Size.Width / 2 + 50 * i, 50); sortButtons[i].Size = new Size(50, 50); sortButtons[i].MouseDown += (_, __) => { sortAfterColor((Colour)sortButtons[i0].Tag); }; Controls.Add(sortButtons[i]); } tb = new TextBox(); Controls.Add(cardCount); Controls.Add(saveButton); Controls.Add(noDeckName); Controls.Add(loadButton); Controls.Add(tb); Controls.Add(p); Controls.Add(backToMainMenuButton); }
private void drawTheseButtons(CardButton[] cards) { int x = cards[0].Size.Width; for (int i = 0; i < cards.Length; i++) { x += cards[i].Width; if (i % CARDS_PER_ROW == 0) x = cards[0].Size.Width * 2; cards[i].setWidth(Size.Width / (cards.Length/2)); cards[i].Location = new Point(x + (i % CARDS_PER_ROW) * paddingX, cards[i].Size.Height/3 + cards[i].Size.Height * (i / CARDS_PER_ROW)); } }
private void sizeButton(CardButton b) { int height = Size.Height; int width = Size.Width; if (layoutArgs.topDown) { b.setWidth(width - sidePadding * 2); } else { b.setHeight(height - sidePadding * 2); } }
private void clicked(CardButton b) { //b.Card.attacking = !b.Card.attacking; }