Model-view-Controller c# bring the gui and the model together - c#

I am making the game of minesweeper and I wrote the game all on the gui in c#. I want to now work on the model-view aspect of things and I need help bringing the gui together with the model.
Meaning:
I made a call called MinesweeperModel which in it will contain a 10 x 10 grid[,] of values. If the grid has a bomb the value will be -1 if not it will be 0. In the model view all of the methods are written there, like NewGame(), GameOver(), SetUp(), GameLogicChecker()(this checks if there are any bombs and assigns the square a value to how many bombs it is near) etc. However in the gui aspect of things I have a similar grid of buttons[,] which are also 10X10. What I am trying to do is when I click on a button that coordinate will correspond to a coordinate in the model grid, and therefore the method created in the model grid can work on the buttons as well. But I am not exactly sure how to bring it together.
Thanks!

You could go through and add button click events to each button by double clicking it in the gui editor. Then having it call the GameLogicChecker() function inside of it. Maybe you could give a little bit more information I'm not quite sure what your asking for.

Related

Get List of Animators in Script

I've got a UI menu in world space with camera flying around the canvases (representing the menu sections).
As for buttons I made some animations with separate animator for each button, so that I click "Single Player", for example, and the buttons in this canvas should be replaced (using animations) with other buttons that're outside the canvas and vice versa (when I hit "Back").
The thing is that I wanted to use List UIAnimators in the UIGameObject that holds all scripts to the scene. The problem is that Unity seems unable to receive Lists when I set the script to the button onClick thing. It doesn't show the methods with Lists at all. Is there a way to walk around it. So I can trigger several controllers in the same script, since I need to replace several buttons in the canvas using controllers of each one. Just looking for some tips, no coding needed, or maybe there are some references or tutorials. I'd really appreciate some help.
Menu layout, just to get a picture of the idea
Thanks in advance!
I am not entirely sure that I am following but if I understand correctly then you want to have a collection of different UI Elements and use the OnClick events from the Buttons to activate the corresponding animations for multiple elements at once.
Not sure if it is the best solution but you can make an array on the parent game object with all of your buttons with their animators and then with the OnClick event call a public function that plays the animation for the corresponding index
public void MyFunction(int index)
{
myUIElements[index].GetComponent<Animator>().Play();
}
Then just add multiple calls to that function with indices for all of the elements that you want to animate when that button is clicked as below:

Display labels in horizontal tree [treeView] Windows Forms

I am working now on the project for my client, which is something like Display Editor, where user can add display, write something in it etc... Every display is connected to another display, by that I mean, it has Parent, Left/Right Sibling and Child. Its practically linked list. And you can jump from one display to another with arrows keys Up, Left, Right and Down. All this is completely okay. My problem is, that client want something like treeView, but horizontal. Because when I use normal treeView, Display dont match with the arrows rules (Up,Left etc...), Its vice versa.
I was desperate so I created my own Control, where I am adding Labels and every time new Node is added I am changing Location of already exists Labels. Here are some images.
Second child of "Right Sibling"
"Right Sibling
But as you can see, its not looking very nice and also its not very good for using. Also I cant figure how to delete there, because location changing when deleting something is too much complicated. I searched a lot and I saw like thousand articles, but everything useful is for WPF and I am using Windows Forms, that is the problem. I am afraid I will have to figure it out, but first I am calling for help. Thank you.

Converting GUI from C# to Java

I'm trying to convert a form which I currently have in C# to Java, utilising layout managers. And it's turning out to be a nightmare.
I've tried setting the sizes of the components, however no difference is present. Also, I cannot get the labels and textboxes to move closer to each other.
For all of the buttons and text fields, just put then in a Panel that has nothing but that one item in it. That will prevent the button/textfield from filling the entire space in the layout.
Other than that the only thing it seems you need to do is put a bit of a margin around the whole thing so that your items aren't right up against the edges of the window.
Try GridBagLayout instead of GridLayout.
GridLayout forces all components to be the same size.
See also javax.swing.Box, to put the label - text field pairs in one pane.

WPF animation to create new object and swap old one out of view

I have for example a rectangle in a grid and I have a button "new" I want to make a new rectangle like the exist one and I want to make animation using c# to transfer the old rectangle to right out of View and transfer the new one from left to be on the show and I have a button back to reverse the animation and I want this animation everytime I press new and back how ?
I'm not exactly sure if this is what you are looking for. The way to go with Animations is to use Storyboards. MSDN has excellent code examples for this:
Check out: http://msdn.microsoft.com/en-us/library/ms742868.aspx
To execute your storyboard you can use Trigger. In your case would want to listen for Click events. An example can also be found in the link above (although they are using a different event).
I hope that helps you.

c#/java Drag points and draw lines between them

Hey,
is there a a simple way in c# or java to let the user "drop" points onto the form and then draw lines between the new point and existing ones ?
with simple way i mean a component/framework/whatever (or even already existend in c#/java ?)
Sure; it'll be framework and architecture dependent though. C# WPF will have a different way to do it then C# WinForms which will be different than Java Swing.
For Winforms, you'll simply create a Graphics object based on some area of your form bounded by a control (like a Panel or PictureBox), then on that Control's MouseClick event, log the mouse's current location and draw a line between that location and the location of the previous click (or all other clicks).
If you want to drag and drop, like from a toolbar, that's a little more complex; basically you need to track what you dragged and where you dropped it so when you drop it you can perform the proper action. I believe the arguments you'll get in the DragDrop handler will give you this information.
I am not aware of any lib that does that, but what I did to simplify things a bit is created usercontrol 2x2 which represented a point and allowed user to drop it onto form by drag and drop. Lines were drawn manually, however, in OnPaint(...)

Categories