Skip to content

Commit

Permalink
Added InteractionAction.
Browse files Browse the repository at this point in the history
Added IDialogService.
  • Loading branch information
vovgou committed Jun 25, 2019
1 parent 973a89f commit 0c82e3e
Show file tree
Hide file tree
Showing 35 changed files with 1,863 additions and 41 deletions.
Binary file modified Assets/LoxodonFramework/Docs/LoxodonFramework.pdf
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public override T LoadView<T>(string name)

GameObject go = GameObject.Instantiate(viewTemplateGo);
go.name = viewTemplateGo.name;
return go.GetComponent<T>();
T view = go.GetComponent<T>();
if (view == null && go != null)
GameObject.Destroy(go);
return view;
}

public override IProgressTask<float, T> LoadViewAsync<T>(string name)
Expand Down Expand Up @@ -132,8 +135,17 @@ protected virtual IEnumerator DoLoad<T>(IProgressPromise<float, T> promise, stri

GameObject go = GameObject.Instantiate(viewTemplateGo);
go.name = viewTemplateGo.name;
promise.UpdateProgress(1f);
promise.SetResult(go.GetComponent<T>());
T view = go.GetComponent<T>();
if (view == null)
{
GameObject.Destroy(go);
promise.SetException(new NotFoundException(name));
}
else
{
promise.UpdateProgress(1f);
promise.SetResult(view);
}
}

public override T LoadWindow<T>(string name)
Expand Down
2 changes: 2 additions & 0 deletions Assets/LoxodonFramework/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ UPDATE NOTES
version 1.8.4
Added a logging system to the Lua plugin
Added CommandParameter for data binding,support multiple buttons to bind to the same command.
Added InteractionAction.
Added IDialogService.

version 1.8.2
Fixed a bug in expression binding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public ITargetProxy CreateProxy(object target, BindingDescription description)
{
IProxyType type = target.GetType().AsProxy();
IProxyMemberInfo memberInfo = type.GetMember(description.TargetName);
if (memberInfo == null)
memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic);

if (memberInfo == null)
return null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Loxodon.Framework.Interactivity;
using System;

namespace Loxodon.Framework.Binding.Proxy.Targets
{
public class InteractionTargetProxy : TargetProxyBase, IObtainable
{
protected readonly EventHandler<InteractionEventArgs> handler;

public InteractionTargetProxy(object target, IInteractionAction interactionAction) : base(target)
{
this.handler = interactionAction.OnRequest;
}

public override Type Type { get { return typeof(EventHandler<InteractionEventArgs>); } }

public override BindingMode DefaultMode { get { return BindingMode.OneWayToSource; } }

public object GetValue()
{
return handler;
}

public TValue GetValue<TValue>()
{
return (TValue)GetValue();
}
}
}

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Loxodon.Framework.Binding.Reflection;
using Loxodon.Framework.Interactivity;
using Loxodon.Framework.Observables;
using System.Reflection;

Expand Down Expand Up @@ -29,6 +30,15 @@ public ITargetProxy CreateProxy(object target, BindingDescription description)
return new ObservableTargetProxy(target, (IObservableProperty)observableValue);
}

if (typeof(IInteractionAction).IsAssignableFrom(valueType))
{
object interactionAction = propertyInfo.GetValue(target);
if (interactionAction == null)
return null;

return new InteractionTargetProxy(target, (IInteractionAction)interactionAction);
}

return new PropertyTargetProxy(target, propertyInfo);
}

Expand All @@ -45,6 +55,15 @@ public ITargetProxy CreateProxy(object target, BindingDescription description)
return new ObservableTargetProxy(target, (IObservableProperty)observableValue);
}

if (typeof(IInteractionAction).IsAssignableFrom(valueType))
{
object interactionAction = fieldInfo.GetValue(target);
if (interactionAction == null)
return null;

return new InteractionTargetProxy(target, (IInteractionAction)interactionAction);
}

return new FieldTargetProxy(target, fieldInfo);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Loxodon.Framework.Asynchronous;
using Loxodon.Framework.ViewModels;

namespace Loxodon.Framework.Interactivity
{
public interface IDialogService
{
/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="title">The title of the dialog box. This may be null.</param>
/// <param name="message">The message to be shown to the user.</param>
/// <returns>The result</returns>
IAsyncResult<int> ShowDialog(string title, string message);

/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="title">The title of the dialog box. This may be null.</param>
/// <param name="message">The message to be shown to the user.</param>
/// <param name="buttonText">The text shown in the only button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <returns>The result</returns>
IAsyncResult<int> ShowDialog(string title, string message, string buttonText);

/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="title">The title of the dialog box. This may be null.</param>
/// <param name="message">The message to be shown to the user.</param>
/// <param name="confirmButtonText">The text shown in the "confirm" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <param name="cancelButtonText">The text shown in the "cancel" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <returns>The result</returns>
IAsyncResult<int> ShowDialog(string title, string message, string confirmButtonText, string cancelButtonText);

/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="title">The title of the dialog box. This may be null.</param>
/// <param name="message">The message to be shown to the user.</param>
/// <param name="confirmButtonText">The text shown in the "confirm" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <param name="cancelButtonText">The text shown in the "cancel" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <param name="neutralButtonText">The text shown in the "neutral" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <returns>The result</returns>
IAsyncResult<int> ShowDialog(string title, string message, string confirmButtonText, string cancelButtonText, string neutralButtonText);

/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="title">The title of the dialog box. This may be null.</param>
/// <param name="message">The message to be shown to the user.</param>
/// <param name="confirmButtonText">The text shown in the "confirm" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <param name="cancelButtonText">The text shown in the "cancel" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <param name="neutralButtonText">The text shown in the "neutral" button
/// in the dialog box. If left null, the button will be invisible.</param>
/// <param name="canceledOnTouchOutside">Whether the dialog box is canceled when
/// touched outside the window's bounds. </param>
/// <returns>The result</returns>
IAsyncResult<int> ShowDialog(string title, string message, string confirmButtonText, string cancelButtonText, string neutralButtonText, bool canceledOnTouchOutside);

/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="viewName">The name of the dialog view, loading the dialog view based on the view name</param>
/// <param name="viewModel">The view model of the dialog</param>
/// <returns>The result</returns>
IAsyncResult ShowDialog(string viewName, object viewModel);

/// <summary>
/// Displays information to the user.
/// </summary>
/// <param name="viewName">The name of the dialog view, loading the dialog view based on the view name</param>
/// <param name="viewModel">The view model of the dialog</param>
/// <returns>The result</returns>
IAsyncResult<TViewModel> ShowDialog<TViewModel>(string viewName, TViewModel viewModel);
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Loxodon.Framework.Interactivity
{
public interface IInteractionAction
{
void OnRequest(object sender, InteractionEventArgs args);
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Loxodon.Framework.Interactivity
{
public abstract class InteractionActionBase<TNotification> : IInteractionAction
{
public void OnRequest(object sender, InteractionEventArgs args)
{
Action callback = args.Callback;
TNotification notification = (TNotification)args.Context;
this.Action(notification, callback);
}

public abstract void Action(TNotification notification, Action callback);
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Raise(Action callback)
/// <summary>
/// Implementation of the <see cref="IInteractionRequest"/> interface.
/// </summary>
public class InteractionRequest<T> : IInteractionRequest where T : class
public class InteractionRequest<T> : IInteractionRequest
{
private static readonly InteractionEventArgs emptyEventArgs = new InteractionEventArgs(null, null);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Loxodon.Framework.Interactivity
{
public class ToastNotification
{
private readonly float duration;
private readonly string message;

public ToastNotification(string message) : this(message, 3f)
{
}

public ToastNotification(string message, float duration)
{
this.duration = duration;
this.message = message;
}

public float Duration
{
get { return this.duration; }
}

public string Message
{
get { return this.message; }
}
}
}

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

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

Loading

0 comments on commit 0c82e3e

Please sign in to comment.