Skip to content

Commit

Permalink
Merge pull request #352 from Sandrem/stable-0.3.0
Browse files Browse the repository at this point in the history
22.11.17 nightly
  • Loading branch information
Sandrem authored Nov 22, 2017
2 parents 2cc8f7c + 3d51d82 commit 114c24e
Show file tree
Hide file tree
Showing 40 changed files with 408 additions and 45 deletions.
Binary file modified Assets/Resources/Prefabs/OptionsScale.prefab
Binary file not shown.
Binary file added Assets/Resources/Prefabs/UI/ModPanel.prefab
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Resources/Prefabs/UI/ModPanel.prefab.meta

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

Binary file modified Assets/Scenes/MainMenu.unity
Binary file not shown.
3 changes: 2 additions & 1 deletion Assets/Scripts/MainMenu/Model/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameModes;
using Mods;

public partial class MainMenu : MonoBehaviour {

Expand All @@ -24,6 +24,7 @@ private void InitializeMenu()

DontDestroyOnLoad(GameObject.Find("GlobalUI").gameObject);

ModsManager.Initialize();
Options.ReadOptions();
Options.UpdateVolume();
StartCoroutine(CheckUpdates());
Expand Down
46 changes: 33 additions & 13 deletions Assets/Scripts/MainMenu/Model/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
using System.Linq;
using System.Text;
using UnityEngine;
using Mods;

public static class Options
{
private static OptionsUI optionsUI;

public static string Playmat;
public static string CheckVersionUrl;
public static int MusicVolume;
public static int SfxVolume;
public static int AnimationSpeed;
public static int ManeuverSpeed;
public static float MusicVolume;
public static float SfxVolume;
public static float AnimationSpeed;
public static float ManeuverSpeed;

static Options()
{
Expand All @@ -24,17 +25,28 @@ public static void ReadOptions()
{
Playmat = PlayerPrefs.GetString("PlaymatName", "Endor");
CheckVersionUrl = PlayerPrefs.GetString("CheckVersionUrl", "http://sandrem.freeasphost.net/data/currentversion.txt");
MusicVolume = PlayerPrefs.GetInt("Music Volume", 2);
SfxVolume = PlayerPrefs.GetInt("Sfx Volume", 2);
AnimationSpeed = PlayerPrefs.GetInt("Animation Speed", 2);
ManeuverSpeed = PlayerPrefs.GetInt("Maneuver Speed", 2);
MusicVolume = PlayerPrefs.GetFloat("Music Volume", 0.25f);
SfxVolume = PlayerPrefs.GetFloat("Sfx Volume", 0.25f);
AnimationSpeed = PlayerPrefs.GetFloat("Animation Speed", 0.25f);
ManeuverSpeed = PlayerPrefs.GetFloat("Maneuver Speed", 0.25f);

ReadMods();
}

private static void ReadMods()
{
foreach (var modHolder in ModsManager.Mods)
{
modHolder.Value.IsOn = PlayerPrefs.GetInt("mods/" + modHolder.Key.ToString(), 0) == 1;
}
}

public static void InitializePanel()
{
optionsUI = GameObject.Find("UI/Panels/OptionsPanel").GetComponentInChildren<OptionsUI>();

SetPlaymatOption();
SetValueControllers();
}

private static void SetPlaymatOption()
Expand All @@ -49,9 +61,17 @@ private static void SetPlaymatOption()
}
}

public static void ChangeParameterValue(string parameter, int value)
private static void SetValueControllers()
{
foreach (OptionsValueController valueController in GameObject.Find("UI/Panels/OptionsPanel").GetComponentsInChildren<OptionsValueController>())
{
valueController.Start();
}
}

public static void ChangeParameterValue(string parameter, float value)
{
PlayerPrefs.SetInt(parameter, value);
PlayerPrefs.SetFloat(parameter, value);
PlayerPrefs.Save();

switch (parameter)
Expand All @@ -76,12 +96,12 @@ public static void ChangeParameterValue(string parameter, int value)

public static void UpdateVolume()
{
SetMusicVolume(PlayerPrefs.GetInt("Music Volume", 2));
SetMusicVolume(PlayerPrefs.GetFloat("Music Volume", 0.25f));
}

private static void SetMusicVolume(int value)
private static void SetMusicVolume(float value)
{
GameObject.Find("Music").GetComponent<AudioSource>().volume = 0.3f * value * 1f / 5f;
GameObject.Find("Music").GetComponent<AudioSource>().volume = value * 0.2f;
}

public static void SetCheckVersionUrl(string newUrl)
Expand Down
31 changes: 23 additions & 8 deletions Assets/Scripts/MainMenu/Model/OptionsValueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@ public class OptionsValueController : MonoBehaviour
{
public void Start()
{
SetValue(PlayerPrefs.GetInt(this.transform.Find("Text").GetComponent<Text>().text, 2));
SetValue(PlayerPrefs.GetFloat(this.transform.Find("Text").GetComponent<Text>().text, 0.25f));
}

public void SetValue(int value)
public void UpdateProgressByClick()
{
Options.ChangeParameterValue(this.transform.Find("Text").GetComponent<Text>().text, value);
PlayerPrefs.Save();
float percentage = (Input.mousePosition.x - this.gameObject.transform.position.x - 20) / 520;

int i = 1;
foreach (Transform scalePanel in this.transform.Find("ValueList"))
string optionName = this.transform.Find("Text").GetComponent<Text>().text;
if (optionName.Contains("Speed"))
{
if (percentage < 0.05f) percentage = 0.05f;
}
else
{
scalePanel.GetComponent<Image>().color = (i <= value) ? Color.blue : new Color(1, 1, 1, 100f/255f);
i++;
if (percentage < 0.05f) percentage = 0f;
}

if (percentage > 0.95f) percentage = 1f;

SetValue(percentage);
}

public void SetValue(float percentage)
{
Options.ChangeParameterValue(this.transform.Find("Text").GetComponent<Text>().text, percentage);
PlayerPrefs.Save();

this.transform.Find("ValueList/PanelValue").GetComponent<RectTransform>().sizeDelta = new Vector2(520f * percentage, 50);
this.transform.Find("ValueList/PanelEmpty").GetComponent<RectTransform>().sizeDelta = new Vector2(520f * (1f - percentage), 50);
}

}
20 changes: 16 additions & 4 deletions Assets/Scripts/MainMenu/Model/RosterBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static void Initialize()

private static void InitializeSquadBuilderRoster()
{
RemoveAllShips();
SquadBuilderRoster.ClearRoster();
}

Expand Down Expand Up @@ -356,6 +357,9 @@ private static List<string> GetShipsByFaction(Faction faction)

private static void GenerateShipsList()
{
AllShips = new List<ShipRecord>();
AllPilots = new List<PilotRecord>();

IEnumerable<string> namespaceIEnum =
from types in Assembly.GetExecutingAssembly().GetTypes()
where types.Namespace != null
Expand Down Expand Up @@ -383,8 +387,8 @@ where types.Namespace.StartsWith("Ship.")
}
}

Messages.ShowInfo("Ships loaded: " + AllShips.Count);
Messages.ShowInfo("Pilots loaded: " + AllPilots.Count);
//Messages.ShowInfo("Ships loaded: " + AllShips.Count);
//Messages.ShowInfo("Pilots loaded: " + AllPilots.Count);
}

private static List<string> GetPilotsList(string shipName, Faction faction = Faction.None)
Expand All @@ -400,7 +404,7 @@ private static List<string> GetPilotsList(string shipName, Faction faction = Fac
if (type.MemberType == MemberTypes.NestedType) continue;

GenericShip newShipContainer = (GenericShip)System.Activator.CreateInstance(type);
if ((newShipContainer.PilotName != null) && (!newShipContainer.IsHidden) && (!newShipContainer.IsCustomContent))
if ((newShipContainer.PilotName != null) && (newShipContainer.IsAllowedForSquadBuilder()))
{
if ((newShipContainer.faction == faction) || faction == Faction.None)
{
Expand Down Expand Up @@ -429,6 +433,8 @@ private static List<string> GetPilotsList(string shipName, Faction faction = Fac

private static void GenerateUpgradesList()
{
AllUpgrades = new List<UpgradeRecord>();

List<Type> typelist = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => String.Equals(t.Namespace, "UpgradesList", StringComparison.Ordinal))
.ToList();
Expand All @@ -453,7 +459,7 @@ private static void GenerateUpgradesList()
}
}

Messages.ShowInfo("Upgrades loaded: " + AllUpgrades.Count);
//Messages.ShowInfo("Upgrades loaded: " + AllUpgrades.Count);
}

private static void SetAvailableUpgrades(SquadBuilderShip squadBuilderShip)
Expand Down Expand Up @@ -788,6 +794,12 @@ public static void CreateSquadFromImportedjson(string jsonString, PlayerNo playe
SetPlayerSquadFromImportedJson(squadJson, playerNo, ShowRoster);
}

public static void RemoveAllShips()
{
RemoveAllShipsByPlayer(PlayerNo.Player1);
RemoveAllShipsByPlayer(PlayerNo.Player2);
}

public static void RemoveAllShipsByPlayer(PlayerNo playerNo)
{
List<SquadBuilderShip> shipsList = SquadBuilderRoster.GetShipsByPlayer(playerNo);
Expand Down
4 changes: 4 additions & 0 deletions Assets/Scripts/MainMenu/View/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reflection;
using System.Linq;
using Players;
using Mods;

public partial class MainMenu : MonoBehaviour {

Expand Down Expand Up @@ -45,6 +46,9 @@ private void InitializePanelContent(string panelName, string previousPanelName)
case "OptionsPanel":
Options.InitializePanel();
break;
case "ModsPanel":
ModsManager.InitializePanel();
break;
}
}

Expand Down
15 changes: 15 additions & 0 deletions Assets/Scripts/MainMenu/View/ModUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mods;

public class ModUI : MonoBehaviour {

public void OnClickModActivationChange(GameObject ModGO)
{
bool toggleValue = ModGO.transform.Find("Toggle").GetComponent<Toggle>().isOn;
ModsManager.ModToggleIsActive(ModGO.name, toggleValue);
}

}
12 changes: 12 additions & 0 deletions Assets/Scripts/MainMenu/View/ModUI.cs.meta

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

56 changes: 56 additions & 0 deletions Assets/Scripts/MainMenu/View/ModsUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mods;

public class ModsUI : MonoBehaviour {

public const float FREE_SPACE = 20f;

public void Start()
{
ModsManager.UI = this;
}

public void InitializePanel()
{
GameObject prefab = (GameObject)Resources.Load("Prefabs/UI/ModPanel", typeof(GameObject));
GameObject ModsPanel = GameObject.Find("UI/Panels").transform.Find("ModsPanel").gameObject;

RectTransform modsPanelRectTransform = ModsPanel.GetComponent<RectTransform>();
Vector3 currentPosition = new Vector3(ModsPanel.transform.position.x - modsPanelRectTransform.sizeDelta.x/2 + FREE_SPACE, ModsPanel.transform.position.y + modsPanelRectTransform.sizeDelta.y / 2 - FREE_SPACE, ModsPanel.transform.position.z);

foreach (var mod in ModsManager.Mods)
{
Transform existingModeRecord = ModsPanel.transform.Find(mod.Key.ToString());
GameObject ModRecord;

if (existingModeRecord == null)
{
ModRecord = MonoBehaviour.Instantiate(prefab, ModsPanel.transform);
ModRecord.transform.position = currentPosition;
ModRecord.name = mod.Key.ToString();

ModRecord.transform.Find("Label").GetComponent<Text>().text = mod.Value.Name;

Text description = ModRecord.transform.Find("Text").GetComponent<Text>();
description.text = mod.Value.Description;
RectTransform descriptionRectTransform = description.GetComponent<RectTransform>();
descriptionRectTransform.sizeDelta = new Vector2(descriptionRectTransform.sizeDelta.x, description.preferredHeight);

RectTransform modRecordRectTransform = ModRecord.GetComponent<RectTransform>();
modRecordRectTransform.sizeDelta = new Vector2(modRecordRectTransform.sizeDelta.x, modRecordRectTransform.sizeDelta.y + description.preferredHeight);

currentPosition = new Vector3(currentPosition.x, currentPosition.y - modRecordRectTransform.sizeDelta.y - FREE_SPACE, currentPosition.z);
}
else
{
ModRecord = existingModeRecord.gameObject;
}

ModRecord.transform.Find("Toggle").GetComponent<Toggle>().isOn = ModsManager.Mods[mod.Key].IsOn;
}
}

}
12 changes: 12 additions & 0 deletions Assets/Scripts/MainMenu/View/ModsUI.cs.meta

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

11 changes: 11 additions & 0 deletions Assets/Scripts/MainMenu/View/OptionsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public void OnClickPlaymatChange(GameObject playmatImage)
PlaymatSelector.transform.position = playmatImage.transform.position;
}

public void RestoreDefaults()
{
Options.Playmat = "Endor";
Options.ChangeParameterValue("Music Volume", 0.25f);
Options.ChangeParameterValue("SFX Volume", 0.25f);
Options.ChangeParameterValue("Animation Speed", 0.25f);
Options.ChangeParameterValue("Maneuver Speed", 0.25f);

Options.InitializePanel();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public override void Update()

private void DoBarrelRollAnimation()
{
float progressStep = 0.5f * Time.deltaTime * Options.AnimationSpeed;
float progressStep = 2.5f * Time.deltaTime * Options.AnimationSpeed;
progressStep = Mathf.Min(progressStep, progressTarget-progressCurrent);
progressCurrent += progressStep;

Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/Model/Mods.meta

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

9 changes: 9 additions & 0 deletions Assets/Scripts/Model/Mods/ModsList.meta

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

Loading

0 comments on commit 114c24e

Please sign in to comment.