Skip to content

Commit

Permalink
Add fly mode cursor option
Browse files Browse the repository at this point in the history
Fix fly cursor not being centered when form is loaded, and before it is resized
  • Loading branch information
ItsPepperpot committed Sep 24, 2024
1 parent 91b4ea6 commit d48e911
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 3 deletions.
43 changes: 41 additions & 2 deletions IndustrialPark/MainForm/MainForm.Designer.cs

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

59 changes: 58 additions & 1 deletion IndustrialPark/MainForm/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ namespace IndustrialPark
{
public partial class MainForm : Form
{
public enum FlyModeCursor
{
Default = 0,
Crosshair = 1,
Hide = 2
}

public MainForm()
{
StartPosition = FormStartPosition.CenterScreen;
Expand Down Expand Up @@ -126,6 +133,7 @@ private void MainForm_Load(object sender, EventArgs e)
SetProjectToolStripStatusLabel();
StartRenderer();
UpdateTitleBar();
ResetMouseCenter(null, null);
}

private void ApplyIPSettings(IPSettings settings)
Expand Down Expand Up @@ -160,6 +168,8 @@ private void ApplyIPSettings(IPSettings settings)

BuildISO.PCSX2Path = settings.pcsx2Path;
BuildISO.recentGameDirPaths = settings.recentBuildIsoGamePaths;

setFlyCursor(settings.flyModeCursor);

foreach (string filepath in settings.recentArchivePaths)
SetRecentOpenedArchives(filepath);
Expand Down Expand Up @@ -234,6 +244,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
pcsx2Path = BuildISO.PCSX2Path,
recentBuildIsoGamePaths = BuildISO.recentGameDirPaths,
recentArchivePaths = openLastToolStripMenuItem.DropDownItems.Cast<ToolStripMenuItem>().Select(x => x.Text).ToArray(),
flyModeCursor = (int)flyModeCursor
};

File.WriteAllText(pathToSettings, JsonConvert.SerializeObject(settings, Formatting.Indented));
Expand Down Expand Up @@ -519,7 +530,9 @@ private void SetProjectToolStripStatusLabel()
public SharpRenderer renderer;

private bool mouseMode = false;
private System.Drawing.Point MouseCenter = new System.Drawing.Point();
private bool cursorHidden = false;
private FlyModeCursor flyModeCursor = FlyModeCursor.Crosshair;
private System.Drawing.Point MouseCenter;
private MouseEventArgs oldMousePosition = new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0);

private void MouseMoveControl(object sender, MouseEventArgs e)
Expand All @@ -539,13 +552,43 @@ private void MouseMoveControl(object sender, MouseEventArgs e)
{
if (mouseMode)
{


switch (flyModeCursor)
{
case FlyModeCursor.Default:
if (Cursor.Current != Cursors.Default)
Cursor = Cursors.Default;
break;
case FlyModeCursor.Crosshair:
if (Cursor.Current != Cursors.Cross)
Cursor = Cursors.Cross;
break;
case FlyModeCursor.Hide:
if (!cursorHidden)
{
cursorHidden = true;
Cursor.Hide();
}
break;
}

renderer.Camera.AddYaw(MathUtil.DegreesToRadians(Cursor.Position.X - MouseCenter.X) / 4);
renderer.Camera.AddPitch(MathUtil.DegreesToRadians(Cursor.Position.Y - MouseCenter.Y) / 4);

Cursor.Position = MouseCenter;
}
else
{
if (cursorHidden)
{
cursorHidden = false;
Cursor.Show();
}

if (Cursor.Current != Cursors.Default)
Cursor = Cursors.Default;

if (e.Button == MouseButtons.Middle)
{
renderer.Camera.AddYaw(MathUtil.DegreesToRadians(e.X - oldMousePosition.X));
Expand Down Expand Up @@ -1948,5 +1991,19 @@ private void MainForm_Shown(object sender, EventArgs e)
}
}
}

private void changeFlyModeCursor(object sender, EventArgs e)
{
setFlyCursor(Convert.ToInt32(((ToolStripMenuItem)sender).Tag));
}

private void setFlyCursor(int flyModeCursor)
{
this.flyModeCursor = (FlyModeCursor)flyModeCursor;

// Updaate the toolstrip dropdown items
foreach (ToolStripMenuItem item in cursorInFlyModeToolStripMenuItem.DropDownItems)
item.Checked = Convert.ToInt32(item.Tag) == flyModeCursor;
}
}
}
48 changes: 48 additions & 0 deletions IndustrialPark/MainForm/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,30 @@
<data name="useLegacyAssetTypeFormatToolStripMenuItem.Text" xml:space="preserve">
<value>Use Legacy Asset Type &amp;Format</value>
</data>
<data name="defaultToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
</data>
<data name="defaultToolStripMenuItem.Text" xml:space="preserve">
<value>Default</value>
</data>
<data name="crosshairToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
</data>
<data name="crosshairToolStripMenuItem.Text" xml:space="preserve">
<value>Crosshair</value>
</data>
<data name="hiddenToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
</data>
<data name="hiddenToolStripMenuItem.Text" xml:space="preserve">
<value>Hidden</value>
</data>
<data name="cursorInFlyModeToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>301, 22</value>
</data>
<data name="cursorInFlyModeToolStripMenuItem.Text" xml:space="preserve">
<value>Cursor in Fly Mode</value>
</data>
<data name="optionsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>61, 19</value>
</data>
Expand Down Expand Up @@ -2621,6 +2645,30 @@
<data name="&gt;&gt;useLegacyAssetTypeFormatToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cursorInFlyModeToolStripMenuItem.Name" xml:space="preserve">
<value>cursorInFlyModeToolStripMenuItem</value>
</data>
<data name="&gt;&gt;cursorInFlyModeToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;defaultToolStripMenuItem.Name" xml:space="preserve">
<value>defaultToolStripMenuItem</value>
</data>
<data name="&gt;&gt;defaultToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;crosshairToolStripMenuItem.Name" xml:space="preserve">
<value>crosshairToolStripMenuItem</value>
</data>
<data name="&gt;&gt;crosshairToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;hiddenToolStripMenuItem.Name" xml:space="preserve">
<value>hiddenToolStripMenuItem</value>
</data>
<data name="&gt;&gt;hiddenToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolsToolStripMenuItem.Name" xml:space="preserve">
<value>toolsToolStripMenuItem</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions IndustrialPark/Other/IPSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public class IPSettings

public string pcsx2Path;
public string[] recentBuildIsoGamePaths;
public int flyModeCursor = 1;
}
}

0 comments on commit d48e911

Please sign in to comment.