Viking245 wrote: ↑Mon Jan 22, 2024 2:13 pm
segaduck wrote: ↑Mon Jan 22, 2024 9:06 am
What I am struggling right now is the keys/buttons/joystick mapping UI, and wish I can find a best way to finish it ASAP.
I've used SharpDX (and SharpDX.XInput and SharpDX.DirectInput) in the past to capture inputs. Though now 'archived', it may still be useful or lead you in the right direction.
If you'd like any help with the project, feel free to DM me. You can keep 100% of the credit for the project. Makes no matter to me.

(I did try to DM you, but 'lurkers' aren't allowed.

)
Hi, Viking245,
Nice to meet you here. It is very welcome to invite you to join the new frontend project's development, and I believe we can finish the project sooner with your great help.
I've tried SharpDX.XInput in the development and get the inputs successfully. What I am confused is how to map the naming in SharpDX.Xinput or Dinput to the Suerpmodel's naming. For example, in Supermodel "JOY1_BUTTON1" to SharpDX's names, especially there are more than only 1 joystick connected.
I am thinking if you can develop a C# class with method which will return the user's input name once a time and I will implement other UI and Key mapping stuff for each game. Or you can give me other suggestion will be great.
Thank you.
Following are the source codes that I've written for Joystick input testing UI.
======================================================================================
using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;
using System.Drawing.Drawing2D;
using SharpDX.XInput;
using SharpDX.DirectInput;
using SharpDX.Mathematics.Interop;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
namespace SuperM3UI
{
public partial class FormControlTest : Form
{
private Timer updateTimer;
private Controller controller;
int JStickPos;
int JStickPos_pre;
int shiftX = 120;
int shiftY = 120;
int shiftUR = 84;
int ballPosX = 220;
int ballPosY = 170;
Bitmap myBitmap;
Rectangle expansionRectangle;
public Image sourceImage;
public FormControlTest()
{
InitializeComponent();
// Initialize Timer
updateTimer = new Timer();
updateTimer.Interval = 16; // every16ms, around 60fps
updateTimer.Tick += UpdateTimer_Tick;
// Intialize JStick Position on UI
JStickPos = 5;
JStickPos_pre = 5;
sourceImage = Image.FromFile(@"C:\Development\SuperM3UI\SuperM3UI\icons\sticks-ball-mid.png");
myBitmap = new Bitmap(@"C:\Development\SuperM3UI\SuperM3UI\icons\sticks-ball-mid.png");
// Initialize Xbox controller
controller = new Controller(UserIndex.One);
if (!controller.IsConnected)
{
MessageBox.Show("Xbox Controller is not connected。");
}
}
private void FormControlTest_Load(object sender, EventArgs e)
{
updateTimer.Start();
this.Location = new System.Drawing.Point(this.Location.X + 110, this.Location.Y + 65);
}
private void UpdateTimer_Tick(object sender, EventArgs e)
{
if (controller.IsConnected)
{
State st = controller.GetState();
//lb_PosX.Text = "Parent's X/Y =" + this.Parent.Location.X.ToString() + "//" + this.Parent.Location.Y.ToString();
//lb_PosY.Text = "It's X/Y =" + this.Location.X.ToString() + "//" + this.Location.Y.ToString();
// Checked buttons / joystick 's input
Boolean A_Btn_Now_pressed = ((st.Gamepad.Buttons & GamepadButtonFlags.A) != 0);
if (A_Btn_Now_pressed) { picBox_GreenBtnPress.Visible = true; } else { picBox_GreenBtnPress.Visible = false; }
//labelButton_A.Text = $"A Button: {A_Btn_Now_pressed}";
Boolean B_Btn_Now_pressed = ((st.Gamepad.Buttons & GamepadButtonFlags.B) != 0);
if (B_Btn_Now_pressed) { picBox_BlueBtnPress.Visible = true; } else { picBox_BlueBtnPress.Visible = false; }
//labelButton_B.Text = $"B Button: {(st.Gamepad.Buttons & GamepadButtonFlags.B) != 0}";
Boolean X_Btn_Now_pressed = ((st.Gamepad.Buttons & GamepadButtonFlags.X) != 0);
if (X_Btn_Now_pressed) { picBox_PinkBtnPress.Visible = true; } else { picBox_PinkBtnPress.Visible = false; }
//labelButton_X.Text = $"X Button: {(st.Gamepad.Buttons & GamepadButtonFlags.X) != 0}";
Boolean Y_Btn_Now_pressed = ((st.Gamepad.Buttons & GamepadButtonFlags.Y) != 0);
if (Y_Btn_Now_pressed) { picBox_RedBtnPress.Visible = true; } else { picBox_RedBtnPress.Visible = false; }
//labelButton_Y.Text = $"Y Button: {(st.Gamepad.Buttons & GamepadButtonFlags.Y) != 0}";
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0)
{
JStickPos = 8;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0) JStickPos = 9;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0) JStickPos = 7;
}
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0)
{
JStickPos = 2;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0) JStickPos = 3;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0) JStickPos = 1;
}
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0)
{
JStickPos = 6;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0) JStickPos = 9;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0) JStickPos = 3;
}
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0)
{
JStickPos = 4;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0) JStickPos = 7;
if ((st.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0 && (st.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0) JStickPos = 1;
}
if (((st.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) == 0) && ((st.Gamepad.Buttons & GamepadButtonFlags.DPadRight) == 0)
&& ((st.Gamepad.Buttons & GamepadButtonFlags.DPadUp) == 0) && ((st.Gamepad.Buttons & GamepadButtonFlags.DPadDown) == 0))
{
JStickPos = 5;
}
if (JStickPos_pre != JStickPos) panel1.Invalidate();
JStickPos_pre = JStickPos;
}
}
private void FormControlTest_FormClosed(object sender, FormClosedEventArgs e)
{
updateTimer.Stop();
}
private void rjButton2_Click(object sender, EventArgs e)
{
this.Close();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
expansionRectangle = new Rectangle(ballPosX, ballPosY, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
// Draw a portion of the source image.
if (JStickPos == 1)
{
expansionRectangle = new Rectangle(ballPosX - shiftUR, ballPosY + shiftUR, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 2)
{
expansionRectangle = new Rectangle(ballPosX, ballPosY + shiftY, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 3)
{
expansionRectangle = new Rectangle(ballPosX + shiftUR, ballPosY + shiftUR, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 4)
{
expansionRectangle = new Rectangle(ballPosX - shiftX, ballPosY, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 5)
{
expansionRectangle = new Rectangle(ballPosX, ballPosY, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 6)
{
expansionRectangle = new Rectangle(ballPosX + shiftX, ballPosY, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 7)
{
expansionRectangle = new Rectangle(ballPosX - shiftUR, ballPosY - shiftUR, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 8)
{
expansionRectangle = new Rectangle(ballPosX, ballPosY - shiftY, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
if (JStickPos == 9)
{
expansionRectangle = new Rectangle(ballPosX + shiftUR, ballPosY - shiftUR, myBitmap.Width * 14 / 10, myBitmap.Height * 14 / 10);
graphics.DrawImage(myBitmap, expansionRectangle);
}
}
}
}
======================================================================================