Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
keiwando committed Sep 20, 2019
1 parent b13eaa3 commit 53a535a
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Controllers/CreatureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Start() {

viewController.Refresh();

InputRegistry.shared.Register(InputType.Click | InputType.Key | InputType.Touch, this, EventHandleMode.PassthroughEvent);
InputRegistry.shared.Register(InputType.Click | InputType.Key | InputType.Touch | InputType.AndroidBack, this, EventHandleMode.PassthroughEvent);

var androidBackButton = GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer();
androidBackButton.OnGesture += delegate (AndroidBackButtonGestureRecognizer recognizer) {
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Controllers/CreatureFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void ShowUI() {

public void PromptCreatureSave() {
saveDialog.Show(this);
DidChangeValue(saveDialog, GetSuggestedName(saveDialog));
}

// MARK: - SaveDialogDelegate
Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Controllers/SimulationFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SimulationFileManager : MonoBehaviour, FileSelectionViewControllerD
private UIFade failedImportIndicator;

private int selectedIndex = 0;
private List<string> filenames;
private List<string> filenames = new List<string>();

void Start() {
NativeFileSOMobile.shared.FilesWereOpened += delegate (OpenedFile[] files) {
Expand Down Expand Up @@ -118,7 +118,9 @@ private void TryImport(OpenedFile[] files) {
RefreshCache();
try {
viewController.Refresh();
} catch {}
} catch {
DelayExtensions.Delay(this, 0.2f, delegate() { viewController.Refresh(); });
}
if (successfulImport) {
importIndicator.FadeInOut();
}
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Controllers/SimulationInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ void Start() {
var androidRecognizer = GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer();
androidRecognizer.OnGesture += delegate (AndroidBackButtonGestureRecognizer recognizer) {
if (InputRegistry.shared.MayHandle(InputType.AndroidBack, this)) {
InputRegistry.shared.Deregister(this);
viewController.GoBackToEditor();
}
};
Expand Down
17 changes: 17 additions & 0 deletions Assets/Scripts/Util/DelayExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;

namespace Keiwando {

public static class DelayExtensions {

public static void Delay(this MonoBehaviour self, float seconds, System.Action action) {
self.StartCoroutine(Delayed(seconds, action));
}

private static IEnumerator Delayed(float seconds, System.Action action) {
yield return new WaitForSeconds(seconds);
action();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Util/DelayExtensions.cs.meta

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

5 changes: 3 additions & 2 deletions Assets/Scripts/Util/SafeArea.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// #define SAFE_AREA_DEBUG

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(RectTransform))]
public class SafeArea : MonoBehaviour {
Expand All @@ -14,10 +15,10 @@ public class SafeArea : MonoBehaviour {
void Start() {
safeAreaRect = GetComponent<RectTransform>();
canvas = GetComponentInParent<Canvas>();
OnRectTransformDimensionsChange();
OnRectTransformDimensionsChanged();
}

private void OnRectTransformDimensionsChange() {
private void OnRectTransformDimensionsChanged() {

if (GetSafeArea() != lastSafeArea && canvas != null) {
lastSafeArea = GetSafeArea();
Expand Down
54 changes: 36 additions & 18 deletions Assets/Scripts/View/DeleteConfirmationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,51 @@
using UnityEngine.UI;
using UnityEngine;

public class DeleteConfirmationDialog : MonoBehaviour {
namespace Keiwando.Evolution.UI {

public delegate void Delete(string name);
public class DeleteConfirmationDialog : MonoBehaviour {

private Delete deleteHandler;
public delegate void Delete(string name);

[SerializeField] private Text filenameLabel;
private Delete deleteHandler;

public void ConfirmDeletionFor(string filename, Delete deleteHandler) {
[SerializeField] private Text filenameLabel;

filenameLabel.text = filename;
this.deleteHandler = deleteHandler;
public void ConfirmDeletionFor(string filename, Delete deleteHandler) {

gameObject.SetActive(true);
}
filenameLabel.text = filename;
this.deleteHandler = deleteHandler;

public void ConfirmedDeletion() {
InputRegistry.shared.Register(InputType.AndroidBack, this, EventHandleMode.ConsumeEvent);
GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer().OnGesture += OnAndroidBack;

//SimulationSerializer.DeleteSaveFile(filenameLabel.text);
deleteHandler(filenameLabel.text);
gameObject.SetActive(true);
}

gameObject.SetActive(false);
}
public void ConfirmedDeletion() {

//SimulationSerializer.DeleteSaveFile(filenameLabel.text);
deleteHandler(filenameLabel.text);

DeregisterAndroidBack();
gameObject.SetActive(false);
}

public void Cancel() {
filenameLabel.text = "";

DeregisterAndroidBack();
gameObject.SetActive(false);
}

public void Cancel() {
filenameLabel.text = "";
private void DeregisterAndroidBack() {
InputRegistry.shared.Deregister(this);
GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer().OnGesture -= OnAndroidBack;
}

gameObject.SetActive(false);
private void OnAndroidBack(AndroidBackButtonGestureRecognizer recognizer) {
if (InputRegistry.shared.MayHandle(InputType.AndroidBack, this))
Cancel();
}
}
}
}
19 changes: 19 additions & 0 deletions Assets/Scripts/View/SimulationExitConfirmationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ public class SimulationExitConfirmationView: MonoBehaviour {
[SerializeField] private Button exitButton;
[SerializeField] private Button cancelButton;

private DidCancelExit onCancel;

public void Show(DidConfirmExit onConfirm, DidCancelExit onCancel) {

InputRegistry.shared.Register(InputType.AndroidBack, this);
GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer().OnGesture += OnAndroidBack;

#if UNITY_WEBGL
onConfirm();
return;
#endif

if (Settings.DontShowExitConfirmationOverlayAgain) {
onConfirm();
return;
Expand All @@ -27,6 +37,7 @@ public void Show(DidConfirmExit onConfirm, DidCancelExit onCancel) {
cancelButton.onClick.AddListener(delegate () {
onCancel();
});
this.onCancel = onCancel;

dontAskAgainToggle.isOn = Settings.DontShowExitConfirmationOverlayAgain;
dontAskAgainToggle.onValueChanged.AddListener(delegate (bool value) {
Expand All @@ -40,7 +51,15 @@ public void Close() {

exitButton.onClick.RemoveAllListeners();
cancelButton.onClick.RemoveAllListeners();
InputRegistry.shared.Deregister(this);
GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer().OnGesture -= OnAndroidBack;
gameObject.SetActive(false);
}

private void OnAndroidBack(AndroidBackButtonGestureRecognizer rec) {
if (InputRegistry.shared.MayHandle(InputType.AndroidBack, this)) {
onCancel();
}
}
}
}
125 changes: 64 additions & 61 deletions Assets/Scripts/View/SimulationLoadDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,101 @@
using UnityEngine;
using UnityEngine.UI;

public class SimulationLoadDialog : MonoBehaviour {
namespace Keiwando.Evolution.UI {

public bool IsShowing {
get { return bugFixEmpty.activeSelf; }
}
public class SimulationLoadDialog : MonoBehaviour {

[SerializeField]
private CreatureEditor editor;
public bool IsShowing {
get { return bugFixEmpty.activeSelf; }
}

[SerializeField]
private Dropdown dropdown;
[SerializeField]
private CreatureEditor editor;

[SerializeField]
private GameObject bugFixEmpty;
[SerializeField]
private Dropdown dropdown;

[SerializeField]
private DeleteConfirmationDialog deleteConfirmation;
[SerializeField]
private GameObject bugFixEmpty;

private const string NO_SAVE_FILES = "You haven't saved any simulations yet";
[SerializeField]
private DeleteConfirmationDialog deleteConfirmation;

private const string NO_SAVE_FILES = "You haven't saved any simulations yet";

public void PromptDialog() {
//this.gameObject.SetActive(true);
bugFixEmpty.SetActive(true);
SetupDropDown();
}

public void OnCancelClicked() {
//this.gameObject.SetActive(false);
bugFixEmpty.SetActive(false);
}
public void PromptDialog() {
//this.gameObject.SetActive(true);
bugFixEmpty.SetActive(true);
SetupDropDown();
}

public void OnLoadClicked() {
public void OnCancelClicked() {
//this.gameObject.SetActive(false);
bugFixEmpty.SetActive(false);
}

var filename = dropdown.options[dropdown.value].text;
public void OnLoadClicked() {

if (filename == NO_SAVE_FILES) return;
var filename = dropdown.options[dropdown.value].text;

filename += ".txt";
if (filename == NO_SAVE_FILES) return;

//SimulationSerializer.LoadSimulationFromSaveFile(filename, creatureBuilder, evolution);
StartCoroutine(LoadOnNextFrame(filename));
}
filename += ".txt";

private IEnumerator LoadOnNextFrame(string filename) {
//SimulationSerializer.LoadSimulationFromSaveFile(filename, creatureBuilder, evolution);
StartCoroutine(LoadOnNextFrame(filename));
}

yield return new WaitForEndOfFrame();
private IEnumerator LoadOnNextFrame(string filename) {

var simulationData = SimulationSerializer.LoadSimulationData(filename);
editor.StartSimulation(simulationData);
}
yield return new WaitForEndOfFrame();

private void SetupDropDown() {
var simulationData = SimulationSerializer.LoadSimulationData(filename);
editor.StartSimulation(simulationData);
}

var filenames = SimulationSerializer.GetEvolutionSaveFilenames();
private void SetupDropDown() {

var saveFiles = new List<string>();
var filenames = SimulationSerializer.GetEvolutionSaveFilenames();

if (filenames.Count == 0) {
saveFiles.Add(NO_SAVE_FILES);
} else {
//saveFilesExists = true;
}
var saveFiles = new List<string>();

foreach (var name in filenames) {
saveFiles.Add(name.Replace(".txt", ""));
}
if (filenames.Count == 0) {
saveFiles.Add(NO_SAVE_FILES);
} else {
//saveFilesExists = true;
}

dropdown.ClearOptions();
dropdown.AddOptions(saveFiles);
foreach (var name in filenames) {
saveFiles.Add(name.Replace(".txt", ""));
}

if (filenames.Count > 0) {
dropdown.Show();
dropdown.ClearOptions();
dropdown.AddOptions(saveFiles);

if (filenames.Count > 0) {
dropdown.Show();
}
}
}

public void PromptSavefileDelete() {
public void PromptSavefileDelete() {

var filename = dropdown.options[dropdown.value].text;
var filename = dropdown.options[dropdown.value].text;

if (filename == NO_SAVE_FILES) return;
if (filename == NO_SAVE_FILES) return;

filename += ".txt";
filename += ".txt";

//deleteConfirmation.ConfirmDeletionFor(filename);
deleteConfirmation.ConfirmDeletionFor(filename, delegate(string name) {
//deleteConfirmation.ConfirmDeletionFor(filename);
deleteConfirmation.ConfirmDeletionFor(filename, delegate(string name) {

SimulationSerializer.DeleteSaveFile(filename);
SimulationSerializer.DeleteSaveFile(filename);

SetupDropDown();
dropdown.value = 0;
});
}
SetupDropDown();
dropdown.value = 0;
});
}

}
}
10 changes: 10 additions & 0 deletions Assets/Scripts/View/V2PlaybackNoticeOverlayView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ void Start() {
public void Show(bool hideToggle = false) {

dontShowAgainToggle.gameObject.SetActive(!hideToggle);
InputRegistry.shared.Register(InputType.AndroidBack, this);
GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer().OnGesture += OnAndroidBack;
this.gameObject.SetActive(true);
Time.timeScale = 0;
}

public void Close() {
Time.timeScale = 1;
InputRegistry.shared.Deregister(this);
GestureRecognizerCollection.shared.GetAndroidBackButtonGestureRecognizer().OnGesture -= OnAndroidBack;
this.gameObject.SetActive(false);
}

private void OnAndroidBack(AndroidBackButtonGestureRecognizer rec) {
if (InputRegistry.shared.MayHandle(InputType.AndroidBack, this)) {
Close();
}
}
}
}

0 comments on commit 53a535a

Please sign in to comment.