Changes

→‎Concepts: + UI scaling
Line 90: Line 90:  
|}
 
|}
   −
In game code, this is represented by the <tt>Game1.options.zoomLevel</tt> field. Coordinates are generally adjusted for zoom level automatically, so you rarely need to account for this; but you can convert an unadjusted coordinate using <code>position * (1f / Game1.options.zoomLevel)</code> if needed.
+
; Effect on SMAPI mods
 +
: In game code, this is represented by the <tt>Game1.options.zoomLevel</tt> field. Coordinates are generally adjusted for zoom level automatically, so you rarely need to account for this; but you can convert an unadjusted coordinate using <code>position * (1f / Game1.options.zoomLevel)</code> if needed.
 +
 
 +
===UI scaling===
 +
The player can scale the UI between 75% and 150%, separately from and alongside the [[#Zoom level|zoom level]]. That adjusts the size of pixels shown on the screen for UI elements only. For example, here's a player with the same window size at different UI scaling levels:
 +
 
 +
{| class="wikitable"
 +
|-
 +
! min UI scale (75%)
 +
! max UI scale (150%)
 +
|-
 +
| [[File:UI scale 75.png|300px]]
 +
| [[File:UI scale 150.png|300px]]
 +
|}
 +
 
 +
; Effect on SMAPI mods
 +
: The game has two distinct scaling modes depending on the context: ''UI mode'' and ''non-UI mode''. You can check <tt>Game1.uiMode</tt> to know which mode is active. You should be careful not to mix UI and non-UI coordinates to avoid tricky calculations; for example, do all your work in one coordinate system and then convert them once.
 +
 
 +
: A quick reference of common scenarios:
 +
: {| class="wikitable"
 +
|-
 +
! context
 +
! scaling mode which applies
 +
|-
 +
| clickable menus
 +
| UI mode (usually)
 +
|-
 +
| HUD elements
 +
| UI mode
 +
|-
 +
| [[Modding:Modder Guide/APIs/Events#Display.RenderingActiveMenu|<tt>RenderingActiveMenu</tt>]]<br />[[Modding:Modder Guide/APIs/Events#Display.RenderedActiveMenu|<tt>RenderedActiveMenu</tt>]]
 +
| UI mode
 +
|-
 +
| [[Modding:Modder Guide/APIs/Events#Display.Rendering|<tt>Rendering</tt>]]<br />[[Modding:Modder Guide/APIs/Events#Display.Rendering|<tt>Rendered</tt>]]
 +
| depends on the context; check <tt>Game1.uiMode</tt>
 +
|-
 +
| <tt>draw</tt> method for world objects
 +
| non-UI mode
 +
|-
 +
| tile (non-pixel) coordinates
 +
| not affected by UI scaling
 +
|}
 +
 
 +
: If you need to draw UI when the game isn't in UI mode, you can explicitly set UI scaling mode:
 +
: <source lang="c#">Game1.game1.InUIMode(() =>
 +
{
 +
  // your UI draw code here
 +
});
 +
</source>
 +
 
 +
: In UI mode, you should usually replace <tt>Game1.viewport</tt> with <tt>Game1.uiViewport</tt>. '''Don't''' do this if you'll adjust the positions for UI scaling separately, since double-conversion will give you incorrect results. You can convert between UI and non-UI coordinates using <tt>Utility.ModifyCoordinatesForUIScale</tt> and <tt>Utility.ModifyCoordinatesFromUIScale</tt>.
 +
 
 +
: You can test whether your mod accounts for this correctly by setting the zoom to maximum and the UI scale to minimum (i.e. have them at opposite values) or vice versa; in particular check any logic which handles pixel positions, like menus clicking.
    
==Main classes==
 
==Main classes==
translators
8,404

edits