Dem1se

995 bytes added ,  06:51, 12 November 2021
Add first two sections of additional info
Line 121: Line 121:  
     }
 
     }
 
}
 
}
 +
</syntaxhighlight>
 +
 +
== Important Info ==
 +
 +
=== The Screen Positions ===
 +
 +
The number literals used in the UI element initializations and to define the UI dialog's contants are pixel values that represent the UI's [[Modding:Modder_Guide/Game_Fundamentals#Positions | positions]] in the screen.
 +
 +
The top-left corner of the screen is (0, 0) and increases across to the right and downwards.
 +
 +
=== Accounting for Scaling ===
 +
 +
Stardew valley video settings has an option to increase or decrease the UI scale which causes all the UI in the game to appear larger or smaller. This needs to be accounted for if you want your UI to be centered properly on the screen without being offset to either side.
 +
 +
This can be done by dividing with the UI Scale option.
 +
 +
<syntaxhighlight lang="c#">
 +
// Scaling accounted for
 +
int XPos = (int)(Game1.viewport.Width * Game1.options.zoomLevel * (1 / Game1.options.uiScale)) / 2 - (UIWidth / 2);
 +
 +
// Scaling unaccounted
 +
int XPos = (Game1.viewport.Width / 2) - (UIWidth / 2);
 
</syntaxhighlight>
 
</syntaxhighlight>
21

edits