Exemplo n.º 1
0
        public DragHandle(IObject handle, AGSEditor editor, IGameState state, ActionManager actions, bool needMoveCursor)
        {
            _editor                = editor;
            _actions               = actions;
            _state                 = state;
            _handle                = handle;
            _handle.Visible        = false;
            _handle.Enabled        = true;
            _handle.Border         = editor.Editor.Factory.Graphics.Borders.SolidColor(Colors.WhiteSmoke, 2f);
            _handle.RenderLayer    = AGSLayers.UI;
            _handle.IsPixelPerfect = false;
            _handle.AddComponent <IUIEvents>();
            _draggable = _handle.AddComponent <IDraggableComponent>();
            _draggable.OnDragStart.Subscribe(onDragStart);

            if (needMoveCursor)
            {
                var moveCursor = editor.Editor.Factory.UI.GetLabel("MoveCursor", "", 25f, 25f, 0f, 0f, config: FontIcons.IconConfig, addToUi: false);
                _moveCursor      = moveCursor;
                moveCursor.Pivot = new PointF(0.5f, 0.5f);
                moveCursor.Text  = FontIcons.Move;

                _handle.AddComponent <IHasCursorComponent>().SpecialCursor = moveCursor;
            }

            state.UI.Add(_handle);

            _handle.GetComponent <ITranslateComponent>().PropertyChanged += onHandleMoved;
        }
Exemplo n.º 2
0
        public static void Add(IObject obj, Color idleTint, Color hoverTint)
        {
            obj.Tint = idleTint;
            var uiEvents = obj.AddComponent <IUIEvents>();

            uiEvents.MouseEnter.Subscribe(_ => obj.Tint = hoverTint);
            uiEvents.MouseLeave.Subscribe(_ => obj.Tint = idleTint);
        }
Exemplo n.º 3
0
        public IObject GetAdventureObject(string id, string[] sayWhenLook = null, string[] sayWhenInteract = null)
        {
            IObject           obj     = GetObject(id);
            IHotspotComponent hotspot = obj.AddComponent <IHotspotComponent>();

            subscribeSentences(sayWhenLook, hotspot.Interactions.OnInteract(AGSInteractions.LOOK));
            subscribeSentences(sayWhenInteract, hotspot.Interactions.OnInteract(AGSInteractions.INTERACT));
            return(obj);
        }
Exemplo n.º 4
0
        public IObject GetAdventureObject(string id, [MethodParam(Browsable = false)] IRoom room = null,
                                          string[] sayWhenLook = null, string[] sayWhenInteract = null)
        {
            IObject           obj     = GetObject(id);
            IHotspotComponent hotspot = obj.AddComponent <IHotspotComponent>();

            subscribeSentences(sayWhenLook, hotspot.Interactions.OnInteract(AGSInteractions.LOOK));
            subscribeSentences(sayWhenInteract, hotspot.Interactions.OnInteract(AGSInteractions.INTERACT));
            room?.Objects.Add(obj);
            return(obj);
        }
Exemplo n.º 5
0
        private void subscribeClicks(IObject fileObj, Action <MouseButtonEventArgs> onClick, Action <MouseButtonEventArgs> onDoubleClick)
        {
            IUIEvents uiEvents = fileObj.AddComponent <IUIEvents>();

            uiEvents.MouseClicked.Subscribe(onClick);
            uiEvents.MouseDoubleClicked.Subscribe(onDoubleClick);
            fileObj.OnDisposed(() =>
            {
                uiEvents.MouseClicked.Unsubscribe(onClick);
                uiEvents.MouseDoubleClicked.Unsubscribe(onDoubleClick);
            });
        }
Exemplo n.º 6
0
        public void Prepare(IObject obj, IDrawableInfoComponent drawable, IViewport viewport)
        {
            if (!TextBackgroundVisible && !TextVisible)
            {
                return;
            }

            if (_lastObject != obj)
            {
                IBlockingEvent          boxChangeEvent = obj.GetComponent <IBoundingBoxComponent>()?.OnBoundingBoxesChanged ?? new AGSEvent();
                AGSBoundingBoxComponent box            = new AGSBoundingBoxComponent(_settings, _viewport,
                                                                                     _labelBoundingBoxFakeBuilder, _state, _events, boxChangeEvent);
                obj.RemoveComponent <IBoundingBoxComponent>();
                obj.AddComponent <IBoundingBoxComponent>(box);
                _lastObject = obj;
                foreach (var binding in _bindings)
                {
                    binding?.Unbind();
                }
                var scaleBinding    = obj.Bind <IScaleComponent>(c => c.PropertyChanged += onScalePropertyChanged, c => c.PropertyChanged -= onScalePropertyChanged);
                var matrixBinding   = obj.Bind <IModelMatrixComponent>(c => c.OnMatrixChanged.Subscribe(onMatrixChanged), c => c.OnMatrixChanged.Unsubscribe(onMatrixChanged));
                var drawableBinding = obj.Bind <IDrawableInfoComponent>(c => c.PropertyChanged += onDrawablePropertyChanged, c => c.PropertyChanged -= onDrawablePropertyChanged);
                onBoundingBoxShouldChange();
                _bindings.Clear();
                _bindings.Add(scaleBinding);
                _bindings.Add(matrixBinding);
                _bindings.Add(drawableBinding);
            }
            _glTextHitTest = _glTextHitTest ?? new GLText(_graphics, _messagePump, _fonts, _bitmapPool, false);
            _glTextRender  = _glTextRender ?? new GLText(_graphics, _messagePump, _fonts, _bitmapPool, true);

            updateBoundingBoxes(obj, drawable, viewport);
            if (_usedLabelBoundingBoxes != null)
            {
                _labelBoundingBoxFakeBuilder.BoundingBoxes = _usedLabelBoundingBoxes;
            }
            _bgRenderer.Prepare(obj, drawable, viewport);
            Width  = _usedLabelBoundingBoxes == null ? 1f : _usedLabelBoundingBoxes.RenderBox.Width;
            Height = _usedLabelBoundingBoxes == null ? 1f : _usedLabelBoundingBoxes.RenderBox.Height;
        }
Exemplo n.º 7
0
        private async Task <bool> walkStraightLine(WalkInstruction currentWalk, Position destination, List <IObject> debugRenderers)
        {
            if (_room?.Room != currentWalk.Room)
            {
                return(false);
            }

            if (debugRenderers != null)
            {
                IObject renderer = _objFactory.GetObject("Debug Line");
                var     line     = renderer.AddComponent <GLLineRenderer>();
                if (line != null)
                {
                    line.X1 = _translate.X;
                    line.Y1 = _translate.Y;
                    line.X2 = destination.X;
                    line.Y2 = destination.Y;
                }
                await renderer.ChangeRoomAsync(currentWalk.Room);

                debugRenderers.Add(renderer);
            }

            if (_cutscene.IsSkipping)
            {
                _translate.Position = destination;
                return(true);
            }

            if (!isDistanceVeryShort(destination))
            {
                var  lastDirection  = _faceDirection.Direction;
                var  walkAnimation  = _outfit.Outfit[AGSOutfit.Walk];
                bool alreadyWalking = _faceDirection.CurrentDirectionalAnimation == walkAnimation;
                _faceDirection.CurrentDirectionalAnimation = walkAnimation;
                await _faceDirection.FaceDirectionAsync(_translate.X, _translate.Y, destination.X, destination.Y);

                if (lastDirection != _faceDirection.Direction && alreadyWalking)
                {
                    await Task.Delay(200);
                }
            }

            float xSteps = Math.Abs(destination.X - _translate.X);
            float ySteps = Math.Abs(destination.Y - _translate.Y);

            float numSteps    = Math.Max(xSteps, ySteps);
            bool  isBaseStepX = xSteps >= ySteps;

            float xStep = xSteps / numSteps;

            if (_translate.X > destination.X)
            {
                xStep = -xStep;
            }

            float yStep = ySteps / numSteps;

            if (_translate.Y > destination.Y)
            {
                yStep = -yStep;
            }

            WalkLineInstruction instruction = new WalkLineInstruction(numSteps, xStep, yStep,
                                                                      isBaseStepX, destination);

            currentWalk.CurrentLine = instruction;
            if (_currentWalk != currentWalk)
            {
                onWalkLineCompleted(currentWalk, instruction, false);
                currentWalk.CancelToken.Cancel();
                return(false);
            }
            Task timeout       = Task.Delay(WalkLineTimeoutInMilliseconds);
            Task completedTask = await Task.WhenAny(instruction.OnCompletion.Task, currentWalk.OnCompletion.Task, timeout);

            if (completedTask == timeout)
            {
                currentWalk.CancelToken.Cancel();
                return(false);
            }

            if (completedTask == currentWalk.OnCompletion.Task)
            {
                return(false);
            }

            if (!instruction.OnCompletion.Task.Result || currentWalk.CancelToken.IsCancellationRequested ||
                _room?.Room != currentWalk.Room || (!currentWalk.WalkAnywhere && !isWalkable(_translate.Position)))
            {
                return(false);
            }

            if (currentWalk.WalkAnywhere || isWalkable(destination))
            {
                _translate.Position = destination;
                return(true);
            }

            return(false);
        }