Skip to content

Commit

Permalink
v1.6.4.4
Browse files Browse the repository at this point in the history
* Fixed portal zooming properly
  • Loading branch information
hamstar committed Jul 24, 2017
1 parent 3b0ca9f commit c45e029
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
32 changes: 18 additions & 14 deletions Wormholes/WormholePortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,28 @@ public void AnimateOpen( int? amt=null ) {

public void DrawForMe() {
if( this.IsClosed ) { return; }

int screen_wid = (int)((float)Main.screenWidth / Main.GameZoomTarget);
int screen_hei = (int)((float)Main.screenHeight / Main.GameZoomTarget);
int screen_x = (int)Main.screenPosition.X + ((Main.screenWidth - screen_wid) / 2);
int screen_y = (int)Main.screenPosition.Y + ((Main.screenHeight - screen_hei) / 2);
var screen_pos = new Vector2( screen_x, screen_y );
var screen_rect = new Rectangle( screen_x, screen_y, screen_wid, screen_hei );
if( !this.Rect.Intersects(screen_rect) ) { return; }

//float zoom = Main.GameZoomTarget;
//float zoom_scr_wid = (float)Main.screenWidth / zoom;
//float zoom_scr_hei = (float)Main.screenHeight / zoom;
//float zoom_world_scr_x = Main.screenPosition.X + ((Main.screenWidth - zoom_scr_wid) / 2);
//float zoom_world_scr_y = Main.screenPosition.Y + ((Main.screenHeight - zoom_scr_hei) / 2);
//var zoom_world_scr_pos = new Vector2( zoom_world_scr_x, zoom_world_scr_y );
//var zoom_world_scr_rect = new Rectangle( (int)zoom_world_scr_x, (int)zoom_world_scr_y, (int)zoom_scr_wid, (int)zoom_scr_hei );

var world_scr_rect = new Rectangle( (int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight );
if( !this.Rect.Intersects( world_scr_rect ) ) { return; }
Vector2 world_scr_pos = Main.screenPosition;

this.Animator.Animate();

var offset = this.Animator.GetPositionOffset();
var pos = ((this.Pos - screen_pos) + offset) * Main.GameZoomTarget;
//var color = this.Animator.GetColorFlicker();
var color = this.BaseColor;
var scale = this.Animator.GetScale() * Main.GameZoomTarget;
Vector2 offset = this.Animator.GetPositionOffset();
Vector2 scr_scr_pos = ((this.Pos - world_scr_pos) + offset);//* zoom;
//Color color = this.Animator.GetColorFlicker();
Color color = this.BaseColor;
Vector2 scale = this.Animator.GetScale();//* zoom;

Main.spriteBatch.Draw( WormholePortal.Tex, pos, this.Animator.Frame, color, 0f, new Vector2(), scale, SpriteEffects.None, 1f );
Main.spriteBatch.Draw( WormholePortal.Tex, scr_scr_pos, this.Animator.Frame, color, 0f, new Vector2(), scale, SpriteEffects.None, 1f );

Dust.NewDust( this.Pos, this.Rect.Width, this.Rect.Height, 15, 0, 0, 150, color, 1f );
}
Expand Down
16 changes: 11 additions & 5 deletions WormholesPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HamstarHelpers.MiscHelpers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.ModLoader;
Expand Down Expand Up @@ -39,8 +38,12 @@ public override void clientClone( ModPlayer clone ) {


public override void Load( TagCompound tag ) {
var modworld = this.mod.GetModWorld<WormholesWorld>();
int wormholes = tag.GetInt( "wormholes_count" );


this.TownPortalRightPositions = new Dictionary<string, Vector2>();
this.TownPortalLeftPositions = new Dictionary<string, Vector2>();

for( int i = 0; i < wormholes; i++ ) {
string id = tag.GetString( "wormhole_id_"+i );
if( id == "" ) { continue; }
Expand All @@ -54,9 +57,11 @@ public override void Load( TagCompound tag ) {
float right_y = tag.GetFloat( "my_town_right_portal_y_" + i );
float left_x = tag.GetFloat( "my_town_left_portal_x_" + i );
float left_y = tag.GetFloat( "my_town_left_portal_y_" + i );
var right = new Vector2( right_x, right_y );
var left = new Vector2( left_x, left_y );

this.TownPortalRightPositions[ world_id ] = new Vector2( right_x, right_y );
this.TownPortalLeftPositions[ world_id ] = new Vector2( left_x, left_y );
this.TownPortalRightPositions[ world_id ] = right;
this.TownPortalLeftPositions[ world_id ] = left;
}
}

Expand Down Expand Up @@ -95,6 +100,7 @@ public override TagCompound Save() {
tags.Set( "my_town_right_portal_y_" + i, this.TownPortalRightPositions[id].Y );
tags.Set( "my_town_left_portal_x_" + i, this.TownPortalLeftPositions[id].X );
tags.Set( "my_town_left_portal_y_" + i, this.TownPortalLeftPositions[id].Y );
//ErrorLogger.Log( "save for "+id+": "+this.TownPortalLeftPositions[id]+", "+this.TownPortalRightPositions[id] );
i++;
}

Expand Down
8 changes: 6 additions & 2 deletions WormholesWorld.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using Terraria;
Expand Down Expand Up @@ -95,7 +96,10 @@ public override void PostDrawTiles() {
var myplayer = Main.player[Main.myPlayer].GetModPlayer<WormholesPlayer>( this.mod );
var mymod = (WormholesMod)this.mod;

Main.spriteBatch.Begin();
//Main.spriteBatch.Begin();
RasterizerState rasterizer = Main.gameMenu || (double)Main.player[Main.myPlayer].gravDir == 1.0 ? RasterizerState.CullCounterClockwise : RasterizerState.CullClockwise;
Main.spriteBatch.Begin( SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, rasterizer, (Effect)null, Main.GameViewMatrix.TransformationMatrix );

try {
this.Wormholes.DrawAll( mymod, myplayer.MyPortal );
} catch( Exception e ) {
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = hamstar
version = 1.6.4.3
version = 1.6.4.4
displayName = Wormholes
modReferences = HamstarHelpers
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*
Expand Down

0 comments on commit c45e029

Please sign in to comment.