Changes

985 bytes added ,  21:21, 1 November 2019
expand menu info
Line 223: Line 223:     
==User-interface (UI)==
 
==User-interface (UI)==
   
The User-interface (UI) is a collection of separate elements which make up the HUD and occasional popups.
 
The User-interface (UI) is a collection of separate elements which make up the HUD and occasional popups.
    
//TODO: This section needs to be expanded.  Please contribute if you have knowledge in this area.
 
//TODO: This section needs to be expanded.  Please contribute if you have knowledge in this area.
      
===Banner message===
 
===Banner message===
Line 273: Line 271:  
</source>
 
</source>
   −
==Menus==
+
===Active clickable menu===
 
+
An ''active clickable menu'' is a UI drawn over everything else which accepts user input. For example, the game menu (shown in-game when you hit {{key|ESC}} or controller {{key|B}}) is an active clickable menu. The menu is stored in <code>Game1.activeClickableMenu</code>; if that field has a non-null value, the menu will be drawn and receive input automatically.
// TODO: describe section
  −
 
  −
 
  −
===Get the Active Menu===
  −
You can use ''Reflection'' to get the current active menu in ''GameMenu''. The ''GameMenu'' contains the Inventory, Skills, Social, Map, Crafting, Collections, and Options pages in this respective order, accessed by the tab index with ''inventoryTab'' at 0.
      +
Each menu is different, so you need to look at the menu code to know how to interact with it. Since mods often need to get the current tab on the game menu, here's an example which handles the map tab:
 
<source lang="c#">
 
<source lang="c#">
if (Game1.activeClickableMenu is GameMenu menu) {
+
if (Game1.activeClickableMenu is GameMenu menu)
 +
{
 +
  // get the tab pages
 
   IList<IClickableMenu> pages = this.Helper.Reflection.GetField<List<IClickableMenu>>(menu, "pages").GetValue();
 
   IList<IClickableMenu> pages = this.Helper.Reflection.GetField<List<IClickableMenu>>(menu, "pages").GetValue();
  IClickableMenu page = pages[menu.currentTab];
     −
   // Example for getting the MapPage
+
   // option A: check tab ID
   MapPage mapPage = (MapPage) pages[menu.currentTab];
+
   if (menu.currentTab == GameMenu.mapTab)
 +
  {
 +
    ...
 +
  }
   −
   // Two examples of checking if MapPage is open
+
   // option B: check page type
   pages[menu.currentTab] is MapPage || menu.currentTab == GameMenu.mapTab;
+
   switch (pages[menu.currentTab])
 +
  {
 +
    case MapPage mapPage:
 +
      ...
 +
      break;
 +
  }
 
}
 
}
 
</source>
 
</source>
   −
 
+
To create a custom menu, you need to create a subclass of <tt>IClickableMenu</tt> and assign it to <tt>Game1.activeClickableMenu</tt>. At its most basic, a menu is basically just a few methods you override (usually <tt>draw</tt> and <tt>receiveLeftClick</tt> at a minimum). When <tt>draw</tt> is called, you draw whatever you want to the screen; when <tt>receiveLeftClick</tt> is called, you check if it's within one of the clickable areas and handle it. Normally you'd use some convenience classes like <tt>ClickableTextureButton</tt> (which has a texture and position, and simplifies checking if they were clicked), though that's not strictly necessary. Here's [https://github.com/janavarro95/Stardew_Valley_Mods/blob/master/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs a simple menu] you can use as an example, which draws the birthday menu for {{nexus mod|520|Birthday Mod}}.
===Set the Active Menu===
  −
Game1.activeClickableMenu = <Menu>
  −
 
  −
 
  −
===Simple Menu===
  −
Copy the menu you want from the game and make it your own
  −
 
  −
 
      
===DialogueBox===
 
===DialogueBox===
   
[[File:DialogueBox_NoChoices_Example.jpg|200px|thumb|right|Example of DialogueBox without choices.]]A '''DialogueBox''' is a text box with a slightly larger, slightly boldfaced text, with "typewriter-like" effect.
 
[[File:DialogueBox_NoChoices_Example.jpg|200px|thumb|right|Example of DialogueBox without choices.]]A '''DialogueBox''' is a text box with a slightly larger, slightly boldfaced text, with "typewriter-like" effect.
  
translators
8,446

edits