Skip to content

Commit

Permalink
#10 Replaced Keyboard events. Removed Windows.Forms references.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanWouters committed May 18, 2016
1 parent e21ce98 commit 2cf55ea
Show file tree
Hide file tree
Showing 27 changed files with 235 additions and 128 deletions.
2 changes: 1 addition & 1 deletion CivOne.Unix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<!--<Reference Include="System.Windows.Forms" />-->
<Reference Include="atk-sharp" />
<Reference Include="glib-sharp" />
<Reference Include="gdk-sharp" />
Expand Down
39 changes: 39 additions & 0 deletions src/Enums/Key.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// CivOne
//
// To the extent possible under law, the person who associated CC0 with
// CivOne has waived all copyright and related or neighboring rights
// to CivOne.
//
// You should have received a copy of the CC0 legalcode along with this
// work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

namespace CivOne.Enums
{
public enum Key
{
None,
Character,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
Up,
Left,
Right,
Down,
Enter,
Space,
Escape,
Delete,
Backspace,
Other
}
}
22 changes: 22 additions & 0 deletions src/Enums/KeyModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// CivOne
//
// To the extent possible under law, the person who associated CC0 with
// CivOne has waived all copyright and related or neighboring rights
// to CivOne.
//
// You should have received a copy of the CC0 legalcode along with this
// work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

using System;

namespace CivOne.Enums
{
[Flags]
public enum KeyModifier
{
None = 0,
Control = 1,
Alt = 2,
Shift = 4
}
}
59 changes: 59 additions & 0 deletions src/Events/KeyboardEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// CivOne
//
// To the extent possible under law, the person who associated CC0 with
// CivOne has waived all copyright and related or neighboring rights
// to CivOne.
//
// You should have received a copy of the CC0 legalcode along with this
// work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

using System;
using CivOne.Enums;

namespace CivOne.Events
{
public class KeyboardEventArgs : EventArgs
{
public Key Key { get; private set; }
public char KeyChar { get; private set; }
public KeyModifier Modifier { get; private set; }

public bool Control
{
get
{
return (Modifier & KeyModifier.Control) > 0;
}
}

public bool Alt
{
get
{
return (Modifier & KeyModifier.Alt) > 0;
}
}

public bool Shift
{
get
{
return (Modifier & KeyModifier.Shift) > 0;
}
}

public KeyboardEventArgs(Key key, KeyModifier modifier = KeyModifier.None)
{
Key = key;
KeyChar = (char)0x00;
Modifier = modifier;
}

public KeyboardEventArgs(char keyChar, KeyModifier modifier = KeyModifier.None)
{
Key = Key.Character;
KeyChar = keyChar;
Modifier = modifier;
}
}
}
5 changes: 2 additions & 3 deletions src/Interfaces/IScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// You should have received a copy of the CC0 legalcode along with this
// work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
Expand All @@ -18,8 +17,8 @@ public interface IScreen
{
Picture Canvas { get; }
MouseCursor Cursor { get; }
bool HasUpdate(uint gameTick);
bool KeyDown(KeyEventArgs args);
bool HasUpdate(uint gameTick);
bool KeyDown(KeyboardEventArgs args);
bool MouseDown(ScreenEventArgs args);
bool MouseUp(ScreenEventArgs args);
bool MouseDrag(ScreenEventArgs args);
Expand Down
1 change: 0 additions & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

using System;
using System.Windows.Forms;

namespace CivOne
{
Expand Down
3 changes: 1 addition & 2 deletions src/Screens/Civilopedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using CivOne.Buildings;
using CivOne.Enums;
using CivOne.Events;
Expand Down Expand Up @@ -118,7 +117,7 @@ public override bool HasUpdate(uint gameTick)
return true;
}

public override bool KeyDown(KeyEventArgs args)
public override bool KeyDown(KeyboardEventArgs args)
{
if (_singlePage != null && NextPage())
{
Expand Down
3 changes: 1 addition & 2 deletions src/Screens/Credits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System;
using System.Drawing.Imaging;
using System.Linq;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
Expand Down Expand Up @@ -234,7 +233,7 @@ private void CustomizeWorld(object sender, EventArgs args)
Common.AddScreen(new CustomizeWorld());
}

public override bool KeyDown(KeyEventArgs args)
public override bool KeyDown(KeyboardEventArgs args)
{
if (_done && _overlay != null)
return _overlay.KeyDown(args);
Expand Down
1 change: 0 additions & 1 deletion src/Screens/CustomizeWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.GFX;
using CivOne.Templates;
Expand Down
1 change: 0 additions & 1 deletion src/Screens/Demo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.GFX;
using CivOne.Templates;
Expand Down
31 changes: 17 additions & 14 deletions src/Screens/GameMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
Expand Down Expand Up @@ -159,25 +158,29 @@ private void CenterOnUnit()
_y = Game.Instance.ActiveUnit.Y - 6;
}

public override bool KeyDown(KeyEventArgs args)
public override bool KeyDown(KeyboardEventArgs args)
{
switch (args.KeyCode)
switch (args.Key)
{
case Keys.C:
if (Game.Instance.ActiveUnit == null) break;
CenterOnUnit();
break;
case Keys.D:
if (!args.Shift) break;
Game.Instance.DisbandUnit(Game.Instance.ActiveUnit);
break;
case Keys.Space:
case Keys.Enter:
case Key.Space:
case Key.Enter:
if (Game.Instance.ActiveUnit != null)
Game.Instance.ActiveUnit.SkipTurn();
else
Game.Instance.NextTurn();
break;
return true;
}

switch (args.KeyChar)
{
case 'C':
if (Game.Instance.ActiveUnit == null) break;
CenterOnUnit();
return true;
case 'D':
if (!args.Shift) break;
Game.Instance.DisbandUnit(Game.Instance.ActiveUnit);
return true;
}

return false;
Expand Down
1 change: 0 additions & 1 deletion src/Screens/GameMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
Expand Down
1 change: 0 additions & 1 deletion src/Screens/GameOver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

using System;
using System.Drawing;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.GFX;
using CivOne.IO;
Expand Down
21 changes: 10 additions & 11 deletions src/Screens/GamePlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

using System;
using System.Drawing;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
Expand Down Expand Up @@ -227,33 +226,33 @@ public override bool HasUpdate(uint gameTick)
return true;
}

public override bool KeyDown(KeyEventArgs args)
public override bool KeyDown(KeyboardEventArgs args)
{
switch (args.KeyCode)
switch (args.Key)
{
case Keys.F1:
case Key.F1:
Common.AddScreen(new CityStatus());
return true;
case Keys.F2:
case Key.F2:
Common.AddScreen(new MilitaryLosses());
Common.AddScreen(new MilitaryStatus());
return true;
case Keys.F3:
case Key.F3:
Common.AddScreen(new IntelligenceReport());
return true;
case Keys.F4:
case Key.F4:
Common.AddScreen(new AttitudeSurvey());
return true;
case Keys.F5:
case Key.F5:
Common.AddScreen(new TradeReport());
return true;
case Keys.F6:
case Key.F6:
Common.AddScreen(new ScienceReport());
return true;
case Keys.F9:
case Key.F9:
Common.AddScreen(new CivilizationScore());
return true;
case Keys.F10:
case Key.F10:
Common.AddScreen(new WorldMap());
return true;
}
Expand Down
25 changes: 13 additions & 12 deletions src/Screens/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CivOne.Enums;
using CivOne.Events;
using CivOne.GFX;
using CivOne.Templates;

Expand Down Expand Up @@ -69,34 +70,34 @@ public override bool HasUpdate(uint gameTick)
return true;
}

public override bool KeyDown(KeyEventArgs args)
public override bool KeyDown(KeyboardEventArgs args)
{
StringBuilder sb;
switch (args.KeyCode)
switch (args.Key)
{
case Keys.Left:
case Key.Left:
if (_cursorPosition > 0) _cursorPosition--;
else _cursorPosition = 0;
_update = true;
return true;
case Keys.Right:
case Key.Right:
if (_cursorPosition < 0) _cursorPosition = 0;
if (_cursorPosition < _text.Length) _cursorPosition++;
else _cursorPosition = _text.Length;
_update = true;
return true;
case Keys.Escape:
case Key.Escape:
if (Cancel != null)
Cancel(this, null);
break;
case Keys.Enter:
case Key.Enter:
if (Accept != null)
Accept(this, null);
break;
case Keys.Delete:
case Key.Delete:
//TODO: Handle delete
break;
case Keys.Back:
case Key.Backspace:
if (_cursorPosition <= 0) return false;

sb = new StringBuilder(_text);
Expand All @@ -106,10 +107,10 @@ public override bool KeyDown(KeyEventArgs args)
_update = true;
return true;
default:
char c = (char)(args.KeyCode);
char c = args.KeyChar;
if (!args.Shift) c = Char.ToLower(c);
if (args.KeyData == Keys.OemPeriod) c = '.';
if (args.KeyData == Keys.Oemcomma) c = ',';
//if (args.KeyData == Keys.OemPeriod) c = '.';
//if (args.KeyData == Keys.Oemcomma) c = ',';
if (args.Shift && (c >= '0' && c <= '9')) c -= (char)16;
if (!Resources.Instance.ValidCharacter(_fontId, c)) return false;

Expand Down
Loading

0 comments on commit 2cf55ea

Please sign in to comment.