Skip to content

Commit

Permalink
v1.0.1 - Fixed emitter pseudo-tiles not scaling with game zoom
Browse files Browse the repository at this point in the history
* Fixed emitter pseudo-tiles not scaling with game zoom
* Added setting to restrict emitter distance
* Reset emitters on world load (ModWorld.Initialize)
* Fixed UISliders not handling arrow clicks well
  • Loading branch information
hamstar0 committed Apr 27, 2020
1 parent ec67651 commit 59e1195
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 20 deletions.
22 changes: 17 additions & 5 deletions Emitters/EmitterDefinition_Draw.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using HamstarHelpers.Helpers.Debug;
using HamstarHelpers.Helpers.UI;
using Emitters.Items;


Expand All @@ -19,14 +21,18 @@ public void Draw( int tileX, int tileY, bool isOnScreen ) {
////////////////

public void DrawEmitter( int tileX, int tileY ) {
Vector2 pos = Main.screenPosition;
int scrX = (tileX<<4) - (int)pos.X;
int scrY = (tileY<<4) - (int)pos.Y;
Vector2 scr = UIHelpers.ConvertToScreenPosition( new Vector2(tileX<<4, tileY<<4) );

Main.spriteBatch.Draw(
texture: EmittersMod.Instance.Emitter,
position: new Vector2(scrX, scrY),
color: Color.White
position: scr,
sourceRectangle: null,
color: Color.White,
rotation: 0f,
origin: default(Vector2),
scale: Main.GameZoomTarget,
effects: SpriteEffects.None,
layerDepth: 1f
);
}

Expand All @@ -44,6 +50,12 @@ public void AnimateEmitter( Vector2 worldPos ) {
}
this.Timer = 0;

int maxDistSqr = EmittersConfig.Instance.DustEmitterMinimumRangeBeforeEmit;
maxDistSqr *= maxDistSqr;
if( (Main.LocalPlayer.Center - worldPos).LengthSquared() >= maxDistSqr ) {
return;
}

if( this.IsGoreMode ) {
var scatter = new Vector2(
Main.rand.NextFloat() * this.Scatter,
Expand Down
2 changes: 2 additions & 0 deletions Emitters/Libraries/Classes/UI/UISlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public partial class UISlider : UIThemedElement {
////////////////

private UITextInputElement NumericInput;
private UIThemedText LeftArrowElem;
private UIThemedText RightArrowElem;

private bool IsNowSettingValue = false;

Expand Down
26 changes: 13 additions & 13 deletions Emitters/Libraries/Classes/UI/UISlider_Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ bool ProcessInput( StringBuilder fullInput ) {
this.NumericInput.OnTextChange += ProcessInput;
this.Append( this.NumericInput );

var leftArrowElem = new UIThemedText( this.Theme, true, " < " );
leftArrowElem.Height.Set( 24f, 0f );
leftArrowElem.OnMouseOver += ( _, __ ) => leftArrowElem.TextColor = Color.Yellow;
leftArrowElem.OnMouseOut += ( _, __ ) => leftArrowElem.TextColor = Color.White;
leftArrowElem.OnClick += ( _, __ ) => this.ScrollLeft();
this.Append( (UIElement)leftArrowElem );
this.LeftArrowElem = new UIThemedText( this.Theme, true, " < " );
this.LeftArrowElem.Height.Set( 24f, 0f );
this.LeftArrowElem.OnMouseOver += ( _, __ ) => this.LeftArrowElem.TextColor = Color.Yellow;
this.LeftArrowElem.OnMouseOut += ( _, __ ) => this.LeftArrowElem.TextColor = Color.Gray;
this.LeftArrowElem.OnClick += ( _, __ ) => this.ScrollLeft();
this.Append( (UIElement)this.LeftArrowElem );

var rightArrowElem = new UIThemedText( this.Theme, true, " > " );
rightArrowElem.Left.Set( -30f, 1f );
rightArrowElem.Height.Set( 24f, 0f );
rightArrowElem.OnMouseOver += ( _, __ ) => rightArrowElem.TextColor = Color.Yellow;
rightArrowElem.OnMouseOut += ( _, __ ) => rightArrowElem.TextColor = Color.White;
rightArrowElem.OnClick += ( _, __ ) => this.ScrollRight();
this.Append( (UIElement)rightArrowElem );
this.RightArrowElem = new UIThemedText( this.Theme, true, " > " );
this.RightArrowElem.Left.Set( -30f, 1f );
this.RightArrowElem.Height.Set( 24f, 0f );
this.RightArrowElem.OnMouseOver += ( _, __ ) => this.RightArrowElem.TextColor = Color.Yellow;
this.RightArrowElem.OnMouseOut += ( _, __ ) => this.RightArrowElem.TextColor = Color.Gray;
this.RightArrowElem.OnClick += ( _, __ ) => this.ScrollRight();
this.Append( (UIElement)this.RightArrowElem );
}
}
}
7 changes: 6 additions & 1 deletion Emitters/Libraries/Classes/UI/UISlider_Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ private void UpdateMouseInteractivity() {
return;
}

//Rectangle rect = this.GetInnerDimensions().ToRectangle();
Rectangle rect = this.GetInnerRectangle();
if( !rect.Contains( Main.mouseX, Main.mouseY ) ) {
return;
}
if( this.LeftArrowElem.GetOuterDimensions().ToRectangle().Contains(Main.mouseX, Main.mouseY) ) {
return;
}
if( this.RightArrowElem.GetOuterDimensions().ToRectangle().Contains(Main.mouseX, Main.mouseY) ) {
return;
}

UISlider.SelectedSlider = this;

Expand Down
31 changes: 31 additions & 0 deletions Emitters/MyConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.ComponentModel;
using Terraria.ModLoader.Config;
using HamstarHelpers.Services.Configs;


namespace Emitters {
//class MyFloatInputElement : FloatInputElement { }
//[CustomModConfigItem( typeof( MyFloatInputElement ) )]




public partial class EmittersConfig : StackableModConfig {
public static EmittersConfig Instance => ModConfigStack.GetMergedConfigs<EmittersConfig>();



////////////////

public override ConfigScope Mode => ConfigScope.ServerSide;



////////////////

[Range( 16 * 16, 16 * 1000 )]
[DefaultValue( 16 * 96 )]
public int DustEmitterMinimumRangeBeforeEmit { get; set; } = 16 * 96;
}
}
6 changes: 6 additions & 0 deletions Emitters/MyWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ private IDictionary<ushort, IDictionary<ushort, EmitterDefinition>> Emitters



////////////////

public override void Initialize() {
this.Emitters.Clear();
}

////////////////

public override void Load( TagCompound tag ) {
Expand Down
2 changes: 1 addition & 1 deletion Emitters/build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Emitters
author = hamstar
version = 1.0.0.2
version = 1.0.1
modReferences = [email protected]
buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\*
homepage = https://forums.terraria.org/index.php?threads/emitters.87584/

0 comments on commit 59e1195

Please sign in to comment.