Exemplo n.º 1
0
    void FixedUpdate()
    {
        switch (state)
        {
        case ScrollingState.Starting:
            scrollingSpeed = Mathf.Lerp(scrollingSpeed, targetScrollingSpeed, speedupFactor);
            if (Mathf.Abs(scrollingSpeed - targetScrollingSpeed) < 1e-6)
            {
                state = ScrollingState.Scrolling;
            }
            break;

        case ScrollingState.Stopping:
            scrollingSpeed = Mathf.Lerp(scrollingSpeed, 0.0f, slowdownFactor);
            if (scrollingSpeed < 1e-6)
            {
                state = ScrollingState.Stopped;
            }
            break;

        case ScrollingState.Scrolling:
            float targetSpeed = targetScrollingSpeed;
            if (numPlayersWithActiveTurbo > 0)
            {
                int numActivePlayers = PlayerController.NumPlayersAlive;
                targetSpeed = numPlayersWithActiveTurbo == numActivePlayers ?
                              targetTurboScrollingSpeed : targetPartialTurboScrollingSpeed;
            }
            scrollingSpeed = Mathf.Lerp(scrollingSpeed, targetSpeed, turboSpeedupFactor);
            break;
        }
    }
Exemplo n.º 2
0
    public void ScrollTo(int index)
    {
        acceleration = defaultAccerelation;
        buttonObjects [target].GetComponent <MouseOnButtonAnimation> ().Selected = false;
        buttonObjects [index].GetComponent <MouseOnButtonAnimation> ().Selected  = true;
        target = index;

        direction = (-1) * (panelRect [target].anchoredPosition.x - defaultPosX);
        state     = ScrollingState.SCROLLING;
    }
Exemplo n.º 3
0
 void Awake()
 {
     state        = ScrollingState.DEFAULT;
     currentSpeed = 0;
     panelRect    = new RectTransform[panelObjects.Length];
     for (int i = 0; i < panelObjects.Length; ++i)
     {
         panelRect[i] = panelObjects[i].GetComponent <RectTransform>();
     }
     defaultPosX = panelRect [0].anchoredPosition.x;
     for (int i = 0; i < panelObjects.Length; ++i)
     {
         panelObjects[i].SetActive(true);
         newPos   = panelRect[i].anchoredPosition;
         newPos.x = defaultPosX + Screen.width * i;
         panelRect[i].anchoredPosition = newPos;
     }
     buttonObjects [target].GetComponent <MouseOnButtonAnimation> ().Selected = true;
 }
Exemplo n.º 4
0
        public Controller(IModel model, Form mainForm, IView view)
        {
            this.mainForm = mainForm;
            this.model    = model;
            this.view     = view;

            commandLineParser       = new CommandLineParser(this);
            networkClient           = new NetworkClient(model.NetworkClient);
            videoConferencingClient = new VideoConferencingClient(this);
            dieSimulator            = new DieSimulator();

            DraggingPieceState     = new DraggingPieceState(this);
            DraggingStackState     = new DraggingStackState(this);
            IdleState              = new IdleState(this);
            MeasuringState         = new MeasuringState(this);
            MovingState            = new MovingState(this);
            ScrollingState         = new ScrollingState(this);
            SelectingPieceState    = new SelectingPieceState(this);
            SelectingStackState    = new SelectingStackState(this);
            DialogState            = new DialogState(this);
            ResizingHandState      = new ResizingHandState(this);
            DraggingHandPieceState = new DraggingHandPieceState(this);

            state = IdleState;

            view.Menu.ShowMenuSwitch = new ZunTzu.Visualization.MenuItem(null, false, new Menu.ShowMenuSwitchMenuItem());

            mainForm.Closing          += new CancelEventHandler(onMainFormClosing);
            mainForm.KeyPress         += new KeyPressEventHandler(onKeyPress);
            mainForm.KeyDown          += new KeyEventHandler(onKeyDown);
            mainForm.KeyUp            += new KeyEventHandler(onKeyUp);
            mainForm.MouseDown        += new MouseEventHandler(onMouseDown);
            mainForm.MouseMove        += new MouseEventHandler(onMouseMove);
            mainForm.MouseUp          += new MouseEventHandler(onMouseUp);
            mainForm.MouseDoubleClick += new MouseEventHandler(onMouseDoubleClick);
            mainForm.MouseWheel       += new MouseEventHandler(onMouseWheel);

            //view.Tabs.BoardSelected += new BoardSelectedHandler(onBoardSelected);
            view.Prompter.TextEntered += new TextEnteredHandler(onTextEntered);
        }
Exemplo n.º 5
0
//	public void ClosePanels(){
//		for (int i=0; i<panelObjects.Length; ++i) {
//			panelObjects[i].SetActive(false);
//		}
//	}
    void Update()
    {
        switch (state)
        {
        case ScrollingState.SCROLLING:
            currentX = panelRect [target].anchoredPosition.x - defaultPosX;
            if (currentX > 0)
            {
                if (-currentSpeed < maxSpeed)
                {
                    currentSpeed -= Time.deltaTime * acceleration;
                }
            }
            else if (currentX < 0)
            {
                if (currentSpeed < maxSpeed)
                {
                    currentSpeed += Time.deltaTime * acceleration;
                }
            }

            if (Mathf.Abs(currentX) <= errorMargin || (direction > 0 && currentX > 0) || (direction < 0 && currentX < 0))
            {
                Debug.Log("BREAKING");
                direction     = currentSpeed;
                currentSpeed *= breakingSpeedMPL;
                acceleration *= breakingAccerelationMPL;
                state         = ScrollingState.BREAKING;
                break;
            }
            for (int i = 0; i < panelRect.Length; ++i)
            {
                newPos    = panelRect [i].anchoredPosition;
                newPos.x += Time.deltaTime * currentSpeed;
                panelRect [i].anchoredPosition = newPos;
            }
            break;

        case ScrollingState.BREAKING:
            currentX = panelRect [target].anchoredPosition.x - defaultPosX;


            if ((direction > 0 && currentSpeed < 0) || (direction < 0 && currentSpeed > 0))
            {
                if ((Mathf.Abs(currentX) <= errorMarginBreaking || (direction > 0 && currentX < 0) || (direction < 0 && currentX > 0)))
                {
                    state = ScrollingState.DEFAULT;
                    for (int i = 0; i < panelObjects.Length; ++i)
                    {
                        newPos    = panelRect[i].anchoredPosition;
                        newPos.x -= currentX;
                        panelRect[i].anchoredPosition = newPos;
                    }
                    currentSpeed = 0;
                    break;
                }
            }
            if (currentX > 0)
            {
                if (-currentSpeed < maxSpeed)
                {
                    currentSpeed -= Time.deltaTime * acceleration;
                }
                else
                {
                    currentSpeed = -maxSpeed;
                }
            }
            else if (currentX < 0)
            {
                if (currentSpeed < maxSpeed)
                {
                    currentSpeed += Time.deltaTime * acceleration;
                }
                else
                {
                    currentSpeed = maxSpeed;
                }
            }
            for (int i = 0; i < panelRect.Length; ++i)
            {
                newPos    = panelRect [i].anchoredPosition;
                newPos.x += Time.deltaTime * currentSpeed;
                panelRect [i].anchoredPosition = newPos;
            }

            break;
        }
    }
Exemplo n.º 6
0
    public void Update()
    {
        ld.Reset();

        int activeCount = 0;

        foreach (var op in optionsPool)
        {
            activeCount += op.isFadingOut ? 0 : 1;
        }

        singlePhraseBoxHeight.Portion(ld, activeCount > 0 ? 0 : 1);
        historyPool.active.Portion(ld);
        optionsPool.active.Portion(ld);

        bool lerpSeparator = false;

        if (Math.Abs(separatorPosition.TargetValue - separatorPosition.CurrentValue) > 0.00001f || poolsDirty)
        {
            lerpSeparator = true;
            poolsDirty    = false;
            separatorPosition.Portion(ld, Mathf.Min(0.6f, 0.3f + activeCount * 0.2f));
        }

        // LERP:

        singlePhraseBoxHeight.Lerp(ld);
        historyPool.active.Lerp(ld);
        optionsPool.active.Lerp(ld);

        if (lerpSeparator)
        {
            separatorPosition.Lerp(ld);
        }

        //ld.LerpAndReset();

        var   tf           = singlePhraseBg.rectTransform;
        var   size         = tf.sizeDelta;
        float curBoxFadeIn = singlePhraseBoxHeight.CurrentValue;

        size.y = curBoxFadeIn * 400;
        singlePhraseBg.TrySetAlpha_DisableGameObjectIfZero(curBoxFadeIn * 20);
        singlePhraseText.TrySetAlpha_DisableGameObjectIfZero((curBoxFadeIn - 0.9f) * 10);
        tf.sizeDelta = size;

        if (lerpSeparator)
        {
            UpdateCourners();
        }

        const float scrollbackSpeed = 1000;

        if (state == ScrollingState.None)
        {
            if (Input.GetMouseButton(0))
            {
                state = (Input.mousePosition.y / Screen.height) > separatorPosition.CurrentValue
                    ? ScrollingState.ScrollingHistory
                    : ScrollingState.ScrollingOptions;

                prevousMousePos = Input.mousePosition;

                scrollSoundPlayed = false;
            }
        }
        else
        {
            if (!Input.GetMouseButton(0))
            {
                state = ScrollingState.None;
            }
            else
            {
                float diff = Input.mousePosition.y - prevousMousePos.y;

                bool up = diff > 0;

                if ((!scrollSoundPlayed || (up != scrollSoundPlayedUp)) && Mathf.Abs(diff) > 10)
                {
                    scrollSoundPlayedUp = up;
                    scrollSoundPlayed   = true;
                }

                (state == ScrollingState.ScrollingHistory ? historyScroll : optionsScroll).AddOffset(diff);

                prevousMousePos = Input.mousePosition;
            }
        }

        if (scrollHistoryUpRequested && state != ScrollingState.None)
        {
            scrollHistoryUpRequested = false;
        }

        float pos = historyScroll.offset;

        foreach (var h in historyPool.active)
        {
            var rt   = h.rectTransform;
            var anch = rt.anchoredPosition;
            anch.y = pos;
            rt.anchoredPosition = anch;
            pos += historyScroll.gap;
        }

        if (state != ScrollingState.ScrollingHistory)
        {
            historyScroll.ApplyInnertia();

            bool outOfList = true;

            if (historyScroll.offset > 0 || scrollHistoryUpRequested)
            {
                LerpUtils.IsLerpingBySpeed(ref historyScroll.offset, 0, scrollbackSpeed);
            }
            else if (pos < historyScroll.gap)
            {
                LerpUtils.IsLerpingBySpeed(ref historyScroll.offset, historyScroll.offset + historyScroll.gap - pos, scrollbackSpeed);
            }
            else
            {
                outOfList = false;
            }

            if (outOfList)
            {
                historyScroll.FadeInnertia();
            }
        }

        pos = optionsScroll.offset;

        foreach (var h in optionsPool.active)
        {
            if (!h.isFadingOut)
            {
                var rt   = h.rectTransform;
                var anch = rt.anchoredPosition;
                anch.y = pos;
                rt.anchoredPosition = anch;
                pos -= optionsScroll.gap;
            }
        }

        if (state != ScrollingState.ScrollingOptions)
        {
            optionsScroll.ApplyInnertia();

            bool outOfTheList = true;

            if (optionsScroll.offset < 0)
            {
                LerpUtils.IsLerpingBySpeed(ref optionsScroll.offset, 0, scrollbackSpeed);
            }
            else if (pos > -optionsScroll.gap)
            {
                LerpUtils.IsLerpingBySpeed(ref optionsScroll.offset, optionsScroll.offset - optionsScroll.gap - pos, scrollbackSpeed);
            }
            else
            {
                outOfTheList = false;
            }

            if (outOfTheList)
            {
                optionsScroll.FadeInnertia();
            }
        }
    }
    private void nothingPressed()
    {
        //prediction here now

        Vector3 deltaPos = (lastPos - currentPos) * damper;

        //don't want no y portion for the movement!
        deltaPos.y = 0;

        if (wandClone != null)
           wandClone.transform.position += deltaPos;

        float direction = Mathf.Sign(Vector3.Dot(Vector3.Cross(lastPos, currentPos), playerTransform.position));
        float angle = (Vector3.Angle(lastPos, currentPos) * direction);

        //stop scrolling or ratating if we are only moving slightly
        if (deltaPos.magnitude <= threshold || angle <= threshold)
        {
            state = ScrollingState.None;
            Destroy(wandClone);
        }

        //set the prediction
        currentPos += (currentPos - lastPos) * damper;

        switch (state)
        {
            case ScrollingState.Scrolling:
                setPos();
                break;
            case ScrollingState.Rotating:
                setRot();
                break;
            case ScrollingState.None:
                break;
        }
    }
 private void scrollReleased()
 {
     clickedOnFloor = false;
     //set state here so tahat we can now predict
     state = ScrollingState.Scrolling;
 }
    private void scrollPressed()
    {
        //if we are looking at the floor
        clickedOnFloor = true;

        //calculate how much we need to scale down by if we are pointing outside of radius
        float distance = xzVector3Distance(playerTransform.position, wandRayCast.point);

        if (distance > effectiveRadius)
            effectiveScale = effectiveRadius / distance;
        else
            effectiveScale = 1f;

        //unset current movement
        resetPos();

        state = ScrollingState.None;
    }
 private void rotateReleased()
 {
     //set state here so tahat we can now predict
     state = ScrollingState.Rotating;
 }
    private void rotatePressed()
    {
        //generate a temp game object for the calulating of trajectory
        wandClone = new GameObject();
        wandClone.transform.parent = wand.parent;

        //unset current movement
        resetPos();

        state = ScrollingState.None;
    }
Exemplo n.º 12
0
 public void StopScroling()
 {
     state = ScrollingState.Stopping;
 }
Exemplo n.º 13
0
 public void StartScrolling()
 {
     state = ScrollingState.Starting;
 }
Exemplo n.º 14
0
 void Start()
 {
     scrollingSpeed = 0.0f;
     state          = ScrollingState.Stopped;
 }