Exemplo n.º 1
0
    protected JSONObject parseCommon(JSONObject raw, Vector2 containerSize, MagicUIControl.ControlType type)
    {
        JSONObject control = JSONObject.obj;

        Rect bounds = raw.GetRect();

        bounds.x      /= containerSize.x;
        bounds.width  /= containerSize.x;
        bounds.y      /= containerSize.y;
        bounds.height /= containerSize.y;
        control.SetRect(bounds);

        control.SetAnchors(raw.GetAnchors());

        control.AddField("zOrder", raw.GetFloatSafely("zOrder", 0));

        int link = raw.GetIntSafely("pageLink", -1);

        if (link > 0)
        {
            control.AddField("link", link);
        }

        control.SetControlType(type);

        return(control);
    }
Exemplo n.º 2
0
    public static MagicUIControl CreateFromMarkup(string id, JSONObject markup, IMagicUIPanel page)
    {
        DebugManager.Log("...{0}: {1}", id, markup);

        MagicUIControl.ControlType type = markup.GetControlType();

        MagicUIControl control = null;

        switch (type)
        {
        case ControlType.Label:
            control = MagicUILabelControl.Create();
            break;

        case ControlType.Image:
            control = MagicUIImageControl.Create();
            break;

        case ControlType.Button:
            control = MagicUIButton.Create();
            break;

        case ControlType.Container:
            control = MagicUIContainer.Create();
            break;

        case ControlType.Rectangle:
            control = MagicUIRectangle.Create();
            break;

        case ControlType.Checkbox:
            control = MagicUICheckbox.Create();
            break;

        case ControlType.TextBox:
            control = MagicUITextBox.Create();
            break;

        case ControlType.Slider:
            control = MagicUISlider.Create();
            break;

        default:
            break;
        }

        if (control != null)
        {
            control.name = id;
            control.setContainer(page);

            control.initialize(markup);
            control.setExtents(control.calculateExtents(markup.GetRect(), markup.GetAnchors()));
            int z = markup.GetIntSafely("zOrder", 0);
            control.setZOrder(z * 10);

            int link = markup.GetIntSafely("link", int.MinValue);
            if (link >= -1)
            {
                control.setLink(link);
            }

            if (control is IMagicUIPanel)
            {
                ((IMagicUIPanel)control).Populate(markup["contents"]["children"].list);
            }

            control.register();
        }

        return(null);
    }