コード例 #1
0
 public AGSStringItem(IFont font = null)
 {
     font            = font ?? AGSGame.Game.Settings.Defaults.SpeechFont;
     IdleTextConfig  = new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText, font: font);
     HoverTextConfig = AGSTextConfig.ChangeColor(IdleTextConfig, Colors.Yellow, Colors.Black, 0f);
     Properties      = new AGSCustomProperties();
 }
コード例 #2
0
        public void BeforeDisplayingNode(ITreeStringNode item, ITreeNodeView nodeView,
                                         bool isCollapsed, bool isHovered, bool isSelected)
        {
            var textConfig = isHovered ? item.HoverTextConfig : item.IdleTextConfig;
            var label      = nodeView.TreeItem as ITextComponent;

            if (label != null)
            {
                label.TextConfig            = textConfig;
                label.Text                  = item.Text;
                label.TextBackgroundVisible = isSelected;
            }
            nodeView.TreeItem.Tint = isSelected ? Colors.DarkSlateBlue : Colors.Transparent;
            var expandButton = nodeView.ExpandButton;

            if (expandButton != null)
            {
                var expandTextConfig = textConfig;
                if (item.TreeNode.ChildrenCount == 0)
                {
                    expandTextConfig = AGSTextConfig.ChangeColor(textConfig, textConfig.Brush.Color.WithAlpha(0), textConfig.OutlineBrush.Color, textConfig.OutlineWidth);
                }
                expandButton.TextConfig = expandTextConfig;
                expandButton.Text       = isCollapsed ? "+" : "-";
                expandButton.Enabled    = expandButton.TextVisible;
            }
        }
コード例 #3
0
        public ITextBox GetTextBox(string id, float x, float y, IObject parent = null, string watermark = "", ITextConfig config = null,
                                   bool addToUi = true, float width = -1F, float height = -1F)
        {
            TypedParameter idParam = new TypedParameter(typeof(string), id);
            ITextBox       textbox = _resolver.Container.Resolve <ITextBox>(idParam);

            textbox.LabelRenderSize = new SizeF(width, height);
            textbox.X = x;
            textbox.Y = y;
            if (config == null)
            {
                config = new AGSTextConfig(autoFit: AutoFit.TextShouldCrop);
            }
            textbox.TextConfig = config;
            textbox.Text       = "";
            setParent(textbox, parent);
            if (!string.IsNullOrEmpty(watermark))
            {
                var watermarkConfig = AGSTextConfig.Clone(config);
                watermarkConfig.Brush = _graphics.Brushes.LoadSolidBrush(Colors.LightGray);
                var watermarkLabel = GetLabel($"{id}_watermark", watermark, width, height, 0f, 0f, textbox, watermarkConfig, addToUi);
                watermarkLabel.Opacity = 50;
                textbox.Watermark      = watermarkLabel;
            }

            if (addToUi)
            {
                _gameState.UI.Add(textbox);
            }

            return(textbox);
        }
コード例 #4
0
        public void AddEditorUI(string id, ITreeNodeView view, InspectorProperty property)
        {
            _property = property;
            var           label   = view.TreeItem;
            AGSTextConfig config  = new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText);
            var           textbox = _factory.GetTextBox(id,
                                                        label.X, label.Y, label.TreeNode.Parent,
                                                        "", config, width: 100f, height: 20f);

            textbox.Text = property.Value;
            textbox.TextBackgroundVisible = false;
            _textbox            = textbox;
            textbox.RenderLayer = label.RenderLayer;
            textbox.Z           = label.Z;
            HoverEffect.Add(textbox, Colors.Transparent, Colors.DarkSlateBlue);
            textbox.OnPressingKey.Subscribe(args =>
            {
                if (args.PressedKey != Key.Enter)
                {
                    return;
                }
                args.ShouldCancel = true;
                textbox.IsFocused = false;
                property.Prop.SetValue(property.Object, textbox.Text);
            });
        }
コード例 #5
0
        public static AGSTextConfig FromConfig(ITextConfig config, float paddingBottomOffset = 0f)
        {
            AGSTextConfig textConfig = Clone(config);

            textConfig.PaddingBottom += paddingBottomOffset;
            return(textConfig);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: AGSSayConfig.cs プロジェクト: tzachshabtay/MonoAGS
		public AGSSayConfig()
		{
			TextConfig = new AGSTextConfig(font : AGSGameSettings.DefaultSpeechFont, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, alignment: Alignment.BottomLeft);
			TextDelay = 70;
			LabelSize = new AGS.API.SizeF (250f, 200f);
			SkipText = SkipText.ByTimeAndMouse;
			BackgroundColor = Colors.Transparent;
		}
コード例 #8
0
ファイル: AGSTextConfig.cs プロジェクト: brianjlacy/MonoAGS
 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;
 }
コード例 #9
0
 public AGSSayConfig()
 {
     TextConfig      = new AGSTextConfig(font: AGSGame.Game?.Settings.Defaults.SpeechFont, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, alignment: Alignment.BottomLeft);
     TextDelay       = 70;
     LabelSize       = new AGS.API.SizeF(250f, 200f);
     SkipText        = SkipText.ByTimeAndMouse;
     BackgroundColor = Colors.Transparent;
 }
コード例 #10
0
ファイル: ContractTextConfig.cs プロジェクト: saizant/MonoAGS
        public ITextConfig ToItem(AGSSerializationContext context)
        {
            AGSTextConfig config = new AGSTextConfig(Brush.ToItem(context), Font.ToItem(context), OutlineBrush.ToItem(context), OutlineWidth,
                                                     ShadowBrush.ToItem(context), ShadowOffsetX, ShadowOffsetY, Alignment, AutoFit, PaddingLeft,
                                                     PaddingRight, PaddingTop, PaddingBottom);

            return(config);
        }
コード例 #11
0
ファイル: GLText.cs プロジェクト: tzachshabtay/MonoAGS
        private void prepareBitmapDraw()
        {
            string originalText = _text ?? "";
            string text         = _text;

            var    config        = AGSTextConfig.ScaleConfig(_config, _scaleUp.X);
            int    maxWidth      = _maxWidth == int.MaxValue ? _maxWidth : (int)(_maxWidth * _scaleUp.X - config.PaddingLeft - config.PaddingRight);
            string textToMeasure = text;

            if (_renderCaret && textToMeasure == "")
            {
                textToMeasure = "|";
            }
            SizeF originalTextSize = config.Font.MeasureString(textToMeasure, config.Alignment, _cropText ? int.MaxValue : maxWidth);
            SizeF textSize         = originalTextSize;

            if (_cropText && textSize.Width > maxWidth)
            {
                textSize = cropText(maxWidth, config, ref text);
            }

            float widthOffset  = Math.Max(config.OutlineWidth, Math.Abs(config.ShadowOffsetX));
            float heightOffset = Math.Max(config.OutlineWidth, Math.Abs(config.ShadowOffsetY));
            float widthF       = textSize.Width + widthOffset + config.PaddingLeft + config.PaddingRight;
            float heightF      = textSize.Height + heightOffset + config.PaddingTop + config.PaddingBottom;
            // ReSharper disable CompareOfFloatsByEqualityOperator
            SizeF baseSize = new SizeF(_baseSize.Width == EmptySize.Width ? widthF : _baseSize.Width * _scaleUp.X,
                                       _baseSize.Height == EmptySize.Height ? heightF : _baseSize.Height * _scaleUp.Y);

            // ReSharper restore CompareOfFloatsByEqualityOperator

            Width  = (widthF / _scaleUp.X);
            Height = (heightF / _scaleUp.Y);
            int bitmapWidth  = MathUtils.GetNextPowerOf2(Math.Max((int)(widthF) + 1, (int)(baseSize.Width) + 1));
            int bitmapHeight = MathUtils.GetNextPowerOf2(Math.Max((int)(heightF) + 1, (int)(baseSize.Height) + 1));

            BitmapWidth  = (int)(bitmapWidth / _scaleDown.X);
            BitmapHeight = (int)(bitmapHeight / _scaleDown.Y);
            if (_measureOnly || _alwaysMeasureOnly)
            {
                return;
            }

            _draw.BitmapWidth  = bitmapWidth;
            _draw.BitmapHeight = bitmapHeight;
            _draw.BaseSize     = baseSize;
            _draw.TextSize     = textSize;
            _draw.HeightF      = heightF;
            _draw.Text         = text;
            _draw.OriginalText = originalText;
            _draw.MaxWidth     = maxWidth;
            _draw.Config       = config;

            _renderChanged = true;
        }
コード例 #12
0
ファイル: GLText.cs プロジェクト: tzachshabtay/MonoAGS
        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);
        }
コード例 #13
0
ファイル: AGSTextConfig.cs プロジェクト: brianjlacy/MonoAGS
 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;
 }
コード例 #14
0
        public static AGSSayConfig FromConfig(ISayConfig config, float paddingBottomOffset = 0f)
        {
            AGSSayConfig sayConfig = new AGSSayConfig();

            sayConfig.TextConfig      = AGSTextConfig.FromConfig(config.TextConfig, paddingBottomOffset);
            sayConfig.TextDelay       = config.TextDelay;
            sayConfig.SkipText        = config.SkipText;
            sayConfig.LabelSize       = config.LabelSize;
            sayConfig.Border          = config.Border;
            sayConfig.BackgroundColor = config.BackgroundColor;
            sayConfig.PortraitConfig  = config.PortraitConfig;
            return(sayConfig);
        }
コード例 #15
0
ファイル: AGSTextConfig.cs プロジェクト: jeancallisti/MonoAGS
        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);
        }
コード例 #16
0
 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);
 }
コード例 #17
0
 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);
 }
コード例 #18
0
ファイル: GLText.cs プロジェクト: ebrucucen/MonoAGS
        private void drawToBitmap()
        {
            string originalText = _text ?? "";
            string text         = _text;

            var   config           = AGSTextConfig.ScaleConfig(_config, TextResolutionFactorX);
            int   maxWidth         = _maxWidth == int.MaxValue ? _maxWidth : _maxWidth * TextResolutionFactorX;
            SizeF originalTextSize = config.Font.MeasureString(text, _cropText ? int.MaxValue : maxWidth);
            SizeF textSize         = originalTextSize;

            if (_cropText && textSize.Width > maxWidth)
            {
                textSize = cropText(maxWidth, config, ref text);
            }

            float widthOffset  = Math.Max(config.OutlineWidth, Math.Abs(config.ShadowOffsetX));
            float heightOffset = Math.Max(config.OutlineWidth, Math.Abs(config.ShadowOffsetY));
            float widthF       = textSize.Width + widthOffset + config.PaddingLeft + config.PaddingRight;
            float heightF      = textSize.Height + heightOffset + config.PaddingTop + config.PaddingBottom;
            SizeF baseSize     = new SizeF(_baseSize.Width == EmptySize.Width ? widthF : _baseSize.Width * TextResolutionFactorX,
                                           _baseSize.Height == EmptySize.Height ? heightF : _baseSize.Height * TextResolutionFactorY);

            Width  = (widthF / GLText.TextResolutionFactorX);
            Height = (heightF / GLText.TextResolutionFactorY);
            int     bitmapWidth  = MathUtils.GetNextPowerOf2(Math.Max((int)widthF + 1, (int)baseSize.Width + 1));
            int     bitmapHeight = MathUtils.GetNextPowerOf2(Math.Max((int)heightF + 1, (int)baseSize.Height + 1));
            IBitmap bitmap       = _bitmap;

            if (bitmap == null || bitmap.Width != bitmapWidth || bitmap.Height != bitmapHeight)
            {
                if (bitmap != null)
                {
                    _bitmapPool.Release(bitmap);
                }
                _bitmap = _bitmapPool.Acquire(bitmapWidth, bitmapHeight);
                bitmap  = _bitmap;
            }
            IBitmapTextDraw textDraw = bitmap.GetTextDraw();

            using (var context = textDraw.CreateContext())
            {
                textDraw.DrawText(text, config, textSize, baseSize, maxWidth, (int)heightF, 0f);
                drawCaret(originalText, textSize, heightF, baseSize, textDraw, config, maxWidth);
            }

            _renderChanged = true;
        }
コード例 #19
0
ファイル: AGSTextConfig.cs プロジェクト: tzachshabtay/MonoAGS
 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;
 }
コード例 #20
0
ファイル: AGSTextConfig.cs プロジェクト: jeancallisti/MonoAGS
        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);
        }
コード例 #21
0
        public static SizeF GetTextSize(this ITextConfig config, string text, SizeF labelSize)
        {
            config    = AGSTextConfig.ScaleConfig(config, GLText.TextResolutionFactorX);
            labelSize = labelSize.Scale(GLText.TextResolutionFactorX, GLText.TextResolutionFactorY);
            float scaleBackX = 1f / GLText.TextResolutionFactorX;
            float scaleBackY = 1f / GLText.TextResolutionFactorY;

            switch (config.AutoFit)
            {
            case AutoFit.TextShouldFitLabel:
                var textSize = config.Font.MeasureString(text);
                return(new SizeF(Math.Min(textSize.Width, labelSize.Width), Math.Min(textSize.Height, labelSize.Height)).Scale(scaleBackX, scaleBackY));

            case AutoFit.TextShouldWrapAndLabelShouldFitHeight:
                return(config.Font.MeasureString(text, (int)labelSize.Width).Scale(scaleBackX, scaleBackY));

            default:
                return(config.Font.MeasureString(text).Scale(scaleBackX, scaleBackY));
            }
        }
コード例 #22
0
        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);
        }
コード例 #23
0
ファイル: AGSDialogFactory.cs プロジェクト: saizant/MonoAGS
        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>();

            if (config == null)
            {
                config = new AGSTextConfig(autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight,
                                           brush: _brushLoader.LoadSolidBrush(Colors.White), font: _fontLoader.LoadFont(null, 10f));
            }
            if (hoverConfig == null)
            {
                hoverConfig = new AGSTextConfig(autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight,
                                                brush: _brushLoader.LoadSolidBrush(Colors.Yellow), font: _fontLoader.LoadFont(null, 10f));
            }
            if (hasBeenChosenConfig == null)
            {
                hasBeenChosenConfig = new AGSTextConfig(autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight,
                                                        brush: _brushLoader.LoadSolidBrush(Colors.Gray), font: _fontLoader.LoadFont(null, 10f));
            }
            ILabel label = _ui.GetLabel($"Dialog option: {text}", text, game.Settings.VirtualResolution.Width, 20f, 0f, 0f,
                                        config: config, addToUi: false);

            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);
        }
コード例 #24
0
		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;
		}
コード例 #25
0
        public async Task<string> Run()
        {
            IGameFactory factory = _game.Factory;
            float panelWidth = _game.Settings.VirtualResolution.Width * 3 / 4f;
            float panelHeight = _game.Settings.VirtualResolution.Height * 3 / 4f;
            const float labelHeight = 20f;
            const float textBoxHeight = 20f;
            const float buttonHeight = 20f;
            const float itemHeight = 20f;
            const float itemPaddingX = 5f;
            const float itemPaddingY = 5f;
            const float scrollButtonWidth = 20f;
            const float scrollButtonHeight = 20f;
            const float scrollButtonOffsetX = 5f;
            const float scrollButtonOffsetY = 5f;
            const float okButtonWidth = 50f;
            const float okButtonHeight = 20f;
            const float okButtonPaddingX = 20f;
            const float okButtonPaddingY = 20f;
            float okCancelWidth = okButtonWidth * 2 + okButtonPaddingX;
            float okButtonX = panelWidth / 2f - okCancelWidth / 2f;
            float cancelButtonX = okButtonX + okButtonWidth + okButtonPaddingX;
            float panelX = _game.Settings.VirtualResolution.Width / 2f - panelWidth / 2f;
            float panelY = _game.Settings.VirtualResolution.Height / 2f - panelHeight / 2f;
            ITextConfig textBoxConfig = new AGSTextConfig(alignment: Alignment.BottomLeft,
                autoFit: AutoFit.TextShouldCrop, font: Hooks.FontLoader.LoadFont(null, 10f));

            IPanel panel = factory.UI.GetPanel("SelectFilePanel", panelWidth, panelHeight, panelX, panelY);
            panel.SkinTags.Add(AGSSkin.DialogBoxTag);
            panel.Skin.Apply(panel);
            ILabel titleLabel = factory.UI.GetLabel("SelectFileTitle", _title, panelWidth, labelHeight, 0f, panelHeight - labelHeight, _buttonsTextConfig);
            _fileTextBox = factory.UI.GetTextBox("SelectFileTextBox", 0f, panelHeight - labelHeight - textBoxHeight, _startPath, textBoxConfig, width: panelWidth, height: textBoxHeight);

            _inventory = new AGSInventory();
            IInventoryWindow invWindow = factory.Inventory.GetInventoryWindow("SelectFileInventory", panelWidth - scrollButtonWidth - scrollButtonOffsetX * 2,
                                                                              panelHeight - labelHeight - buttonHeight - textBoxHeight - okButtonPaddingY, ITEM_WIDTH + itemPaddingX, itemHeight + itemPaddingY, 0f, okButtonPaddingY + okButtonHeight, _inventory);
            invWindow.Z = 1;
            IButton okButton = factory.UI.GetButton("SelectFileOkButton", (string)null, null, null, okButtonX, okButtonPaddingY, "OK", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton cancelButton = factory.UI.GetButton("SelectFileCancelButton", (string)null, null, null, cancelButtonX, okButtonPaddingY, "Cancel", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton scrollDownButton = factory.UI.GetButton("SelectFileScrollDown", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, okButton.Y + okButtonHeight + scrollButtonOffsetY, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            IButton scrollUpButton = factory.UI.GetButton("SelectFileScrollUp", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, panelHeight - labelHeight - textBoxHeight - scrollButtonHeight - scrollButtonOffsetY, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            titleLabel.TreeNode.SetParent(panel.TreeNode);
            _fileTextBox.TreeNode.SetParent(panel.TreeNode);
            invWindow.TreeNode.SetParent(panel.TreeNode);
            okButton.TreeNode.SetParent(panel.TreeNode);
            cancelButton.TreeNode.SetParent(panel.TreeNode);
            scrollDownButton.TreeNode.SetParent(panel.TreeNode);
            scrollUpButton.TreeNode.SetParent(panel.TreeNode);

            cancelButton.MouseClicked.Subscribe(onCancelClicked);
            okButton.MouseClicked.Subscribe(onOkClicked);

            scrollDownButton.MouseClicked.Subscribe((sender, args) => invWindow.ScrollDown());
            scrollUpButton.MouseClicked.Subscribe((sender, args) => invWindow.ScrollUp());

            _fileIcon = new FileIcon(_glUtils);
            _fileIconSelected = new FileIcon(_glUtils) { IsSelected = true };
            _folderIcon = new FolderIcon(_glUtils);
            _folderIconSelected = new FolderIcon(_glUtils) { IsSelected = true };

            var arrowDownIcon = getIcon("ArrowDown", factory, scrollButtonWidth, scrollButtonHeight, 
                                        new ArrowIcon(_glUtils) { Direction = ArrowIcon.ArrowDirection.Down });
            arrowDownIcon.Anchor = new PointF();
            arrowDownIcon.Enabled = false;
            arrowDownIcon.TreeNode.SetParent(scrollDownButton.TreeNode);
            _game.State.UI.Add(arrowDownIcon);

            var arrowUpIcon = getIcon("ArrowUp", factory, scrollButtonWidth, scrollButtonHeight,
                                      new ArrowIcon(_glUtils) { Direction = ArrowIcon.ArrowDirection.Up });
            arrowUpIcon.Anchor = new PointF();
            arrowUpIcon.Enabled = false;
            arrowUpIcon.TreeNode.SetParent(scrollUpButton.TreeNode);
            _game.State.UI.Add(arrowUpIcon);

            _fileGraphics = getIcon("FileGraphics", factory, ITEM_WIDTH, itemHeight, _fileIcon);
            _folderGraphics = getIcon("FolderGraphics", factory, ITEM_WIDTH, itemHeight, _folderIcon);

            fillAllFiles(_startPath);

            _fileTextBox.OnPressingKey.Subscribe(onTextBoxKeyPressed);

            bool okGiven = await _tcs.Task;
            removeAllUI(panel);
            if (!okGiven) return null;
            return _fileTextBox.Text;
        }
コード例 #26
0
ファイル: AGSUIFactory.cs プロジェクト: tzachshabtay/MonoAGS
        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;
        }
コード例 #27
0
 public AGSStringItem()
 {
     IdleTextConfig  = new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText, font: AGSGameSettings.DefaultSpeechFont);
     HoverTextConfig = AGSTextConfig.ChangeColor(IdleTextConfig, Colors.Yellow, Colors.Black, 1f);
     Properties      = new AGSCustomProperties();
 }
コード例 #28
0
ファイル: GameDebugView.cs プロジェクト: saizant/MonoAGS
        public void Load()
        {
            const float  headerHeight = 50f;
            const float  borderWidth  = 3f;
            IGameFactory factory      = _game.Factory;

            _panel = factory.UI.GetPanel(_panelId, _layer.IndependentResolution.Value.Width / 4f, _layer.IndependentResolution.Value.Height,
                                         5f, _layer.IndependentResolution.Value.Height / 2f);
            _panel.Pivot        = new PointF(0f, 0.5f);
            _panel.Visible      = false;
            _panel.Tint         = Colors.Black.WithAlpha(150);
            _panel.Border       = AGSBorders.SolidColor(Colors.Green, borderWidth, hasRoundCorners: true);
            _panel.RenderLayer  = _layer;
            _panel.ClickThrough = false;
            _game.State.FocusedUI.CannotLoseFocus.Add(_panelId);

            var headerLabel = factory.UI.GetLabel("GameDebugTreeLabel", "Game Debug", _panel.Width, headerHeight, 0f, _panel.Height - headerHeight,
                                                  _panel, new AGSTextConfig(alignment: Alignment.MiddleCenter, autoFit: AutoFit.TextShouldFitLabel));

            headerLabel.Tint        = Colors.Transparent;
            headerLabel.Border      = _panel.Border;
            headerLabel.RenderLayer = _layer;

            var xButton = factory.UI.GetButton("GameDebugTreeCloseButton", (IAnimation)null, null, null, 0f, _panel.Height - headerHeight + 5f, _panel, "X",
                                               new AGSTextConfig(factory.Graphics.Brushes.LoadSolidBrush(Colors.Red),
                                                                 autoFit: AutoFit.TextShouldFitLabel, alignment: Alignment.MiddleCenter),
                                               width: 40f, height: 40f);

            xButton.Pivot       = new PointF();
            xButton.RenderLayer = _layer;
            xButton.Tint        = Colors.Transparent;
            xButton.MouseEnter.Subscribe(_ => xButton.TextConfig = AGSTextConfig.ChangeColor(xButton.TextConfig, Colors.Yellow, Colors.White, 0.3f));
            xButton.MouseLeave.Subscribe(_ => xButton.TextConfig = AGSTextConfig.ChangeColor(xButton.TextConfig, Colors.Red, Colors.Transparent, 0f));
            xButton.MouseClicked.Subscribe(_ => Hide());

            _panesButton = factory.UI.GetButton("GameDebugViewPanesButton", (IAnimation)null, null, null, _panel.Width, xButton.Y, _panel, "Display List",
                                                new AGSTextConfig(autoFit: AutoFit.TextShouldFitLabel, alignment: Alignment.MiddleRight),
                                                width: 120f, height: 40f);
            _panesButton.Pivot       = new PointF(1f, 0f);
            _panesButton.RenderLayer = _layer;
            _panesButton.Tint        = Colors.Black;
            _panesButton.MouseEnter.Subscribe(_ => _panesButton.TextConfig = AGSTextConfig.ChangeColor(xButton.TextConfig, Colors.Yellow, Colors.White, 0.3f));
            _panesButton.MouseLeave.Subscribe(_ => _panesButton.TextConfig = AGSTextConfig.ChangeColor(xButton.TextConfig, Colors.White, Colors.Transparent, 0f));
            _panesButton.MouseClicked.SubscribeToAsync(onPaneSwitch);

            var parentPanelHeight = _panel.Height - headerHeight;
            var parentPanel       = factory.UI.GetPanel("GameDebugParentPanel", _panel.Width, parentPanelHeight, 0f, parentPanelHeight, _panel);

            parentPanel.Pivot       = new PointF(0f, 1f);
            parentPanel.Tint        = Colors.Transparent;
            parentPanel.RenderLayer = _layer;

            var topPanel = factory.UI.GetPanel("GameDebugTopPanel", _panel.Width, parentPanelHeight / 2f, 0f, parentPanelHeight / 2f, parentPanel);

            topPanel.Pivot       = new PointF(0f, 0f);
            topPanel.Tint        = Colors.Transparent;
            topPanel.RenderLayer = _layer;

            var bottomPanel = factory.UI.GetPanel("GameDebugBottomPanel", _panel.Width, parentPanelHeight / 2f, 0f, parentPanelHeight / 2f, parentPanel);

            bottomPanel.Pivot       = new PointF(0f, 1f);
            bottomPanel.Tint        = Colors.Transparent;
            bottomPanel.RenderLayer = _layer;

            _debugTree.Load(topPanel);
            _displayList.Load(topPanel);
            _inspector.Load(bottomPanel);
            _currentTab             = _debugTree;
            _splitPanel             = parentPanel.AddComponent <ISplitPanelComponent>();
            _splitPanel.TopPanel    = topPanel;
            _splitPanel.BottomPanel = bottomPanel;

            var horizSplit = _panel.AddComponent <ISplitPanelComponent>();

            horizSplit.IsHorizontal = true;
            horizSplit.TopPanel     = _panel;

            _panel.GetComponent <IScaleComponent>().PropertyChanged += (_, args) =>
            {
                if (args.PropertyName != nameof(IScaleComponent.Width))
                {
                    return;
                }
                _panesButton.X = _panel.Width;
                headerLabel.LabelRenderSize = new SizeF(_panel.Width, headerLabel.LabelRenderSize.Height);
                parentPanel.BaseSize        = new SizeF(_panel.Width, parentPanel.Height);
                topPanel.BaseSize           = new SizeF(_panel.Width, topPanel.Height);
                bottomPanel.BaseSize        = new SizeF(_panel.Width, bottomPanel.Height);
                _currentTab.Resize();
                _inspector.Resize();
            };
        }
コード例 #29
0
        public async Task <string> Run()
        {
            IGameFactory factory             = _game.Factory;
            float        panelWidth          = _game.Settings.VirtualResolution.Width * 3 / 4f;
            float        panelHeight         = _game.Settings.VirtualResolution.Height * 3 / 4f;
            const float  labelHeight         = 20f;
            const float  textBoxHeight       = 20f;
            const float  buttonHeight        = 20f;
            const float  itemHeight          = 20f;
            const float  itemPaddingX        = 5f;
            const float  itemPaddingY        = 5f;
            const float  scrollButtonWidth   = 20f;
            const float  scrollButtonHeight  = 20f;
            const float  scrollButtonOffsetX = 5f;
            const float  scrollButtonOffsetY = 5f;
            const float  okButtonWidth       = 50f;
            const float  okButtonHeight      = 20f;
            const float  okButtonPaddingX    = 20f;
            const float  okButtonPaddingY    = 20f;
            float        okCancelWidth       = okButtonWidth * 2 + okButtonPaddingX;
            float        okButtonX           = panelWidth / 2f - okCancelWidth / 2f;
            float        cancelButtonX       = okButtonX + okButtonWidth + okButtonPaddingX;
            float        panelX        = _game.Settings.VirtualResolution.Width / 2f - panelWidth / 2f;
            float        panelY        = _game.Settings.VirtualResolution.Height / 2f - panelHeight / 2f;
            ITextConfig  textBoxConfig = new AGSTextConfig(alignment: Alignment.BottomLeft,
                                                           autoFit: AutoFit.TextShouldCrop, font: _game.Factory.Fonts.LoadFont(null, 10f));

            IPanel panel = factory.UI.GetPanel("SelectFilePanel", panelWidth, panelHeight, panelX, panelY);

            panel.SkinTags.Add(AGSSkin.DialogBoxTag);
            panel.Skin.Apply(panel);
            panel.AddComponent <IModalWindowComponent>().GrabFocus();
            ILabel titleLabel = factory.UI.GetLabel("SelectFileTitle", _title, panelWidth, labelHeight, 0f, panelHeight - labelHeight, panel, _buttonsTextConfig);

            _fileTextBox = factory.UI.GetTextBox("SelectFileTextBox", 0f, panelHeight - labelHeight - textBoxHeight, panel, _startPath, textBoxConfig, width: panelWidth, height: textBoxHeight);

            _inventory = new AGSInventory();
            IInventoryWindow invWindow = factory.Inventory.GetInventoryWindow("SelectFileInventory", panelWidth - scrollButtonWidth - scrollButtonOffsetX * 2,
                                                                              panelHeight - labelHeight - buttonHeight - textBoxHeight - okButtonPaddingY, ITEM_WIDTH + itemPaddingX, itemHeight + itemPaddingY, 0f, okButtonPaddingY + okButtonHeight, _inventory);

            invWindow.Z = 1;
            IButton okButton         = factory.UI.GetButton("SelectFileOkButton", (string)null, null, null, okButtonX, okButtonPaddingY, panel, "OK", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton cancelButton     = factory.UI.GetButton("SelectFileCancelButton", (string)null, null, null, cancelButtonX, okButtonPaddingY, panel, "Cancel", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton scrollDownButton = factory.UI.GetButton("SelectFileScrollDown", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, okButton.Y + okButtonHeight + scrollButtonOffsetY, panel, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            IButton scrollUpButton   = factory.UI.GetButton("SelectFileScrollUp", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, panelHeight - labelHeight - textBoxHeight - scrollButtonHeight - scrollButtonOffsetY, panel, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);

            invWindow.TreeNode.SetParent(panel.TreeNode);

            cancelButton.MouseClicked.Subscribe(onCancelClicked);
            okButton.MouseClicked.SubscribeToAsync(onOkClicked);

            scrollDownButton.MouseClicked.Subscribe(_ => invWindow.ScrollDown());
            scrollUpButton.MouseClicked.Subscribe(_ => invWindow.ScrollUp());

            var iconFactory = factory.Graphics.Icons;

            _fileIcon           = iconFactory.GetFileIcon();
            _fileIconSelected   = iconFactory.GetFileIcon(true);
            _folderIcon         = iconFactory.GetFolderIcon();
            _folderIconSelected = iconFactory.GetFolderIcon(true);

            var arrowDownIcon = getIcon("ArrowDown", factory, scrollButtonWidth, scrollButtonHeight,
                                        iconFactory.GetArrowIcon(ArrowDirection.Down));

            arrowDownIcon.Pivot   = new PointF();
            arrowDownIcon.Enabled = false;
            arrowDownIcon.TreeNode.SetParent(scrollDownButton.TreeNode);
            _game.State.UI.Add(arrowDownIcon);

            var arrowUpIcon = getIcon("ArrowUp", factory, scrollButtonWidth, scrollButtonHeight,
                                      iconFactory.GetArrowIcon(ArrowDirection.Up));

            arrowUpIcon.Pivot   = new PointF();
            arrowUpIcon.Enabled = false;
            arrowUpIcon.TreeNode.SetParent(scrollUpButton.TreeNode);
            _game.State.UI.Add(arrowUpIcon);

            _fileGraphics   = getIcon("FileGraphics", factory, ITEM_WIDTH, itemHeight, _fileIcon);
            _folderGraphics = getIcon("FolderGraphics", factory, ITEM_WIDTH, itemHeight, _folderIcon);

            fillAllFiles(_startPath);

            _fileTextBox.OnPressingKey.Subscribe(onTextBoxKeyPressed);

            bool okGiven = await _tcs.Task;

            _inventory.Items.Clear();
            removeAllUI(panel);
            panel.GetComponent <IModalWindowComponent>().LoseFocus();
            if (!okGiven)
            {
                return(null);
            }
            return(_fileTextBox.Text);
        }