Changes

Jump to navigation Jump to search
1,462 bytes added ,  06:48, 12 November 2021
Add Create UIs Section
Line 14: Line 14:     
After defining the UI, it is a matter of assigning an instance of that class to <code>Game1.activeClickableMenu</code>. We'll look at how to do both in detail below.
 
After defining the UI, it is a matter of assigning an instance of that class to <code>Game1.activeClickableMenu</code>. We'll look at how to do both in detail below.
 +
 +
== Creating UIs ==
 +
 +
=== Define your UI ===
 +
 +
The general steps you want to take are as follows:
 +
 +
# Create a new class (preferably in a new .cs file), that implements <code>IClickableMenu</code>
 +
# Create constants / readonly fields that define the:-
 +
## X, Y positions of the UI.
 +
## Width and Height of the UI dialogue box.
 +
# Declare all the UI elements that you going to be a part of your UI.
 +
## Usually this means creating fields like, e.g., OkButton or Title, etc. of types <code>ClickableTextureComponent</code> and <code>ClickableComponent</code> (both of which are under the <code>StartdewValley.Menus</code> namespace).
 +
# Initialize all the declared UI elements, either in constructor or in a method called by the constructor.
 +
# Override method in the <code>IClickableMenu</code> abstract class, to add desired behaviour to the UI.
 +
## Behaviour like handling clicks on the UI, reacting to cursor hovering over any element. Both of those are handled by the methods <code>void receiveLeftClick(...)</code> and <code>void performHoverAction(...)</code>.
 +
# Override the <code>void draw(...)</code> method to draw all the UI and UI elements you declared and set up, to the screen.
 +
## This method is called by Stardew Valley's draw code every render tick whenever your UI is actively displayed.
 +
## The latter statements draw '''over''' the earlier statment's output. So things like the cursor should always be drawn at last so they are on top of everything else.
21

edits

Navigation menu