예제 #1
0
 //刷新button的cd
 private void RefreshButtonCD(SuperButton sb)
 {
     sb.CDTick    = sb.MaxCDTick;
     sb.Tick.text = sb.CDTick.ToString();
     sb.Tick.gameObject.CustomSetActive(true);
     sb.Mask.fillAmount = 1.0f;
     sb.Mask.gameObject.CustomSetActive(true);
     if (sb.UpdateSeq == 0)
     {
         sb.UpdateSeq = ILRTimerManager.instance.AddTimer(1000, 0, (seq) =>
         {
             if (sb.CDTick > 0)
             {
                 sb.CDTick--;
                 int cd             = sb.CDTick;
                 float percent      = cd * 1.0f / sb.MaxCDTick;
                 sb.Mask.fillAmount = percent;
                 sb.Tick.text       = cd.ToString();
                 if (cd == 0)
                 {
                     sb.Tick.gameObject.CustomSetActive(false);
                     sb.Mask.fillAmount = 0.0f;
                     sb.Mask.gameObject.CustomSetActive(false);
                     sb.CDTick = 0;
                     ILRTimerManager.instance.RemoveTimerSafely(ref sb.UpdateSeq);
                 }
             }
         });
     }
 }
예제 #2
0
    private void onTileClick(SuperButton button)
    {
        var tileReference = button.GetComponent <TileReference>();

        tileReference.showValue();
        button.enabled = false;

        if (tileReferenceA == null)
        {
            tileReferenceA = tileReference;
        }
        else
        {
            setButtonsEnabled(false);
            tileReferenceB = tileReference;

            if (tileReferenceA.node.match == tileReferenceB.node)
            {
                matchedButtons.Add(tileReferenceA.GetComponent <SuperButton>());
                matchedButtons.Add(button);

                resetButtons();
                matchedCount++;
                if (matchedCount >= tileCount * .5f)
                {
                    onMatchWon();
                }
            }
            else
            {
                StartCoroutine(resetTiles());
            }
        }
    }
예제 #3
0
        private void StartGame_Click(object sender, RoutedEventArgs e)
        {
            if (currentGame == null)
            {
                buttons    = new Button[5]; // buttons in UI
                buttons[0] = Button_0;
                buttons[1] = Button_1;
                buttons[2] = Button_2;
                buttons[3] = Button_3;
                buttons[4] = Button_4;

                for (int i = 0; i < 5; i++)
                {
                    buttons[i].Click += new RoutedEventHandler(GeneralButtonClick);
                }

                wordsOnBoard = new List <SuperButton>();  // buttons for game logic
                currentGame  = GameModel.Instance;
                cursor       = null;

                spawnTimer          = new System.Windows.Threading.DispatcherTimer(); // Timer for spawning words
                spawnTimer.Tick    += WordSpawnEvent;
                spawnTimer.Interval = TimeSpan.FromSeconds(0.5);

                fallTimer          = new System.Windows.Threading.DispatcherTimer(); // Timer for falling words
                fallTimer.Tick    += WordFallEvent;
                fallTimer.Interval = TimeSpan.FromSeconds(0.1);

                gameTimer          = new System.Windows.Threading.DispatcherTimer(); // Timer for the game
                gameTimer.Tick    += GameTimer;
                gameTimer.Interval = TimeSpan.FromSeconds(1);

                rand = new Random();
            }

            currentGame.Reset();
            foreach (SuperButton element in wordsOnBoard)
            {
                element.GoBack();
            }
            wordsOnBoard.Clear();
            game_timer  = 68;
            Time.Text   = "60s";
            Score.Text  = currentGame.Score;
            Health.Text = currentGame.Health;

            Announce.Text      = "";
            TextBox.Text       = "";
            TextBox.Visibility = Visibility.Visible;
            TextBox.Focus();

            spawnTimer.Start();
            fallTimer.Start();
            gameTimer.Start();
        }
예제 #4
0
        private void InitControls_UI()
        {
            var t       = controller.transform;
            var node_ui = t.Find("node_ui");

            #region buttons
            {
                var sb      = new SuperButton();
                var btn_egg = node_ui.GetComponent <ConsecutiveClickCoolTrigger>("btn_egg");
                btn_egg.clickEvent.Add(new EventDelegate(() => OnButtonClicked(SuperButton.ButtonType.tEgg)));
                var mask = btn_egg.gameObject.GetComponent <UITexture>("sp_mask");
                var tick = btn_egg.gameObject.GetComponent <UILabel>("lb_tick");
                mask.gameObject.CustomSetActive(false);
                tick.gameObject.CustomSetActive(false);
                sb.Button = btn_egg;
                sb.Mask   = mask;
                sb.Tick   = tick;
                _buttons.Add(sb);
            }

            {
                var sb     = new SuperButton();
                var btn_go = node_ui.GetComponent <ConsecutiveClickCoolTrigger>("btn_go");
                btn_go.clickEvent.Add(new EventDelegate(() => OnButtonClicked(SuperButton.ButtonType.tGo)));
                var mask = btn_go.gameObject.GetComponent <UITexture>("sp_mask");
                var tick = btn_go.gameObject.GetComponent <UILabel>("lb_tick");
                mask.gameObject.CustomSetActive(false);
                tick.gameObject.CustomSetActive(false);
                sb.Button = btn_go;
                sb.Mask   = mask;
                sb.Tick   = tick;
                _buttons.Add(sb);
            }

            {
                var sb        = new SuperButton();
                var btn_speed = node_ui.GetComponent <ConsecutiveClickCoolTrigger>("btn_speed");
                btn_speed.clickEvent.Add(new EventDelegate(() => OnButtonClicked(SuperButton.ButtonType.tSpeed)));
                sb.Button         = btn_speed;
                sb.List_SpeedText = new List <UISprite> {
                    btn_speed.gameObject.GetComponent <UISprite>("Deactive"),
                    btn_speed.gameObject.GetComponent <UISprite>("Active")
                };
                sb.Index_SpeedText = 0;
                _buttons.Add(sb);
            }
            #endregion

            #region 321go
            _start321go = new Start321Go(node_ui);
            #endregion
        }
예제 #5
0
 public void NewCursor(Button new_cursor)
 {
     for (int i = 0; i < wordsOnBoard.Count; i++)
     {
         if (wordsOnBoard[i].button == new_cursor)
         {
             cursor = wordsOnBoard[i];
         }
     }
     for (int i = 0; i < 5; i++)
     {
         buttons[i].Background = Brushes.FloralWhite;
     }
     if (cursor != null)
     {
         cursor.button.Background = Brushes.Yellow;
     }
 }
예제 #6
0
        private void WordFallEvent(object sender, EventArgs e)
        {
            if (game_timer > 60)
            {
                return;
            }

            for (int i = 0; i < wordsOnBoard.Count; i++)
            {
                SuperButton sb = wordsOnBoard[i];
                sb.Fall();

                if (sb.Isbottom() == 1)
                {
                    wordsOnBoard.Remove(sb);
                    if (wordsOnBoard.Count == 0 && currentGame.Words_length == 0)
                    {
                        sb.GoBack();
                        currentGame.TypingFailed(sb.word);
                        GameEnd(1);
                        return;
                    }

                    if (cursor == sb)
                    {
                        NewCursor(wordsOnBoard[0].button);
                    }
                    sb.GoBack();

                    currentGame.TypingFailed(sb.word);
                    Score.Text   = currentGame.Score;
                    Health.Text  = currentGame.Health;
                    TextBox.Text = "";

                    if (currentGame.Health == "0")
                    {
                        GameEnd(-1);
                        return;
                    }
                }
            }
        }
예제 #7
0
    //Custom classes don't need to create a ProcessNode that doesn't take maybe_recycled_node, since
    //the only way to get here is through the Container/Label/Sprite configs passing it through
    public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        string name = (string)node["name"];

        GameObject  game_object = maybe_recycled_node;
        SuperButton button      = null;

        if (game_object == null)
        {
            game_object = new GameObject();
            button      = game_object.AddComponent(typeof(SuperButton)) as SuperButton;

            button.createAnimation();
        }
        else
        {
            button = game_object.GetComponent <SuperButton>();

            //TODO: should probably verify that we still have our UpState/HighlightedState/PressedState/DisabledState
            //but for now just assume we're not changing classes
        }

        button.CreateRectTransform(game_object, node);
        button.name                 = name;
        button.rootNode             = root_node;
        button.cachedMetadata       = node;
        button.hierarchyDescription = "BUTTON";

        root_node.buttonReferences.Add(new ButtonReference(name, button));

        game_object.transform.SetParent(parent);
        button.Reset();

        //image nodes don't have children
        if (node.ContainsKey("children"))
        {
            root_node.ProcessChildren(game_object.transform, node["children"] as List <object>);
        }

        //we post process our children into our state objects so they can turn on/off correctly
        button.sortChildren();
    }
예제 #8
0
        public void GameEnd(int flag)  // flag=1 means finished, flag=-1 means failed
        {
            cursor = null;
            spawnTimer.Stop();
            fallTimer.Stop();
            gameTimer.Stop();

            Score.Text   = currentGame.Score;
            Health.Text  = currentGame.Health;
            TextBox.Text = "";

            foreach (SuperButton sb in wordsOnBoard)
            {
                sb.GoBack();
            }
            wordsOnBoard.Clear();

            for (int i = 0; i < 5; i++)
            {
                buttons[i].Background = Brushes.FloralWhite;
            }
            TextBox.Visibility = Visibility.Hidden;

            ProfNgDisappear_png.Visibility = Visibility.Hidden;
            ProfNg_png.Visibility          = Visibility.Visible;

            if (flag == 1)
            {
                Console.WriteLine("Finished!!");
                Announce.Visibility = Visibility.Visible;
                Announce.Text       = "You passed!";
            }
            else if (flag == -1)
            {
                Console.WriteLine("Failed!!");
                Announce.Visibility = Visibility.Visible;
                Announce.Text       = "You failed!";
            }

            Console.WriteLine("Game end! Thank you!");
        }
예제 #9
0
        private void WordSpawnEvent(object sender, EventArgs e)
        {
            if (game_timer > 60)
            {
                return;
            }

            List <int> idle = new List <int>();
            int        spawnIndex;

            if (currentGame.Words_length != 0)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (buttons[i].Content.ToString() == "")
                    {
                        idle.Add(i);
                    }
                }
                if (idle.Count > 0)
                {
                    spawnIndex = idle[rand.Next(0, idle.Count)];
                    SuperButton sb = new SuperButton(currentGame.WordsDequeue(), buttons[spawnIndex]);
                    wordsOnBoard.Add(sb);
                    buttons[spawnIndex].Content    = sb.GetSuperWordContent;
                    buttons[spawnIndex].Visibility = Visibility.Visible;

                    if (wordsOnBoard.Count == 1)
                    {
                        NewCursor(wordsOnBoard[0].button);
                    }

                    Console.WriteLine("Word -{0}- spawned", sb.button.Content);
                }
                else
                {
                    Console.WriteLine("All buttons busy, no space to spawn word");
                }
            }
        }
예제 #10
0
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            string text = TextBox.Text;

            if (wordsOnBoard.Count == 0 && currentGame.Words_length == 0)
            {
                GameEnd(1);
                return;
            }

            if (cursor == null)
            {
                TextBox.Text = "";
                return;
            }

            if (text.Length == 0)
            {
                if (typingPosition == 1)
                {
                    TextBox.Text = cursor.GetSuperWordContent.Substring(0, typingPosition);
                    TextBox.Select(TextBox.Text.Length, 0);
                }
                return;
            }


            // otherwise, the input is normal
            Console.WriteLine("current text : |{0}|, position = {1}", TextBox.Text, typingPosition);
            char newInput = text[text.Length - 1];

            typingPosition = cursor.word.Typing(newInput);
            Console.WriteLine("new input : {0} on position {1}", newInput, typingPosition);

            if (typingPosition >= 0)  // the word has not been finished yet
            {
                TextBox.Text = cursor.GetSuperWordContent.Substring(0, typingPosition);
                TextBox.Select(TextBox.Text.Length, 0);
            }
            else if (typingPosition == -1)  // the word is finished
            {
                Console.WriteLine("else");
                Console.WriteLine("wordsOnBoard length = {0}, currentGame.Words_length = {1}", wordsOnBoard.Count, currentGame.Words_length);

                SuperButton sb = cursor;
                wordsOnBoard.Remove(cursor);
                if (wordsOnBoard.Count != 0)
                {
                    NewCursor(wordsOnBoard[0].button);
                }
                else
                {
                    cursor = null;
                }
                sb.GoBack();

                currentGame.TypingFinished(sb.word);
                Score.Text   = currentGame.Score;
                Health.Text  = currentGame.Health;
                TextBox.Text = "";

                if (wordsOnBoard.Count == 0 && currentGame.Words_length == 0)
                {
                    GameEnd(1);
                    return;
                }
            }
        }
예제 #11
0
    public override void OnInspectorGUI()
    {
        if (button == null)
        {
            button = (SuperButton)target;
            labelStyle.fontStyle        = FontStyle.Bold;
            labelStyle.normal.textColor = new Color(0.75f, 0.75f, 0.75f);
            button.transition           = Selectable.Transition.None;
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Button", labelStyle);

        bool interactable;

        EditorGUI.BeginChangeCheck();
        {
            interactable = EditorGUILayout.Toggle(interactableLabel, button.interactable);
        }
        if (EditorGUI.EndChangeCheck())         // Avoids it refreshing on every frame even when it hasn't changed
        {
            button.interactable = interactable;
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Animation", labelStyle);
        button.transformToAnimate = (RectTransform)EditorGUILayout.ObjectField(transformLabel, button.transformToAnimate, typeof(RectTransform), true);
        button.animationType      = (SuperButton.AnimationTypes)EditorGUILayout.EnumPopup(animTypeLabel, button.animationType);
        switch (button.animationType)
        {
        case SuperButton.AnimationTypes.Scale:
            button.animCurveScale = EditorGUILayout.CurveField(animCurveLabel, button.animCurveScale);
            break;

        case SuperButton.AnimationTypes.MoveUpDown:
        case SuperButton.AnimationTypes.MoveLeftRight:
            button.animCurveMove = EditorGUILayout.CurveField(animCurveLabel, button.animCurveMove);
            break;
        }
        button.animDuration = EditorGUILayout.FloatField(animDurationLabel, button.animDuration);
        if ((button.animationType == SuperButton.AnimationTypes.MoveLeftRight) || (button.animationType == SuperButton.AnimationTypes.MoveUpDown))
        {
            button.moveDistance = EditorGUILayout.FloatField(moveDistanceLabel, button.moveDistance);
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Highlight (Optional)", labelStyle);
        button.highlightCanvasGroup = (CanvasGroup)EditorGUILayout.ObjectField(highlightCanvasGroupLabel, button.highlightCanvasGroup, typeof(CanvasGroup), true);
        button.animCurveHighlight   = EditorGUILayout.CurveField(animCurveLabel, button.animCurveHighlight);

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Disabled Effect", labelStyle);
        button.disableType = (SuperButton.DisableTypes)EditorGUILayout.EnumPopup(disableTypeLabel, button.disableType);
        switch (button.disableType)
        {
        case SuperButton.DisableTypes.CanvasGroupAlpha:
            button.disableCanvasGroup      = (CanvasGroup)EditorGUILayout.ObjectField(disableCanvasGroupLabel, button.disableCanvasGroup, typeof(CanvasGroup), true);
            button.disableCanvasGroupAlpha = EditorGUILayout.FloatField(disableAlphaLabel, button.disableCanvasGroupAlpha);
            break;

        case SuperButton.DisableTypes.HierarchySwap:
            SerializedProperty enableWhenInteractable = serializedObject.FindProperty("enableWhenInteractable");
            EditorGUILayout.PropertyField(enableWhenInteractable, true);
            SerializedProperty enableWhenNotInteractable = serializedObject.FindProperty("enableWhenNotInteractable");
            EditorGUILayout.PropertyField(enableWhenNotInteractable, true);
            break;
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField(audioLabel, labelStyle);
        button.audioOnAnimStart = (UIMaster.AudioClips)EditorGUILayout.EnumPopup(audioOnAnimStartLabel, button.audioOnAnimStart);

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Cooldown (Locks Out Other Buttons)", labelStyle);

        button.lockOtherButtonsDuringAnim = EditorGUILayout.Toggle(lockOthersDuringAnimLabel, button.lockOtherButtonsDuringAnim);
        button.lockCooldownAfterAnim      = EditorGUILayout.FloatField(lockCooldownAfterAnimLabel, button.lockCooldownAfterAnim);

        SerializedProperty onAnimStart = serializedObject.FindProperty("onAnimStart");

        EditorGUILayout.PropertyField(onAnimStart);

        if (button.animationType != SuperButton.AnimationTypes.None)
        {
            SerializedProperty onAnimFinish = serializedObject.FindProperty("onAnimFinish");
            EditorGUILayout.PropertyField(onAnimFinish);
        }

        if (GUI.changed)
        {
            serializedObject.ApplyModifiedProperties();
        }
    }