public IButton GetButton(string id, IAnimation idle, IAnimation hovered, IAnimation pushed, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1f, float height = -1f) { if (width == -1f && idle != null && idle.Frames.Count > 0) { width = idle.Frames[0].Sprite.Width; } if (height == -1f && idle != null && idle.Frames.Count > 0) { height = idle.Frames[0].Sprite.Height; } TypedParameter idParam = new TypedParameter (typeof(string), id); IButton button = _resolver.Resolve <IButton>(idParam); button.LabelRenderSize = new AGS.API.SizeF(width, height); if (idle != null && idle.Frames.Count > 0) button.IdleAnimation = idle; if (hovered != null && hovered.Frames.Count > 0) button.HoverAnimation = hovered; if (pushed != null && pushed.Frames.Count > 0) button.PushedAnimation = pushed; button.StartAnimation(button.IdleAnimation); button.Tint = Colors.White; button.X = x; button.Y = y; button.TextConfig = config; button.Text = text; if (addToUi) _gameState.UI.Add(button); return button; }
public ButtonAnimation(IAnimation animation, IBorderStyle border, ITextConfig textConfig, Color?tint) { Border = border; TextConfig = textConfig; Tint = tint; Animation = animation; }
public IDialogOption GetDialogOption(string text, ITextConfig config = null, ITextConfig hoverConfig = null, ITextConfig hasBeenChosenConfig = null, bool speakOption = true, bool showOnce = false) { var game = _resolver.Container.Resolve <IGame>(); config = config ?? _defaults.Idle; hoverConfig = hoverConfig ?? _defaults.Hovered; hasBeenChosenConfig = hasBeenChosenConfig ?? _defaults.Chosen; ILabel label = _ui.GetLabel($"Dialog option: {text}", text, game.Settings.VirtualResolution.Width, 20f, 0f, 0f, config: config, addToUi: false); label.RenderLayer = _defaults.RenderLayer; label.Enabled = true; TypedParameter labelParam = new TypedParameter(typeof(ILabel), label); NamedParameter speakParam = new NamedParameter("speakOption", speakOption); NamedParameter showOnceParam = new NamedParameter("showOnce", showOnce); NamedParameter hoverParam = new NamedParameter("hoverConfig", hoverConfig); NamedParameter wasChosenParam = new NamedParameter("hasBeenChosenConfig", hasBeenChosenConfig); TypedParameter playerParam = new TypedParameter(typeof(ICharacter), _gameState.Player); IDialogActions dialogActions = _resolver.Container.Resolve <IDialogActions>(playerParam); TypedParameter dialogActionsParam = new TypedParameter(typeof(IDialogActions), dialogActions); IDialogOption option = _resolver.Container.Resolve <IDialogOption>(labelParam, speakParam, showOnceParam, hoverParam, wasChosenParam, playerParam, dialogActionsParam); return(option); }
public void SetProperties(AGS.API.SizeF baseSize, string text = null, ITextConfig config = null, int? maxWidth = null, int caretPosition = 0, bool renderCaret = false, bool? cropText = null) { bool changeNeeded = (text != null && text != _text) || (config != null && config != _config) || (maxWidth != null && maxWidth.Value != _maxWidth) || !baseSize.Equals(_baseSize) || _caretPosition != caretPosition || _renderCaret != renderCaret || (cropText != null && cropText.Value != _cropText); if (!changeNeeded) return; _text = text; if (config != null && config != _config) { _config = config; _spaceWidth = measureSpace(); } if (maxWidth != null) _maxWidth = maxWidth.Value; if (cropText != null) _cropText = cropText.Value; _baseSize = baseSize; _caretPosition = caretPosition; _renderCaret = renderCaret; drawToBitmap(); }
public static AGSTextConfig FromConfig(ITextConfig config, float paddingBottomOffset = 0f) { AGSTextConfig textConfig = Clone(config); textConfig.PaddingBottom += paddingBottomOffset; return(textConfig); }
public static AGSTextConfig ChangeColor(ITextConfig config, Color color, Color outline, float outlineWidth) { AGSTextConfig textConfig = Clone(config); textConfig.Brush = Hooks.BrushLoader.LoadSolidBrush(color); textConfig.OutlineBrush = Hooks.BrushLoader.LoadSolidBrush(outline); textConfig.OutlineWidth = outlineWidth; return textConfig; }
public static AGSTextConfig ChangeColor(ITextConfig config, Color color, Color outline, float outlineWidth) { AGSTextConfig textConfig = Clone(config); textConfig.Brush = _brushes.LoadSolidBrush(color); textConfig.OutlineBrush = _brushes.LoadSolidBrush(outline); textConfig.OutlineWidth = outlineWidth; return textConfig; }
public static AGSTextConfig Clone(ITextConfig config) { AGSTextConfig textConfig = new AGSTextConfig(config.Brush, config.Font, config.OutlineBrush, config.OutlineWidth, config.ShadowBrush, config.ShadowOffsetX, config.ShadowOffsetY, config.Alignment, config.AutoFit, config.PaddingLeft, config.PaddingRight, config.PaddingTop, config.PaddingBottom); return(textConfig); }
public async Task <ISlider> GetSliderAsync(string id, string imagePath, string handleImagePath, float value, float min, float max, ITextConfig config = null, ILoadImageConfig loadConfig = null, bool addToUi = true) { var image = await _graphics.LoadImageAsync(imagePath, loadConfig); var handleImage = await _graphics.LoadImageAsync(handleImagePath, loadConfig); return(getSlider(id, image, handleImage, value, min, max, config, addToUi)); }
public IButton GetButton(string id, string idleImagePath, string hoveredImagePath, string pushedImagePath, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1f, float height = -1f) { IAnimation idle = _graphics.LoadAnimationFromFiles(files: new[] { idleImagePath }); IAnimation hovered = _graphics.LoadAnimationFromFiles(files: new[] { hoveredImagePath }); IAnimation pushed = _graphics.LoadAnimationFromFiles(files: new[] { pushedImagePath }); return(GetButton(id, idle, hovered, pushed, x, y, text, config, addToUi, width, height)); }
public ICheckBox GetCheckBox(string id, string notCheckedPath, string notCheckedHoveredPath, string checkedPath, string checkedHoveredPath, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1F, float height = -1F, bool isCheckButton = false) { IAnimation notChecked = _graphics.LoadAnimationFromFiles(files: new[] { notCheckedPath }); IAnimation notCheckedHovered = _graphics.LoadAnimationFromFiles(files: new[] { notCheckedHoveredPath }); IAnimation @checked = _graphics.LoadAnimationFromFiles(files: new[] { checkedPath }); IAnimation checkedHovered = _graphics.LoadAnimationFromFiles(files: new[] { checkedHoveredPath }); return(GetCheckBox(id, notChecked, notCheckedHovered, @checked, checkedHovered, x, y, text, config, addToUi, width, height, isCheckButton)); }
public bool Equals(ITextConfig config) { if (config == null) return false; if (ReferenceEquals(config, this)) return true; return Brush == config.Brush && Font == config.Font && Alignment == config.Alignment && OutlineBrush == config.OutlineBrush && MathUtils.FloatEquals(OutlineWidth, config.OutlineWidth) && ShadowBrush == config.ShadowBrush && MathUtils.FloatEquals(ShadowOffsetX, config.ShadowOffsetX) && MathUtils.FloatEquals(ShadowOffsetY, config.ShadowOffsetY) && AutoFit == config.AutoFit && MathUtils.FloatEquals(PaddingLeft, config.PaddingLeft) && MathUtils.FloatEquals(PaddingTop, config.PaddingTop) && MathUtils.FloatEquals(PaddingRight, config.PaddingRight) && MathUtils.FloatEquals(PaddingBottom, config.PaddingBottom); }
public GLText (IGraphicsBackend graphics, BitmapPool pool, string text = "", int maxWidth = int.MaxValue) { _graphics = graphics; this._maxWidth = maxWidth; this._text = text; this._bitmapPool = pool; _texture = createTexture (); _config = new AGSTextConfig (); drawToBitmap(); }
public bool SetProperties(SizeF baseSize, string text = null, ITextConfig config = null, int?maxWidth = null, PointF?scaleUp = null, PointF?scaleDown = null, int caretPosition = 0, int caretXOffset = 0, bool renderCaret = false, bool cropText = false, bool measureOnly = false) { bool configIsDifferent = config != null && !config.Equals(_config); bool changeNeeded = (text != null && text != _text) || configIsDifferent || (maxWidth != null && maxWidth.Value != _maxWidth) || !baseSize.Equals(_baseSize) || _caretPosition != caretPosition || _renderCaret != renderCaret || _caretXOffset != caretXOffset || cropText != _cropText || measureOnly != _measureOnly || (scaleUp != null && !scaleUp.Value.Equals(_scaleUp)) || (scaleDown != null && !scaleDown.Value.Equals(_scaleDown)); if (!changeNeeded) { return(false); } _text = text; if (configIsDifferent) { _config = AGSTextConfig.Clone(config); _spaceWidth = measureSpace(); } if (maxWidth != null) { _maxWidth = maxWidth.Value; } _cropText = cropText; _measureOnly = measureOnly; if (scaleUp != null) { _scaleUp = scaleUp.Value; } if (scaleDown != null) { _scaleDown = scaleDown.Value; } _baseSize = baseSize; _caretPosition = caretPosition; _caretXOffset = caretXOffset; _renderCaret = renderCaret; prepareBitmapDraw(); return(true); }
public GLText(IGraphicsBackend graphics, IFontLoader fonts, BitmapPool pool, string text = "", int maxWidth = int.MaxValue) { _fonts = fonts; _graphics = graphics; this._maxWidth = maxWidth; this._text = text; this._bitmapPool = pool; _texture = createTexture(); _config = new AGSTextConfig(); drawToBitmap(); }
public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset) { _height = height; _text = text; _config = config; _maxWidth = maxWidth; IFont font = _config.Font; IBrush outlineBrush = _config.OutlineBrush; float left = xOffset + _config.AlignX(textSize.Width, baseSize); float top = _config.AlignY(_bitmap.Height, textSize.Height, baseSize); float centerX = left + _config.OutlineWidth / 2f; float centerY = top + _config.OutlineWidth / 2f; float right = left + _config.OutlineWidth; float bottom = top + _config.OutlineWidth; var gfx = _gfx; if (_config.OutlineWidth > 0f) { drawString(gfx, outlineBrush, left, top); drawString(gfx, outlineBrush, centerX, top); drawString(gfx, outlineBrush, right, top); drawString(gfx, outlineBrush, left, centerY); drawString(gfx, outlineBrush, right, centerY); drawString(gfx, outlineBrush, left, bottom); drawString(gfx, outlineBrush, centerX, bottom); drawString(gfx, outlineBrush, right, bottom); } if (_config.ShadowBrush != null) { drawString(gfx, _config.ShadowBrush, centerX + _config.ShadowOffsetX, centerY + _config.ShadowOffsetY); } drawString(gfx, _config.Brush, centerX, centerY); //This should be a better way to render the outline (DrawPath renders the outline, and FillPath renders the text) //but for some reason some lines are missing when we render like that, at least on the mac /*if (_outlineWidth > 0f) { GraphicsPath path = new GraphicsPath (); Pen outlinePen = new Pen (_outlineBrush, _outlineWidth) { LineJoin = LineJoin.Round }; path.AddString(_text, _font.FontFamily, (int)_font.Style, _font.Size, new Point (), new StringFormat ()); //gfx.ScaleTransform(1.3f, 1.35f); gfx.DrawPath(outlinePen, path); gfx.FillPath(_brush, path); } else gfx.DrawString (_text, _font, _brush, 0f, 0f);*/ }
public IButton GetButton(string id, [MethodParam(DefaultProvider = nameof(GetDefaultIdleAnimation))] ButtonAnimation idle, [MethodParam(DefaultProvider = nameof(GetDefaultHoverAnimation))] ButtonAnimation hovered, [MethodParam(DefaultProvider = nameof(GetDefaultPushedAnimation))] ButtonAnimation pushed, float x, float y, [MethodParam(Browsable = false)] IObject parent = null, string text = "", [MethodParam(Browsable = false)] ITextConfig config = null, [MethodParam(Browsable = false, Default = false)] bool addToUi = true, [MethodParam(Browsable = false, Default = 25f)] float width = -1f, [MethodParam(Browsable = false, Default = 25f)] float height = -1f) { bool pixelArtButton = idle?.Image != null || (idle?.Animation != null && idle.Animation.Frames.Count > 0); // ReSharper disable once CompareOfFloatsByEqualityOperator if (width == -1f && pixelArtButton) { width = idle.Image?.Width ?? idle.Animation.Frames[0].Sprite.Width; } // ReSharper disable once CompareOfFloatsByEqualityOperator if (height == -1f && pixelArtButton) { height = idle.Image?.Height ?? idle.Animation.Frames[0].Sprite.Height; } Func <ButtonAnimation> defaultAnimation = () => new ButtonAnimation((IImage)null); idle = validateAnimation(id, idle, defaultAnimation, width, height); hovered = validateAnimation(id, hovered, defaultAnimation, width, height); pushed = validateAnimation(id, pushed, defaultAnimation, width, height); TypedParameter idParam = new TypedParameter(typeof(string), id); IButton button = _resolver.Container.Resolve <IButton>(idParam); button.LabelRenderSize = new SizeF(width, height); button.IdleAnimation = idle; button.HoverAnimation = hovered; button.PushedAnimation = pushed; button.Tint = pixelArtButton ? Colors.White : Colors.Transparent; button.X = x; button.Y = y; button.TextConfig = config ?? _fonts.GetTextConfig(alignment: Alignment.MiddleCenter); button.Text = text; setParent(button, parent); button.Skin?.Apply(button); button.IdleAnimation.StartAnimation(button, button, button, button); if (addToUi) { _gameState.UI.Add(button); } return(button); }
public static AGSTextConfig ScaleConfig(ITextConfig config, float sizeFactor) { AGSTextConfig textConfig = Clone(config); textConfig.Font = Hooks.FontLoader.LoadFont(config.Font.FontFamily, config.Font.SizeInPoints * sizeFactor, config.Font.Style); textConfig.OutlineWidth *= sizeFactor; textConfig.ShadowOffsetX *= sizeFactor; textConfig.ShadowOffsetY *= sizeFactor; textConfig.PaddingLeft *= sizeFactor; textConfig.PaddingRight *= sizeFactor; textConfig.PaddingTop *= sizeFactor; textConfig.PaddingBottom *= sizeFactor; return textConfig; }
public static AGSTextConfig ScaleConfig(ITextConfig config, float sizeFactor) { AGSTextConfig textConfig = Clone(config); textConfig.Font = config.Font.Resize(config.Font.SizeInPoints * sizeFactor); textConfig.OutlineWidth *= sizeFactor; textConfig.ShadowOffsetX *= sizeFactor; textConfig.ShadowOffsetY *= sizeFactor; textConfig.PaddingLeft *= sizeFactor; textConfig.PaddingRight *= sizeFactor; textConfig.PaddingTop *= sizeFactor; textConfig.PaddingBottom *= sizeFactor; return textConfig; }
public RunningTween(string name, Tween tween, IGame game, IObject parent) { _game = game; _tween = tween; var factory = game.Factory.UI; var borders = game.Factory.Graphics.Borders; var tweenId = ++id; _panel = factory.GetPanel($"FeaturesTweenPanel_{tweenId}", 300f, 20f, 0f, 0f, null, false); _panel.Visible = false; _panel.RenderLayer = parent.RenderLayer; _panel.Tint = Colors.Transparent; _panel.Pivot = (0f, 1f); _slider = factory.GetSlider($"FeaturesTweenSlider_{tweenId}", null, null, 0f, 0f, tween.DurationInTicks, _panel); _slider.Position = (10f, 10f); _slider.HandleGraphics.Pivot = (0.5f, 0.5f); _slider.Direction = SliderDirection.LeftToRight; _slider.Graphics.Pivot = (0f, 0.5f); _slider.Graphics.Image = new EmptyImage(_panel.Width - 100f, 10f); _slider.Graphics.Border = borders.SolidColor(Colors.DarkGray, 0.5f, true); _slider.HandleGraphics.Border = borders.SolidColor(Colors.White, 0.5f, true); HoverEffect.Add(_slider.Graphics, Colors.Green, Colors.LightGray); HoverEffect.Add(_slider.HandleGraphics, Colors.DarkGreen, Colors.WhiteSmoke); _label = factory.GetLabel($"FeaturesTweenLabel_{tweenId}", name, 100f, 20f, _slider.X + _slider.Graphics.Width / 2f, _slider.Y + 10f, _panel, _game.Factory.Fonts.GetTextConfig(autoFit: AutoFit.TextShouldFitLabel)); _label.Pivot = (0.5f, 0f); ITextConfig idleConfig = _game.Factory.Fonts.GetTextConfig(alignment: Alignment.MiddleCenter, brush: _game.Factory.Graphics.Brushes.LoadSolidBrush(Colors.White)); ITextConfig hoverConfig = _game.Factory.Fonts.GetTextConfig(alignment: Alignment.MiddleCenter, brush: _game.Factory.Graphics.Brushes.LoadSolidBrush(Colors.Black)); var idle = new ButtonAnimation(borders.SolidColor(Colors.AliceBlue, 2f), idleConfig, Colors.Transparent); var hovered = new ButtonAnimation(borders.SolidColor(Colors.Goldenrod, 2f), hoverConfig, Colors.Yellow); var pushed = new ButtonAnimation(borders.SolidColor(Colors.AliceBlue, 4f), idleConfig, Colors.Transparent); _rewindButton = factory.GetButton($"FeaturesTweenRewindButton_{tweenId}", idle, hovered, pushed, 235f, 0f, _panel, "Rewind", width: 100f, height: 30f); _playPauseButton = factory.GetButton($"FeaturesTweenPlayPauseButton_{tweenId}", idle, hovered, pushed, 345f, 0f, _panel, "Pause", width: 100f, height: 30f); _stopButton = factory.GetButton($"FeaturesTweenStopButton_{tweenId}", idle, hovered, pushed, 455f, 0f, _panel, "Stop", width: 100f, height: 30f); _stopButton.MouseClicked.Subscribe(_ => Stop()); _rewindButton.MouseClicked.Subscribe(_ => _tween.Rewind()); _playPauseButton.MouseClicked.Subscribe(onPlayPauseClick); _slider.OnValueChanging.Subscribe(onSliderValueChanging); _panel.TreeNode.SetParent(parent.TreeNode); game.State.UI.Add(_panel); _panel.Visible = true; game.Events.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); }
public ICheckBox GetCheckBox(string id, IAnimation notChecked, IAnimation notCheckedHovered, IAnimation @checked, IAnimation checkedHovered, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1F, float height = -1F, bool isCheckButton = false) { if (width == -1f && notChecked != null && notChecked.Frames.Count > 0) { width = notChecked.Frames[0].Sprite.Width; } if (height == -1f && notChecked != null && notChecked.Frames.Count > 0) { height = notChecked.Frames[0].Sprite.Height; } TypedParameter idParam = new TypedParameter(typeof(string), id); ICheckBox checkbox = _resolver.Resolve <ICheckBox>(idParam); checkbox.TextConfig = config; checkbox.Text = text; if (!isCheckButton) { checkbox.SkinTags.Add(AGSSkin.CheckBoxTag); checkbox.Skin.Apply(checkbox); } checkbox.LabelRenderSize = new AGS.API.SizeF(width, height); if (notChecked != null) { checkbox.NotCheckedAnimation = notChecked; } if (notCheckedHovered != null) { checkbox.HoverNotCheckedAnimation = notCheckedHovered; } if (@checked != null) { checkbox.CheckedAnimation = @checked; } if (checkedHovered != null) { checkbox.HoverCheckedAnimation = checkedHovered; } checkbox.StartAnimation(checkbox.NotCheckedAnimation); checkbox.Tint = Colors.White; checkbox.X = x; checkbox.Y = y; if (addToUi) { _gameState.UI.Add(checkbox); } return(checkbox); }
public static AGSTextConfig ScaleConfig(ITextConfig config, float sizeFactor) { AGSTextConfig textConfig = Clone(config); textConfig.Font = AGSGame.Game.Factory.Fonts.LoadFont(config.Font.FontFamily, config.Font.SizeInPoints * sizeFactor, config.Font.Style); textConfig.OutlineWidth *= sizeFactor; textConfig.ShadowOffsetX *= sizeFactor; textConfig.ShadowOffsetY *= sizeFactor; textConfig.PaddingLeft *= sizeFactor; textConfig.PaddingRight *= sizeFactor; textConfig.PaddingTop *= sizeFactor; textConfig.PaddingBottom *= sizeFactor; return(textConfig); }
private AGSSelectFileDialog(IGame game, IGLUtils glUtils, string title, FileSelection fileSelection, string startPath = null) { _glUtils = glUtils; _game = game; _title = title; _fileSelection = fileSelection; _startPath = startPath ?? Hooks.FileSystem.GetCurrentDirectory(); _buttonsTextConfig = new AGSTextConfig(alignment: Alignment.BottomCenter, autoFit: AutoFit.TextShouldFitLabel, font: Hooks.FontLoader.LoadFont(null, 10f)); _filesTextConfig = new AGSTextConfig(alignment: Alignment.BottomCenter, autoFit: AutoFit.TextShouldFitLabel, font: Hooks.FontLoader.LoadFont(null, 10f), brush: Hooks.BrushLoader.LoadSolidBrush(Colors.Black)); _tcs = new TaskCompletionSource<bool>(false); }
private AGSSelectFileDialog(IGame game, IGLUtils glUtils, string title, FileSelection fileSelection, string startPath = null) { _glUtils = glUtils; _game = game; _title = title; _fileSelection = fileSelection; _startPath = startPath ?? _device.FileSystem.GetCurrentDirectory() ?? ""; _buttonsTextConfig = new AGSTextConfig(alignment: Alignment.BottomCenter, autoFit: AutoFit.TextShouldFitLabel, font: game.Factory.Fonts.LoadFont(null, 10f)); _filesTextConfig = new AGSTextConfig(alignment: Alignment.BottomCenter, autoFit: AutoFit.TextShouldFitLabel, font: game.Factory.Fonts.LoadFont(null, 10f), brush: _device.BrushLoader.LoadSolidBrush(Colors.Black)); _tcs = new TaskCompletionSource <bool>(false); }
public GLText(IGraphicsBackend graphics, IRenderMessagePump messagePump, IFontFactory fonts, IFont defaultFont, BitmapPool pool, bool alwaysMeasureOnly, string text = "", int maxWidth = int.MaxValue) { _messagePump = messagePump; _fonts = fonts; _graphics = graphics; _alwaysMeasureOnly = alwaysMeasureOnly; _maxWidth = maxWidth; _text = text; _bitmapPool = pool; _config = fonts.GetTextConfig(font: defaultFont); prepareBitmapDraw(); }
public ILabel GetLabel(string id, string text, float width, float height, float x, float y, ITextConfig config = null, bool addToUi = true) { AGS.API.SizeF baseSize = new AGS.API.SizeF(width, height); TypedParameter idParam = new TypedParameter (typeof(string), id); ILabel label = _resolver.Resolve<ILabel>(idParam); label.LabelRenderSize = baseSize; label.Text = text; label.X = x; label.Y = y; label.Tint = Colors.Transparent; label.TextConfig = config ?? new AGSTextConfig(); if (addToUi) _gameState.UI.Add(label); return label; }
private void subscribeTextConfigChanges() { var config = _lastTextConfig; if (config != null) { config.PropertyChanged -= onTextConfigPropertyChanged; } config = Config; _lastTextConfig = config; if (config != null) { config.PropertyChanged += onTextConfigPropertyChanged; } }
//Parameter names for speakOption and showOnce are used in the factory, changing the names requires factory code change as well public AGSDialogOption(IDialogActions actions, ICharacter player, ILabel label, bool exitDialogOnFinish = false, bool speakOption = true, bool showOnce = false, ITextConfig hoverConfig = null, ITextConfig hasBeenChosenConfig = null) { _actions = actions; _player = player; Label = label; _normalConfig = label.TextConfig; HoverConfig = hoverConfig; HasBeenChosenConfig = hasBeenChosenConfig; ExitDialogWhenFinished = exitDialogOnFinish; SpeakOption = speakOption; ShowOnce = showOnce; label.MouseEnter.Subscribe(onMouseEnter); label.MouseLeave.Subscribe(onMouseLeave); }
//Parameter names for speakOption and showOnce are used in the factory, changing the names requires factory code change as well public AGSDialogOption(IDialogActions actions, ICharacter player, ILabel label, bool exitDialogOnFinish = false, bool speakOption = true, bool showOnce = false, ITextConfig hoverConfig = null, ITextConfig hasBeenChosenConfig = null) { _actions = actions; _player = player; Label = label; _normalConfig = label.TextConfig; HoverConfig = hoverConfig; HasBeenChosenConfig = hasBeenChosenConfig; ExitDialogWhenFinished = exitDialogOnFinish; SpeakOption = speakOption; ShowOnce = showOnce; label.MouseEnter.Subscribe(onMouseEnter); label.MouseLeave.Subscribe(onMouseLeave); }
public bool Equals(ITextConfig config) { if (config == null) { return(false); } if (config == this) { return(true); } return(Brush == config.Brush && Font == config.Font && Alignment == config.Alignment && OutlineBrush == config.OutlineBrush && MathUtils.FloatEquals(OutlineWidth, config.OutlineWidth) && ShadowBrush == config.ShadowBrush && MathUtils.FloatEquals(ShadowOffsetX, config.ShadowOffsetX) && MathUtils.FloatEquals(ShadowOffsetY, config.ShadowOffsetY) && AutoFit == config.AutoFit && MathUtils.FloatEquals(PaddingLeft, config.PaddingLeft) && MathUtils.FloatEquals(PaddingTop, config.PaddingTop) && MathUtils.FloatEquals(PaddingRight, config.PaddingRight) && MathUtils.FloatEquals(PaddingBottom, config.PaddingBottom)); }
public static AGSTextConfig Clone(ITextConfig config) { AGSTextConfig textConfig = new AGSTextConfig(); textConfig.Brush = config.Brush; textConfig.Font = config.Font; textConfig.Alignment = config.Alignment; textConfig.OutlineBrush = config.OutlineBrush; textConfig.OutlineWidth = config.OutlineWidth; textConfig.ShadowBrush = config.ShadowBrush; textConfig.ShadowOffsetX = config.ShadowOffsetX; textConfig.ShadowOffsetY = config.ShadowOffsetY; textConfig.AutoFit = config.AutoFit; textConfig.PaddingLeft = config.PaddingLeft; textConfig.PaddingRight = config.PaddingRight; textConfig.PaddingTop = config.PaddingTop; textConfig.PaddingBottom = config.PaddingBottom; return textConfig; }
public static AGSTextConfig Clone(ITextConfig config) { AGSTextConfig textConfig = new AGSTextConfig(); textConfig.Brush = config.Brush; textConfig.Font = config.Font; textConfig.Alignment = config.Alignment; textConfig.OutlineBrush = config.OutlineBrush; textConfig.OutlineWidth = config.OutlineWidth; textConfig.ShadowBrush = config.ShadowBrush; textConfig.ShadowOffsetX = config.ShadowOffsetX; textConfig.ShadowOffsetY = config.ShadowOffsetY; textConfig.AutoFit = config.AutoFit; textConfig.PaddingLeft = config.PaddingLeft; textConfig.PaddingRight = config.PaddingRight; textConfig.PaddingTop = config.PaddingTop; textConfig.PaddingBottom = config.PaddingBottom; return(textConfig); }
public IButton GetButton(string id, IAnimation idle, IAnimation hovered, IAnimation pushed, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1f, float height = -1f) { if (width == -1f && idle != null && idle.Frames.Count > 0) { width = idle.Frames[0].Sprite.Width; } if (height == -1f && idle != null && idle.Frames.Count > 0) { height = idle.Frames[0].Sprite.Height; } TypedParameter idParam = new TypedParameter(typeof(string), id); IButton button = _resolver.Resolve <IButton>(idParam); button.LabelRenderSize = new AGS.API.SizeF(width, height); if (idle != null && idle.Frames.Count > 0) { button.IdleAnimation = idle; } if (hovered != null && hovered.Frames.Count > 0) { button.HoverAnimation = hovered; } if (pushed != null && pushed.Frames.Count > 0) { button.PushedAnimation = pushed; } button.StartAnimation(button.IdleAnimation); button.Tint = Colors.White; button.X = x; button.Y = y; button.TextConfig = config; button.Text = text; if (addToUi) { _gameState.UI.Add(button); } return(button); }
public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset) { //_height = height; todo: support height _text = text; _config = config; _maxWidth = maxWidth; TextPaint paint = getPaint(_config.Brush); float left = xOffset + _config.AlignX(textSize.Width, baseSize); float top = _config.AlignY(_bitmap.Height, textSize.Height, baseSize); float centerX = left + _config.OutlineWidth / 2f; float centerY = top + _config.OutlineWidth / 2f; float right = left + _config.OutlineWidth; float bottom = top + _config.OutlineWidth; var canvas = _canvas; if (_config.OutlineWidth > 0f) { TextPaint outlinePaint = getPaint(_config.OutlineBrush); drawString(canvas, outlinePaint, left, top); drawString(canvas, outlinePaint, centerX, top); drawString(canvas, outlinePaint, right, top); drawString(canvas, outlinePaint, left, centerY); drawString(canvas, outlinePaint, right, centerY); drawString(canvas, outlinePaint, left, bottom); drawString(canvas, outlinePaint, centerX, bottom); drawString(canvas, outlinePaint, right, bottom); } if (_config.ShadowBrush != null) { TextPaint shadowPaint = getPaint(_config.ShadowBrush); drawString(canvas, shadowPaint, centerX + _config.ShadowOffsetX, centerY + _config.ShadowOffsetY); } drawString(canvas, paint, centerX, centerY); }
public IDialogOption GetDialogOption(string text, ITextConfig config = null, ITextConfig hoverConfig = null, ITextConfig hasBeenChosenConfig = null, bool speakOption = true, bool showOnce = false) { IGame game = _resolver.Resolve<IGame>(); if (config == null) config = new AGSTextConfig (autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, brush: Hooks.BrushLoader.LoadSolidBrush(Colors.White), font: Hooks.FontLoader.LoadFont(null,10f)); if (hoverConfig == null) hoverConfig = new AGSTextConfig (autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, brush: Hooks.BrushLoader.LoadSolidBrush(Colors.Yellow), font: Hooks.FontLoader.LoadFont(null, 10f)); if (hasBeenChosenConfig == null) hasBeenChosenConfig = new AGSTextConfig(autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, brush: Hooks.BrushLoader.LoadSolidBrush(Colors.Gray), font: Hooks.FontLoader.LoadFont(null, 10f)); ILabel label = _ui.GetLabel(string.Format("Dialog option: {0}", text), text, game.Settings.VirtualResolution.Width, 20f, 0f, 0f, config); label.Enabled = true; TypedParameter labelParam = new TypedParameter (typeof(ILabel), label); NamedParameter speakParam = new NamedParameter ("speakOption", speakOption); NamedParameter showOnceParam = new NamedParameter ("showOnce", showOnce); NamedParameter hoverParam = new NamedParameter ("hoverConfig", hoverConfig); NamedParameter wasChosenParam = new NamedParameter("hasBeenChosenConfig", hasBeenChosenConfig); TypedParameter playerParam = new TypedParameter(typeof(ICharacter), _gameState.Player); IDialogActions dialogActions = _resolver.Resolve<IDialogActions>(playerParam); TypedParameter dialogActionsParam = new TypedParameter(typeof(IDialogActions), dialogActions); IDialogOption option = _resolver.Resolve<IDialogOption>(labelParam, speakParam, showOnceParam, hoverParam, wasChosenParam, playerParam, dialogActionsParam); return option; }
private SizeF cropText(int maxWidth, ITextConfig config, ref string text) { var caretPosition = _caretPosition; if (caretPosition >= text.Length) caretPosition = text.Length - 1; SizeF newTextSize = new SizeF(); SizeF prevTextSize = newTextSize; StringBuilder textBuilder = new StringBuilder(); string newText = ""; string result = ""; int currentPosition = caretPosition; while (newTextSize.Width < maxWidth) { result = newText; prevTextSize = newTextSize; if (currentPosition > caretPosition) { textBuilder.Append(text[currentPosition]); currentPosition++; } else { textBuilder.Insert(0, text[currentPosition]); currentPosition--; if (currentPosition < 0) currentPosition = caretPosition + 1; } newText = textBuilder.ToString(); newTextSize = config.Font.MeasureString(newText, int.MaxValue); } text = result; return prevTextSize; }
private ISlider getSlider (string id, IImage image, IImage handleImage, float value, float min, float max, ITextConfig config = null, bool addToUi = true) { IObject graphics = _object.GetObject (string.Format ("{0}(graphics)", id)); graphics.Image = image; graphics.IgnoreViewport = true; ILabel label = null; if (config != null) { label = GetLabel (string.Format ("{0}(label)", id), "", graphics.Width, 30f, 0f, -30f, config, false); label.Anchor = new PointF (0.5f, 0f); } IObject handle = _object.GetObject (string.Format ("{0}(handle)", id)); handle.Image = handleImage; handle.IgnoreViewport = true; TypedParameter idParam = new TypedParameter (typeof (string), id); ISlider slider = _resolver.Resolve<ISlider> (idParam, idParam); slider.Label = label; slider.MinValue = min; slider.MaxValue = max; slider.Value = value; slider.Graphics = graphics; slider.HandleGraphics = handle; slider.IgnoreViewport = true; if (addToUi) _gameState.UI.Add (slider); return slider; }
public async Task<ISlider> GetSliderAsync(string id, string imagePath, string handleImagePath, float value, float min, float max, ITextConfig config = null, ILoadImageConfig loadConfig = null, bool addToUi = true) { var image = await _graphics.LoadImageAsync(imagePath, loadConfig); var handleImage = await _graphics.LoadImageAsync(handleImagePath, loadConfig); return getSlider(id, image, handleImage, value, min, max, config, addToUi); }
public async Task<ICheckBox> GetCheckBoxAsync(string id, string notCheckedPath, string notCheckedHoveredPath, string checkedPath, string checkedHoveredPath, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1F, float height = -1F, bool isCheckButton = false) { IAnimation notChecked = await _graphics.LoadAnimationFromFilesAsync(files: new[] { notCheckedPath }); IAnimation notCheckedHovered = await _graphics.LoadAnimationFromFilesAsync(files: new[] { notCheckedHoveredPath }); IAnimation @checked = await _graphics.LoadAnimationFromFilesAsync(files: new[] { checkedPath }); IAnimation checkedHovered = await _graphics.LoadAnimationFromFilesAsync(files: new[] { checkedHoveredPath }); return GetCheckBox(id, notChecked, notCheckedHovered, @checked, checkedHovered, x, y, text, config, addToUi, width, height, isCheckButton); }
public ICheckBox GetCheckBox(string id, IAnimation notChecked, IAnimation notCheckedHovered, IAnimation @checked, IAnimation checkedHovered, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1F, float height = -1F, bool isCheckButton = false) { if (width == -1f && notChecked != null && notChecked.Frames.Count > 0) { width = notChecked.Frames[0].Sprite.Width; } if (height == -1f && notChecked != null && notChecked.Frames.Count > 0) { height = notChecked.Frames[0].Sprite.Height; } TypedParameter idParam = new TypedParameter(typeof(string), id); ICheckBox checkbox = _resolver.Resolve<ICheckBox>(idParam); checkbox.TextConfig = config; checkbox.Text = text; if (!isCheckButton) { checkbox.SkinTags.Add(AGSSkin.CheckBoxTag); checkbox.Skin.Apply(checkbox); } checkbox.LabelRenderSize = new AGS.API.SizeF(width, height); if (notChecked != null) checkbox.NotCheckedAnimation = notChecked; if (notCheckedHovered != null) checkbox.HoverNotCheckedAnimation = notCheckedHovered; if (@checked != null) checkbox.CheckedAnimation = @checked; if (checkedHovered != null) checkbox.HoverCheckedAnimation = checkedHovered; checkbox.StartAnimation(checkbox.NotCheckedAnimation); checkbox.Tint = Colors.White; checkbox.X = x; checkbox.Y = y; if (addToUi) _gameState.UI.Add(checkbox); return checkbox; }
public ITextBox GetTextBox(string id, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1F, float height = -1F) { TypedParameter idParam = new TypedParameter(typeof(string), id); ITextBox textbox = _resolver.Resolve<ITextBox>(idParam); textbox.LabelRenderSize = new SizeF(width, height); textbox.X = x; textbox.Y = y; if (width < 0f && config == null) { config = new AGSTextConfig(autoFit: AutoFit.TextShouldCrop); } textbox.TextConfig = config; textbox.Text = text; if (addToUi) _gameState.UI.Add(textbox); return textbox; }
public async Task<IButton> GetButtonAsync(string id, string idleImagePath, string hoveredImagePath, string pushedImagePath, float x, float y, string text = "", ITextConfig config = null, bool addToUi = true, float width = -1f, float height = -1f) { IAnimation idle = await _graphics.LoadAnimationFromFilesAsync(files: new [] { idleImagePath }); IAnimation hovered = await _graphics.LoadAnimationFromFilesAsync(files: new [] { hoveredImagePath }); IAnimation pushed = await _graphics.LoadAnimationFromFilesAsync(files: new [] { pushedImagePath }); return GetButton (id, idle, hovered, pushed, x, y, text, config, addToUi, width, height); }
public static AGSTextConfig FromConfig(ITextConfig config, float paddingBottomOffset = 0f) { AGSTextConfig textConfig = Clone(config); textConfig.PaddingBottom += paddingBottomOffset; return textConfig; }
private void drawCaret(string text, SizeF textSize, SizeF baseSize, IBitmapTextDraw textDraw, ITextConfig config, int maxWidth) { if (!_renderCaret) return; var caretPosition = _caretPosition; if (caretPosition > text.Length) caretPosition = text.Length; string untilCaret = text.Substring(0, caretPosition); AGS.API.SizeF caretOffset = config.Font.MeasureString(untilCaret, maxWidth); float spaceOffset = 0f; if (untilCaret.EndsWith(" ")) spaceOffset = _spaceWidth * (untilCaret.Length - untilCaret.TrimEnd().Length); textDraw.DrawText("|", config, textSize, baseSize, maxWidth, (int)Height, caretOffset.Width + spaceOffset - 1f); }