Beispiel #1
0
 // Initialise from a token
 public TokenControl(QuestData.Token t)
 {
     UnityEngine.UI.Button button = t.gameObject.AddComponent <UnityEngine.UI.Button>();
     button.interactable = true;
     button.onClick.AddListener(delegate { startEvent(); });
     e = t;
 }
    override public float AddSubEventComponents(float offset)
    {
        tokenComponent = component as QuestData.Token;

        UIElement ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform());

        ui.SetLocation(0, offset, 6, 1);
        ui.SetText(new StringKey("val", "X_COLON", new StringKey("val", "ROTATION")));

        ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform());
        ui.SetLocation(6, offset, 3, 1);
        ui.SetText(tokenComponent.rotation.ToString());
        ui.SetButton(delegate { Rotate(); });
        new UIElementBorder(ui);
        offset += 2;

        ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform());
        ui.SetLocation(0, offset, 4, 1);
        ui.SetText(new StringKey("val", "X_COLON", CommonStringKeys.TYPE));

        ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform());
        ui.SetLocation(4, offset, 12, 1);
        ui.SetText(tokenComponent.tokenName);
        ui.SetButton(delegate { Type(); });
        new UIElementBorder(ui);
        offset += 2;

        game.quest.ChangeAlpha(tokenComponent.sectionName, 1f);

        return(offset);
    }
    public EditorComponentToken(string nameIn) : base()
    {
        Game game = Game.Get();

        tokenComponent = game.quest.qd.components[nameIn] as QuestData.Token;
        component      = tokenComponent;
        name           = component.sectionName;
        Update();
    }
Beispiel #4
0
        // Construct with quest info and reference to Game
        public Token(QuestData.Token questToken, Game gameObject) : base(gameObject)
        {
            qToken = questToken;

            string tokenName = qToken.tokenName;

            // Check that token exists
            if (!game.cd.tokens.ContainsKey(tokenName))
            {
                game.quest.log.Add(new Quest.LogEntry("Warning: Quest component " + qToken.sectionName + " is using missing token type: " + tokenName, true));
                // Catch for older quests with different types (0.4.0 or older)
                if (game.cd.tokens.ContainsKey("TokenSearch"))
                {
                    tokenName = "TokenSearch";
                }
            }

            // Get texture for token
            Vector2   texPos  = new Vector2(game.cd.tokens[tokenName].x, game.cd.tokens[tokenName].y);
            Vector2   texSize = new Vector2(game.cd.tokens[tokenName].width, game.cd.tokens[tokenName].height);
            Texture2D newTex  = ContentData.FileToTexture(game.cd.tokens[tokenName].image, texPos, texSize);

            // Create object
            unityObject     = new GameObject("Object" + qToken.sectionName);
            unityObject.tag = "board";

            unityObject.transform.parent = game.tokenCanvas.transform;

            // Create the image
            image = unityObject.AddComponent <UnityEngine.UI.Image>();
            Sprite tileSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);

            image.color  = new Color(1, 1, 1, 0);
            image.sprite = tileSprite;

            float PPS = game.cd.tokens[tokenName].pxPerSquare;

            if (PPS == 0)
            {
                PPS = (float)newTex.width;
            }

            // Set the size to the image size
            image.rectTransform.sizeDelta = new Vector2((float)newTex.width / PPS, (float)newTex.height / PPS);
            // Rotate around 0,0 rotation amount
            unityObject.transform.RotateAround(Vector3.zero, Vector3.forward, qToken.rotation);
            // Move to square
            unityObject.transform.Translate(new Vector3(qToken.location.x, qToken.location.y, 0), Space.World);

            game.tokenBoard.Add(this);
        }
Beispiel #5
0
    public void NewToken()
    {
        Game game  = Game.Get();
        int  index = 0;

        while (game.quest.qd.components.ContainsKey("Token" + index))
        {
            index++;
        }
        QuestData.Token token = new QuestData.Token("Token" + index);
        game.quest.qd.components.Add("Token" + index, token);

        CameraController cc = GameObject.FindObjectOfType <CameraController>();

        token.location.x = game.gameType.SelectionRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.SelectionRound());
        token.location.y = game.gameType.SelectionRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.SelectionRound());

        game.quest.Add("Token" + index);
        SelectComponent("Token" + index);
    }
Beispiel #6
0
        // Construct with quest info and reference to Game
        public Token(QuestData.Token questToken, Game gameObject) : base(gameObject)
        {
            qToken = questToken;

            string tokenName = qToken.tokenName;

            // Check that token exists
            if (!game.cd.tokens.ContainsKey(tokenName))
            {
                Debug.Log("Warning: Quest component " + qToken.name + " is using missing token type: " + tokenName);
                // Catch for older quests with different types (0.4.0 or older)
                if (game.cd.tokens.ContainsKey("TokenSearch"))
                {
                    tokenName = "TokenSearch";
                }
            }

            // Get texture for token
            Vector2   texPos  = new Vector2(game.cd.tokens[tokenName].x, game.cd.tokens[tokenName].y);
            Vector2   texSize = new Vector2(game.cd.tokens[tokenName].width, game.cd.tokens[tokenName].height);
            Texture2D newTex  = ContentData.FileToTexture(game.cd.tokens[tokenName].image, texPos, texSize);

            // Create object
            unityObject     = new GameObject("Object" + qToken.name);
            unityObject.tag = "board";

            unityObject.transform.parent = game.tokenCanvas.transform;

            // Create the image
            image = unityObject.AddComponent <UnityEngine.UI.Image>();
            Sprite tileSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);

            image.color  = new Color(1, 1, 1, 0);
            image.sprite = tileSprite;
            image.rectTransform.sizeDelta = new Vector2(1f, 1f);
            // Move to square
            unityObject.transform.Translate(new Vector3(qToken.location.x, qToken.location.y, 0), Space.World);

            game.tokenBoard.Add(this);
        }
Beispiel #7
0
    public void SelectAddVisibility(bool add, int index, string component)
    {
        string target = component;
        int    i;

        if (component.Equals("{NEW:Door}"))
        {
            i = 0;
            while (game.quest.qd.components.ContainsKey("Door" + i))
            {
                i++;
            }
            target = "Door" + i;
            QuestData.Door door = new QuestData.Door(target);
            Game.Get().quest.qd.components.Add(target, door);

            CameraController cc = GameObject.FindObjectOfType <CameraController>();
            door.location.x = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.TileRound());
            door.location.y = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.TileRound());

            game.quest.Add(target);
        }
        if (component.Equals("{NEW:Tile}"))
        {
            i = 0;
            while (game.quest.qd.components.ContainsKey("Tile" + i))
            {
                i++;
            }
            target = "Tile" + i;
            QuestData.Tile tile = new QuestData.Tile(target);
            Game.Get().quest.qd.components.Add(target, tile);

            CameraController cc = GameObject.FindObjectOfType <CameraController>();
            tile.location.x = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.TileRound());
            tile.location.y = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.TileRound());

            game.quest.Add(target);
        }
        if (component.Equals("{NEW:Token}"))
        {
            i = 0;
            while (game.quest.qd.components.ContainsKey("Token" + i))
            {
                i++;
            }
            target = "Token" + i;
            QuestData.Token token = new QuestData.Token(target);
            Game.Get().quest.qd.components.Add(target, token);

            CameraController cc = GameObject.FindObjectOfType <CameraController>();
            token.location.x = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.x / game.gameType.TileRound());
            token.location.y = game.gameType.TileRound() * Mathf.Round(cc.gameObject.transform.position.y / game.gameType.TileRound());

            game.quest.Add(target);
        }
        if (component.Equals("{NEW:UI}"))
        {
            i = 0;
            while (game.quest.qd.components.ContainsKey("UI" + i))
            {
                i++;
            }
            target = "UI" + i;
            Game.Get().quest.qd.components.Add(target, new QuestData.UI(target));
        }
        if (component.Equals("{NEW:QItem}"))
        {
            i = 0;
            while (game.quest.qd.components.ContainsKey("QItem" + i))
            {
                i++;
            }
            target = "QItem" + i;
            Game.Get().quest.qd.components.Add(target, new QuestData.QItem(target));
        }

        if (index != -1)
        {
            if (add)
            {
                eventComponent.addComponents[index] = target;
            }
            else
            {
                eventComponent.removeComponents[index] = target;
            }
            Update();
            return;
        }
        string[] oldC = null;

        if (add)
        {
            oldC = eventComponent.addComponents;
        }
        else
        {
            oldC = eventComponent.removeComponents;
        }
        string[] newC = new string[oldC.Length + 1];
        for (i = 0; i < oldC.Length; i++)
        {
            newC[i] = oldC[i];
        }

        newC[i] = target;

        if (add)
        {
            eventComponent.addComponents = newC;
        }
        else
        {
            eventComponent.removeComponents = newC;
        }
        Update();
    }
Beispiel #8
0
 // Add a token
 public void add(QuestData.Token t)
 {
     tc.Add(new TokenControl(t));
 }