/// <inheritdoc/> public IObservable <bool> GetActivationForView(IActivatable view) { var fe = view as FrameworkElement; if (fe == null) { return(Observable <bool> .Empty); } var viewLoaded = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>( x => fe.Loaded += x, x => fe.Loaded -= x) .Select(_ => true); var hitTestVisible = Observable.FromEventPattern <DependencyPropertyChangedEventHandler, DependencyPropertyChangedEventArgs>( x => fe.IsHitTestVisibleChanged += x, x => fe.IsHitTestVisibleChanged -= x) .Select(x => (bool)x.EventArgs.NewValue); var viewUnloaded = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>( x => fe.Unloaded += x, x => fe.Unloaded -= x) .Select(_ => false); return(viewLoaded .Merge(viewUnloaded) .Merge(hitTestVisible) .DistinctUntilChanged()); }
// Load the game. public void Load() { if (File.Exists(saveGameName)) { // 1 - deserialize the save game information. XmlSerializer serializer = new XmlSerializer(typeof(SaveGame)); FileStream stream = File.Open(saveGameName, FileMode.Open); Game = serializer.Deserialize(stream) as SaveGame; stream.Dispose(); // 2 - any setup after loading data. InstantiateState(true); // 3 - restart the any objects foreach (Transform child in SceneRoot.transform) { GameObject go = child.gameObject; IActivatable activate = go.GetComponent(typeof(IActivatable)) as IActivatable; if (activate != null) { activate.SetEnabled(true); } } Debug.Log("Game Loaded"); } }
/// <inheritdoc/> public IObservable <bool> GetActivationForView(IActivatable view) { // Startup: Control.HandleCreated > Control.BindingContextChanged > Form.Load > Control.VisibleChanged > Form.Activated > Form.Shown // Shutdown: Form.Closing > Form.FormClosing > Form.Closed > Form.FormClosed > Form.Deactivate // https://docs.microsoft.com/en-us/dotnet/framework/winforms/order-of-events-in-windows-forms if (view is Control control) { if (GetCachedIsDesignMode(control)) { return(Observable <bool> .Empty); } var handleDestroyed = Observable.FromEventPattern(control, "HandleDestroyed").Select(_ => false); var handleCreated = Observable.FromEventPattern(control, "HandleCreated").Select(_ => true); var visibleChanged = Observable.FromEventPattern(control, "VisibleChanged").Select(_ => control.Visible); var controlActivation = Observable.Merge(handleDestroyed, handleCreated, visibleChanged) .DistinctUntilChanged(); if (view is Form form) { var formClosed = Observable.FromEventPattern(form, "FormClosed").Select(_ => false); controlActivation = controlActivation.Merge(formClosed) .DistinctUntilChanged(); } return(controlActivation); } // Show a friendly warning in the log that this view will never be activated this.Log().Warn("Expected a view of type System.Windows.Forms.Control but it is {0}.\r\nYou need to implement your own IActivationForViewFetcher for {0}.", view.GetType()); return(Observable <bool> .Empty); }
public override void _Ready() { Target = GetNode(ActivatableTargetNodePath) as IActivatable; // Note: Could be null! CSGBox = GetNode <CSGBox>(CSGNodePath); SetColour(NotPressedColor); }
public IObservable <bool> GetActivationForView(IActivatable view) { var fe = view as FrameworkElement; if (fe == null) { return(Observable <bool> .Empty); } #if WINDOWS_UWP var viewLoaded = WindowsObservable.FromEventPattern <FrameworkElement, object>(x => fe.Loading += x, x => fe.Loading -= x).Select(_ => true); #else var viewLoaded = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(x => fe.Loaded += x, x => fe.Loaded -= x).Select(_ => true); #endif var viewUnloaded = Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(x => fe.Unloaded += x, x => fe.Unloaded -= x).Select(_ => false); return(viewLoaded .Merge(viewUnloaded) .Select(b => b ? fe.WhenAnyValue(x => x.IsHitTestVisible).SkipWhile(x => !x) : Observables.False) .Switch() .DistinctUntilChanged()); }
public int bulletCount; // inspector protected override void Awake() { base.Awake(); activatable = GetComponent <GunActivatable>(); // equipable.SetEquipableClass(EquipableClass.HandItem); magazineCount = 0; }
/// <inheritdoc/> public IObservable <bool> GetActivationForView(IActivatable view) { var fe = view as FrameworkElement; if (fe == null) { return(Observable <bool> .Empty); } #pragma warning disable SA1114 // Parameter list after. #if NETSTANDARD var viewLoaded = Observable.FromEvent <RoutedEventHandler, bool>( #else var viewLoaded = Observable.FromEvent <TypedEventHandler <DependencyObject, object>, bool>( #endif eventHandler => (_, __) => eventHandler(true), x => fe.Loading += x, x => fe.Loading -= x); var viewUnloaded = Observable.FromEvent <RoutedEventHandler, bool>( handler => { void EventHandler(object sender, RoutedEventArgs e) => handler(false); return(EventHandler); }, x => fe.Unloaded += x, x => fe.Unloaded -= x); return(viewLoaded .Merge(viewUnloaded) .Select(b => b ? fe.WhenAnyValue(x => x.IsHitTestVisible).SkipWhile(x => !x) : Observables.False) .Switch() .DistinctUntilChanged()); }
public IObservable<bool> GetActivationForView(IActivatable view) { var control = view as Control; if (control == null) { // Show a friendly warning in the log that this view will never be activated this.Log().Warn("Expected a view of type System.Windows.Forms.Control but it is {0}.\r\nYou need to implement your own IActivationForViewFetcher for {0}.", view.GetType()); return Observable.Empty<bool>(); } // Create an observable stream of booleans // true representing the control is active, false representing the control is not active // by using DistinctUntilChanged, a control can either be active or not active // This should also fix #610 for winforms var controlVisible = Observable.FromEventPattern(control, "VisibleChanged").Select(_ => control.Visible); var handleDestroyed = Observable.FromEventPattern(control, "HandleDestroyed").Select(_ => false); var handleCreated = Observable.FromEventPattern(control, "HandleCreated").Select(_ => true); var controlActive = Observable.Merge(controlVisible, handleDestroyed, handleCreated) .DistinctUntilChanged(); var form = view as Form; if (form != null) { var formActive = Observable.FromEventPattern(form, "Closed").Select(_ => false); return controlActive.Merge(formActive).DistinctUntilChanged(); } return controlActive; }
public IObservable <bool> GetActivationForView(IActivatable view) { var control = view as Control; if (control == null) { // Show a friendly warning in the log that this view will never be activated this.Log().Warn("Expected a view of type System.Windows.Forms.Control but it is {0}.\r\nYou need to implement your own IActivationForViewFetcher for {0}.", view.GetType()); return(Observable <bool> .Empty); } // Create an observable stream of booleans // true representing the control is active, false representing the control is not active // by using DistinctUntilChanged, a control can either be active or not active // This should also fix #610 for winforms var controlVisible = Observable.FromEventPattern(control, "VisibleChanged").Select(_ => control.Visible); var handleDestroyed = Observable.FromEventPattern(control, "HandleDestroyed").Select(_ => false); var handleCreated = Observable.FromEventPattern(control, "HandleCreated").Select(_ => true); var controlActive = Observable.Merge(controlVisible, handleDestroyed, handleCreated) .DistinctUntilChanged(); var form = view as Form; if (form != null) { var formActive = Observable.FromEventPattern(form, "Closed").Select(_ => false); return(controlActive.Merge(formActive).DistinctUntilChanged()); } return(controlActive); }
public static void RegisterWidgetVariants(this IComponentsApplicationBuilder appBuilder) { IWidgetFactory widgetFactory = appBuilder.Services.GetService <IWidgetFactory>(); widgetFactory.Register(WidgetVariants.SHOW_WIDGET, new WidgetVariant <ButtonWidgetMediator, ButtonWidgetPresenter> { Customisation = new ButtonWidgetCustomisation { // Hind: Example of usage of strategy (delegate) in widget mediator Title = "Activate text widget in first container!", ClickStrategy = () => { // Hind: Manual widget build and activation, in most of cases would be easier to use IWidgetManagementService WidgetInfo info = widgetFactory.Build(WidgetVariants.TEXT_FIRST); IActivatable <string> activatable = (IActivatable <string>)info.Mediator; activatable.Activate("FIRST_WIDGET_CONTAINER"); } } }); var textVariant = new CustomisedWidgetVariant <TextWidgetMediator, TextWidgetCustomisation>(); textVariant.Customisation.Text = "This text has been activated from runtime!"; widgetFactory.Register(WidgetVariants.TEXT_FIRST, textVariant); widgetFactory.Register(WidgetVariants.RANDOM_UPDATER, new WidgetVariant <RandomUpdaterWidgetMediator>()); widgetFactory.Register(WidgetVariants.COUNTER, new WidgetVariant <CounterWidgetMediator, CounterWidgetPresenter, CounterWidgetState>()); widgetFactory.Register(WidgetVariants.LAYOUT, new WidgetVariant(typeof(ExampleLayoutWidget)) { StateType = typeof(LayoutState) }); }
protected void AddExtraEntities(int type, int amountOfEntities) { for (int i = EntityDic.Count; i < amountOfEntities + EntityDic.Count; i++) { IActivatable c = CreateEntity(type); EntityDic[type].Insert(0, c); } }
/// <summary> /// WhenActivated allows you to register a Func to be called when a /// View is Activated. /// </summary> /// <param name="This">Object that supports activation.</param> /// <param name="block">The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'd') allows /// you to register Disposables to be cleaned up when the View is /// deactivated (i.e. "d(someObservable.Subscribe());")</param> /// <param name="view">The IActivatable will ordinarily also host the View /// Model, but in the event it is not, a class implementing <see cref="IViewFor" /> /// can be supplied here. /// <returns>A Disposable that deactivates this registration.</returns> public static IDisposable WhenActivated(this IActivatable This, Action <Action <IDisposable> > block, IViewFor view) { return(This.WhenActivated(() => { var ret = new List <IDisposable>(); block(ret.Add); return ret; }, view)); }
/// <summary> /// WhenActivated allows you to register a Func to be called when a /// View is Activated. /// </summary> /// <param name="This">Object that supports activation.</param> /// <param name="block">The method to be called when the corresponding /// View is activated. The Action parameter (usually called 'disposables') allows /// you to collate all disposables that should be cleaned up during deactivation.</param> /// <param name="view">The IActivatable will ordinarily also host the View /// Model, but in the event it is not, a class implementing <see cref="IViewFor" /> /// can be supplied here. /// <returns>A Disposable that deactivates this registration.</returns> public static IDisposable WhenActivated(this IActivatable This, Action <CompositeDisposable> block, IViewFor view = null) { return(This.WhenActivated(() => { var d = new CompositeDisposable(); block(d); return new[] { d }; }, view)); }
public static void WhenActivated(this IActivatable instance, Action <CompositeDisposable> activate) { instance.WhenActivated(d => { var cd = new CompositeDisposable(); activate(cd); d(cd); }); }
private void Start() { animator = transform.parent.GetComponent <Animator> (); meshRenderer = buttonBase.GetComponent <MeshRenderer> (); collider = GetComponent <Collider> (); defaultColor = meshRenderer.material.color; _targetIActivatable = targetActivatable.GetComponent <IActivatable> (); }
public Tuple<IObservable<Unit>, IObservable<Unit>> GetActivationForView(IActivatable view) { var fe = view as Page; return Tuple.Create( Observable.FromEventPattern<EventHandler, EventArgs>(x => fe.Appearing += x, x => fe.Disappearing -= x).Select(_ => Unit.Default), Observable.FromEventPattern<EventHandler, EventArgs>(x => fe.Appearing += x, x => fe.Disappearing -= x).Select(_ => Unit.Default)); }
public static Db4objects.Db4o.Tests.Common.TA.MockActivator ActivatorFor(IActivatable obj) { Db4objects.Db4o.Tests.Common.TA.MockActivator activator = new Db4objects.Db4o.Tests.Common.TA.MockActivator (); obj.Bind(activator); return(activator); }
public static Db4objects.Db4o.Tests.Common.TA.MockActivator ActivatorFor(IActivatable obj) { Db4objects.Db4o.Tests.Common.TA.MockActivator activator = new Db4objects.Db4o.Tests.Common.TA.MockActivator (); obj.Bind(activator); return activator; }
public static MockActivator ActivatorFor(IActivatable obj) { var activator = new MockActivator (); obj.Bind(activator); return activator; }
private void OnActivateLockerHandler(IActivatable activatable, ActivatableState state) { if (state != ActivatableState.Active) { return; } ReleaseHandlers(true); }
public IObservable <bool> GetActivationForView(IActivatable view) => Observable .CombineLatest( this.globalForce, this.EnsureSubjectFor(view), this.deferTo.GetActivationForView(view).StartWith(false), (forcedGlobally, forcedLocally, activated) => forcedGlobally || forcedLocally || activated) .DistinctUntilChanged();
public bool RemovePassiveBehavior(ITrigger trigger, IActivatable response) { if (!passiveBehaviors.ContainsKey(trigger) || (response != null && passiveBehaviors [trigger] != response)) { return(false); } passiveBehaviors.Remove(trigger); return(true); }
private static void OnWindowDeactivateHandler(IActivatable activatable, ActivatableState state) { if (state != ActivatableState.Inactive) { return; } activatable.ActivatableStateChangedEvent -= OnWindowDeactivateHandler; Destroy(((IWindow)activatable).Canvas.gameObject); }
public IGroup GetReference(IActivatable lightProvider) { lock (_lock) { GroupReference gRef = new GroupReference(Name, Lights, lightProvider); _referring.Add(new WeakReference<GroupReference>(gRef)); return gRef; } }
public static MockActivator ActivatorFor(IActivatable obj) { var activator = new MockActivator (); obj.Bind(activator); return(activator); }
public static IObservable <bool> GetIsActivated(this IActivatable @this) { var activationForViewFetcher = Locator.Current.GetService <IActivationForViewFetcher>(); return(activationForViewFetcher .GetActivationForView(@this) .Replay(1) .RefCount()); }
public IActivatable AddPassiveBehavior(ITrigger trigger, IActivatable response) { if (passiveBehaviors.ContainsKey(trigger)) { return(passiveBehaviors[trigger]); } passiveBehaviors.Add(trigger, response); return(null); }
public IObservable<bool> GetActivationForView(IActivatable view) { var fe = view as Page; var ret = Observable.Merge( Observable.FromEventPattern<EventHandler, EventArgs>(x => fe.Appearing += x, x => fe.Appearing -= x).Select(_ => true), Observable.FromEventPattern<EventHandler, EventArgs>(x => fe.Disappearing += x, x => fe.Disappearing -= x).Select(_ => false)); return ret.DistinctUntilChanged(); }
public IObservable <bool> GetActivationForView(IActivatable view) { var fe = view as Page; var ret = Observable.Merge( Observable.FromEventPattern <EventHandler, EventArgs>(x => fe.Appearing += x, x => fe.Appearing -= x).Select(_ => true), Observable.FromEventPattern <EventHandler, EventArgs>(x => fe.Disappearing += x, x => fe.Disappearing -= x).Select(_ => false)); return(ret.DistinctUntilChanged()); }
public static bool Activate(IActivator activator, IActivatable activatable, Dictionary <object, object> argumentDictionary = null) { bool capable = (int)activator.GetHealthState() >= (int)HealthState.Capable; if (capable && activatable != null) { activatable.BecomeActivated(activator, argumentDictionary); } return(capable); }
public IObservable <bool> GetActivationForView(IActivatable view) { var activation = GetActivationFor(view as ICanActivate) ?? GetActivationFor(view as Page) ?? GetActivationFor(view as View) ?? GetActivationFor(view as Cell) ?? Observable <bool> .Never; return(activation.DistinctUntilChanged()); }
private BehaviorSubject <bool> EnsureSubjectFor(IActivatable view) { BehaviorSubject <bool> subject; if (!this.forcedViews.TryGetValue(view, out subject)) { this.forcedViews[view] = subject = new BehaviorSubject <bool>(false); } return(subject); }
/// <summary> /// Get an observable defining whether the view is active. /// </summary> /// <param name="view">The view to observe.</param> /// <returns>An observable tracking whether the view is active.</returns> public IObservable <bool> GetActivationForView(IActivatable view) { var canActivate = view as ICanActivate; if (canActivate == null) { return(Observable.Empty(false)); } return(canActivate.Activated.Select(_ => true).Merge(canActivate.Deactivated.Select(_ => false))); }
internal GroupReference(String name, IEnumerable<LightAddress> addresses, IActivatable lightProvider) { if(name == null) throw new ArgumentException("Group name cannot be null"); if(name.Length == 0) throw new ArgumentException("Group must have a name. The empty string is not a valid group name"); _name = name; _lightProvider = lightProvider; UpdateMembers(addresses); }
public bool Check() { IActivatable element = elementManager.GetActivatableGameElement(refId); if (element == null) { System.Console.WriteLine("There is no activatable element with the given id! " + refId); return(false); } return(element.IsActive() == valueToCheck); }
public void ActivateHeldItem() { if (heldItem != null) { IActivatable item = heldItem.GetComponentInChildren <IActivatable>(); if (item != null) { item.Activate(); } } }
protected virtual void SafeFire(int eeiHand, bool MB, bool MBD) { if (completeBody.GetEquipmentEquipableArray()[eeiHand] != null) { IActivatable activatable = completeBody.GetEquipmentEquipableArray()[eeiHand] as IActivatable; Dictionary <object, object> argumentDictionary = new Dictionary <object, object>(); argumentDictionary["MB"] = MB; argumentDictionary["MBD"] = MBD; Activator.Activate(completeBody, activatable, argumentDictionary); } }
public IObservable<bool> GetActivationForView(IActivatable view) { var fe = view as FrameworkElement; if (fe == null) return Observable.Empty<bool>(); var viewLoaded = Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(x => fe.Loaded += x, x => fe.Loaded -= x).Select(_ => true); var viewUnloaded = Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(x => fe.Unloaded += x, x => fe.Unloaded -= x).Select(_ => false); return viewLoaded .Merge(viewUnloaded) .Select(b => b ? fe.WhenAnyValue(x => x.IsHitTestVisible).SkipWhile(x => !x) : Observable.Return(false)) .Switch() .DistinctUntilChanged(); }
public Tuple<IObservable<Unit>, IObservable<Unit>> GetActivationForView(IActivatable view) { var fe = view as FrameworkElement; if (fe == null) return Tuple.Create(Observable.Empty<Unit>(), Observable.Empty<Unit>()); var viewLoaded = Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(x => fe.Loaded += x, x => fe.Loaded -= x).Select(_ => Unit.Default); var viewHitTestVisible = fe.WhenAnyValue(v => v.IsHitTestVisible); var viewActivated = viewLoaded.CombineLatest(viewHitTestVisible, (l, h) => h) .Where(v => v) .Select(_ => Unit.Default); var viewUnloaded = Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(x => fe.Unloaded += x, x => fe.Unloaded -= x).Select(_ => Unit.Default); return Tuple.Create(viewActivated, viewUnloaded); }
public void remove(IActivatable responder) { list.Remove(responder); }
internal MasterGroup(string name, IEnumerable<LightAddress> addresses, IActivatable lightProvider) { _me = new GroupReference(name, addresses, lightProvider); }
public IObservable<bool> GetActivationForView(IActivatable view) { throw new NotImplementedException(); }
public IObservable<bool> GetActivationForView(IActivatable view) { var ca = view as ICanActivate; return ca.Activated.Select(_ => true).Merge(ca.Deactivated.Select(_ => false)); }
public KinectPatternStart(IActivatable lightProvider, Scene scene, KinectPlugin kinectPlugin, int bodyIndex) : base(lightProvider, scene, 0, 0, GetBasePattern(), bodyIndex+1) { _ordering = GetOrdering(scene, new Vector3D()); _bodyIndex = bodyIndex; _plugin = kinectPlugin; _patternGen = new PatternGenerator(scene); _patternGen.AvailableOrderings = new List<string>{SpatialOrderingTypes.Expand}; _patternGen.Params.PatternLengthMin = .5; _patternGen.Params.PatternLengthMax = 1; _patternGen.Params.ColorsMin = 2; kinectPlugin.GestureUpdateHandler += HandleGestureUpdate; }
/// <summary> /// Adds and activatable item to the activatables list. /// </summary> /// <param name="tileID">The ID of the tilwe.</param> /// <param name="active">The activatable instance.</param> public void addActivatable(string tileID, IActivatable active) { if(!activatables.ContainsKey(tileID)) activatables.Add(tileID, active); }
private static void Deactivate(IActivatable activatable) { foreach (LEDNode node in activatable.Nodes) { node.IsActive = false; } activatable.IsActive = false; }
public Tuple<IObservable<Unit>, IObservable<Unit>> GetActivationForView(IActivatable view) { var ca = view as ICanActivate; return Tuple.Create(ca.Activated, ca.Deactivated); }
public ActivatableConductor(IActivatable viewModel) { this.viewModel = viewModel; }
public void TieToControl(IActivatable parent) { parent.StateChanged += (_, __) => IsOpen = parent.WindowState != WindowState.Minimized; parent.Activated += (_, __) => IsOpen = true; parent.Deactivated += (_, __) => IsOpen = false; }
/** * Add a new Activatable to this Activator **/ public void add(IActivatable responder) { list.Add(responder); }
public static void ActivateForRead(IActivatable tba) { tba.Activate(ActivationPurpose.Read); }
public void Register(IActivatable item) { _collection.Add(item); if (Activated != item.Activated) item.Activated = Activated; }