Exemplo n.º 1
0
    public void DoLayout()
    {
        float   padding = Config.PADDING_XS;
        Vector2 cursor  = new Vector2(-_width * 0.5f, _height * 0.5f);    //the top left

        float freeWidth = _width;

        freeWidth -= minusBox.GetNeededWidth() + padding; //minus width
        freeWidth -= plusBox.GetNeededWidth() + padding;  //plus width
        freeWidth -= padding;                             //padding between name and score

        if (_hasHandle)
        {
            AddChild(handleBox);
            handleBox.SetSize(handleBox.GetNeededWidth(), _height);
            handleBox.SetTopLeft(cursor.x, cursor.y);
            cursor.x  += handleBox.width + padding;
            freeWidth -= handleBox.width + padding;           //handle width
        }
        else
        {
            handleBox.RemoveFromContainer();
        }

        bool shouldRound = (scoreBox.mathMode.amount == 0 || scoreBox.mathMode.amount == 1);

        freeWidth = Mathf.Round(freeWidth);

        resetWidth = freeWidth;

        float mathModeMultiplier = (1.0f + 1.1f * scoreBox.mathMode.amount);
        float maxScoreWidth      = 100.0f;
        float scoreWidth         = Mathf.Min(maxScoreWidth, freeWidth * 1.5f / 5.0f) * mathModeMultiplier;
        float nameWidth          = freeWidth - scoreWidth;

        scoreWidth = Mathf.Round(scoreWidth);
        nameWidth  = Mathf.Round(nameWidth);


        nameBox.SetSize(nameWidth, _height);
        nameBox.SetTopLeft(cursor.x, cursor.y);
        nameCell.Set(cursor.x + nameWidth * 0.5f, cursor.y - _height * 0.5f, nameWidth, _height);
        cursor.x += nameBox.width + padding;

        scoreBox.SetSize(scoreWidth, _height);
        scoreBox.SetTopLeft(cursor.x, cursor.y);
        cursor.x += scoreBox.width + padding;

        minusBox.SetSize(minusBox.GetNeededWidth(), _height);
        minusBox.SetTopLeft(cursor.x, cursor.y);
        cursor.x += minusBox.width + padding;

        plusBox.SetSize(plusBox.GetNeededWidth(), _height);
        plusBox.SetTopLeft(cursor.x, cursor.y);
        cursor.x += plusBox.width + padding;
    }
Exemplo n.º 2
0
    public ResetGroup(float width)
    {
        this.width = width;

        AddChild(plusBox  = new MathBox(MathType.Plus));
        AddChild(minusBox = new MathBox(MathType.Minus));

        AddChild(zeroBox = new ZeroBox());

        AddChild(cancelBox = new SpriteBox(Player.NullPlayer, "Icons/Cancel", 100, 100));
        AddChild(okBox     = new SpriteBox(Player.NullPlayer, "Icons/Checkmark", 100, 100));

        plusBox.hasFastRepeatZones  = true;
        minusBox.hasFastRepeatZones = true;

        if (PlayerPrefs.HasKey(PREFS_KEY))
        {
            zeroBox.resetAmount = PlayerPrefs.GetInt(PREFS_KEY);
        }

        float boxSize = Config.SLOT_HEIGHT;
        float padding = Config.PADDING_S;

        plusBox.SetSize(boxSize, boxSize);
        minusBox.SetSize(boxSize, boxSize);
        zeroBox.SetSize(width - boxSize * 2 - padding * 2, boxSize);

        plusBox.SetPosition(zeroBox.width / 2 + padding + plusBox.width / 2, padding / 2 + plusBox.height / 2);
        minusBox.SetPosition(-zeroBox.width / 2 - padding - minusBox.width / 2, padding / 2 + minusBox.height / 2);
        zeroBox.SetPosition(0, padding / 2 + zeroBox.height / 2);

        cancelBox.SetSize((width - padding) / 2, boxSize);
        okBox.SetSize((width - padding) / 2, boxSize);

        cancelBox.SetPosition(-padding / 2 - cancelBox.width / 2, -padding / 2 - cancelBox.height / 2);
        okBox.SetPosition(padding / 2 + okBox.width / 2, -padding / 2 - okBox.height / 2);

        minusBox.SignalTick += (b, ticks) =>
        {
            zeroBox.resetAmount -= ticks;
            UpdateResetAmount();
        };

        plusBox.SignalTick += (b, ticks) =>
        {
            zeroBox.resetAmount += ticks;
            UpdateResetAmount();
        };

        zeroBox.SignalRelease += (b) =>
        {
            zeroBox.DoTapEffect();
            FSoundManager.PlaySound("UI/ResetToZero");
            zeroBox.resetAmount = 0;
            UpdateResetAmount();
        };

        cancelBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(false);
            cancelBox.isTouchable = false;
            cancelBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/Cancel");
        };

        okBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(true);
            okBox.isTouchable = false;
            okBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/ResetOk");

            SKDataManager.MarkDirty();
        };

        UpdateResetAmount();

        instance = this;
    }
Exemplo n.º 3
0
    public ResetGroup(float width)
    {
        this.width = width;

        AddChild(plusBox = new MathBox(MathType.Plus));
        AddChild(minusBox = new MathBox(MathType.Minus));

        AddChild(zeroBox = new ZeroBox());

        AddChild(cancelBox = new SpriteBox(Player.NullPlayer,"Icons/Cancel",100,100));
        AddChild(okBox = new SpriteBox(Player.NullPlayer,"Icons/Checkmark",100,100));

        plusBox.hasFastRepeatZones = true;
        minusBox.hasFastRepeatZones = true;

        if(PlayerPrefs.HasKey(PREFS_KEY))
        {
            zeroBox.resetAmount = PlayerPrefs.GetInt(PREFS_KEY);
        }

        float boxSize = Config.SLOT_HEIGHT;
        float padding = Config.PADDING_S;

        plusBox.SetSize(boxSize,boxSize);
        minusBox.SetSize(boxSize,boxSize);
        zeroBox.SetSize(width-boxSize*2-padding*2,boxSize);

        plusBox.SetPosition(zeroBox.width/2 + padding + plusBox.width/2, padding/2 + plusBox.height/2);
        minusBox.SetPosition(-zeroBox.width/2 - padding - minusBox.width/2, padding/2 + minusBox.height/2);
        zeroBox.SetPosition(0,padding/2 + zeroBox.height/2);

        cancelBox.SetSize((width-padding)/2,boxSize);
        okBox.SetSize((width-padding)/2,boxSize);

        cancelBox.SetPosition(-padding/2 - cancelBox.width/2, -padding/2 - cancelBox.height/2);
        okBox.SetPosition(padding/2 + okBox.width/2, -padding/2 - okBox.height/2);

        minusBox.SignalTick += (b,ticks) =>
        {
            zeroBox.resetAmount -= ticks;
            UpdateResetAmount();
        };

        plusBox.SignalTick += (b,ticks) =>
        {
            zeroBox.resetAmount += ticks;
            UpdateResetAmount();
        };

        zeroBox.SignalRelease += (b) =>
        {
            zeroBox.DoTapEffect();
            FSoundManager.PlaySound("UI/ResetToZero");
            zeroBox.resetAmount = 0;
            UpdateResetAmount();
        };

        cancelBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(false);
            cancelBox.isTouchable = false;
            cancelBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/Cancel");
        };

        okBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(true);
            okBox.isTouchable = false;
            okBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/ResetOk");

            SKDataManager.MarkDirty();
        };

        UpdateResetAmount();

        instance = this;
    }