Skip to content

Commit

Permalink
Client improvements
Browse files Browse the repository at this point in the history
Menu bar, variable number of columns in deck builder, copy deck to
clipboard.
  • Loading branch information
thquinn committed Feb 20, 2015
1 parent 58c5381 commit 805839c
Show file tree
Hide file tree
Showing 9 changed files with 1,317 additions and 17 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache
*.cache
obj/x86/Debug/IsochronDrafter.CardWindow.resources
*.resources
obj/x86/Debug/IsochronDrafter.csproj.FileListAbsolute.txt
obj/x86/Debug/IsochronDrafter.exe
obj/x86/Debug/IsochronDrafter.pdb
bin/Debug/tcpServer.pdb
bin/Debug/tcpServer.dll
bin/Debug/IsochronDrafter.vshost.exe.manifest
bin/Debug/IsochronDrafter.vshost.exe
bin/Debug/IsochronDrafter - Copy.exe
bin/Debug/IsochronDrafter.exe
bin/Debug/IsochronDrafter.pdb
50 changes: 49 additions & 1 deletion DeckBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Forms.Layout;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;

namespace IsochronDrafter
{
Expand All @@ -32,6 +33,8 @@ public DeckBuilder()
: base()
{
AutoScroll = true;
AutoScrollMargin = new System.Drawing.Size(0, 0);

columns = new List<List<DeckBuilderCard>[]>();
for (int i = 0; i < NUM_INITIAL_COLUMNS; i++)
{
Expand Down Expand Up @@ -68,6 +71,26 @@ public void Clear()
columns[i][1] = new List<DeckBuilderCard>();
}
}
public void SetNumColumns(int numColumns)
{
while (columns.Count > numColumns)
{
// Remove second-to-last column.
List<DeckBuilderCard>[] column = columns[columns.Count - 2];
columns.RemoveAt(columns.Count - 2);
columns[columns.Count - 2][0].AddRange(column[0]);
columns[columns.Count - 2][1].AddRange(column[1]);
}
while (columns.Count < numColumns)
{
// Add new second-to-last column.
List<DeckBuilderCard>[] column = new List<DeckBuilderCard>[2];
column[0] = new List<DeckBuilderCard>();
column[1] = new List<DeckBuilderCard>();
columns.Insert(columns.Count - 1, column);
}
LayoutControls();
}

protected override void OnInvalidated(InvalidateEventArgs e)
{
Expand All @@ -93,6 +116,7 @@ private void LayoutControls()
}
if (row == 1)
y += layout.secondRowY;
y -= VerticalScroll.Value;
card.Left = (int)Math.Round(x);
card.Top = (int)Math.Round(y);
card.Width = (int)Math.Round(CARD_WIDTH * layout.scale);
Expand Down Expand Up @@ -163,7 +187,6 @@ protected override void OnMouseMove(MouseEventArgs e)
{
DeckBuilderLayout layout = new DeckBuilderLayout(this);
// TODO: COPIED FROM LayoutControls()! Bad!
Console.WriteLine(column + ", " + row + ", " + cardNum);
float x = layout.spacing * (column + 1) + (CARD_WIDTH * layout.scale * column);
float y = layout.spacing + (layout.headerSize * cardNum);
if (column == columns.Count - 1)
Expand All @@ -175,6 +198,7 @@ protected override void OnMouseMove(MouseEventArgs e)
y += layout.secondRowY;
if (cardNum != 0 && cardNum == columns[column][row].Count)
y += CARD_HEIGHT * layout.scale - layout.headerSize;
y -= VerticalScroll.Value;
// END COPY
indicator.Left = (int)Math.Round(x - 2);
indicator.Top = (int)Math.Round(y - 1);
Expand Down Expand Up @@ -236,6 +260,7 @@ private int[] GetColumnRowNumFromCoor(int x, int y)
if (column >= columns.Count)
return null;
bool isEmpty = GetMaxFirstRowLength() == 0;
y += VerticalScroll.Value;
int row = y < layout.secondRowY || isEmpty || column == columns.Count - 1 ? 0 : 1;
int cardNum;
if (columns[column][row].Count == 0) // Dragged card should get put as the first element in the now-empty column.
Expand Down Expand Up @@ -293,6 +318,29 @@ public int GetMaxFirstRowLength()
output = columns[i][0].Count;
return output;
}

public String GetCockatriceDeck()
{
Dictionary<string, int> quantities = new Dictionary<string, int>();
Dictionary<string, int> sideboardQuantities = new Dictionary<string, int>();
for (int column = 0; column < columns.Count; column++)
for (int row = 0; row < 2; row++)
for (int cardNum = 0; cardNum < columns[column][row].Count; cardNum++)
{
Dictionary<string, int> dictionary = column == columns.Count - 1 ? sideboardQuantities : quantities;
string cardName = columns[column][row][cardNum].cardName;
if (dictionary.ContainsKey(cardName))
dictionary[cardName]++;
else
dictionary.Add(cardName, 1);
}
string output = "";
foreach (KeyValuePair<string, int> kvp in quantities)
output += "\r\n" + kvp.Value + " " + kvp.Key;
foreach (KeyValuePair<string, int> kvp in sideboardQuantities)
output += "\r\nSB: " + kvp.Value + " " + kvp.Key;
return output.Trim();
}
}

internal class DeckBuilderCard : PictureBox
Expand Down
1 change: 0 additions & 1 deletion DraftClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private void HandleMessage(string msg)
}
else if (parts[0] == "BOOSTER")
{
draftWindow.PrintLine("Next booster received.");
draftWindow.PopulateDraftPicker(msg);
}
else if (parts[0] == "CARD_POOL")
Expand Down
144 changes: 135 additions & 9 deletions DraftWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions DraftWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void PopulateDraftPicker(string message)
{
List<string> booster = new List<string>(message.Split('|'));
booster.RemoveAt(0);
PrintLine("Received booster with " + booster.Count + (booster.Count == 1 ? " card." : " cards."));
draftPicker.Populate(booster);
}
public void ClearDraftPicker()
Expand Down Expand Up @@ -111,5 +112,53 @@ private void draftPicker1_DoubleClick(object sender, EventArgs e)
if (index != -1)
draftClient.Pick(index, draftPicker.cardNames[index]);
}

// Menu items.
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void copyDeckToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(deckBuilder.GetCockatriceDeck());
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
deckBuilder.SetNumColumns(4);
UnCheckColumns();
toolStripMenuItem2.Checked = true;
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
deckBuilder.SetNumColumns(5);
UnCheckColumns();
toolStripMenuItem3.Checked = true;
}
private void toolStripMenuItem4_Click(object sender, EventArgs e)
{
deckBuilder.SetNumColumns(6);
UnCheckColumns();
toolStripMenuItem4.Checked = true;
}
private void toolStripMenuItem5_Click(object sender, EventArgs e)
{
deckBuilder.SetNumColumns(7);
UnCheckColumns();
toolStripMenuItem5.Checked = true;
}
private void toolStripMenuItem6_Click(object sender, EventArgs e)
{
deckBuilder.SetNumColumns(8);
UnCheckColumns();
toolStripMenuItem6.Checked = true;
}
private void UnCheckColumns()
{
toolStripMenuItem2.Checked = false;
toolStripMenuItem3.Checked = false;
toolStripMenuItem4.Checked = false;
toolStripMenuItem5.Checked = false;
toolStripMenuItem6.Checked = false;
}
}
}
3 changes: 3 additions & 0 deletions DraftWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
1 change: 0 additions & 1 deletion IsochronDrafter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="scripts\magic-isochrondrafter.mse-export-template\export-template" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\tcpServer\tcpServer.csproj">
Expand Down
Loading

0 comments on commit 805839c

Please sign in to comment.