Skip to content

Commit

Permalink
Merge pull request #951 from hyamw/master
Browse files Browse the repository at this point in the history
+ Add plugin for find plantera bulb
  • Loading branch information
BinaryConstruct authored Apr 15, 2017
2 parents 8203687 + 26edb1f commit ed868e6
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TEditXna/Editor/Plugins/FindChestWithPluginResultView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<Button Margin="5" Content="Close" HorizontalAlignment="Center" Padding="20, 3" Click="CloseButtonClick" />
</Grid>

<ListBox Name="LocationList"/>
<ListBox Name="LocationList" MouseDoubleClick="ListBoxMouseDoubleClick"/>
</DockPanel>
</Window>
27 changes: 27 additions & 0 deletions TEditXna/Editor/Plugins/FindChestWithPluginResultView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace TEditXna.Editor.Plugins
/// </summary>
public partial class FindChestWithPluginResultView : Window
{
private char[] splitters = new char[] { ',' };
public FindChestWithPluginResultView(IEnumerable<Vector2> locations)
{
InitializeComponent();
Expand All @@ -33,5 +34,31 @@ public void CloseButtonClick(object sender, RoutedEventArgs routedEventArgs)
{
this.Close();
}

private void ListBoxMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if ( e.OriginalSource is TextBlock )
{
TextBlock item = e.OriginalSource as TextBlock;
if ( !string.IsNullOrEmpty(item.Text) )
{
string[] positions = item.Text.Split(splitters);
if ( positions.Length == 2 )
{
int x = 0;
int y = 0;

if ( int.TryParse(positions[0].Trim(), out x) && int.TryParse(positions[1].Trim(), out y) )
{
MainWindow mainwin = Application.Current.MainWindow as MainWindow;
if (mainwin != null)
{
mainwin.ZoomFocus(x, y);
}
}
}
}
}
}
}
}
62 changes: 62 additions & 0 deletions TEditXna/Editor/Plugins/FindPlanteraBulbPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using TEditXna.ViewModel;
using TEditXNA.Terraria;

namespace TEditXna.Editor.Plugins
{
class FindPlanteraBulbPlugin : BasePlugin
{
public FindPlanteraBulbPlugin(WorldViewModel worldViewModel)
: base(worldViewModel)
{
Name = "Find Plantera's Bulb";
}

public override void Execute()
{
if (_wvm.CurrentWorld == null) return;

List<Vector2> locations = new List<Vector2>();

// Search the whole World
for (int x = 0; x < _wvm.CurrentWorld.TilesWide; x++)
{
for (int y = 0; y < _wvm.CurrentWorld.TilesHigh; y++)
{
// Check if a tile is a chest
if (_wvm.CurrentWorld.Tiles[x, y].Type == (int)TileType.PlanteraBulb)
{
if (!findConnectedTitle(locations, x, y))
{
locations.Add(new Vector2(x, y));
}
}
}
}

// show the result view with the list of locations
FindChestWithPluginResultView resultView = new FindChestWithPluginResultView(locations);
resultView.Show();
}

protected bool findConnectedTitle(List<Vector2> locations, int x, int y)
{
Vector2 position;
for ( int i = 0; i < locations.Count; i++ )
{
position = locations[i];
if ( Math.Abs((int)position.X - x) <= 1 && Math.Abs((int)position.Y - y) <= 1 )
{
return true;
}
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion TEditXna/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
</TabItem>
</TabControl>
</Expander>
<View:WorldRenderXna HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<View:WorldRenderXna x:Name="MapView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</DockPanel>
</Grid>
</Window>
8 changes: 8 additions & 0 deletions TEditXna/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,13 @@ private void SetActiveTool(string toolName)
_vm.SetTool.Execute(tool);
}

public void ZoomFocus(int x, int y)
{
if (this.MapView != null)
{
this.MapView.ZoomFocus(x, y);
}
}

}
}
2 changes: 1 addition & 1 deletion TEditXna/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//

[assembly: AssemblyVersion("3.9.0.0")]
[assembly: AssemblyFileVersion("3.9.16348.0006")]
[assembly: AssemblyFileVersion("3.9.16365.0959")]


[assembly: XmlnsDefinition("http://tedit/wpf", "TEdit.UI.Xaml")]
Expand Down
3 changes: 2 additions & 1 deletion TEditXna/TEditXna.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="Editor\Plugins\FindChestWithPluginResultView.xaml.cs">
<DependentUpon>FindChestWithPluginResultView.xaml</DependentUpon>
</Compile>
<Compile Include="Editor\Plugins\FindPlanteraBulbPlugin.cs" />
<Compile Include="Editor\Plugins\IPlugin.cs" />
<Compile Include="Editor\Plugins\PerlinNoise.cs" />
<Compile Include="Editor\Plugins\RemoveAllChestsPlugin.cs" />
Expand Down Expand Up @@ -566,4 +567,4 @@
<!--<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
1 change: 1 addition & 0 deletions TEditXna/Terraria/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum TileType : int
EbonsandBlock = 112,
PearlsandBlock = 116,
CrimsandBlock = 234,
PlanteraBulb = 238,
IceByRod = 127,
Timer = 144,
AnnouncementBox = 425,
Expand Down
15 changes: 15 additions & 0 deletions TEditXna/View/WorldRenderXna.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,21 @@ public void Zoom(int direction)
}
}

public void ZoomFocus(int x, int y)
{
_zoom = 8;
CenterOnTile(x, y);

if (_wvm.CurrentWorld != null)
{
var r = GetViewingArea();
ScrollBarH.ViewportSize = r.Width;
ScrollBarV.ViewportSize = r.Height;
ScrollBarH.Maximum = _wvm.CurrentWorld.TilesWide - ScrollBarH.ViewportSize;
ScrollBarV.Maximum = _wvm.CurrentWorld.TilesHigh - ScrollBarV.ViewportSize;
}
}



private void xnaViewport_HwndMButtonDown(object sender, HwndMouseEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions TEditXna/ViewModel/ViewModelLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private static WorldViewModel CreateWorldViewModel()
wvm.Plugins.Add(new RemoveAllUnlockedChestsPlugin(wvm));
wvm.Plugins.Add(new UnlockAllChestsPlugin(wvm));
wvm.Plugins.Add(new FindChestWithPlugin(wvm));
wvm.Plugins.Add(new FindPlanteraBulbPlugin(wvm));
return wvm;
}
}
Expand Down
2 changes: 1 addition & 1 deletion teditversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.9.0.0
v3.9.16365.0959

0 comments on commit ed868e6

Please sign in to comment.