Exemplo n.º 1
0
        public void OnActivate()
        {
            if (Warnings.Inactive(this))
            {
                return;
            }

            var glider = GameObj.GetComponent <AlphaGlider>();

            if (!Warnings.NullOrDisposed(glider))
            {
                glider?.Add(new AlphaGlider.Step
                {
                    Duration = EffectSpeed,
                    Patient  = false,
                    Target   = NormalAlpha
                });

                glider?.Add(new AlphaGlider.Step
                {
                    Duration = EffectSpeed,
                    Patient  = true,
                    Target   = 0,
                    Text     = true
                });
            }

            if (_transferMessages != null && _transferMessages.ContainsKey(Channel))
            {
                Flash(_transferMessages[Channel]);
                _transferMessages.Remove(Channel);
            }
        }
Exemplo n.º 2
0
        protected IEnumerable <ICmpLayoutElement> GetChildLayoutElements()
        {
            if (Warnings.NullOrDisposed(GameObj))
            {
                yield break;
            }

            // GameObj does have a method "GetComponentInChildren", but
            // it seems to retrieve components among all descendents instead?
            // This would interfere with child layouts
            foreach (var child in GameObj.Children)
            {
                //if (!child.Active) continue;

                foreach (var item in child.GetComponents <ICmpLayoutElement>())
                {
                    // Ignoring inactive components will cause inconsistencies on init. This will need another look.
                    if ((!item.Active) || item.IgnoreParentLayout)
                    {
                        continue;
                    }
                    yield return(item);
                }
            }
        }
Exemplo n.º 3
0
        private GameObject Get(ContentRef <Prefab> prefab, bool forceCreate)
        {
            string     key = prefab.Path;
            GameObject obj = null;

            if (!forceCreate && _inactive != null)
            {
                if (_inactive.TryGetValue(key, out var inactiveQueue))
                {
                    if (inactiveQueue.Count > 0)
                    {
                        obj = inactiveQueue.Dequeue();
                    }
                }
            }

            if (Warnings.NullOrDisposed(obj, warn: false))
            {
                if (Warnings.NullOrDisposed(prefab.Res))
                {
                    return(null);
                }
                obj = prefab.Res.Instantiate();
                if (Warnings.NullOrDisposed(obj))
                {
                    return(null);
                }

                obj.AddComponent <Transient>();

                if (_roster == null)
                {
                    _roster = new HashSet <GameObject>();
                }

                _roster.Add(obj);
            }

            Queue <GameObject> activeQueue;

            if (_active == null)
            {
                _active = new Dictionary <string, Queue <GameObject> >();
            }

            if (!_active.TryGetValue(key, out activeQueue))
            {
                activeQueue = new Queue <GameObject>();
                _active.Add(key, activeQueue);
            }

            activeQueue.Enqueue(obj);
            obj.ActiveSingle = true;

            return(obj);
        }
Exemplo n.º 4
0
        private void SetupListeners()
        {
            ClearListeners();

            _keyListener = GameObj.GetComponent <KeyListener>();

            if (!Warnings.NullOrDisposed(_keyListener))
            {
                _keyListener.KeyUp += _keyListener_KeyUp;
            }
        }
Exemplo n.º 5
0
        public static IEnumerable <T> GetChildComponents <T>(UIContext parent, string name) where T : class
        {
            if (Warnings.NullOrDisposed(parent))
            {
                return(new T[0]);
            }

            var queue = new Queue <GameObject>(parent.GameObj.Children);

            return(GetComponents <T>(queue, name));
        }
Exemplo n.º 6
0
        public void OnActivate()
        {
            index = 0;

            var renderer = GameObj.GetComponent <TextRenderer>();

            if (Warnings.NullOrDisposed(renderer))
            {
                return;
            }

            renderer.Text.ApplySource("Loading... ");
        }
Exemplo n.º 7
0
        public void ResetAction(Button button)
        {
            Exit();

            var gamePieces = Scene.Current.FindComponent <GamePieces>();

            if (Warnings.NullOrDisposed(gamePieces))
            {
                return;
            }

            gamePieces.ResetPieces();
            GameNetworking.Sync(CupboardApp.Networker);
        }
Exemplo n.º 8
0
        public void OnUpdate()
        {
            if (Content == null)
            {
                return;
            }

            string message = "";

            if (index > 0 && index < Content.Count)
            {
                var nextContent = Content[index];

                // Not sure if both checks are needed here.
                if (nextContent == null || nextContent.IsExplicitNull)
                {
                    Logs.Game.WriteWarning("Some of the preloaders content references are invalid.");
                }

                else
                {
                    message = "Loading " + nextContent.FullName;
                }
            }

            else
            {
                message = "Loading Complete!";
            }

            var renderer = GameObj.GetComponent <TextRenderer>();

            if (!Warnings.NullOrDisposed(renderer))
            {
                renderer.Text.ApplySource(message);
            }

            index--;

            if (index > 0 && index < Content.Count)
            {
                var currentContent = Content[index];
                currentContent.EnsureLoaded();
            }

            index += 2;
        }
Exemplo n.º 9
0
        private static void ParseIncomingDiceMessage(DataRecievedEventArgs e)
        {
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(e.Data)))
            {
                var message = Serializer.TryReadObject <DiceMessage>(stream);

                bool success = false;

                if (message == null || message.DiceID == null)
                {
                    Logs.Game.WriteWarning("Failed to read dice message sent by " + e.RemoteEndPoint);
                }
                else
                {
                    var dice = Scene.Current
                               .FindComponents <Dice>()
                               .Where(x => x.DiceID == message.DiceID)
                               .FirstOrDefault();

                    if (Warnings.NullOrDisposed(dice))
                    {
                        Logs.Game.WriteWarning("Recieved dice message, but could not find a pawn for it.");
                    }

                    else
                    {
                        if (!dice.Rolling)
                        {
                            dice.Roll(message.Time, message.Side);
                        }

                        else
                        {
                            OldContext.ShowNotification("Error", "Simultaneous dice rolls.", 3);
                        }

                        success = true;
                    }
                }

                if (!success)
                {
                    OldContext.ShowNotification("Error", "Failed to load incoming dice message.", 3);
                }
            }
        }
Exemplo n.º 10
0
        public static IEnumerable <UIContext> GetParentContexts(Component child)
        {
            if (Warnings.NullOrDisposed(child))
            {
                return(null);
            }

            IList <UIContext> contexts = new UIContext[0];
            var obj = child.GameObj?.Parent;

            while (obj != null && contexts.Count == 0)
            {
                contexts = obj.GetComponents <UIContext>();
                obj      = obj.Parent;
            }

            return(contexts);
        }
Exemplo n.º 11
0
        private float GetAngle(GameObject obj)
        {
            var glider = obj.GetComponent <Glider>();

            if (!Warnings.NullOrDisposed(glider))
            {
                return(glider.TargetLocalAngle);
            }

            var transform = obj.Transform;

            if (!Warnings.NullOrDisposed(glider))
            {
                return(transform.LocalAngle);
            }

            return(0);
        }
Exemplo n.º 12
0
        private void SetAngle(GameObject obj, float angle)
        {
            if (Smooth)
            {
                var glider = obj.GetComponent <Glider>();

                if (!Warnings.NullOrDisposed(glider))
                {
                    glider.TargetLocalAngle = angle;
                    return;
                }
            }

            var transform = obj.Transform;

            if (!Warnings.NullOrDisposed(transform))
            {
                transform.LocalAngle = angle;
                return;
            }
        }
Exemplo n.º 13
0
        private static void ParseIncomingSpinMessage(DataRecievedEventArgs e)
        {
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(e.Data)))
            {
                var message = Serializer.TryReadObject <SpinMessage>(stream);

                bool success = false;

                if (message == null || message.Name == null)
                {
                    Logs.Game.WriteWarning("Failed to read spin message sent by " + e.RemoteEndPoint);
                }
                else
                {
                    var target  = Scene.Current.FindGameObject(message.Name);
                    var spinner = Scene.Current.FindComponent <Spinner>();

                    if (Warnings.NullOrDisposed(target))
                    {
                        Logs.Game.WriteWarning("Recieved spin message, but could not find a target for it.");
                    }

                    else if (Warnings.NullOrDisposed(spinner))
                    {
                        Logs.Game.WriteWarning("Recieved spin message, but could not find a spinner for it.");
                    }

                    else
                    {
                        spinner.Spin(target, message.Angle);
                        success = true;
                    }
                }

                if (!success)
                {
                    OldContext.ShowNotification("Error", "Failed to load incoming spin message.", 3);
                }
            }
        }
Exemplo n.º 14
0
        private void _keyListener_KeyUp(object sender, KeyboardKeyEventArgs e)
        {
            if (Warnings.NullOrDisposed(Scene))
            {
                return;
            }
            var keeper = Scene.FindComponent <SelectionKeeper>();

            if (Warnings.NullOrDisposed(keeper))
            {
                return;
            }

            if (keeper.Selection == null)
            {
                return;
            }

            var vel = 0;

            if (e.Key == Key.Right)
            {
                vel = 1;
            }

            else if (e.Key == Key.Left)
            {
                vel = -1;
            }

            if (vel != 0)
            {
                var angle = GetAngle(keeper.Selection);
                angle += MathF.DegToRad(Increment) * vel;

                GameNetworking.SendSpin(CupboardApp.Networker, angle, keeper.Selection.Name);

                SetAngle(keeper.Selection, angle);
            }
        }
Exemplo n.º 15
0
        private void SetOriginal()
        {
            if (_current.Text)
            {
                var renderer = GameObj.GetComponent <TextRenderer>();
                if (Warnings.NullOrDisposed(renderer))
                {
                    return;
                }

                _original = renderer.ColorTint.A / 255f;
            }
            else
            {
                var renderer = GameObj.GetComponent <SpriteRenderer>();
                if (Warnings.NullOrDisposed(renderer))
                {
                    return;
                }

                _original = renderer.ColorTint.A / 255f;
            }
        }
Exemplo n.º 16
0
        private void ApplyAlpha(float alpha)
        {
            if (_current.Text)
            {
                var renderer = GameObj.GetComponent <TextRenderer>();
                if (Warnings.NullOrDisposed(renderer))
                {
                    return;
                }

                renderer.ColorTint = renderer.ColorTint.WithAlpha(alpha);
            }
            else
            {
                var renderer = GameObj.GetComponent <SpriteRenderer>();
                if (Warnings.NullOrDisposed(renderer))
                {
                    return;
                }

                renderer.ColorTint = renderer.ColorTint.WithAlpha(alpha);
            }
        }
Exemplo n.º 17
0
        public void Flash(Notification message)
        {
            if (string.IsNullOrWhiteSpace(message.Text))
            {
                return;
            }
            if (Warnings.Inactive(this))
            {
                return;
            }

            var renderer = GameObj.GetComponent <TextRenderer>();

            if (Warnings.NullOrDisposed(renderer))
            {
                return;
            }

            _lastMessage     = message;
            _lastMessageTime = Time.GameTimer.TotalSeconds;

            var source = message.Text;

            renderer.Text.ApplySource(source);

            var bg = GameObj.GetComponent <Background>();

            if (!Warnings.NullOrDisposed(bg))
            {
                bg.PerformLayout();
            }

            var bgRenderer = GameObj.GetComponent <SpriteRenderer>();

            if (!Warnings.NullOrDisposed(bgRenderer))
            {
                bgRenderer.ColorTint = message.Color.WithAlpha(NormalAlpha);
            }

            var glider = GameObj.GetComponent <AlphaGlider>();

            if (Warnings.NullOrDisposed(glider))
            {
                return;
            }

            glider.Add(new AlphaGlider.Step
            {
                Duration = EffectSpeed / 6,
                Patient  = false,
                Target   = 1,
                Text     = true
            });

            glider.Add(new AlphaGlider.Step
            {
                Duration = EffectSpeed,
                Patient  = true,
                Target   = FlashAlpha
            });

            glider.Add(new AlphaGlider.Step
            {
                Duration = EffectSpeed,
                Patient  = true,
                Target   = ActiveAlpha
            });

            glider.Add(new AlphaGlider.Step
            {
                Duration = message.Duration,
                Finite   = message.Finite,
                Patient  = true,
                Target   = ActiveAlpha
            });

            glider.Add(new AlphaGlider.Step
            {
                Duration = EffectSpeed,
                Patient  = true,
                Target   = NormalAlpha
            });

            glider.Add(new AlphaGlider.Step
            {
                Duration = EffectSpeed / 3,
                Patient  = true,
                Target   = 0,
                Text     = true
            });
        }