Skip to content

Commit

Permalink
Merge pull request #497 from Nashet/Map-options
Browse files Browse the repository at this point in the history
Map options
  • Loading branch information
Nashet authored Jun 11, 2018
2 parents 6dfe74c + 2123036 commit fee4244
Show file tree
Hide file tree
Showing 67 changed files with 3,264 additions and 45 deletions.
Binary file modified Assets/EconomicSimulation/ES-base.unity
Binary file not shown.
10 changes: 10 additions & 0 deletions Assets/EconomicSimulation/Resources/Prefabs/Windows.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/EconomicSimulation/Scripts/Logic/Diplomacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nashet.EconomicSimulation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class MainCamera : MonoBehaviour
[SerializeField]
private float xzCameraSpeed = 2f;



[SerializeField]
private float yCameraSpeed = -55f;

Expand Down Expand Up @@ -54,6 +56,9 @@ private void Start()
{
Get = this;
focusHeight = transform.position.z;
//
//var window = Instantiate(LinksManager.Get.MapOptionsPrefab, LinksManager.Get.CameraLayerCanvas.transform);
//window.GetComponent<RectTransform>().anchoredPosition = new Vector2(150f, 150f);
}

public void Move(float xMove, float zMove, float yMove)
Expand Down Expand Up @@ -88,7 +93,7 @@ private void FixedUpdate()
private void LoadGame()
{
Application.runInBackground = true;
game = new Game();
game = new Game(MapOptions.MapImage);
#if UNITY_WEBGL
game.InitializeNonUnityData(); // non multi-threading
#else
Expand All @@ -109,6 +114,8 @@ private void OnGameLoaded()
// Update is called once per frame
private void Update()
{
if (!MapOptions.MadeChoise)
return;
//starts loading thread
if (game == null)// && Input.GetKeyUp(KeyCode.Backspace))
{
Expand Down Expand Up @@ -180,6 +187,7 @@ private void Update()
MessagePanel.showMessageBox(LinksManager.Get.CameraLayerCanvas, this);

}

}

private void RefreshMap()
Expand Down
15 changes: 8 additions & 7 deletions Assets/EconomicSimulation/Scripts/Logic/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Game : ThreadedJob
public static bool logInvestments = false;
public static bool logMarket = false;

private static readonly bool readMapFormFile = false;
public static bool readMapFormFile = false;
private static MyTexture mapTexture;


Expand All @@ -39,23 +39,24 @@ public class Game : ThreadedJob
private static VoxelGrid grid;
private readonly Rect mapBorders;

public Game()
public Game(Texture2D mapImage)
{
if (readMapFormFile)
if (mapImage==null)
generateMapImage();
else
{
Texture2D mapImage = Resources.Load("provinces", typeof(Texture2D)) as Texture2D; ///texture;
//Texture2D mapImage = Resources.Load("provinces", typeof(Texture2D)) as Texture2D; ///texture;
mapTexture = new MyTexture(mapImage);
}
else
generateMapImage();

mapBorders = new Rect(0f, 0f, mapTexture.getWidth() * Options.cellMultiplier, mapTexture.getHeight() * Options.cellMultiplier);
}

public void InitializeNonUnityData()
{
World.market.initialize();

World.Create(mapTexture, !readMapFormFile);
World.Create(mapTexture);
//Game.updateStatus("Making grid..");
grid = new VoxelGrid(mapTexture.getWidth(), mapTexture.getHeight(), Options.cellMultiplier * mapTexture.getWidth(), mapTexture, World.GetAllProvinces());

Expand Down
25 changes: 13 additions & 12 deletions Assets/EconomicSimulation/Scripts/Logic/Mono/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ internal static void CreateCountries()
howMuchCountries += Rand.Get.Next(6);
if (howMuchCountries < 8)
howMuchCountries = 8;

if (howMuchCountries > World.allProvinces.Count)
howMuchCountries = World.allProvinces.Count;
for (int i = 0; i < howMuchCountries; i++)
{
//Game.updateStatus("Making countries.." + i);
Expand Down Expand Up @@ -351,15 +352,16 @@ public static List<Province> getSeaProvinces(MyTexture mapTexture, bool useProvi
/// <summary>
/// Could run in threads
/// </summary>
public static void Create(MyTexture map, bool isMapGenerated)
public static void Create(MyTexture map)
{
bool isMapRandom = MapOptions.MapImage == null;
//FactoryType.getResourceTypes(); // FORCING FactoryType to initialize?

// remake it on messages?
//Game.updateStatus("Reading provinces..");
preReadProvinces(map);
var seaProvinces = getSeaProvinces(map, !isMapGenerated);
deleteSomeProvinces(seaProvinces, isMapGenerated);
var seaProvinces = getSeaProvinces(map, !isMapRandom);
deleteSomeProvinces(seaProvinces, isMapRandom);

// Game.updateStatus("Making countries..");
CreateCountries();
Expand All @@ -377,16 +379,15 @@ public static void Create(MyTexture map, bool isMapGenerated)
private static void setStartResources()
{
//Country.allCountries[0] is null country
//Country.allCountries[1].Capital.setResource(Product.Wood);// player

//Country.allCountries[0].Capital.setResource(Product.Wood;
//Country.allCountries[1].Capital.setResource(Product.Wood);// player

allCountries[2].Capital.setResource(Product.Fruit);
allCountries[3].Capital.setResource(Product.Gold);
allCountries[4].Capital.setResource(Product.Cotton);
allCountries[5].Capital.setResource(Product.Stone);
allCountries[6].Capital.setResource(Product.MetalOre);
allCountries[7].Capital.setResource(Product.Wood);
if (allCountries.Count > 2) allCountries[2].Capital.setResource(Product.Fruit);
if (allCountries.Count > 3) allCountries[3].Capital.setResource(Product.Gold);
if (allCountries.Count > 4) allCountries[4].Capital.setResource(Product.Cotton);
if (allCountries.Count > 5) allCountries[5].Capital.setResource(Product.Stone);
if (allCountries.Count > 6) allCountries[6].Capital.setResource(Product.MetalOre);
if (allCountries.Count > 7) allCountries[7].Capital.setResource(Product.Wood);
}

// temporally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nashet.EconomicSimulation
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/EconomicSimulation/Scripts/Panels/BottomPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BottomPanel : Window
private void Awake() // used to position other windows
{
MainCamera.bottomPanel = this;
generalText.text = "Prosperity Wars v0.20.5";
generalText.text = "Prosperity Wars v0.20.6";
Hide();
}

Expand Down
89 changes: 89 additions & 0 deletions Assets/EconomicSimulation/Scripts/Panels/MapOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Nashet.UnityUIUtils;

using SFB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEngine;
using UnityEngine.UI;

namespace Nashet.EconomicSimulation
{
/// <summary>
/// Warning! This mono object will not work in webGL if instantiated (will not load image file)
/// </summary>
class MapOptions : Hideable
{
static public bool MadeChoise;
[SerializeField]
private Toggle randomMap;

[SerializeField]
private CanvasSampleOpenFileImage imageOpener;

[SerializeField]
private RawImage loadedImage;

[SerializeField]
private Button generate, loadImage;

internal static Texture2D MapImage;

private void Start()
{
//GetComponent<RectTransform>().anchoredPosition = new Vector2(800f, 200f);
GUIChanger.Apply(gameObject);
}
//public override void Refresh()
//{

//}
public void OnMapFromFileToggled(bool value)
{
if (value == true)
{
generate.interactable = false;
loadImage.interactable = true;
}
else
{
generate.interactable = true;
loadImage.interactable = false;
}
}
public void OnLoadImageClicked()
{

}
public void OnGenerate()
{
if (randomMap.isOn)
{
Game.readMapFormFile = false;
MadeChoise = true;
Hide();
}
else //take picture
{
if (loadedImage.texture == null) //todo thats never true
Message.NewMessage("", "Wasn't able to load that image", "Ok", false);
else
{
Game.readMapFormFile = true;
MapImage = loadedImage.texture as Texture2D;
MadeChoise = true;
Hide();
}
}

}
private void Update()
{
if (!randomMap.isOn)
generate.interactable = loadedImage.texture!=null;
generate.interactable = true;
}
}
}
13 changes: 13 additions & 0 deletions Assets/EconomicSimulation/Scripts/Panels/MapOptions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/EconomicSimulation/Scripts/Utils/ExtendedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Nashet.Utils
{
Expand Down
24 changes: 22 additions & 2 deletions Assets/EconomicSimulation/Scripts/Utils/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Nashet.EconomicSimulation;
Expand Down Expand Up @@ -74,9 +75,28 @@ public static bool HasComponentInParentParent<T>(this MonoBehaviour that)
return true;
}
}

//public static class TextureExtensions
//{
// public static bool IsEmpty(Texture2D original)
// {
// }
//}
public static class Texture2DExtensions
{
public static Texture2D LoadPNG(string filePath)
{

Texture2D tex = null;
byte[] fileData;

if (File.Exists(filePath))
{
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2, TextureFormat.RGBAFloat, false);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
}
return tex;
}
public static Texture2D FlipTexture(Texture2D original)
{
Texture2D flipped = new Texture2D(original.width, original.height);
Expand Down Expand Up @@ -605,7 +625,7 @@ public static int FindIndex<T>(this IEnumerable<T> items, Func<T, bool> predicat

//}


public static IEnumerable<T> FirstSameElements<T>(this IEnumerable<T> collection, Func<T, float> selector)
{
T previousElement = collection.FirstOrDefault();
Expand Down
Loading

0 comments on commit fee4244

Please sign in to comment.