private void setDrawable(IDrawableInfoComponent drawable) { foreach (var handle in _resizeHandles) handle.SetDrawable(drawable); foreach (var handle in _rotateHandles) handle.SetDrawable(drawable); _pivotHandle?.SetDrawable(drawable); _dragHandle?.SetDrawable(drawable); }
public override void Init(IEntity entity) { base.Init(entity); entity.Bind <ITranslateComponent>(c => _translate = c, _ => _translate = null); entity.Bind <IUIEvents>(c => c.MouseDown.Subscribe(onMouseDown), c => c.MouseDown.Unsubscribe(onMouseDown)); entity.Bind <IDrawableInfoComponent>(c => _drawable = c, _ => _drawable = null); }
public override void Init(IEntity entity) { base.Init(entity); _entity = entity; entity.Bind <IDrawableInfoComponent>(c => _drawable = c, _ => _drawable = null); _pipeline.Subscribe(entity.ID, this); }
public override void AfterInit() { _entity.Bind <IAnimationComponent>( c => { _animationComponent = c; _animationComponent.PropertyChanged += onAnimationChanged; onSomethingChanged(); }, c => { _animationComponent = null; _animationComponent.PropertyChanged -= onAnimationChanged; onSomethingChanged(); }); _entity.Bind <IHasRoomComponent>( c => { _room = c; refreshAreaScaling(); subscribeRoom(); onSomethingChanged(); }, c => { unsubscribeRoom(c); _room = null; refreshAreaScaling(); onSomethingChanged(); }); _entity.Bind <IScaleComponent>( c => { _scale = c; c.PropertyChanged += onScaleChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onScaleChanged; _scale = null; onSomethingChanged(); }); _entity.Bind <ITranslateComponent>( c => { _translate = c; c.PropertyChanged += onTranslateChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onTranslateChanged; _translate = null; onSomethingChanged(); } ); _entity.Bind <IJumpOffsetComponent>( c => { _jump = c; c.PropertyChanged += onJumpOffsetChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onJumpOffsetChanged; _jump = null; onSomethingChanged(); } ); _entity.Bind <IRotateComponent>( c => { _rotate = c; c.PropertyChanged += onRotateChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onRotateChanged; _rotate = null; onSomethingChanged(); } ); _entity.Bind <IImageComponent>( c => { _image = c; subscribeLabelRenderer(); c.PropertyChanged += onImageChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onImageChanged; _image = null; onSomethingChanged(); } ); _entity.Bind <IDrawableInfoComponent>( c => { _drawable = c; c.PropertyChanged += onDrawableChanged; onSomethingChanged(); }, c => { c.PropertyChanged -= onDrawableChanged; _drawable = null; onSomethingChanged(); }); _entity.Bind <IInObjectTreeComponent>( c => { _tree = c; _parent = _tree.TreeNode.Parent; _tree.TreeNode.OnParentChanged.Subscribe(onParentChanged); _parent?.OnMatrixChanged.Subscribe(onSomethingChanged); onSomethingChanged(); }, c => { c.TreeNode.OnParentChanged.Unsubscribe(onParentChanged); c.TreeNode.Parent?.OnMatrixChanged.Unsubscribe(onSomethingChanged); _tree = null; _parent = null; onSomethingChanged(); }); }
public override void Init(IEntity entity) { base.Init(entity); _entity = entity; entity.Bind <ITextComponent>(c => { _textComponent = c; c.PropertyChanged += onTextPropertyChanged; }, c => { _textComponent = null; c.PropertyChanged -= onTextPropertyChanged; }); entity.Bind <IImageComponent>(c => _imageComponent = c, _ => _imageComponent = null); entity.Bind <IUIEvents>(c => { _uiEvents = c; c.MouseDown.Subscribe(onMouseDown); c.LostFocus.Subscribe(onMouseDownOutside); }, c => { _uiEvents = null; c.MouseDown.Unsubscribe(onMouseDown); c.LostFocus.Unsubscribe(onMouseDownOutside); }); entity.Bind <IInObjectTreeComponent>(c => _tree = c, _ => _tree = null); entity.Bind <IHasRoomComponent>(c => _room = c, _ => _room = null); entity.Bind <IVisibleComponent>(c => _visibleComponent = c, _ => _visibleComponent = null); _game.Events.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); _caretFlashCounter = (int)CaretFlashDelay; _withCaret = _game.Factory.UI.GetLabel(entity.ID + " Caret", "|", 1f, 1f, 0f, 0f, config: new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText)); _withCaret.Pivot = new PointF(0f, 0f); _withCaret.TextBackgroundVisible = false; entity.Bind <IAnimationComponent>(c => { c.PropertyChanged += onAnimationPropertyChanged; _animationComponent = c; updateBorder(); }, c => { c.PropertyChanged -= onAnimationPropertyChanged; _animationComponent = null; updateBorder(); }); entity.Bind <IDrawableInfoComponent>(c => { _drawableComponent = c; c.PropertyChanged += onDrawableChanged; onRenderLayerChanged(); }, c => { c.PropertyChanged -= onDrawableChanged; _drawableComponent = null; }); }
public override void Init() { base.Init(); Entity.Bind <IDrawableInfoComponent>(c => _drawableInfo = c, _ => _drawableInfo = null); Entity.Bind <IImageComponent>(c => _obj = c, _ => _obj = null); Entity.Bind <IScaleComponent>(c => _scale = c, _ => _scale = null); Entity.Bind <IPixelPerfectComponent>(c => _pixelPerfect = c, _ => _pixelPerfect = null); Entity.Bind <IBoundingBoxComponent>(c => _boundingBox = c, _ => _boundingBox = null); }
public void Unsubscribe() { _tree?.TreeNode.OnParentChanged.Unsubscribe(onSomethingChanged); foreach (var binding in _bindings) { binding?.Unbind(); } _drawable = null; }
public override void Init() { base.Init(); Entity.Bind <IAnimationComponent>(c => _animation = c, _ => _animation = null); Entity.Bind <ITranslateComponent>(c => _translate = c, _ => _translate = null); Entity.Bind <IOutfitComponent>(c => _outfit = c, _ => _outfit = null); Entity.Bind <IHasRoomComponent>(c => _room = c, _ => _room = null); Entity.Bind <IDrawableInfoComponent>(c => _drawable = c, _ => _drawable = null); Entity.Bind <IFaceDirectionComponent>(c => _faceDirection = c, _ => _faceDirection = null); }
public override void Init(IEntity entity) { base.Init(entity); _entity = entity; entity.Bind <IDrawableInfoComponent>(c => _drawableInfo = c, _ => _drawableInfo = null); entity.Bind <IAnimationComponent>(c => _obj = c, _ => _obj = null); entity.Bind <IScaleComponent>(c => _scale = c, _ => _scale = null); entity.Bind <IPixelPerfectComponent>(c => _pixelPerfect = c, _ => _pixelPerfect = null); entity.Bind <IBoundingBoxComponent>(c => _boundingBox = c, _ => _boundingBox = null); }
public override void Init() { base.Init(); bindGraphics(Graphics); Entity.Bind <IDrawableInfoComponent>(c => _drawableInfo = c, _ => _drawableInfo = null); Entity.Bind <IInObjectTreeComponent>(c => _tree = c, _ => _tree = null); Entity.Bind <IVisibleComponent>(c => _visible = c, _ => _visible = null); Entity.Bind <IEnabledComponent>(c => _enabled = c, _ => _enabled = null); Entity.Bind <IUIEvents>(c => c.LostFocus.Subscribe(onLostFocus), c => c.LostFocus.Unsubscribe(onLostFocus)); _gameEvents.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); }
public override void Init() { base.Init(); Entity.Bind <IImageComponent>(c => _image = c, _ => _image = null); Entity.Bind <IScaleComponent>(c => { _scale = c; c.PropertyChanged += onScalePropertyChanged; }, c => { _scale = null; c.PropertyChanged -= onScalePropertyChanged; }); Entity.Bind <IDrawableInfoComponent>(c => { _drawable = c; c.PropertyChanged += onDrawablePropertyChanged; }, c => { _drawable = null; c.PropertyChanged -= onDrawablePropertyChanged; }); Entity.Bind <ICropSelfComponent>(c => _cropSelf = c, _ => _cropSelf = null); Entity.Bind <IModelMatrixComponent>(c => { _matrix = c; c.OnMatrixChanged.Subscribe(onMatrixChanged); }, c => { _matrix = null; c.OnMatrixChanged.Unsubscribe(onMatrixChanged); }); Entity.Bind <IVisibleComponent>(c => _visible = c, _ => _visible = null); _events.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); _pipeline.Subscribe(Entity.ID, this, -10); }
public AGSCharacter(string id, Resolver resolver, IOutfit outfit) : base(id, resolver) { _hasRoomComponent = AddComponent <IHasRoomComponent>(); Bind <IHasRoomComponent>(c => _hasRoomComponent = c, _ => {}); _animationComponent = AddComponent <IAnimationComponent>(); Bind <IAnimationComponent>(c => _animationComponent = c, _ => {}); _inObjectTreeComponent = AddComponent <IInObjectTreeComponent>(); Bind <IInObjectTreeComponent>(c => _inObjectTreeComponent = c, _ => {}); _colliderComponent = AddComponent <IColliderComponent>(); Bind <IColliderComponent>(c => _colliderComponent = c, _ => {}); _visibleComponent = AddComponent <IVisibleComponent>(); Bind <IVisibleComponent>(c => _visibleComponent = c, _ => {}); _enabledComponent = AddComponent <IEnabledComponent>(); Bind <IEnabledComponent>(c => _enabledComponent = c, _ => {}); _customPropertiesComponent = AddComponent <ICustomPropertiesComponent>(); Bind <ICustomPropertiesComponent>(c => _customPropertiesComponent = c, _ => {}); _drawableInfoComponent = AddComponent <IDrawableInfoComponent>(); Bind <IDrawableInfoComponent>(c => _drawableInfoComponent = c, _ => {}); _shaderComponent = AddComponent <IShaderComponent>(); Bind <IShaderComponent>(c => _shaderComponent = c, _ => {}); _translateComponent = AddComponent <ITranslateComponent>(); Bind <ITranslateComponent>(c => _translateComponent = c, _ => {}); _imageComponent = AddComponent <IImageComponent>(); Bind <IImageComponent>(c => _imageComponent = c, _ => {}); _borderComponent = AddComponent <IBorderComponent>(); Bind <IBorderComponent>(c => _borderComponent = c, _ => { }); _scaleComponent = AddComponent <IScaleComponent>(); Bind <IScaleComponent>(c => _scaleComponent = c, _ => {}); _rotateComponent = AddComponent <IRotateComponent>(); Bind <IRotateComponent>(c => _rotateComponent = c, _ => {}); _pixelPerfectComponent = AddComponent <IPixelPerfectComponent>(); Bind <IPixelPerfectComponent>(c => _pixelPerfectComponent = c, _ => {}); _modelMatrixComponent = AddComponent <IModelMatrixComponent>(); Bind <IModelMatrixComponent>(c => _modelMatrixComponent = c, _ => {}); _boundingBoxComponent = AddComponent <IBoundingBoxComponent>(); Bind <IBoundingBoxComponent>(c => _boundingBoxComponent = c, _ => {}); _worldPositionComponent = AddComponent <IWorldPositionComponent>(); Bind <IWorldPositionComponent>(c => _worldPositionComponent = c, _ => {}); _faceDirectionComponent = AddComponent <IFaceDirectionComponent>(); Bind <IFaceDirectionComponent>(c => _faceDirectionComponent = c, _ => {}); _outfitComponent = AddComponent <IOutfitComponent>(); Bind <IOutfitComponent>(c => _outfitComponent = c, _ => {}); _inventoryComponent = AddComponent <IInventoryComponent>(); Bind <IInventoryComponent>(c => _inventoryComponent = c, _ => {}); _followComponent = AddComponent <IFollowComponent>(); Bind <IFollowComponent>(c => _followComponent = c, _ => {}); _hotspotComponent = AddComponent <IHotspotComponent>(); Bind <IHotspotComponent>(c => _hotspotComponent = c, _ => {}); beforeInitComponents(resolver, outfit); InitComponents(); afterInitComponents(resolver, outfit); }
public AGSButton(string id, Resolver resolver) : base(id, resolver) { _uIEvents = AddComponent <IUIEvents>(); Bind <IUIEvents>(c => _uIEvents = c, _ => {}); _skinComponent = AddComponent <ISkinComponent>(); Bind <ISkinComponent>(c => _skinComponent = c, _ => {}); _hasRoomComponent = AddComponent <IHasRoomComponent>(); Bind <IHasRoomComponent>(c => _hasRoomComponent = c, _ => {}); _animationComponent = AddComponent <IAnimationComponent>(); Bind <IAnimationComponent>(c => _animationComponent = c, _ => {}); _inObjectTreeComponent = AddComponent <IInObjectTreeComponent>(); Bind <IInObjectTreeComponent>(c => _inObjectTreeComponent = c, _ => {}); _colliderComponent = AddComponent <IColliderComponent>(); Bind <IColliderComponent>(c => _colliderComponent = c, _ => {}); _visibleComponent = AddComponent <IVisibleComponent>(); Bind <IVisibleComponent>(c => _visibleComponent = c, _ => {}); _enabledComponent = AddComponent <IEnabledComponent>(); Bind <IEnabledComponent>(c => _enabledComponent = c, _ => {}); _customPropertiesComponent = AddComponent <ICustomPropertiesComponent>(); Bind <ICustomPropertiesComponent>(c => _customPropertiesComponent = c, _ => {}); _drawableInfoComponent = AddComponent <IDrawableInfoComponent>(); Bind <IDrawableInfoComponent>(c => _drawableInfoComponent = c, _ => {}); _shaderComponent = AddComponent <IShaderComponent>(); Bind <IShaderComponent>(c => _shaderComponent = c, _ => {}); _translateComponent = AddComponent <ITranslateComponent>(); Bind <ITranslateComponent>(c => _translateComponent = c, _ => {}); _imageComponent = AddComponent <IImageComponent>(); Bind <IImageComponent>(c => _imageComponent = c, _ => {}); _borderComponent = AddComponent <IBorderComponent>(); Bind <IBorderComponent>(c => _borderComponent = c, _ => { }); _scaleComponent = AddComponent <IScaleComponent>(); Bind <IScaleComponent>(c => _scaleComponent = c, _ => {}); _rotateComponent = AddComponent <IRotateComponent>(); Bind <IRotateComponent>(c => _rotateComponent = c, _ => {}); _pixelPerfectComponent = AddComponent <IPixelPerfectComponent>(); Bind <IPixelPerfectComponent>(c => _pixelPerfectComponent = c, _ => {}); _modelMatrixComponent = AddComponent <IModelMatrixComponent>(); Bind <IModelMatrixComponent>(c => _modelMatrixComponent = c, _ => {}); _boundingBoxComponent = AddComponent <IBoundingBoxComponent>(); Bind <IBoundingBoxComponent>(c => _boundingBoxComponent = c, _ => {}); _worldPositionComponent = AddComponent <IWorldPositionComponent>(); Bind <IWorldPositionComponent>(c => _worldPositionComponent = c, _ => {}); _textComponent = AddComponent <ITextComponent>(); Bind <ITextComponent>(c => _textComponent = c, _ => {}); _buttonComponent = AddComponent <IButtonComponent>(); Bind <IButtonComponent>(c => _buttonComponent = c, _ => {}); beforeInitComponents(resolver); InitComponents(); afterInitComponents(resolver); }
private void updateHitTestBox(SizeF size, IDrawableInfoComponent drawable, IModelMatrixComponent matrix) { var modelMatrices = matrix.GetModelMatrices(); var modelMatrix = modelMatrices.InVirtualResolutionMatrix; AGSModelMatrixComponent.GetVirtualResolution(false, _settings.VirtualResolution, drawable, null, out PointF resolutionFactor, out Size _); float width = size.Width / resolutionFactor.X; float height = size.Height / resolutionFactor.Y; _intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix); _hitTestBox = _boundingBoxBuilder.BuildHitTestBox(ref _intermediateBox); }
public AGSInventoryWindow(string id, Resolver resolver, IImage image) : base(id, resolver) { _uIEvents = AddComponent <IUIEvents>(); Bind <IUIEvents>(c => _uIEvents = c, _ => {}); _skinComponent = AddComponent <ISkinComponent>(); Bind <ISkinComponent>(c => _skinComponent = c, _ => {}); _hasRoom = AddComponent <IHasRoomComponent>(); Bind <IHasRoomComponent>(c => _hasRoom = c, _ => {}); _animationComponent = AddComponent <IAnimationComponent>(); Bind <IAnimationComponent>(c => _animationComponent = c, _ => {}); _inObjectTree = AddComponent <IInObjectTreeComponent>(); Bind <IInObjectTreeComponent>(c => _inObjectTree = c, _ => {}); _collider = AddComponent <IColliderComponent>(); Bind <IColliderComponent>(c => _collider = c, _ => {}); _visibleComponent = AddComponent <IVisibleComponent>(); Bind <IVisibleComponent>(c => _visibleComponent = c, _ => {}); _enabledComponent = AddComponent <IEnabledComponent>(); Bind <IEnabledComponent>(c => _enabledComponent = c, _ => {}); _customPropertiesComponent = AddComponent <ICustomPropertiesComponent>(); Bind <ICustomPropertiesComponent>(c => _customPropertiesComponent = c, _ => {}); _drawableInfo = AddComponent <IDrawableInfoComponent>(); Bind <IDrawableInfoComponent>(c => _drawableInfo = c, _ => {}); _hotspotComponent = AddComponent <IHotspotComponent>(); Bind <IHotspotComponent>(c => _hotspotComponent = c, _ => {}); _shaderComponent = AddComponent <IShaderComponent>(); Bind <IShaderComponent>(c => _shaderComponent = c, _ => {}); _translateComponent = AddComponent <ITranslateComponent>(); Bind <ITranslateComponent>(c => _translateComponent = c, _ => {}); _imageComponent = AddComponent <IImageComponent>(); Bind <IImageComponent>(c => _imageComponent = c, _ => {}); _scaleComponent = AddComponent <IScaleComponent>(); Bind <IScaleComponent>(c => _scaleComponent = c, _ => {}); _rotateComponent = AddComponent <IRotateComponent>(); Bind <IRotateComponent>(c => _rotateComponent = c, _ => {}); _pixelPerfectComponent = AddComponent <IPixelPerfectComponent>(); Bind <IPixelPerfectComponent>(c => _pixelPerfectComponent = c, _ => {}); _modelMatrixComponent = AddComponent <IModelMatrixComponent>(); Bind <IModelMatrixComponent>(c => _modelMatrixComponent = c, _ => {}); _boundingBoxComponent = AddComponent <IBoundingBoxComponent>(); Bind <IBoundingBoxComponent>(c => _boundingBoxComponent = c, _ => {}); _inventoryWindowComponent = AddComponent <IInventoryWindowComponent>(); Bind <IInventoryWindowComponent>(c => _inventoryWindowComponent = c, _ => {}); beforeInitComponents(resolver, image); InitComponents(); afterInitComponents(resolver, image); }
private void updateHitTestBox(IAnimationComponent animation, IDrawableInfoComponent drawable, IModelMatrixComponent matrix) { var modelMatrices = matrix.GetModelMatrices(); var modelMatrix = modelMatrices.InVirtualResolutionMatrix; Size resolution; PointF resolutionFactor; bool resolutionMatches = AGSModelMatrixComponent.GetVirtualResolution(false, _settings.VirtualResolution, drawable, null, out resolutionFactor, out resolution); var sprite = animation.Animation.Sprite; float width = sprite.BaseSize.Width / resolutionFactor.X; float height = sprite.BaseSize.Height / resolutionFactor.Y; _intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix); _hitTestBox = _boundingBoxBuilder.BuildHitTestBox(ref _intermediateBox); }
public (float x, float y) ToEditorResolution(float x, float y, IDrawableInfoComponent drawable) { var viewport = Game.State.Viewport; if (drawable != null && !drawable.IgnoreViewport) { var matrix = viewport.GetMatrix(drawable.RenderLayer); var vec = Vector3.Transform(new Vector3(x, y, 0f), matrix); x = vec.X; y = vec.Y; } x = MathUtils.Lerp(0f, 0f, Game.Settings.VirtualResolution.Width, viewport.ScreenArea.Width, x); y = MathUtils.Lerp(0f, 0f, Game.Settings.VirtualResolution.Height, viewport.ScreenArea.Height, y); x += viewport.ScreenArea.X; y += viewport.ScreenArea.Y; x = MathUtils.Lerp(0f, 0f, Game.Settings.WindowSize.Width, Editor.Settings.VirtualResolution.Width, x); y = MathUtils.Lerp(0f, 0f, Game.Settings.WindowSize.Height, Editor.Settings.VirtualResolution.Height, y); return(x, y); }
public EntitySubscriber(IEntity entity, Action <int> onLayerChanged) { _onLayerChanged = onLayerChanged; entity.Bind <IDrawableInfoComponent>(c => _drawable = c, _ => _drawable = null); var vBinding = bind <IVisibleComponent>(entity, onObjVisibleChanged); var tBinding = bind <ITranslateComponent>(entity, onObjTranslatePropertyChanged); var dBinding = bind <IDrawableInfoComponent>(entity, onObjDrawablePropertyChanged); var eBinding = bind <IAreaComponent>(entity, onAreaPropertyChanged); var bBinding = bind <IWalkBehindArea>(entity, onWalkBehindPropertyChanged); AnimationSubscriber animSubscriber = new AnimationSubscriber(entity, onSomethingChanged); var aBinding = animSubscriber.Bind(); var trBinding = entity.Bind <IInObjectTreeComponent>(c => { _tree = c; c.TreeNode.OnParentChanged.Subscribe(onSomethingChanged); onSomethingChanged(); }, c => { _tree = null; c.TreeNode.OnParentChanged.Unsubscribe(onSomethingChanged); onSomethingChanged(); }); _bindings = new List <IComponentBinding> { vBinding, tBinding, dBinding, aBinding, trBinding, eBinding, bBinding }; }
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; }
public override void Init() { base.Init(); Entity.Bind <ITextComponent>(c => { _textComponent = c; c.PropertyChanged += onTextPropertyChanged; }, c => { _textComponent = null; c.PropertyChanged -= onTextPropertyChanged; }); Entity.Bind <IUIEvents>(c => { c.MouseDown.Subscribe(onMouseDown); c.LostFocus.Subscribe(onMouseDownOutside); }, c => { c.MouseDown.Unsubscribe(onMouseDown); c.LostFocus.Unsubscribe(onMouseDownOutside); }); Entity.Bind <IInObjectTreeComponent>(c => _tree = c, _ => _tree = null); Entity.Bind <IHasRoomComponent>(c => _room = c, _ => _room = null); Entity.Bind <IVisibleComponent>(c => _visibleComponent = c, _ => _visibleComponent = null); _caretFlashCounter = (int)CaretFlashDelay; _withCaret = new Lazy <ILabel>(() => { var label = _game.Factory.UI.GetLabel(Entity.ID + " Caret", "|", 1f, 1f, 0f, 0f, config: _game.Factory.Fonts.GetTextConfig(autoFit: AutoFit.LabelShouldFitText)); label.Pivot = new PointF(0f, 0f); label.TextBackgroundVisible = false; return(label); }); Entity.Bind <IImageComponent>(c => _imageComponent = c, _ => _imageComponent = null); Entity.Bind <IDrawableInfoComponent>(c => _drawableComponent = c, _ => _drawableComponent = null); _game.Events.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); }
public void Prepare(IObject obj, IDrawableInfoComponent drawable, IViewport viewport) { }
public override void Init() { base.Init(); Entity.Bind <IModelMatrixComponent>(c => { c.OnMatrixChanged.Subscribe(_onHitTextBoxShouldChangeCallback); _matrix = c; }, c => { c.OnMatrixChanged.Unsubscribe(_onHitTextBoxShouldChangeCallback); _matrix = null; }); Entity.Bind <ICropSelfComponent>(c => { c.PropertyChanged += _onCropShouldChangeCallback; _crop = c; }, c => { c.PropertyChanged -= _onCropShouldChangeCallback; _crop = null; }); Entity.Bind <IImageComponent>(c => { _image = c; c.PropertyChanged += _onImageChangedCallback; }, c => { _image = null; c.PropertyChanged -= _onImageChangedCallback; }); Entity.Bind <IScaleComponent>(c => _scale = c, _ => _scale = null); Entity.Bind <IDrawableInfoComponent>(c => { c.PropertyChanged += _onDrawableChangedCallback; _drawable = c; }, c => { c.PropertyChanged -= _onDrawableChangedCallback; _drawable = null; }); Entity.Bind <ITextureOffsetComponent>(c => { c.PropertyChanged += _onTextureOffsetChangedCallback; _textureOffset = c; onAllViewportsShouldChange(); }, c => { c.PropertyChanged -= _onTextureOffsetChangedCallback; _textureOffset = null; onAllViewportsShouldChange(); }); }
public void SetDrawable(IDrawableInfoComponent drawable) => _drawable = drawable;
private void updateBoundingBoxes(IObject obj, IDrawableInfoComponent drawable, IViewport viewport) { var noFactor = AGSModelMatrixComponent.NoScaling; bool resolutionMatches; PointF hitTestResolutionFactor; Size resolution; PointF textScaleFactor = new PointF(GLText.TextResolutionFactorX, GLText.TextResolutionFactorY); if (!textScaleFactor.Equals(_lastTextScaleFactor)) { _lastTextScaleFactor = textScaleFactor; onBoundingBoxShouldChange(); } resolutionMatches = AGSModelMatrixComponent.GetVirtualResolution(false, _virtualResolution, drawable, textScaleFactor, out hitTestResolutionFactor, out resolution); var scaleUpText = hitTestResolutionFactor; var scaleDownText = noFactor; if (!textScaleFactor.Equals(hitTestResolutionFactor)) { textScaleFactor = noFactor; scaleDownText = hitTestResolutionFactor; } AutoFit autoFit = getAutoFit(); float height = obj.Height; float width = obj.Width; bool shouldUpdateBoundingBoxes = _shouldUpdateBoundingBoxes; _shouldUpdateBoundingBoxes = false; if (autoFit == AutoFit.LabelShouldFitText) { updateText(_glTextHitTest, resolutionMatches, GLText.EmptySize, scaleUpText, scaleDownText, int.MaxValue); if (!resolutionMatches) { updateText(_glTextRender, true, GLText.EmptySize, scaleUpText, scaleDownText, int.MaxValue); } CustomImageSize = new SizeF(_glTextHitTest.Width, _glTextHitTest.Height); } else if (autoFit == AutoFit.TextShouldWrapAndLabelShouldFitHeight) { updateText(_glTextHitTest, resolutionMatches, new SizeF(BaseSize.Width, GLText.EmptySize.Height), scaleUpText, scaleDownText, (int)BaseSize.Width); if (!resolutionMatches) { updateText(_glTextRender, true, new SizeF(BaseSize.Width, GLText.EmptySize.Height), scaleUpText, scaleDownText, (int)BaseSize.Width); } CustomImageSize = new SizeF(BaseSize.Width, _glTextHitTest.Height); } else { CustomImageSize = BaseSize; } CustomImageResolutionFactor = hitTestResolutionFactor; var viewportMatrix = drawable.IgnoreViewport ? Matrix4.Identity : _viewport.GetViewport(drawable.RenderLayer.Z).GetMatrix(viewport, drawable.RenderLayer.ParallaxSpeed); if (!viewportMatrix.Equals(_lastViewportMatrix)) { _lastViewportMatrix = viewportMatrix; onBoundingBoxShouldChange(); } var modelMatrices = obj.GetModelMatrices(); if (!modelMatrices.Equals(_lastMatrices)) { _lastMatrices = modelMatrices; onBoundingBoxShouldChange(); } if (!shouldUpdateBoundingBoxes) { return; } IGLMatrices textRenderMatrices = acquireMatrix(0).SetMatrices(modelMatrices.InObjResolutionMatrix, viewportMatrix); IGLMatrices labelRenderMatrices = obj.RenderLayer.IndependentResolution != null ? textRenderMatrices : acquireMatrix(1).SetMatrices(modelMatrices.InVirtualResolutionMatrix, viewportMatrix); IGLMatrices textHitTestMatrices = resolutionMatches ? textRenderMatrices : obj.RenderLayer.IndependentResolution == null ? labelRenderMatrices : acquireMatrix(2).SetMatrices(modelMatrices.InVirtualResolutionMatrix, viewportMatrix); IGLMatrices labelHitTestMatrices = obj.RenderLayer.IndependentResolution == null ? labelRenderMatrices : textHitTestMatrices; if (textScaleFactor.Equals(hitTestResolutionFactor)) { hitTestResolutionFactor = noFactor; } updateBoundingBoxes(_glTextHitTest, autoFit, textHitTestMatrices, labelHitTestMatrices, scaleUpText, noFactor, hitTestResolutionFactor, resolutionMatches, true); if (!resolutionMatches) { updateBoundingBoxes(_glTextRender, autoFit, textRenderMatrices, labelRenderMatrices, scaleUpText, scaleDownText, noFactor, true, false); } if (_lastWidth != Width || _lastHeight != Height) { OnLabelSizeChanged.Invoke(); } _lastWidth = Width; _lastHeight = Height; }
public override void AfterInit() { Entity.Bind <IDrawableInfoComponent>( c => { _drawable = c; c.PropertyChanged += _onDrawbaleChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onDrawbaleChangedCallback; _drawable = null; onSomethingChanged(); }); Entity.Bind <IHasRoomComponent>( c => { _room = c; refreshAreaScaling(); subscribeRoom(); onSomethingChanged(); }, c => { unsubscribeRoom(c); _room = null; refreshAreaScaling(); onSomethingChanged(); }); Entity.Bind <IScaleComponent>( c => { _scale = c; c.PropertyChanged += _onScaleChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onScaleChangedCallback; _scale = null; onSomethingChanged(); }); Entity.Bind <ITranslateComponent>( c => { _translate = c; c.PropertyChanged += _onTranslateChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onTranslateChangedCallback; _translate = null; onSomethingChanged(); } ); Entity.Bind <IWorldPositionComponent>( c => { _worldPosition = c; c.PropertyChanged += _onWorldPositionChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onWorldPositionChangedCallback; _translate = null; onSomethingChanged(); } ); Entity.Bind <IJumpOffsetComponent>( c => { _jump = c; c.PropertyChanged += _onJumpOffsetChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onJumpOffsetChangedCallback; _jump = null; onSomethingChanged(); } ); Entity.Bind <IRotateComponent>( c => { _rotate = c; c.PropertyChanged += _onRotateChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onRotateChangedCallback; _rotate = null; onSomethingChanged(); } ); Entity.Bind <IImageComponent>( c => { _image = c; c.PropertyChanged += _onImageChangedCallback; onSomethingChanged(); }, c => { c.PropertyChanged -= _onImageChangedCallback; _image = null; onSomethingChanged(); } ); Entity.Bind <ITextComponent>( c => { _text = c; subscribeTextComponent(); }, _ => { unsubscribeTextComponent(); _text = null; } ); Entity.Bind <IInObjectTreeComponent>( c => { _tree = c; _parent = _tree.TreeNode.Parent; _tree.TreeNode.OnParentChanged.Subscribe(_onParentChangedCallback); _parent?.OnMatrixChanged.Subscribe(_onSomethingChangedCallback); onSomethingChanged(); }, c => { c.TreeNode.OnParentChanged.Unsubscribe(_onParentChangedCallback); c.TreeNode.Parent?.OnMatrixChanged.Unsubscribe(_onSomethingChangedCallback); _tree = null; _parent = null; onSomethingChanged(); }); }
public static bool GetVirtualResolution(bool flattenLayerResolution, Size virtualResolution, IDrawableInfoComponent drawable, PointF?customResolutionFactor, out PointF resolutionFactor, out Size resolution) { //Priorities for virtual resolution: layer's resolution comes first, if not then the custom resolution (which is the text scaling resolution for text, otherwise null), //and if not use the virtual resolution. var layerResolution = drawable?.RenderLayer?.IndependentResolution; if (layerResolution != null) { if (flattenLayerResolution) { resolutionFactor = NoScaling; resolution = virtualResolution; return(false); } resolution = layerResolution.Value; resolutionFactor = new PointF(resolution.Width / (float)virtualResolution.Width, resolution.Height / (float)virtualResolution.Height); return(layerResolution.Value.Equals(virtualResolution)); } else if (customResolutionFactor != null) { resolutionFactor = customResolutionFactor.Value; resolution = new Size((int)(virtualResolution.Width * customResolutionFactor.Value.X), (int)(virtualResolution.Height * customResolutionFactor.Value.Y)); return(customResolutionFactor.Value.Equals(NoScaling)); } else { resolutionFactor = NoScaling; resolution = virtualResolution; return(true); } }
public override void Init(IEntity entity) { _entity = entity; base.Init(entity); entity.Bind <IModelMatrixComponent>(c => { c.OnMatrixChanged.Subscribe(onHitTextBoxShouldChange); _matrix = c; }, c => { c.OnMatrixChanged.Unsubscribe(onHitTextBoxShouldChange); _matrix = null; }); entity.Bind <ICropSelfComponent>(c => { c.PropertyChanged += onCropShouldChange; _crop = c; }, c => { c.PropertyChanged -= onCropShouldChange; _crop = null; }); entity.Bind <IImageComponent>(c => c.PropertyChanged += onImageChanged, c => c.PropertyChanged -= onImageChanged); entity.Bind <IAnimationComponent>(c => _animation = c, _animation => _animation = null); entity.Bind <IDrawableInfoComponent>(c => { c.PropertyChanged += onDrawableChanged; _drawable = c; }, c => { c.PropertyChanged -= onDrawableChanged; _drawable = null; }); entity.Bind <ITextureOffsetComponent>(c => { c.PropertyChanged += onTextureOffsetChanged; _textureOffset = c; onAllViewportsShouldChange(); }, c => { c.PropertyChanged -= onTextureOffsetChanged; _textureOffset = null; onAllViewportsShouldChange(); }); }
public static void ExpandAroundGameObject(AGSEditor editor, IBoundingBoxComponent boxComponent, IDrawableInfoComponent drawable, IImageComponent image, IObject objToExpand, bool updatePosition) { if (boxComponent == null || image == null) { return; } var box = boxComponent.WorldBoundingBox; objToExpand.Pivot = image.Pivot; var x = MathUtils.Lerp(0f, box.MinX, 1f, box.MaxX, image.Pivot.X); var y = MathUtils.Lerp(0f, box.MinY, 1f, box.MaxY, image.Pivot.Y); (x, y) = editor.ToEditorResolution(x, y, drawable); (var minX, var minY) = editor.ToEditorResolution(box.MinX, box.MinY, drawable); (var maxX, var maxY) = editor.ToEditorResolution(box.MaxX, box.MaxY, drawable); if (updatePosition) { objToExpand.Position = (x, y); } objToExpand.BaseSize = new SizeF(maxX - minX, maxY - minY); }