public void Show()
        {
            if (this.resourcesLoaded)
            {
                try {
                    if (this.configuration.ContainsKey("shim"))
                    {
                        ShimLayer shimLayer = this.gameObject.AddComponent <ShimLayer>();
                        shimLayer.Build(this, this.configuration["shim"] as JSONObject, this.depth);
                    }

                    JSONObject layout = this.configuration["layout"] as JSONObject;
                    object     orientation;
                    if (!layout.TryGetValue("landscape", out orientation) && !layout.TryGetValue("portrait", out orientation))
                    {
                        throw new KeyNotFoundException("Layout missing orientation key.");
                    }

                    BackgroundLayer backgroundLayer = this.gameObject.AddComponent <BackgroundLayer>();
                    backgroundLayer.Build(this, orientation as JSONObject, this.spriteMap.Background, this.depth - 1);

                    ButtonsLayer buttonLayer = this.gameObject.AddComponent <ButtonsLayer>();
                    buttonLayer.Build(this, orientation as JSONObject, this.spriteMap.Buttons, backgroundLayer, this.depth - 2);

                    this.showing = true;
                } catch (KeyNotFoundException exception) {
                    Logger.LogWarning("Failed to show image message, invalid format: " + exception.Message);
                } catch (Exception exception) {
                    Logger.LogWarning("Failed to show image message: " + exception.Message);
                }
            }
        }
        public void Show()
        {
            if (IsReady())
            {
                try{
                    if (spriteMap.Texture == null)
                    {
                        /*
                         * This is a workaround for when we're showing for an
                         * event trigger, as the instance didn't go through the
                         * FetchResources() call to load the texture we need to
                         * do it now.
                         */
                        spriteMap.LoadResource(e => { });
                    }

                    Canvas messageCanvas = gameObject.AddComponent <Canvas>();
                    messageCanvas.renderMode   = RenderMode.ScreenSpaceOverlay;
                    messageCanvas.sortingOrder = 32767;
                    gameObject.AddComponent <GraphicRaycaster>();

                    if (this.configuration.ContainsKey("shim"))
                    {
                        ShimLayer shimLayer = gameObject.AddComponent <ShimLayer>();
                        shimLayer.Build(ddna, gameObject, this, this.configuration["shim"] as JSONObject, this.depth);
                    }

                    JSONObject layout = configuration["layout"] as JSONObject;
                    object     orientation;
                    if (!layout.TryGetValue("landscape", out orientation) &&
                        !layout.TryGetValue("portrait", out orientation))
                    {
                        throw new KeyNotFoundException("Layout missing orientation key.");
                    }

                    BackgroundLayer backgroundLayer = gameObject.AddComponent <BackgroundLayer>();
                    backgroundLayer.Build(ddna, gameObject, this, orientation as JSONObject, spriteMap.Background,
                                          depth - 1);

                    ButtonsLayer buttonLayer = gameObject.AddComponent <ButtonsLayer>();
                    buttonLayer.Build(ddna, gameObject, this, orientation as JSONObject, spriteMap.Buttons,
                                      backgroundLayer, depth - 2);

                    showing = true;
                }
                catch (KeyNotFoundException exception) {
                    Logger.LogWarning("Failed to show image message, invalid format: " + exception.Message);
                }
                catch (Exception exception) {
                    Logger.LogWarning("Failed to show image message: " + exception.Message);
                }
            }
        }
        public void Show()
        {
            if (IsReady)
            {
                try {
                    if (BeforeShow != null)
                    {
                        BeforeShow(this, new EventArgs());
                    }

                    object shimDictObj;
                    if (Configuration.TryGetValue("shim", out shimDictObj))
                    {
                        var       shimDict = shimDictObj as Dictionary <string, object>;
                        ShimLayer shim     = _gameObject.AddComponent <ShimLayer>();
                        shim.Init(this, shimDict, _depth);
                    }

                    object layoutDictObj;
                    if (Configuration.TryGetValue("layout", out layoutDictObj))
                    {
                        var    layoutDict = layoutDictObj as Dictionary <string, object>;
                        object orientationDictObj;
                        if ((layoutDict).TryGetValue("landscape", out orientationDictObj) ||
                            (layoutDict).TryGetValue("portrait", out orientationDictObj))
                        {
                            var orientationDict = orientationDictObj as Dictionary <string, object>;

                            BackgroundLayer background = _gameObject.AddComponent <BackgroundLayer>();
                            background.Init(this, orientationDict, _spritemap.GetBackground(), _depth - 1);

                            ButtonsLayer buttons = _gameObject.AddComponent <ButtonsLayer>();
                            buttons.Init(this, orientationDict, _spritemap.GetButtons(), background, _depth - 2);

                            IsShowing = true;
                        }
                        else
                        {
                            Logger.LogError("No layout orientation found.");
                        }
                    }
                    else
                    {
                        Logger.LogError("No layout found.");
                    }
                } catch (Exception ex) {
                    Logger.LogError("Showing popup failed: " + ex.Message);
                }
            }
        }
            public void Build(DDNA ddna, GameObject parent, ImageMessage imageMessage, JSONObject orientation,
                              List <Sprite> sprites, BackgroundLayer content, int depth)
            {
                this.ddna         = ddna;
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.depth        = depth;
                this.orientation  = orientation;
                this.content      = content;
                this.sprites      = sprites;

                object buttonsObj;

                if (orientation.TryGetValue("buttons", out buttonsObj))
                {
                    UpdatePositions(true);
                }
            }
Exemple #5
0
            public void Build(ImageMessage imageMessage, JSONObject orientation, List<Texture> textures, BackgroundLayer content, int depth)
            {
                this.imageMessage = imageMessage;
                this.depth = depth;

                object buttonsObj;
                if (orientation.TryGetValue("buttons", out buttonsObj)) {
                    var buttons = buttonsObj as List<object>;
                    for (int i = 0; i < buttons.Count; ++i) {
                        var button = buttons[i] as JSONObject;
                        float left = 0, top = 0;
                        object x, y;
                        if (button.TryGetValue("x", out x)) {
                            left = (int)((long)x) * content.Scale + content.Position.xMin;
                        }
                        if (button.TryGetValue("y", out y)) {
                            top = (int)((long)y) * content.Scale + content.Position.yMin;
                        }
                        this.positions.Add(new Rect(left, top, textures[i].width * content.Scale, textures[i].height * content.Scale));

                        object actionObj;
                        if (button.TryGetValue("action", out actionObj)) {
                            RegisterAction((JSONObject)actionObj, "button"+(i+1));
                        }
                        else {
                            RegisterAction();
                        }
                    }
                    this.textures = textures;
                }
            }
            public void Build(GameObject parent, ImageMessage imageMessage, JSONObject orientation, List <Texture> textures, BackgroundLayer content, int depth)
            {
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.depth        = depth;

                object buttonsObj;

                if (orientation.TryGetValue("buttons", out buttonsObj))
                {
                    var buttons = buttonsObj as List <object>;
                    for (int i = 0; i < buttons.Count; ++i)
                    {
                        var    button = buttons[i] as JSONObject;
                        float  left = 0, top = 0;
                        object x, y;
                        if (button.TryGetValue("x", out x))
                        {
                            left = (int)((long)x) * content.Scale + content.Position.xMin;
                        }
                        if (button.TryGetValue("y", out y))
                        {
                            top = (int)((long)y) * content.Scale + content.Position.yMin;
                        }
                        this.positions.Add(new Rect(left, top, textures[i].width * content.Scale, textures[i].height * content.Scale));

                        object actionObj;
                        if (button.TryGetValue("action", out actionObj))
                        {
                            RegisterAction((JSONObject)actionObj, "button" + (i + 1));
                        }
                        else
                        {
                            RegisterAction();
                        }
                    }
                    this.textures = textures;
                }
            }
Exemple #7
0
        public void Init(IPopup popup, Dictionary<string, object> orientation, List<Texture> textures, BackgroundLayer content, int depth)
        {
            _popup = popup;
            _depth = depth;

            object buttonsObj;
            if (orientation.TryGetValue("buttons", out buttonsObj)) {
                var buttons = buttonsObj as List<object>;
                for (int i = 0; i < buttons.Count; ++i) {
                    var button = buttons[i] as Dictionary<string, object>;
                    float left = 0, top = 0;
                    object x, y;
                    if (button.TryGetValue("x", out x)) {
                        left = (int)((long)x) * content.Scale + content.Position.xMin;
                    }
                    if (button.TryGetValue("y", out y)) {
                        top = (int)((long)y) * content.Scale + content.Position.yMin;
                    }
                    _positions.Add(new Rect(left, top, textures[i].width * content.Scale, textures[i].height * content.Scale));

                    object actionObj;
                    if (button.TryGetValue("action", out actionObj)) {
                        RegisterAction((Dictionary<string, object>)actionObj, "button"+(i+1));
                    }
                    else {
                        RegisterAction();
                    }
                }
                _textures = textures;
            }
        }
        public void Init(IPopup popup, Dictionary <string, object> orientation, List <Texture> textures, BackgroundLayer content, int depth)
        {
            _popup = popup;
            _depth = depth;

            object buttonsObj;

            if (orientation.TryGetValue("buttons", out buttonsObj))
            {
                var buttons = buttonsObj as List <object>;
                for (int i = 0; i < buttons.Count; ++i)
                {
                    var    button = buttons[i] as Dictionary <string, object>;
                    float  left = 0, top = 0;
                    object x, y;
                    if (button.TryGetValue("x", out x))
                    {
                        left = (int)((long)x) * content.Scale + content.Position.xMin;
                    }
                    if (button.TryGetValue("y", out y))
                    {
                        top = (int)((long)y) * content.Scale + content.Position.yMin;
                    }
                    _positions.Add(new Rect(left, top, textures[i].width * content.Scale, textures[i].height * content.Scale));

                    object actionObj;
                    if (button.TryGetValue("action", out actionObj))
                    {
                        RegisterAction((Dictionary <string, object>)actionObj, "button" + (i + 1));
                    }
                    else
                    {
                        RegisterAction();
                    }
                }
                _textures = textures;
            }
        }