Advice on Solitaire card game - c#

I am busy with a 'home made' solitaire game just for fun but think however that I worked myself into a bit of a corner and was hoping for some advice perhaps.
In short instead dragging and dropping a card to a different location I click on the card to be moved (displayed in a picturebox) facing upwards and set the visiblity to false and add the cardvalue to an ArrayList(named picFaceUpToBeMoved).
I click on a second card and then of course based on certain conditions the card will be displayed just above the card I clicked now.I create an instance of the PictureBox control setting the size and location.
PictureBox picOneFaceUpA = new PictureBox();
picOneFaceUpA.Location = new Point(42, 202);
picOneFaceUpA.Width = 90;
picOneFaceUpA.Height = 120;
picOneFaceUpA.Image = Image.FromFile("../../Resources/" + picFaceUpToBeMoved[0] + ".png");
Controls.Add(picOneFaceUpA);
picOneFaceUpA.BringToFront();
The problem I have now is how to go about in moving this card as it doesn't have an onClick event.
Sorry, a bit inexperienced and was hoping for advice on how to overcome this issue or how I could approach this game differently.

Try adding an event handler to MouseClick.
More documentation can be found here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseclick.aspx
And have a look at all other events there are available, for dragging you could use MouseDown, MouseMove, MouseUp, etc.
A list of available events can be found here: http://msdn.microsoft.com/en-us/library/1dk48x94.aspx

Related

Change mouse cursor icon in C#

I am building a game for Windows PCs and I need to change the cursor icon when the user is over clickable UI elements. I have found this command Cursor.SetCursor(texture2d, vector2) but it has some lag.
When the mouse is over the UI elements it changes but it has some delay which is really annoying (This is what other users said about that anyway).
After some reading, I learned that Unity basically just changes the cursor icon in the software level. i.e. Hides the cursor and displays my image, and make it follow the cursor position.
My question is: How can I change the icon in hardware level, again, in windows builds only.
When I searched "Changing mouse cursor in C#", I have found the windows.forms option (which doesn't work in unity) and a c++ code but it wasn't full (Only methods' names), and I don't know how to run it in C#…
The SetCursor not work very good on all Windows app, but is the right way to do it.
Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
Another way is to make a Little fake hidding the mouse cursor and making a GUI cursor for your desire case. You can add more conditions for each event you like to customize.
var OnMouseEnterCursor:Texture2D;
var cursorSizeX: int = 32; // your cursor width
var cursorSizeY: int = 32; // your cursor height
var MouseEnterCond = false;
function OnMouseEnter()
{
MouseEnterCond = true;
Screen.showCursor = false;
}
function OnMouseExit()
{
MouseEnterCond = false;
Screen.showCursor = true;
}
function OnGUI()
{
if(MouseEnterCond )
{
GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX/2 + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY/2 + cursorSizeY/2, cursorSizeX, cursorSizeY),OnMouseEnterCursor);
}
}
If there is a way to enforce hardware cursors in Unity the world has not found it yet.
Unity's own documentation explains it pretty well:
A hardware cursor is preferred on supported platforms through the function which you have yourself found (remember to set the cursor-mode to auto), but it will automatically, and uncontrollably, fall back on software for unsupported platforms and resolutions.
An important thing to note is that there is a special field (which the reference only peripherally mentioned) in the project settings/player settings menu called the "Default Cursor".
This is the only supported hardware cursor on e.g. windows store apps.
And remember to set your textures to type "cursor" in their configurations,.
Finally, keep in mind that windows only supports the 32x32px size. This may force Unity's hand when selecting the render type.
The default cursor settings in the player settings worked in the editor but it did not show up in a build. Also limiting the texture size to 32x32. I resolved this issue by using Cursor.SetCursor method in a script to change the cursor.
[SerializeField] Texture2D cursor;
void Start() {
Cursor.SetCursor(cursor, Vector3.zero, CursorMode.ForceSoftware);
}

How to perform PTZ programmatically for Axis Camera Control in C#

Here I get an IP camera from Axis
and Axis camera control showing the live view in my Winform program.
I am now going to write mouse dragging and scrolling event
to perform Pan–tilt–zoom(PTZ) in the C# Program.
However, I can't find any answer
even though I have been read all the manuals from Axis
and searching quite a lot in Google.
(Adding a param continuouszoommove in the Url is not working.)
Please help. Many thanks!
I just find out the answer today, it takes me two days for searching..
And here you get the answer:
viewer.PTZControlURL = "http://ipaddress/axis-cgi/com/ptz.cgi";
viewer.EnableAreaZoom = true;
viewer.OneClicllkZoom = true;
viewer.UIMode = "ptz-user-setting"
For the option of UIMode:
http://wiki.cinemaronline.com/index.php?title=Axis_Client_Side_ActiveX_Streaming_Video_Window
Alternatively, you can add some event like KeyUp/KeyDown to customize your camera control by adding params: pan, tilt and zoom.
Read the manual below about the params:
http://www.axis.com/files/manuals/vapix_ptz_52933_en_1307.pdf

MonoGame - Working With Specific Gestures for Different Purposes

Part of my particular dilemma is that I would like to be able to get the initial position of a drag gesture. Depending on the initial position of that drag gesture, the application would either 1) pan the view or 2) display a menu, but not perform these gestures at the same time (which is where part of struggle lies).
For example, if the user initiated a drag from the very left side of their screen and dragged inwards, a menu would pop in instead of the view panning.
I would also like to be able to execute a double tap gesture without also activating a tap gesture, if that's at all possible. I've tried working with boolean flags - for example,
// ...
if (gesture.GestureType == GestureType.DoubleTap)
{
isDoubleTap == true;
}
// ...
public static Vector2 Tap
{
get
{
if (!isDoubleTap)
return gesture.Position;
// ...
But that doesn't work.
I've tried using TouchCollection - if anyone would like me to elaborate on my issues with that I can, but for now I'll say what I tried hasn't worked. It's entirely possible I may have just goofed as I am a novice when it comes to working with touch input.
I've been working on this for a few days and have done as much searching as I can, and nothing I've found has alleviated my issue - if I happened to have missed something, I apologize.
Thank you for your time!
Concerning start position of a drag:
There is a gesture for a drag ending, so if you receive a drag and its the first one since the last drag ended, thats the initial position.
Concerning tap/doubletap:
MonoGame works the same way as XNA as documented here:
The user tapped the screen twice in quick succession. This
always is preceded by a Tap gesture.
This sounds like a input-bindings design problem more than a technical question imo. Consider also what you can move to instead occur on press or release rather than only making use of gestures.

Windows 8 App: "Snapping" Drag and Drop for Card Game

After trying to use the following snippet to move cards (Images right now) around I was not satisfied with the result.
Card.ManipulationDelta += (o, args) => {
var dragableItem = o as Image;
if (dragableItem == null) return;
var translateTransform = dragableItem.RenderTransform as TranslateTransform;
if (translateTransform == null) return;
translateTransform.X += args.Delta.Translation.X;
translateTransform.Y += args.Delta.Translation.Y;
};
Card.RenderTransform = new TranslateTransform();
The control had a funny behavior to be accelerated and would move / slide a bit after "dropping" it. Although cool I do not want this behavior and therefore changed my mind: what I am looking for is a solution to define specific areas for one active card, a bench for a few more cards and stacks for the deck, such that one can freely drag one card but it can only be dropped if it is above these certain areas otherwise it will get back to the area designated for the hand cards.
What could I try to implement this desired behavior?
I think you and I are in the same boat, I'm working on a Metro card game application and I'm not relly happy with what I've found as far as Drag and Drop goes. My inital approach was going to be to have a grid \ stackpanel or other underlying framework that the user could drag a card image ( acually a custom control ) over and then the image would snap to that framework when the user let go. I have not yet found a suitable way to obtain this behavior however because it seems like drag-drop of controls from one parent to another is not supported in Metro.
As far as your question goes, the sliding effect that you are refering to is most likely intertia, You can disable this by not setting the TranslateInertia mode, for example
Ellipse el = new Ellipse();
el.Fill = new SolidColorBrush(Windows.UI.Colors.Magenta);
el.ManipulationMode = (ManipulationModes.All ^ MainipulationModes.TranslateInteria);
//more code to add your ManipulationDelta handler etc.
You can also gain some control over the Interia by adding a handler for MainipulationInertiaStarting, though just setting e.Handled = true in the handler does not disable interia entirely for me as others have suggested.
I'd love to hear back from you and see what approach you've come up with for snapping cards, at this point I'm considering just using a large Canvas object and writing my own customer handlers for mouse moved to get card objects to be draggable and then snap into a row or other location on the playing board.
Cheers,
James

How do I get a disabled ToolStripButton to paint its image in colour?

We have a button which allows users to 'lock' a form. Users are not permitted to 'unlock' the form, so when pressed, we want the button to be disabled, so that the user receives appropriate visual feedback.
However, the customer reports that the greyed 'lock' icon suggests to them that the form is not locked, so we would like to display the button in a pressed state, but with the icon in colour, even though the button is disabled.
How do we do that, with the absolute minimum amount of overridden painting?
Actually I disagree with the approach. Your customer might have a valid point, but I don't think they have the correct suggestion for the fix. You should look into other ways to make the form appear "locked". Changing borders or font colours, having a big padlock icon appear or change from open to closed etc. Buttons look a certain way because that's what users expect. If you have a disabled button that looks like it might be enabled, that's going to confuse users who might not then understand why they can't click it.
You can set the ToolStripButton Image as BackgroundImage
and then set the DiplayStyle to None.
The picture should stay in colour no matter what's the button Enabled value.
I was in this case few weeks ago and this question doesn't have an answer, so this is my solution 4 years later :
I'm using this solution to repaint the ToolStripButton in many cases : disabled, checked, selected
override OnPaint event or change renderer of your ToolStrip
draw your image without grey filter with this method, just set the image of the button and image's position on your button : http://msdn.microsoft.com/en-us/library/chas0s9c(v=vs.110).aspx
Two good examples who helped me :
http://tutorials.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Customizing_a_Renderer
http://jskiles1.wordpress.com/2009/08/22/33/)
ToolStrip class :
ToolStrip ts = new ToolStrip();
//[...]
ts.RenderMode = ToolStripRenderMode.Professional; //Professional is just an example
ts.Renderer = new CustomRenderer();
CustomRenderer class :
public class CustomRenderer: ToolStripProfessionalRenderer
{
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
{
if (!e.Item.Enabled) //in this case you will just have the image in your button, you need to add text etc in this if
{
//to draw the image
Graphics g = e.Graphics;
g.DrawImageUnscaled(e.Item.Image, new Point(2, 2)); //you need to specify the correct position
}
else //other cases
base.OnRenderButtonBackground(e);
}
}
The problem is to know the correct position of all elements in your ToolStripButton , that's why I drawn the ToolStripButton in every cases
Another way: don't set the button.Enabled = false at all. Just set the button.Checked = true or false and when someone clicks on the button test for the Checked state and do whatever you do. The button will then function as you want and stay colored too.

Categories