Skip to content

Commit

Permalink
Initial commit: WiiBalanceWalker V0.4 by Richard Perry from GreyCube.…
Browse files Browse the repository at this point in the history
  • Loading branch information
lshachar committed Nov 8, 2020
0 parents commit 5453b52
Show file tree
Hide file tree
Showing 21 changed files with 3,887 additions and 0 deletions.
20 changes: 20 additions & 0 deletions WiiBalanceWalker.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WiiBalanceWalker", "WiiBalanceWalker\WiiBalanceWalker.csproj", "{6BAAAAB3-54E0-4D21-A891-1CD69CEB36AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6BAAAAB3-54E0-4D21-A891-1CD69CEB36AF}.Debug|x86.ActiveCfg = Debug|x86
{6BAAAAB3-54E0-4D21-A891-1CD69CEB36AF}.Debug|x86.Build.0 = Debug|x86
{6BAAAAB3-54E0-4D21-A891-1CD69CEB36AF}.Release|x86.ActiveCfg = Release|x86
{6BAAAAB3-54E0-4D21-A891-1CD69CEB36AF}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
209 changes: 209 additions & 0 deletions WiiBalanceWalker/ActionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using System;
using System.Windows.Forms;
using InputManager;

namespace WiiBalanceWalker
{
/// <summary>Actions place holders as controls are passed after they load.</summary>
public class ActionList
{
public ActionItem Left;
public ActionItem Right;
public ActionItem Forward;
public ActionItem Backward;
public ActionItem Modifier;
public ActionItem Jump;
public ActionItem DiagonalLeft;
public ActionItem DiagonalRight;
}

/// <summary>Abstracts away selecting, saving, and sending multiple input types.</summary>
public class ActionItem
{
public bool IsActive { get; private set; }
string settingName;
string inputText;
int inputAmount;
int inputType;
Keys inputKeys;
Mouse.MouseKeys inputMouseKeys;
System.Timers.Timer inputTimer = new System.Timers.Timer() { Interval = 2, Enabled = false };

public ActionItem(string settingName, ComboBox controlType, NumericUpDown controlAmount)
{
// The name where the action should be saved.

this.settingName = settingName;

// Track changes to the controls.

controlType.SelectedIndexChanged += new EventHandler(ControlType_SelectedIndexChanged);
controlAmount.ValueChanged += new EventHandler(ControlAmount_ValueChanged);

// Add nothing and mouse movement options to control.

controlType.Items.Add(new ItemWithText("", "Do Nothing"));
controlType.Items.Add(new ItemWithText("MouseMoveX", "Mouse Move X"));
controlType.Items.Add(new ItemWithText("MouseMoveY", "Mouse Move Y"));

// Add mouse button options to control.

foreach (Mouse.MouseKeys item in Enum.GetValues(typeof(Mouse.MouseKeys)))
{
controlType.Items.Add(new ItemWithText(item, "Mouse Hold " + item));
}

// Add keyboard options to control.

foreach (Keys item in Enum.GetValues(typeof(Keys)))
{
controlType.Items.Add(new ItemWithText(item, "Key " + item));
}

// Get the last known settings.

inputText = (string)Properties.Settings.Default["Action" + settingName];
inputAmount = (int)Properties.Settings.Default["Amount" + settingName];

// Put the controls to the last known settings.

controlType.Text = inputText;
controlAmount.Value = inputAmount;


inputTimer.Elapsed += new System.Timers.ElapsedEventHandler(inputTimer_Elapsed);

}

public void ControlType_SelectedIndexChanged(object sender, EventArgs e)
{
// Convert control generic object back into item.

var itemWithText = (ItemWithText)((ComboBox)sender).SelectedItem;
var itemTypeName = itemWithText.Item.GetType().Name;

// Set the active item.

if (itemTypeName == "Keys")
{
inputKeys = (Keys)itemWithText.Item;
inputType = 1;
}
else if (itemTypeName == "MouseKeys")
{
inputType = 2;
inputMouseKeys = (Mouse.MouseKeys)itemWithText.Item;
}
else if (itemTypeName == "String")
{
var itemText = (String)itemWithText.Item;

if (itemText == "") inputType = 0;
else if (itemText == "MouseMoveX") inputType = 3;
else if (itemText == "MouseMoveY") inputType = 4;
}

// Remember settings.

inputText = ((ComboBox)sender).Text;
Save();
}

public void ControlAmount_ValueChanged(object sender, EventArgs e)
{
// Convert control decimal to integer and remember setting.

inputAmount = (int)((NumericUpDown)sender).Value;
Save();
}

void inputTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
switch (inputType)
{
case 3:
Mouse.MoveRelative(inputAmount, 0);
break;
case 4:
Mouse.MoveRelative(0, inputAmount);
break;
}
}

public void Start()
{
// Keyboard Keys and Mouse buttons need only to signal down then up to hold.
// Mouse movement is incremental jumps so needs a faster repeating timer for smooth movement.

if (this.IsActive) return;
this.IsActive = true;

switch (inputType)
{
case 0:
return;
case 1:
Keyboard.KeyDown(inputKeys);
break;
case 2:
Mouse.ButtonDown(inputMouseKeys);
break;
case 3:
inputTimer.Enabled = true;
break;
case 4:
inputTimer.Enabled = true;
break;
}
}

public void Stop()
{
if (!this.IsActive) return;
this.IsActive = false;

switch (inputType)
{
case 0:
return;
case 1:
Keyboard.KeyUp(inputKeys);
break;
case 2:
Mouse.ButtonUp(inputMouseKeys);
break;
case 3:
inputTimer.Enabled = false;
break;
case 4:
inputTimer.Enabled = false;
break;
}
}

public void Save()
{
Properties.Settings.Default["Action" + settingName] = inputText;
Properties.Settings.Default["Amount" + settingName] = inputAmount;
Properties.Settings.Default.Save();
}
}

/// <summary>Used to store objects with custom text as a control item.</summary>
public class ItemWithText
{
public object Item { get; private set; }
public string Text { get; private set; }

public ItemWithText(object item, string text)
{
this.Item = item;
this.Text = text;
}

public override string ToString()
{
return this.Text;
}
}
}
Loading

0 comments on commit 5453b52

Please sign in to comment.