Skip to content

Commit

Permalink
Merge pull request #985 from enigmaquip/master
Browse files Browse the repository at this point in the history
Fix Christmas Trees
  • Loading branch information
enigmaquip authored Apr 27, 2017
2 parents 81372bf + c8fc02b commit c61bdbe
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 11 deletions.
9 changes: 9 additions & 0 deletions TEditXna/Editor/Tools/ArrowTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public override void MouseUp(TileMouseState e)
}
_wvm.SelectedRack = RackLocation;
}
else if (curTile.Type == 171)
{
Vector2Int32 XmasLocation = _wvm.CurrentWorld.GetXmas(e.Location.X, e.Location.Y);
_wvm.SelectedXmasStar = _wvm.CurrentWorld.Tiles[XmasLocation.X, XmasLocation.Y].V & 7;
_wvm.SelectedXmasGarland = (_wvm.CurrentWorld.Tiles[XmasLocation.X, XmasLocation.Y].V >> 3) & 7;
_wvm.SelectedXmasBulb = (_wvm.CurrentWorld.Tiles[XmasLocation.X, XmasLocation.Y].V >> 6) & 0xf;
_wvm.SelectedXmasLight = (_wvm.CurrentWorld.Tiles[XmasLocation.X, XmasLocation.Y].V >> 10) & 0xf;
_wvm.SelectedXmas = XmasLocation;
}
}
}
}
23 changes: 22 additions & 1 deletion TEditXna/Editor/Tools/SpriteTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,28 @@ public override void MouseDown(TileMouseState e)
{
if (_wvm.SelectedSprite == null)
return;
if (_wvm.SelectedSprite.Size.X > 1 || _wvm.SelectedSprite.Size.Y > 1)
if (_wvm.SelectedSprite.Tile == 171)
{
for (int x = 0; x < _wvm.SelectedSprite.Size.X; x++)
{
int tilex = x + e.Location.X;
for (int y = 0; y < _wvm.SelectedSprite.Size.Y; y++)
{
int tiley = y + e.Location.Y;
_wvm.UndoManager.SaveTile(tilex, tiley);
Tile curtile = _wvm.CurrentWorld.Tiles[tilex, tiley];
curtile.IsActive = true;
curtile.Type = _wvm.SelectedSprite.Tile;
if (x == 0 && y == 0)
curtile.U = 10;
else
curtile.U = (short)x;
curtile.V = (short)y;
_wvm.UpdateRenderPixel(tilex, tiley);
}
}
}
else if (_wvm.SelectedSprite.Size.X > 1 || _wvm.SelectedSprite.Size.Y > 1)
{
Vector2Short[,] tiles = _wvm.SelectedSprite.GetTiles();
for (int x = 0; x < _wvm.SelectedSprite.Size.X; x++)
Expand Down
11 changes: 11 additions & 0 deletions TEditXna/Terraria/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ public Vector2Int32 GetRack(int x, int y)
return new Vector2Int32(x, y);
}

public Vector2Int32 GetXmas(int x, int y)
{
Tile tile = Tiles[x, y];
if (tile.U < 10)
{
x -= tile.U;
y -= tile.V;
}
return new Vector2Int32(x, y);
}

// find upper left corner of sprites
public Vector2Int32 GetAnchor(int x, int y)
{
Expand Down
135 changes: 127 additions & 8 deletions TEditXna/View/SpecialTileView.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<UserControl x:Class="TEditXna.View.SpecialTileView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:enum="clr-namespace:TEdit.UI.Xaml.Enum"
xmlns:System="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">

<UserControl.Resources>
Expand Down Expand Up @@ -95,10 +97,62 @@
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type GroupBox}" x:Key="XmasVisiblity" BasedOn="{StaticResource {x:Type GroupBox}}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedSpecialTile}" Value="6">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
<enum:EnumItemList x:Key="XmasStarCollection" EnumType="{x:Type System:Int32}" SortBy="Value" >
<enum:EnumItem Value="0">None</enum:EnumItem>
<enum:EnumItem Value="1">Star Topper 1</enum:EnumItem>
<enum:EnumItem Value="2">Star Topper 2</enum:EnumItem>
<enum:EnumItem Value="3">Star Topper 3</enum:EnumItem>
<enum:EnumItem Value="4">Bow Topper</enum:EnumItem>
</enum:EnumItemList>
<enum:EnumItemList x:Key="XmasGarlandCollection" EnumType="{x:Type System:Int32}" SortBy="Value" >
<enum:EnumItem Value="0">None</enum:EnumItem>
<enum:EnumItem Value="1">White</enum:EnumItem>
<enum:EnumItem Value="2">White and Red</enum:EnumItem>
<enum:EnumItem Value="3">Red</enum:EnumItem>
<enum:EnumItem Value="4">Red and Green</enum:EnumItem>
<enum:EnumItem Value="5">Green</enum:EnumItem>
<enum:EnumItem Value="6">Green and White</enum:EnumItem>
</enum:EnumItemList>
<enum:EnumItemList x:Key="XmasBulbCollection" EnumType="{x:Type System:Int32}" SortBy="Value" >
<enum:EnumItem Value="0">None</enum:EnumItem>
<enum:EnumItem Value="1">Multicolored</enum:EnumItem>
<enum:EnumItem Value="2">Red</enum:EnumItem>
<enum:EnumItem Value="3">Yellow</enum:EnumItem>
<enum:EnumItem Value="4">Green</enum:EnumItem>
<enum:EnumItem Value="5">Red and Green</enum:EnumItem>
<enum:EnumItem Value="6">Yellow and Green</enum:EnumItem>
<enum:EnumItem Value="7">Red and Yellow</enum:EnumItem>
<enum:EnumItem Value="8">White</enum:EnumItem>
<enum:EnumItem Value="9">White and Red</enum:EnumItem>
<enum:EnumItem Value="10">White and Yellow</enum:EnumItem>
<enum:EnumItem Value="11">White and Green</enum:EnumItem>
</enum:EnumItemList>
<enum:EnumItemList x:Key="XmasLightCollection" EnumType="{x:Type System:Int32}" SortBy="Value" >
<enum:EnumItem Value="0">None</enum:EnumItem>
<enum:EnumItem Value="1">Multicolored</enum:EnumItem>
<enum:EnumItem Value="2">Red</enum:EnumItem>
<enum:EnumItem Value="3">Green</enum:EnumItem>
<enum:EnumItem Value="4">Blue</enum:EnumItem>
<enum:EnumItem Value="5">Yellow</enum:EnumItem>
<enum:EnumItem Value="6">Red and Yellow</enum:EnumItem>
<enum:EnumItem Value="7">Red and Green</enum:EnumItem>
<enum:EnumItem Value="8">Yellow and Green</enum:EnumItem>
<enum:EnumItem Value="9">Blue and Green</enum:EnumItem>
<enum:EnumItem Value="10">Red and Blue</enum:EnumItem>
<enum:EnumItem Value="11">Blue and Yellow</enum:EnumItem>
</enum:EnumItemList>
</UserControl.Resources>
<Grid Background="{DynamicResource WindowBackgroundBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid Background="{DynamicResource WindowBackgroundBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<GroupBox BorderThickness="0" Style="{StaticResource InstructionsVisiblity}">
<TextBlock Text="With the Arrow Tool right click on a sign, chest, mannequin, weapon rack or item frame" TextWrapping="Wrap" HorizontalAlignment="Stretch" Margin="3" FontWeight="Bold" Foreground="{DynamicResource TextBrush}"/>
<TextBlock Text="With the Arrow Tool right click on a sign, chest, mannequin, weapon rack,item frame or christmas tree" TextWrapping="Wrap" HorizontalAlignment="Stretch" Margin="3" FontWeight="Bold" Foreground="{DynamicResource TextBrush}"/>
</GroupBox>
<GroupBox BorderThickness="0" Style="{StaticResource SignVisiblity}">
<Grid Background="{DynamicResource WindowBackgroundBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
Expand Down Expand Up @@ -129,7 +183,7 @@
</TextBlock.Text>
</TextBlock>
</StackPanel>
<TextBox Grid.Row="2" Text="{Binding SelectedSign.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="150"
<TextBox Grid.Row="2" Text="{Binding SelectedSign.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="150"
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" TextWrapping="Wrap"
Margin="2" FontWeight="Bold" MaxLines="10" PreviewKeyDown="ValidateLines" />
<UniformGrid Columns="2" Grid.Row="4">
Expand All @@ -151,7 +205,7 @@
<StackPanel Orientation="Horizontal" Grid.Row="0">
<TextBlock Text="Chest Name: " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" VerticalAlignment="Center" />
<TextBox Margin="2" Width="100px" Height="20px" MaxLength="20" MaxLines="1" Text="{Binding SelectedChest.Name}" />
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Chest Type: " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" VerticalAlignment="Center" />
<ComboBox Width="150px"
Expand Down Expand Up @@ -238,7 +292,7 @@
<TextBlock Text="Mannequin Clothing " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" />
<TextBlock Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" DockPanel.Dock="Top">
<TextBlock.Text>
<MultiBinding StringFormat="({0:0}, {1:0})">
<MultiBinding StringFormat="({0}, {1})">
<Binding Path="SelectedMannequin.X" />
<Binding Path="SelectedMannequin.Y" />
</MultiBinding>
Expand Down Expand Up @@ -326,5 +380,70 @@
</UniformGrid>
</Grid>
</GroupBox>
<GroupBox BorderThickness="0" Style="{StaticResource XmasVisiblity}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<TextBlock Text="Christmas Tree Decorations " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" />
<TextBlock Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" DockPanel.Dock="Top">
<TextBlock.Text>
<MultiBinding StringFormat="({0:D}, {1:D})">
<Binding Path="SelectedXmas.X" />
<Binding Path="SelectedXmas.Y" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Star: " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" VerticalAlignment="Center" Width="90px"/>
<ComboBox Width="150px"
ItemsSource="{StaticResource XmasStarCollection}"
SelectedValue="{Binding SelectedXmasStar, Mode=TwoWay}"
SelectedValuePath="Value"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Stretch" Margin="1,0" ItemsPanel="{StaticResource Template_ComboPanel}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Garlands: " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" VerticalAlignment="Center" Width="90px"/>
<ComboBox Width="150px"
ItemsSource="{StaticResource XmasGarlandCollection}"
SelectedValue="{Binding SelectedXmasGarland, Mode=TwoWay}"
SelectedValuePath="Value"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Stretch" Margin="1,0" ItemsPanel="{StaticResource Template_ComboPanel}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="Bulbs: " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" VerticalAlignment="Center" Width="90px"/>
<ComboBox Width="150px"
ItemsSource="{StaticResource XmasBulbCollection}"
SelectedValue="{Binding SelectedXmasBulb, Mode=TwoWay}"
SelectedValuePath="Value"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Stretch" Margin="1,0" ItemsPanel="{StaticResource Template_ComboPanel}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4">
<TextBlock Text="Lights: " Foreground="{DynamicResource TextBrush}" Margin="2" FontWeight="Bold" VerticalAlignment="Center" Width="90px"/>
<ComboBox Width="150px"
ItemsSource="{StaticResource XmasLightCollection}"
SelectedValue="{Binding SelectedXmasLight, Mode=TwoWay}"
SelectedValuePath="Value"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Stretch" Margin="1,0" ItemsPanel="{StaticResource Template_ComboPanel}" />
</StackPanel>
<UniformGrid Columns="2" Grid.Row="5">
<Button Margin="2" Content="Cancel" Command="{Binding SaveXmasCommand}"
CommandParameter="{StaticResource False}" />
<Button Margin="2" Content="Save" Command="{Binding SaveXmasCommand}"
CommandParameter="{StaticResource True}" />
</UniformGrid>
</Grid>
</GroupBox>
</Grid>
</UserControl>
2 changes: 2 additions & 0 deletions TEditXna/View/WorldRenderXna.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ private void LoadTerrariaTextures(GraphicsDeviceEventArgs e)
for (int y = 0; y < sprite.Size.Y; y++)
{
var source = new Rectangle(x * (tile.TextureGrid.X + 2) + sprite.Origin.X, y * (tile.TextureGrid.Y + 2) + sprite.Origin.Y, tile.TextureGrid.X, tile.TextureGrid.Y);
if (sprite.Tile == 171)
source = new Rectangle(x * (tile.TextureGrid.X) + sprite.Origin.X, y * (tile.TextureGrid.Y) + sprite.Origin.Y, tile.TextureGrid.X, tile.TextureGrid.Y);
if (source.Bottom > tileTex.Height)
source.Height -= (source.Bottom - tileTex.Height);
if (source.Right > tileTex.Width)
Expand Down
25 changes: 25 additions & 0 deletions TEditXna/ViewModel/WorldViewModel.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public partial class WorldViewModel
private ICommand _saveChestCommand;
private ICommand _saveSignCommand;
private ICommand _saveMannCommand;
private ICommand _saveXmasCommand;
private ICommand _saveTileEntityCommand;
private ICommand _saveRackCommand;
private ICommand _npcRemoveCommand;
Expand Down Expand Up @@ -127,6 +128,11 @@ public ICommand SaveMannCommand
get { return _saveMannCommand ?? (_saveMannCommand = new RelayCommand<bool>(SaveMannequin)); }
}

public ICommand SaveXmasCommand
{
get { return _saveXmasCommand ?? (_saveXmasCommand = new RelayCommand<bool>(SaveXmasTree)); }
}

public ICommand SaveTileEntityCommand
{
get { return _saveTileEntityCommand ?? (_saveTileEntityCommand = new RelayCommand<bool>(SaveTileEntity)); }
Expand Down Expand Up @@ -170,6 +176,25 @@ private void SaveMannequin(bool save)
}
}

private void SaveXmasTree(bool save)
{
if (save)
{
if (SelectedXmas != null)
{
int tree = SelectedXmasStar;
tree += (SelectedXmasGarland << 3);
tree += (SelectedXmasBulb << 6);
tree += (SelectedXmasLight << 10);
CurrentWorld.Tiles[SelectedXmas.X, SelectedXmas.Y].V = (short)tree;
}
}
else
{
SelectedSpecialTile = 0;
}
}

private void SaveSign(bool save)
{
if (save)
Expand Down
42 changes: 41 additions & 1 deletion TEditXna/ViewModel/WorldViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public partial class WorldViewModel : ViewModelBase
private TileEntity _selectedItemFrame;
private Vector2Int32 _selectedMannequin;
private Vector2Int32 _selectedRack;
private Vector2Int32 _selectedXmas;
private int _selectedXmasStar;
private int _selectedXmasGarland;
private int _selectedXmasBulb;
private int _selectedXmasLight;
private byte _selectedRackPrefix;
private int _selectedRackNetId;
private int _selectedMannHead;
Expand Down Expand Up @@ -269,6 +274,41 @@ public int SelectedRackNetId
set { Set("SelectedRackNetId", ref _selectedRackNetId, value); }
}

public Vector2Int32 SelectedXmas
{
get { return _selectedXmas; }
set
{
Set("SelectedXmas", ref _selectedXmas, value);
SelectedTabIndex = 1;
SelectedSpecialTile = 6;
}
}

public int SelectedXmasStar
{
get { return _selectedXmasStar; }
set { Set("SelectedXmasStar", ref _selectedXmasStar, value); }
}

public int SelectedXmasGarland
{
get { return _selectedXmasGarland; }
set { Set("SelectedXmasGarland", ref _selectedXmasGarland, value); }
}

public int SelectedXmasBulb
{
get { return _selectedXmasBulb; }
set { Set("SelectedXmasBulb", ref _selectedXmasBulb, value); }
}

public int SelectedXmasLight
{
get { return _selectedXmasLight; }
set { Set("SelectedXmasLight", ref _selectedXmasLight, value); }
}

public Sign SelectedSign
{
get { return _selectedSign; }
Expand Down Expand Up @@ -609,7 +649,7 @@ public async void CheckVersion(bool auto = true)
var versions = Regex.Match(githubReleases, versionRegex);

isoutofdate = versions.Success && IsVersionNewerThanApplicationVersion(versions?.Groups?[1].Value);

// ignore revision, build should be enough
// if ((revis != -1) && (revis > App.Version.ProductPrivatePart)) return true;
}
Expand Down
Loading

0 comments on commit c61bdbe

Please sign in to comment.