Пример #1
0
    protected void init()
    {
        _atlas = GetComponent <UIAtlas>();

        string text = Definition.text;

        JSONObject json = new JSONObject(text);
        JSONObject def  = json["skin"];

        bool?safe = def.GetBoolSafely("copyrightSafe", true);

        if (safe.HasValue && !safe.Value && !Debug.isDebugBuild)
        {
            Debug.LogError("COPYRIGHT NOT VALID FOR PRODUCTION USE");
            Application.Quit();

            // Force the app to die, in case Quit() doesn't work
            throw new System.InvalidProgramException();
        }

        _frameData = new Dictionary <MagicUIControl.ControlType, JSONObject>();
        JSONObject mapping = def["mapping"];

        setData(mapping, "container", MagicUIControl.ControlType.Container);
        setData(mapping, "rectangle", MagicUIControl.ControlType.Rectangle);
        setData(mapping, "button", MagicUIControl.ControlType.Button);
        setData(mapping, "checkbox", MagicUIControl.ControlType.Checkbox);
        setData(mapping, "slider", MagicUIControl.ControlType.Slider);
        setData(mapping, "label", MagicUIControl.ControlType.Label);
        setData(mapping, "textbox", MagicUIControl.ControlType.TextBox);
        setData(mapping, "image", MagicUIControl.ControlType.Image);
    }
Пример #2
0
    protected override void initialize(JSONObject markup)
    {
        _chrome = Vector2.one;
        _margin = Vector2.zero;

        _key = markup.GetStringSafely("name", "");

        bool?iconOnly = markup.GetBoolSafely("iconOnly", false);

        if (iconOnly.HasValue && iconOnly.Value)
        {
            JSONObject icon = markup["icon"];
            if (icon != null)
            {
                _icon = MagicUIImage.CreateAsComponent(gameObject);
                _icon.Initialize(icon);
            }
        }
        else
        {
            _sprite       = gameObject.AddComponent <UISprite>();
            _sprite.atlas = MagicUIManager.Instance.Skin.Atlas;
            _sprite.type  = UISprite.Type.Sliced;
            _sprite.autoResizeBoxCollider = true;
            _sprite.color = MagicUIManager.Instance.Skin.PrimaryColor;

            _label = MagicUILabel.CreateAsComponent(gameObject);
            _label.Initialize(MagicUIManager.Instance.GetString(_key), true, markup);

            JSONObject frameData = MagicUIManager.Instance.Skin.GetFrameData(ControlType.Button);
            _sprite.spriteName = frameData["on"].str;

            if (_label != null)
            {
                _label.Color = MagicUIManager.Instance.Skin.FontParameters.DefaultColor;
                bool?invert = frameData.GetBoolSafely("fgInvert", false);
                if (invert.HasValue && invert.Value)
                {
                    _label.Color = MagicUIManager.Instance.Skin.FontParameters.AlternateColor;
                }
            }

            UISpriteData data = MagicUIManager.Instance.Skin.Atlas.GetSprite(_sprite.spriteName);

            if (frameData.keys.Contains("margin"))
            {
                _margin = frameData["margin"].GetVector2();
            }

            if (frameData.keys.Contains("chrome"))
            {
                _chrome   = frameData["chrome"].GetVector2();
                _chrome.x = data.width / (data.width - _chrome.x);
                _chrome.y = data.height / (data.height - _chrome.y);
            }
        }

        NGUITools.AddWidgetCollider(gameObject);
    }
Пример #3
0
    protected JSONObject parseLabel(JSONObject raw, Vector2 containerSize)
    {
        JSONObject control = parseCommon(raw, containerSize, MagicUIControl.ControlType.Label);

        string text = raw.GetStringSafely("text", null);

        if (text == null)
        {
            text = raw.GetStringSafely("name", "unnamed");
        }
        control.AddField("name", text);

        string align = null;
        bool?  scale = raw.GetBoolSafely("scaleWithFontSize", false);

        if (scale.HasValue && scale.Value)
        {
            align = "center";
        }
        else
        {
            align = raw.GetStringSafely("textalign", "left");
        }
        control.AddField("halign", align);

        bool?multiline = raw.GetBoolSafely("multiline", false);

        control.AddField("multiline", multiline.HasValue ? multiline.Value : false);

        string valign = raw.GetStringSafely("textverticalalign", "top");

        control.AddField("valign", valign);

        float size = raw.GetFloatSafely("font.size", 25);

        control.AddField("fontsize", size);

        return(control);
    }
Пример #4
0
    public void Initialize(string text, bool isButton, JSONObject markup)
    {
        _isTextBox = false;

        _label.text                = text;
        _label.trueTypeFont        = MagicUIManager.Instance.Skin.FontParameters.Font;
        _label.color               = Color.black;
        _label.keepCrispWhenShrunk = UILabel.Crispness.Always;

        if (isButton)
        {
            _isButton    = true;
            _isMultiline = false;
            _horizontal  = NGUIText.Alignment.Center;
            // _vertical
            _fontSize = 999;
        }
        else
        {
            _isButton = false;

            bool?multiline = markup.GetBoolSafely("multiline", false);
            if (multiline.HasValue)
            {
                _isMultiline = multiline.Value;
            }

            switch (markup.GetStringSafely("halign", "center").ToLower()[0])
            {
            case 'l':
                _horizontal = NGUIText.Alignment.Left;
                break;

            case 'r':
                _horizontal = NGUIText.Alignment.Right;
                break;

            case 'c':
            default:
                _horizontal = NGUIText.Alignment.Center;
                break;
            }
            _label.alignment = _horizontal;

            //control.AddField("valign", valign);

            _fontSize = markup.GetFloatSafely("fontsize", 25);
        }
    }
Пример #5
0
    protected override void initialize(JSONObject markup)
    {
        _sprite       = gameObject.AddComponent <UISprite>();
        _sprite.atlas = MagicUIManager.Instance.Skin.Atlas;
        _sprite.type  = UISprite.Type.Sliced;
        _sprite.color = MagicUIManager.Instance.Skin.PrimaryColor;

        NGUITools.AddWidgetCollider(gameObject);
        _sprite.autoResizeBoxCollider = true;

        _key = markup.GetStringSafely("name", "");

        _label = MagicUILabel.CreateAsChild(gameObject);
        _label.Initialize(MagicUIManager.Instance.GetString(_key), false, markup);
        _input.label = _label.SetForTextBox();

        JSONObject frameData = MagicUIManager.Instance.Skin.GetFrameData(ControlType.TextBox);

        _label.Color = MagicUIManager.Instance.Skin.FontParameters.DefaultColor;
        bool?invert = frameData.GetBoolSafely("fgInvert", false);

        if (invert.HasValue && invert.Value)
        {
            _label.Color = MagicUIManager.Instance.Skin.FontParameters.AlternateColor;
        }

        _input.activeTextColor = _input.label.color;
        EventDelegate.Set(_input.onSubmit, OnSubmit);

        _sprite.spriteName = frameData["on"].str;

        UISpriteData data = MagicUIManager.Instance.Skin.Atlas.GetSprite(_sprite.spriteName);

        if (frameData.keys.Contains("margin"))
        {
            _margin = frameData["margin"].GetVector2();
        }

        _chrome = Vector2.one;
        if (frameData.keys.Contains("chrome"))
        {
            _chrome   = frameData["chrome"].GetVector2();
            _chrome.x = data.width / (data.width - _chrome.x);
            _chrome.y = data.height / (data.height - _chrome.y);
        }
    }