Skip to content

Commit

Permalink
Added InitializeUiSystem and InitializeInputHandler to MlemGame to al…
Browse files Browse the repository at this point in the history
…low overriding default initialization
  • Loading branch information
Ellpeck committed Jan 8, 2025
1 parent b5cea03 commit 0250580
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ Improvements
Fixes
- Fixed DataTextureAtlas creating unnamed entries if there are empty lines at the start or end of the atlas file

### MLEM.Startup
Additions
- Added InitializeUiSystem and InitializeInputHandler to MlemGame to allow overriding default initialization

## 7.1.1

### MLEM
Expand Down
23 changes: 21 additions & 2 deletions MLEM.Startup/MlemGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public MlemGame(int windowWidth = 1280, int windowHeight = 720) {
/// </summary>
protected override void LoadContent() {
this.SpriteBatch = new SpriteBatch(this.GraphicsDevice);
this.InputHandler = new InputHandler(this);
this.InputHandler = this.InitializeInputHandler();
this.Components.Add(this.InputHandler);
this.UiSystem = new UiSystem(this, this.InitializeDefaultUiStyle(this.SpriteBatch), this.InputHandler);
this.UiSystem = this.InitializeUiSystem(this.InitializeDefaultUiStyle(this.SpriteBatch));
this.Components.Add(this.UiSystem);
this.OnLoadContent?.Invoke(this);
}
Expand Down Expand Up @@ -151,6 +151,25 @@ protected virtual UiStyle InitializeDefaultUiStyle(SpriteBatch batch) {
return new UntexturedStyle(batch);
}

/// <summary>
/// This method is called in <see cref="LoadContent"/> when the <see cref="UiSystem"/> is initialized.
/// Override this method to easily modify or create a new <see cref="MLEM.Ui.UiSystem"/> for this game.
/// </summary>
/// <param name="style">The ui style to use, gathered from <see cref="InitializeDefaultUiStyle"/>.</param>
/// <returns>The <see cref="MLEM.Ui.UiSystem"/> to use for this game.</returns>
protected virtual UiSystem InitializeUiSystem(UiStyle style) {
return new UiSystem(this, style, this.InputHandler);
}

/// <summary>
/// This method is called in <see cref="LoadContent"/> when the <see cref="InputHandler"/> is initialized.
/// Override this method to easily modify or create a new <see cref="MLEM.Input.InputHandler"/> for this game.
/// </summary>
/// <returns>The <see cref="MLEM.Input.InputHandler"/> to use for this game.</returns>
protected virtual InputHandler InitializeInputHandler() {
return new InputHandler(this);
}

/// <summary>
/// Static helper method for <see cref="ContentManager.Load{T}"/>.
/// This just invokes the game instance's load method.
Expand Down

0 comments on commit 0250580

Please sign in to comment.