fixed assets loading incorrectly occasionally

This commit is contained in:
Ellpeck 2020-06-29 00:41:49 +02:00
parent caa5a92382
commit efbe1a64ac
11 changed files with 109 additions and 78 deletions

View file

@ -50,7 +50,7 @@
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot> <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies> <BundleAssemblies>false</BundleAssemblies>
<MandroidI18n /> <MandroidI18n />
<AndroidPackageFormat>aab</AndroidPackageFormat> <AndroidPackageFormat>apk</AndroidPackageFormat>
<AndroidUseAapt2>true</AndroidUseAapt2> <AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidCreatePackagePerAbi>false</AndroidCreatePackagePerAbi> <AndroidCreatePackagePerAbi>false</AndroidCreatePackagePerAbi>
</PropertyGroup> </PropertyGroup>
@ -81,7 +81,7 @@
<PackageReference Include="Contentless" Version="3.0.0" /> <PackageReference Include="Contentless" Version="3.0.0" />
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.1" /> <PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.1" />
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" /> <PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
<PackageReference Include="MonoGame.Framework.Android" Version="3.8.0.1375-develop" /> <PackageReference Include="MonoGame.Framework.Android" Version="3.7.1.189" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\TouchyTickets\TouchyTickets.csproj"> <ProjectReference Include="..\TouchyTickets\TouchyTickets.csproj">

View file

@ -2,9 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.ellpeck.touchytickets" android:installLocation="auto" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.ellpeck.touchytickets" android:installLocation="auto"
android:versionCode="100" android:versionName="1.0.0"> android:versionCode="100" android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
<application android:label="Touchy Tickets" android:resizeableActivity="false"> <application android:label="Touchy Tickets" android:resizeableActivity="true"/>
<meta-data android:name="android.max_aspect" android:value="2.1"/>
</application>
<permission android:name="ACCESS_NETWORK_STATE"/> <permission android:name="ACCESS_NETWORK_STATE"/>
<permission android:name="INTERNET"/> <permission android:name="INTERNET"/>
</manifest> </manifest>

35
TouchyTickets/Assets.cs Normal file
View file

@ -0,0 +1,35 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Startup;
using MLEM.Textures;
namespace TouchyTickets {
public static class Assets {
public static UniformTextureAtlas TilesTexture { get; private set; }
public static UniformTextureAtlas AttractionTexture { get; private set; }
public static UniformTextureAtlas UiTexture { get; private set; }
public static SoundEffect ClickSound { get; private set; }
public static SoundEffect PlaceSound { get; private set; }
public static SoundEffect BuySound { get; private set; }
public static Vector2 TileSize { get; private set; }
public static SpriteFont Font { get; private set; }
public static void Load() {
TilesTexture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Tiles"), 16, 16);
AttractionTexture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Attractions"), 16, 16);
UiTexture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Ui"), 16, 16);
ClickSound = MlemGame.LoadContent<SoundEffect>("Sounds/Click");
PlaceSound = MlemGame.LoadContent<SoundEffect>("Sounds/Place");
BuySound = MlemGame.LoadContent<SoundEffect>("Sounds/StarBuy");
TileSize = new Vector2(AttractionTexture.RegionWidth, AttractionTexture.RegionHeight);
Font = MlemGame.LoadContent<SpriteFont>("Fonts/Regular");
}
}
}

View file

@ -16,9 +16,6 @@ namespace TouchyTickets.Attractions {
[DataContract] [DataContract]
public class Attraction { public class Attraction {
public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Attractions"), 16, 16);
public static readonly Vector2 TileSize = new Vector2(Texture.RegionWidth, Texture.RegionHeight);
[DataMember] [DataMember]
public readonly List<ActiveModifier> Modifiers = new List<ActiveModifier>(); public readonly List<ActiveModifier> Modifiers = new List<ActiveModifier>();
[DataMember] [DataMember]
@ -54,7 +51,7 @@ namespace TouchyTickets.Attractions {
if (this.animationSizeModifier > 0) if (this.animationSizeModifier > 0)
drawScale += (float) Math.Sin(this.animationSizeModifier) * 0.05F; drawScale += (float) Math.Sin(this.animationSizeModifier) * 0.05F;
var center = this.Type.TextureRegion.Size.ToVector2() / 2; var center = this.Type.TextureRegion.Size.ToVector2() / 2;
batch.Draw(this.Type.TextureRegion, position + center * scale, Color.White * alpha, 0, center, drawScale, SpriteEffects.None, 0); batch.Draw(Assets.AttractionTexture[this.Type.TextureRegion], position + center * scale, Color.White * alpha, 0, center, drawScale, SpriteEffects.None, 0);
} }
public float GetGenerationRate(ParkMap map, Point position) { public float GetGenerationRate(ParkMap map, Point position) {

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Microsoft.Xna.Framework;
using MLEM.Textures; using MLEM.Textures;
using Newtonsoft.Json; using Newtonsoft.Json;
using static TouchyTickets.Attractions.AttractionFlags; using static TouchyTickets.Attractions.AttractionFlags;
@ -12,21 +13,21 @@ namespace TouchyTickets.Attractions {
public static readonly Dictionary<string, AttractionModifier> Modifiers = new Dictionary<string, AttractionModifier>(); public static readonly Dictionary<string, AttractionModifier> Modifiers = new Dictionary<string, AttractionModifier>();
static AttractionModifier() { static AttractionModifier() {
Register(new AttractionModifier("Lubricant", 200, Cars | FastCars, 1.02F, Ui.Texture[0, 4])); Register(new AttractionModifier("Lubricant", 200, Cars | FastCars, 1.02F, new Point(0, 4)));
Register(new AttractionModifier("LouderMusic", 500, Relaxed, 1.03F, Ui.Texture[2, 4])); Register(new AttractionModifier("LouderMusic", 500, Relaxed, 1.03F, new Point(2, 4)));
Register(new AttractionModifier("SmallAds", 800, Small, 1.5F, Ui.Texture[5, 4])); Register(new AttractionModifier("SmallAds", 800, Small, 1.5F, new Point(5, 4)));
Register(new AttractionModifier("LongerQueue", 1000, All, 1.06F, Ui.Texture[1, 4])); Register(new AttractionModifier("LongerQueue", 1000, All, 1.06F, new Point(1, 4)));
Register(new AttractionModifier("Bouncer", 1500, Walking, 1.2F, Ui.Texture[3, 4])); Register(new AttractionModifier("Bouncer", 1500, Walking, 1.2F, new Point(3, 4)));
Register(new AttractionModifier("OnRideCameras", 2500, FastCars, 1.1F, Ui.Texture[4, 4])); Register(new AttractionModifier("OnRideCameras", 2500, FastCars, 1.1F, new Point(4, 4)));
} }
public readonly string Name; public readonly string Name;
public readonly long InitialPrice; public readonly long InitialPrice;
public readonly TextureRegion Texture; public readonly Point Texture;
public readonly float Multiplier; public readonly float Multiplier;
private readonly AttractionFlags affectedFlags; private readonly AttractionFlags affectedFlags;
public AttractionModifier(string name, long initialPrice, AttractionFlags affectedFlags, float multiplier, TextureRegion texture) { public AttractionModifier(string name, long initialPrice, AttractionFlags affectedFlags, float multiplier, Point texture) {
this.Name = name; this.Name = name;
this.InitialPrice = initialPrice; this.InitialPrice = initialPrice;
this.affectedFlags = affectedFlags; this.affectedFlags = affectedFlags;

View file

@ -10,35 +10,35 @@ namespace TouchyTickets.Attractions {
public class AttractionType { public class AttractionType {
public static readonly Dictionary<string, AttractionType> Attractions = new Dictionary<string, AttractionType>(); public static readonly Dictionary<string, AttractionType> Attractions = new Dictionary<string, AttractionType>();
public static readonly AttractionType Carousel = Register(new AttractionType("Carousel", RectArea(1, 1), Attraction.Texture[0, 0, 1, 1], 0.5F, 50, Relaxed | Cars | Small)); public static readonly AttractionType Carousel = Register(new AttractionType("Carousel", RectArea(1, 1), new Rectangle(0, 0, 1, 1), 0.5F, 50, Relaxed | Cars | Small));
public static readonly AttractionType MirrorHouse = Register(new AttractionType("MirrorHouse", RectArea(1, 1), Attraction.Texture[3, 0, 1, 1], 1, 150, Relaxed | Walking | NonTechnology | Small)); public static readonly AttractionType MirrorHouse = Register(new AttractionType("MirrorHouse", RectArea(1, 1), new Rectangle(3, 0, 1, 1), 1, 150, Relaxed | Walking | NonTechnology | Small));
public static readonly AttractionType FoodCourt = Register(new AttractionType("FoodCourt", RectArea(2, 1), Attraction.Texture[1, 0, 2, 1], 2F, 300, None)); public static readonly AttractionType FoodCourt = Register(new AttractionType("FoodCourt", RectArea(2, 1), new Rectangle(1, 0, 2, 1), 2F, 300, None));
public static readonly AttractionType SpiralSlide = Register(new AttractionType("SpiralSlide", RectArea(1, 2), Attraction.Texture[5, 0, 1, 2], 4, 1200, Relaxed | Walking)); public static readonly AttractionType SpiralSlide = Register(new AttractionType("SpiralSlide", RectArea(1, 2), new Rectangle(5, 0, 1, 2), 4, 1200, Relaxed | Walking));
public static readonly AttractionType HedgeMaze = Register(new AttractionType("HedgeMaze", RectArea(2, 2), Attraction.Texture[3, 3, 2, 2], 8, 2500, Relaxed | Walking | NonTechnology)); public static readonly AttractionType HedgeMaze = Register(new AttractionType("HedgeMaze", RectArea(2, 2), new Rectangle(3, 3, 2, 2), 8, 2500, Relaxed | Walking | NonTechnology));
public static readonly AttractionType FerrisWheel = Register(new AttractionType("FerrisWheel", RectArea(2, 2), Attraction.Texture[0, 1, 2, 2], 12, 4000, Relaxed | Cars)); public static readonly AttractionType FerrisWheel = Register(new AttractionType("FerrisWheel", RectArea(2, 2), new Rectangle(0, 1, 2, 2), 12, 4000, Relaxed | Cars));
public static readonly AttractionType FreefallCoaster = Register(new AttractionType("FreefallCoaster", new[,] {{true, false, true}, {true, true, true}}, Attraction.Texture[6, 0, 3, 2], 24, 8000, FastCars)); public static readonly AttractionType FreefallCoaster = Register(new AttractionType("FreefallCoaster", new[,] {{true, false, true}, {true, true, true}}, new Rectangle(6, 0, 3, 2), 24, 8000, FastCars));
public static readonly AttractionType HauntedHouse = Register(new AttractionType("HauntedHouse", RectArea(2, 2), Attraction.Texture[3, 5, 2, 2], 30, 12000, FastCars)); public static readonly AttractionType HauntedHouse = Register(new AttractionType("HauntedHouse", RectArea(2, 2), new Rectangle(3, 5, 2, 2), 30, 12000, FastCars));
public static readonly AttractionType GoKarts = Register(new AttractionType("GoKarts", RectArea(2, 2), Attraction.Texture[5, 2, 2, 2], 50, 24000, Cars | Relaxed)); public static readonly AttractionType GoKarts = Register(new AttractionType("GoKarts", RectArea(2, 2), new Rectangle(5, 2, 2, 2), 50, 24000, Cars | Relaxed));
public static readonly AttractionType MiniGolf = Register(new AttractionType("MiniGolf", RectArea(2, 3), Attraction.Texture[9, 0, 2, 3], 75, 35000, Relaxed | Walking | NonTechnology)); public static readonly AttractionType MiniGolf = Register(new AttractionType("MiniGolf", RectArea(2, 3), new Rectangle(9, 0, 2, 3), 75, 35000, Relaxed | Walking | NonTechnology));
public static readonly AttractionType WildMouse = Register(new AttractionType("WildMouse", RectArea(3, 2), Attraction.Texture[2, 1, 3, 2], 100, 60000, FastCars)); public static readonly AttractionType WildMouse = Register(new AttractionType("WildMouse", RectArea(3, 2), new Rectangle(2, 1, 3, 2), 100, 60000, FastCars));
public static readonly AttractionType LogFlume = Register(new AttractionType("LogFlume", new[,] {{true, true, false}, {true, true, true}}, Attraction.Texture[0, 3, 3, 2], 160, 90000, FastCars)); public static readonly AttractionType LogFlume = Register(new AttractionType("LogFlume", new[,] {{true, true, false}, {true, true, true}}, new Rectangle(0, 3, 3, 2), 160, 90000, FastCars));
public static readonly AttractionType HeartlineTwister = Register(new AttractionType("HeartlineTwister", RectArea(4, 2), Attraction.Texture[5, 4, 4, 2], 250, 150000, FastCars)); public static readonly AttractionType HeartlineTwister = Register(new AttractionType("HeartlineTwister", RectArea(4, 2), new Rectangle(5, 4, 4, 2), 250, 150000, FastCars));
public static readonly AttractionType WoodCoaster = Register(new AttractionType("WoodCoaster", RectArea(3, 3), Attraction.Texture[0, 5, 3, 3], 300, 215000, FastCars)); public static readonly AttractionType WoodCoaster = Register(new AttractionType("WoodCoaster", RectArea(3, 3), new Rectangle(0, 5, 3, 3), 300, 215000, FastCars));
public static readonly AttractionType SafariZone = Register(new AttractionType("SafariZone", RectArea(5, 3), Attraction.Texture[11, 0, 5, 3], 600, 750000, Relaxed | Walking | NonTechnology)); public static readonly AttractionType SafariZone = Register(new AttractionType("SafariZone", RectArea(5, 3), new Rectangle(11, 0, 5, 3), 600, 750000, Relaxed | Walking | NonTechnology));
public readonly string Name; public readonly string Name;
public readonly bool[,] Area; public readonly bool[,] Area;
public int Width => this.Area.GetLength(1); public int Width => this.Area.GetLength(1);
public int Height => this.Area.GetLength(0); public int Height => this.Area.GetLength(0);
public readonly TextureRegion TextureRegion; public readonly Rectangle TextureRegion;
private readonly float generationPerSecond; private readonly float generationPerSecond;
public readonly long InitialPrice; public readonly long InitialPrice;
public readonly AttractionFlags Flags; public readonly AttractionFlags Flags;
public AttractionType(string name, bool[,] area, TextureRegion texture, float generationPerSecond, long initialPrice, AttractionFlags flags) { public AttractionType(string name, bool[,] area, Rectangle textureRegion, float generationPerSecond, long initialPrice, AttractionFlags flags) {
this.Name = name; this.Name = name;
this.Area = area; this.Area = area;
this.TextureRegion = texture; this.TextureRegion = textureRegion;
this.generationPerSecond = generationPerSecond; this.generationPerSecond = generationPerSecond;
this.InitialPrice = initialPrice; this.InitialPrice = initialPrice;
this.Flags = flags; this.Flags = flags;

View file

@ -31,6 +31,7 @@ namespace TouchyTickets {
protected override void LoadContent() { protected override void LoadContent() {
base.LoadContent(); base.LoadContent();
Assets.Load();
Options.Load(); Options.Load();
// start the load sequence // start the load sequence

View file

@ -15,7 +15,6 @@ namespace TouchyTickets {
[DataContract] [DataContract]
public class ParkMap { public class ParkMap {
private static readonly UniformTextureAtlas TilesTexture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Tiles"), 16, 16);
private const int AdditionalRadius = 15; private const int AdditionalRadius = 15;
[DataMember] [DataMember]
public readonly int Width; public readonly int Width;
@ -89,7 +88,7 @@ namespace TouchyTickets {
} else if (MlemGame.Input.GetGesture(GestureType.FreeDrag, out var drag)) { } else if (MlemGame.Input.GetGesture(GestureType.FreeDrag, out var drag)) {
if (this.draggingAttraction) { if (this.draggingAttraction) {
// move the current placing position // move the current placing position
var nextPos = (camera.ToWorldPos(drag.Position + drag.Delta) / Attraction.TileSize).ToPoint(); var nextPos = (camera.ToWorldPos(drag.Position + drag.Delta) / Assets.TileSize).ToPoint();
// drag the center of the attraction // drag the center of the attraction
nextPos -= new Point(this.PlacingAttraction.Type.Width / 2, this.PlacingAttraction.Type.Height / 2); nextPos -= new Point(this.PlacingAttraction.Type.Width / 2, this.PlacingAttraction.Type.Height / 2);
if (this.PlacingAttraction.Type.GetCoveredTiles().Select(p => nextPos + p).All(this.IsInBounds)) if (this.PlacingAttraction.Type.GetCoveredTiles().Select(p => nextPos + p).All(this.IsInBounds))
@ -103,14 +102,14 @@ namespace TouchyTickets {
if (touch.State != TouchLocationState.Pressed) if (touch.State != TouchLocationState.Pressed)
continue; continue;
// when first pressing down, go into attraction drag mode if we're touching the place location // when first pressing down, go into attraction drag mode if we're touching the place location
var offset = (camera.ToWorldPos(touch.Position) / Attraction.TileSize).ToPoint(); var offset = (camera.ToWorldPos(touch.Position) / Assets.TileSize).ToPoint();
this.draggingAttraction = this.PlacingAttraction.Type.GetCoveredTiles() this.draggingAttraction = this.PlacingAttraction.Type.GetCoveredTiles()
.Any(p => this.PlacingPosition + p == offset); .Any(p => this.PlacingPosition + p == offset);
} }
} else { } else {
// we're not placing an attraction, so we're in remove and move mode // we're not placing an attraction, so we're in remove and move mode
if (MlemGame.Input.GetGesture(GestureType.Tap, out var tap) && GameImpl.Instance.UiSystem.Controls.GetElementUnderPos(tap.Position) == null) { if (MlemGame.Input.GetGesture(GestureType.Tap, out var tap) && GameImpl.Instance.UiSystem.Controls.GetElementUnderPos(tap.Position) == null) {
var pos = (camera.ToWorldPos(tap.Position) / Attraction.TileSize).ToPoint(); var pos = (camera.ToWorldPos(tap.Position) / Assets.TileSize).ToPoint();
var attraction = this.GetAttractionAt(pos); var attraction = this.GetAttractionAt(pos);
if (attraction != null && (this.PlacingModifier == null || this.PlacingModifier.IsAffected(attraction))) { if (attraction != null && (this.PlacingModifier == null || this.PlacingModifier.IsAffected(attraction))) {
// actually select the top left for easy usage later // actually select the top left for easy usage later
@ -120,12 +119,12 @@ namespace TouchyTickets {
} }
} }
} }
camera.ConstrainWorldBounds(new Vector2(-AdditionalRadius) * Attraction.TileSize, new Vector2(this.Width + AdditionalRadius, this.Height + AdditionalRadius) * Attraction.TileSize); camera.ConstrainWorldBounds(new Vector2(-AdditionalRadius) * Assets.TileSize, new Vector2(this.Width + AdditionalRadius, this.Height + AdditionalRadius) * Assets.TileSize);
} }
} }
public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, bool showSurroundings, RectangleF visibleArea) { public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, bool showSurroundings, RectangleF visibleArea) {
var tileSize = Attraction.TileSize * scale; var tileSize = Assets.TileSize * scale;
// draw ground // draw ground
var additionalRadius = showSurroundings ? AdditionalRadius : 0; var additionalRadius = showSurroundings ? AdditionalRadius : 0;
var minX = Math.Max(-additionalRadius, visibleArea.Left / tileSize.X).Floor(); var minX = Math.Max(-additionalRadius, visibleArea.Left / tileSize.X).Floor();
@ -136,12 +135,12 @@ namespace TouchyTickets {
for (var y = minY; y < maxY; y++) { for (var y = minY; y < maxY; y++) {
var pos = new Vector2(x, y); var pos = new Vector2(x, y);
var drawPos = position + pos * tileSize; var drawPos = position + pos * tileSize;
batch.Draw(TilesTexture[0, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); batch.Draw(Assets.TilesTexture[0, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
if (this.fencePositions.TryGetValue(pos.ToPoint(), out var fenceType)) { if (this.fencePositions.TryGetValue(pos.ToPoint(), out var fenceType)) {
batch.Draw(TilesTexture[fenceType, 1], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); batch.Draw(Assets.TilesTexture[fenceType, 1], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
} else if (this.treePositions.TryGetValue(pos.ToPoint(), out var treeType)) { } else if (this.treePositions.TryGetValue(pos.ToPoint(), out var treeType)) {
batch.Draw(TilesTexture[1 + treeType, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); batch.Draw(Assets.TilesTexture[1 + treeType, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
} }
} }
} }

View file

@ -27,7 +27,7 @@ namespace TouchyTickets {
} }
public void Draw(SpriteBatch batch, Vector2 viewport, float scale, Color color) { public void Draw(SpriteBatch batch, Vector2 viewport, float scale, Color color) {
var tex = Ui.Texture[2, 0]; var tex = Assets.UiTexture[2, 0];
batch.Draw(tex, this.position * viewport, color, this.rotation, tex.Size.ToVector2() / 2, scale, SpriteEffects.None, 0); batch.Draw(tex, this.position * viewport, color, this.rotation, tex.Size.ToVector2() / 2, scale, SpriteEffects.None, 0);
} }

View file

@ -22,7 +22,6 @@ using TouchyTickets.Attractions;
namespace TouchyTickets { namespace TouchyTickets {
public class Ui { public class Ui {
public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Ui"), 16, 16);
private static readonly BigInteger[] ExpoNums = Enumerable.Range(0, Localization.NumberFormat.Count).Select(i => BigInteger.Pow(1000, i + 1)).ToArray(); private static readonly BigInteger[] ExpoNums = Enumerable.Range(0, Localization.NumberFormat.Count).Select(i => BigInteger.Pow(1000, i + 1)).ToArray();
private readonly UiSystem uiSystem; private readonly UiSystem uiSystem;
private readonly Element[] swipeRelations; private readonly Element[] swipeRelations;
@ -32,11 +31,6 @@ namespace TouchyTickets {
public Ui(UiSystem uiSystem) { public Ui(UiSystem uiSystem) {
this.uiSystem = uiSystem; this.uiSystem = uiSystem;
this.uiSystem.Style.ActionSound = new SoundEffectInfo(MlemGame.LoadContent<SoundEffect>("Sounds/Click"), 0.5F);
this.uiSystem.TextFormatter.AddImage("ticket", Texture[2, 0]);
this.uiSystem.TextFormatter.AddImage("star", Texture[3, 0]);
foreach (var modifier in AttractionModifier.Modifiers.Values)
this.uiSystem.TextFormatter.AddImage(modifier.Name, modifier.Texture);
// main ticket store ui // main ticket store ui
var rainingTickets = new List<RainingTicket>(); var rainingTickets = new List<RainingTicket>();
@ -87,7 +81,7 @@ namespace TouchyTickets {
} }
} }
}); });
storeGroup.AddChild(new Image(Anchor.TopLeft, Vector2.One, Texture[0, 0, 2, 3]) { storeGroup.AddChild(new Image(Anchor.TopLeft, Vector2.One, Assets.UiTexture[0, 0, 2, 3]) {
OnPressed = e => { OnPressed = e => {
var rate = 1; var rate = 1;
if (Upgrade.TapIncrease[2].IsActive()) { if (Upgrade.TapIncrease[2].IsActive()) {
@ -109,7 +103,7 @@ namespace TouchyTickets {
Padding = new Padding(6, 6, 12, 6), Padding = new Padding(6, 6, 12, 6),
OnDrawn = (e, time, batch, alpha) => { OnDrawn = (e, time, batch, alpha) => {
var map = GameImpl.Instance.Map; var map = GameImpl.Instance.Map;
var mapSize = new Vector2(map.Width, map.Height) * Attraction.TileSize; var mapSize = new Vector2(map.Width, map.Height) * Assets.TileSize;
var (scaleX, scaleY) = e.DisplayArea.Size / mapSize; var (scaleX, scaleY) = e.DisplayArea.Size / mapSize;
var scale = Math.Min(scaleX, scaleY); var scale = Math.Min(scaleX, scaleY);
var pos = e.DisplayArea.Location + (e.DisplayArea.Size - mapSize * scale) / 2; var pos = e.DisplayArea.Location + (e.DisplayArea.Size - mapSize * scale) / 2;
@ -126,7 +120,7 @@ namespace TouchyTickets {
OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name)) OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name))
}); });
infoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Remove")) { infoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Remove")) {
ActionSound = new SoundEffectInfo(MlemGame.LoadContent<SoundEffect>("Sounds/Place")), ActionSound = new SoundEffectInfo(Assets.PlaceSound),
OnPressed = e2 => { OnPressed = e2 => {
if (map.SelectedPosition == null) if (map.SelectedPosition == null)
return; return;
@ -161,7 +155,7 @@ namespace TouchyTickets {
var map = GameImpl.Instance.Map; var map = GameImpl.Instance.Map;
map.PlacingAttraction = attraction.Value.Create(); map.PlacingAttraction = attraction.Value.Create();
// set placing position to center of camera's view // set placing position to center of camera's view
var (posX, posY) = (GameImpl.Instance.Camera.LookingPosition / Attraction.TileSize).ToPoint(); var (posX, posY) = (GameImpl.Instance.Camera.LookingPosition / Assets.TileSize).ToPoint();
map.PlacingPosition = new Point(MathHelper.Clamp(posX, 0, map.Width - attraction.Value.Width), MathHelper.Clamp(posY, 0, map.Height - attraction.Value.Height)); map.PlacingPosition = new Point(MathHelper.Clamp(posX, 0, map.Width - attraction.Value.Width), MathHelper.Clamp(posY, 0, map.Height - attraction.Value.Height));
var yesNoUi = new Group(Anchor.BottomLeft, new Vector2(1)); var yesNoUi = new Group(Anchor.BottomLeft, new Vector2(1));
@ -169,7 +163,7 @@ namespace TouchyTickets {
OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name)) OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name))
}); });
yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Place")) { yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Place")) {
ActionSound = new SoundEffectInfo(MlemGame.LoadContent<SoundEffect>("Sounds/Place")), ActionSound = new SoundEffectInfo(Assets.PlaceSound),
OnPressed = e2 => { OnPressed = e2 => {
GameImpl.Instance.Tickets -= price; GameImpl.Instance.Tickets -= price;
GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", price, "Attraction", attraction.Key); GameImpl.Instance.Platform.AddResourceEvent(true, "Tickets", price, "Attraction", attraction.Key);
@ -192,7 +186,7 @@ namespace TouchyTickets {
price = (long) Math.Ceiling(attraction.Value.InitialPrice * Math.Pow(1 + 0.1F, attractionAmount)); price = (long) Math.Ceiling(attraction.Value.InitialPrice * Math.Pow(1 + 0.1F, attractionAmount));
} }
}); });
var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), attraction.Value.TextureRegion) { var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), Assets.AttractionTexture[attraction.Value.TextureRegion]) {
Padding = new Vector2(4) Padding = new Vector2(4)
}); });
var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1), false) {CanBeMoused = false}); var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1), false) {CanBeMoused = false});
@ -233,7 +227,7 @@ namespace TouchyTickets {
OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name)) OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name))
}); });
var addButton = infoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), string.Empty) { var addButton = infoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), string.Empty) {
ActionSound = new SoundEffectInfo(MlemGame.LoadContent<SoundEffect>("Sounds/Place")), ActionSound = new SoundEffectInfo(Assets.PlaceSound),
OnPressed = e2 => { OnPressed = e2 => {
if (map.SelectedPosition == null) if (map.SelectedPosition == null)
return; return;
@ -282,7 +276,7 @@ namespace TouchyTickets {
this.FadeUi(true); this.FadeUi(true);
} }
}); });
var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), modifier.Texture) { var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), Assets.UiTexture[modifier.Texture]) {
Padding = new Vector2(4) Padding = new Vector2(4)
}); });
var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1)) {CanBeMoused = false}); var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1)) {CanBeMoused = false});
@ -322,7 +316,7 @@ namespace TouchyTickets {
upgradeHeader.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.Stars + "<i star>", true) {TextScale = 0.3F}); upgradeHeader.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.Stars + "<i star>", true) {TextScale = 0.3F});
upgradeHeader.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.8F, 30), Localization.Get("EarnStar")) { upgradeHeader.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.8F, 30), Localization.Get("EarnStar")) {
PositionOffset = new Vector2(0, 4), PositionOffset = new Vector2(0, 4),
ActionSound = new SoundEffectInfo(MlemGame.LoadContent<SoundEffect>("Sounds/StarBuy")), ActionSound = new SoundEffectInfo(Assets.BuySound),
OnUpdated = (e, time) => ((Button) e).IsDisabled = GameImpl.Instance.GetBuyableStars() <= 0, OnUpdated = (e, time) => ((Button) e).IsDisabled = GameImpl.Instance.GetBuyableStars() <= 0,
OnPressed = e => { OnPressed = e => {
var infoBox = new Group(Anchor.TopLeft, Vector2.One, false) { var infoBox = new Group(Anchor.TopLeft, Vector2.One, false) {
@ -449,10 +443,15 @@ namespace TouchyTickets {
uiSystem.GlobalScale = 4; uiSystem.GlobalScale = 4;
uiSystem.AutoScaleWithScreen = true; uiSystem.AutoScaleWithScreen = true;
uiSystem.AutoScaleReferenceSize = new Point(720, 1280); uiSystem.AutoScaleReferenceSize = new Point(720, 1280);
uiSystem.Style.Font = new GenericSpriteFont(MlemGame.LoadContent<SpriteFont>("Fonts/Regular")); uiSystem.Style.Font = new GenericSpriteFont(Assets.Font);
uiSystem.Style.PanelTexture = uiSystem.Style.ScrollBarBackground = new NinePatch(Texture[2, 1], 4); uiSystem.Style.PanelTexture = uiSystem.Style.ScrollBarBackground = new NinePatch(Assets.UiTexture[2, 1], 4);
uiSystem.Style.ButtonTexture = uiSystem.Style.ScrollBarScrollerTexture = new NinePatch(Texture[3, 1], 4); uiSystem.Style.ButtonTexture = uiSystem.Style.ScrollBarScrollerTexture = new NinePatch(Assets.UiTexture[3, 1], 4);
uiSystem.Style.TextScale = 0.1F; uiSystem.Style.TextScale = 0.1F;
uiSystem.Style.ActionSound = new SoundEffectInfo(Assets.ClickSound, 0.5F);
uiSystem.TextFormatter.AddImage("ticket", Assets.UiTexture[2, 0]);
uiSystem.TextFormatter.AddImage("star", Assets.UiTexture[3, 0]);
foreach (var modifier in AttractionModifier.Modifiers.Values)
uiSystem.TextFormatter.AddImage(modifier.Name, Assets.UiTexture[modifier.Texture]);
} }
public static IEnumerator<Wait> DisplaySplash(Action loadGame) { public static IEnumerator<Wait> DisplaySplash(Action loadGame) {
@ -460,7 +459,7 @@ namespace TouchyTickets {
OnDrawn = (e, time, batch, alpha) => batch.Draw(batch.GetBlankTexture(), e.DisplayArea, Color.Black * alpha) OnDrawn = (e, time, batch, alpha) => batch.Draw(batch.GetBlankTexture(), e.DisplayArea, Color.Black * alpha)
}; };
var center = splash.AddChild(new Group(Anchor.Center, new Vector2(0.5F, 0.5F), false) {DrawAlpha = 0}); var center = splash.AddChild(new Group(Anchor.Center, new Vector2(0.5F, 0.5F), false) {DrawAlpha = 0});
center.AddChild(new Image(Anchor.AutoCenter, new Vector2(1, -1), Texture[4, 0])); center.AddChild(new Image(Anchor.AutoCenter, new Vector2(1, -1), Assets.UiTexture[4, 0]));
center.AddChild(new Paragraph(Anchor.AutoCenter, 10000, Localization.Get("AGameByEllpeck"), true)); center.AddChild(new Paragraph(Anchor.AutoCenter, 10000, Localization.Get("AGameByEllpeck"), true));
GameImpl.Instance.UiSystem.Add("Splash", splash).Priority = 100000; GameImpl.Instance.UiSystem.Add("Splash", splash).Priority = 100000;
while (center.DrawAlpha < 1) { while (center.DrawAlpha < 1) {
@ -580,7 +579,7 @@ namespace TouchyTickets {
button.OnUpdated += (e, time) => HideAndDisable(); button.OnUpdated += (e, time) => HideAndDisable();
HideAndDisable(); HideAndDisable();
button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), upgrade.Texture) { button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), Assets.UiTexture[upgrade.Texture]) {
Padding = new Vector2(4) Padding = new Vector2(4)
}); });
var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1)) {CanBeMoused = false}); var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1)) {CanBeMoused = false});

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Textures; using MLEM.Textures;
@ -8,30 +9,30 @@ namespace TouchyTickets {
public class Upgrade { public class Upgrade {
public static readonly Dictionary<string, Upgrade> Upgrades = new Dictionary<string, Upgrade>(); public static readonly Dictionary<string, Upgrade> Upgrades = new Dictionary<string, Upgrade>();
public static readonly Upgrade[] MapSize = RegisterTiers("MapSize", 5, 1, 1, Ui.Texture[0, 3]); public static readonly Upgrade[] MapSize = RegisterTiers("MapSize", 5, 1, 1, new Point(0, 3));
public static readonly Upgrade[] TapIncrease = RegisterTiers("TapIncrease", 3, 1, 0.5F, Ui.Texture[6, 3]); public static readonly Upgrade[] TapIncrease = RegisterTiers("TapIncrease", 3, 1, 0.5F, new Point(6, 3));
public static readonly Upgrade[] ModifierIncrease = RegisterTiers("ModifierIncrease", 3, 1, 1.5F, Ui.Texture[9, 3]); public static readonly Upgrade[] ModifierIncrease = RegisterTiers("ModifierIncrease", 3, 1, 1.5F, new Point(9, 3));
public static readonly Upgrade FerrisWheelModifier = Register(new Upgrade("FerrisWheelModifier", 1, Ui.Texture[2, 3])); public static readonly Upgrade FerrisWheelModifier = Register(new Upgrade("FerrisWheelModifier", 1, new Point(2, 3)));
public static readonly Upgrade NatureModifier = Register(new Upgrade("NatureModifier", 1, Ui.Texture[8, 3])); public static readonly Upgrade NatureModifier = Register(new Upgrade("NatureModifier", 1, new Point(8, 3)));
public static readonly Upgrade FoodCourtModifier = Register(new Upgrade("FoodCourtModifier", 2, Ui.Texture[1, 3])); public static readonly Upgrade FoodCourtModifier = Register(new Upgrade("FoodCourtModifier", 2, new Point(1, 3)));
public static readonly Upgrade RollerCoasterModifier = Register(new Upgrade("RollerCoasterModifier", 2, Ui.Texture[3, 3])); public static readonly Upgrade RollerCoasterModifier = Register(new Upgrade("RollerCoasterModifier", 2, new Point(3, 3)));
public static readonly Upgrade ManualRideModifier = Register(new Upgrade("ManualRideModifier", 2, Ui.Texture[4, 3])); public static readonly Upgrade ManualRideModifier = Register(new Upgrade("ManualRideModifier", 2, new Point(4, 3)));
public static readonly Upgrade SpiralSlideModifier = Register(new Upgrade("SpiralSlideModifier", 2, Ui.Texture[5, 3])); public static readonly Upgrade SpiralSlideModifier = Register(new Upgrade("SpiralSlideModifier", 2, new Point(5, 3)));
public static readonly Upgrade HauntedHouseModifier = Register(new Upgrade("HauntedHouseModifier", 2, Ui.Texture[7, 3])); public static readonly Upgrade HauntedHouseModifier = Register(new Upgrade("HauntedHouseModifier", 2, new Point(7, 3)));
public readonly string Name; public readonly string Name;
public readonly int Price; public readonly int Price;
public readonly TextureRegion Texture; public readonly Point Texture;
public readonly Upgrade[] Dependencies; public readonly Upgrade[] Dependencies;
public Upgrade(string name, int price, TextureRegion texture, params Upgrade[] dependencies) { public Upgrade(string name, int price, Point texture, params Upgrade[] dependencies) {
this.Name = name; this.Name = name;
this.Price = price; this.Price = price;
this.Texture = texture; this.Texture = texture;
this.Dependencies = dependencies; this.Dependencies = dependencies;
} }
private static Upgrade[] RegisterTiers(string name, int amount, int startPrice, float priceIncrease, TextureRegion texture) { private static Upgrade[] RegisterTiers(string name, int amount, int startPrice, float priceIncrease, Point texture) {
var ret = new Upgrade[amount]; var ret = new Upgrade[amount];
for (var i = 0; i < amount; i++) { for (var i = 0; i < amount; i++) {
// every tier except first depends on last tier // every tier except first depends on last tier