/// <summary>
        /// Paste questions in certain position
        /// </summary>
        /// <param name="position">Position to paste questions</param>
        private void OnPasteQuestions(Point position)
        {
            this.ClearSelection();

            // for the case when mouse position was out of UI change start position
            if (position.X < 0 || position.Y < 0)
            {
                position.X = position.Y = 30;
            }

            // calculate delta between topmost item and paste position
            BaseQuestionViewModel topmostItem = this.copiedQuestionsBuffer.OrderByDescending(x => x.Top).Last();
            double deltaTop  = topmostItem.Top - position.Y;
            double deltaLeft = topmostItem.Left - position.X;

            // buffer for undo/redo
            BaseQuestionViewModel[] copiedElements = new BaseQuestionViewModel[this.copiedQuestionsBuffer.Count];

            for (int i = 0; i < this.copiedQuestionsBuffer.Count; i++)
            {
                // create new copy and update name and position
                BaseQuestionViewModel copy = this.copiedQuestionsBuffer[i].CreateCopy();
                copy.Name  = NamingManager.GetNextAvailableElementName(this.PageQuestions);
                copy.Top  -= deltaTop;
                copy.Left -= deltaLeft;

                this.OnAddQuestion(copy);
                copy.IsSelected = true;

                copiedElements[i] = copy;
            }

            ActionTracker.TrackAction(new AddElementsAction(copiedElements, this.PageQuestions));
        }
Пример #2
0
        private void OnButtonDown(ControllerAction action, ControllerSnapshot snapshot)
        {
            ActionTracker tracker = GetTracker(action);

            if (tracker.UpdateCurrentPoint())
            {
                PointerEventData pevent = tracker.pevent;
                pevent.pressPosition       = pevent.position;
                pevent.pointerPressRaycast = pevent.pointerCurrentRaycast;
                pevent.pointerPress        = null;

                GameObject target = pevent.pointerPressRaycast.gameObject;
                tracker.current_pressed = ExecuteEvents.ExecuteHierarchy(target, pevent, ExecuteEvents.pointerDownHandler);

                if (tracker.current_pressed == null)
                {
                    // some UI elements might only have click handler and not pointer down handler
                    tracker.current_pressed = ExecuteEvents.ExecuteHierarchy(target, pevent, ExecuteEvents.pointerClickHandler);
                }
                else
                {
                    // we want to do click on button down at same time, unlike regular mouse processing
                    // which does click when mouse goes up over same object it went down on
                    // reason to do this is head tracking might be jittery and this makes it easier to click buttons
                    ExecuteEvents.Execute(tracker.current_pressed, pevent, ExecuteEvents.pointerClickHandler);
                }

                if (tracker.current_pressed != null)
                {
                    ExecuteEvents.Execute(tracker.current_pressed, pevent, ExecuteEvents.beginDragHandler);
                    pevent.pointerDrag = tracker.current_pressed;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Update bubbles count within question
        /// </summary>
        /// <param name="newCount">New amount of bubbles</param>
        /// <param name="toTrack">Flag indicating whether action should be tracked for Undo/Redo support</param>
        public void UpdateBubbleCount(int newCount, bool toTrack)
        {
            if (newCount > this.maxAllowedBubblesCount)
            {
                return;
            }

            // update static count field so that freshly added questions has latest amount of bubbles
            latestBubblesCount = newCount;

            var bubblesBefore = new List <BubbleViewModel>();

            bubblesBefore.AddRange(this.Bubbles);

            this.Bubbles.Clear();
            if (this.Orientation == Orientations.Horizontal)
            {
                this.FitBubblesHorizontal(newCount);
            }
            else
            {
                this.FitBubblesVertical(newCount);
            }

            this.UpdateBubblesNames();

            var bubblesAfter = new List <BubbleViewModel>();

            bubblesAfter.AddRange(this.Bubbles);

            if (toTrack)
            {
                ActionTracker.TrackChangeBubblesCount(this, bubblesBefore, bubblesAfter);
            }
        }
        /// <summary>
        /// Update amount of sections inside grid
        /// </summary>
        /// <param name="newCount">New amount of sections</param>
        private void UpdateSectionsCount(int newCount)
        {
            // update static count field so that freshly added questions has latest amount of bubbles
            latestQuestionsCount = newCount;

            var choiceBoxesBefore = new List <ChoiceBoxViewModel>();

            choiceBoxesBefore.AddRange(this.ChoiceBoxes);

            this.ChoiceBoxes.Clear();
            if (this.Orientation == Orientations.Horizontal)
            {
                this.FitChoiceBoxesHorizontal(newCount);
            }
            else
            {
                this.FitChoiceBoxesVertical(newCount);
            }

            var choiceBoxesAfter = new List <ChoiceBoxViewModel>();

            choiceBoxesAfter.AddRange(this.ChoiceBoxes);

            ActionTracker.TrackChangeSectionsCount(this, choiceBoxesBefore, choiceBoxesAfter);
        }
Пример #5
0
        ActionTracker AddTracker(ControllerAction action)
        {
            ActionTracker tracker = new ActionTracker(action, this);

            current_actions[action] = tracker;
            return(tracker);
        }
Пример #6
0
        /// <summary>
        /// Thumb drag completed event handler
        /// </summary>
        private void MoveThumbDragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (this.DataContext is BaseQuestionViewModel)
            {
                // move question
                BaseQuestionViewModel questionViewModel = (BaseQuestionViewModel)this.DataContext;

                double deltaTop  = this.startTop - questionViewModel.Top;
                double deltaLeft = this.startLeft - questionViewModel.Left;

                if (Math.Abs(deltaTop) > 0.01 || Math.Abs(deltaLeft) > 0.01)
                {
                    if (questionViewModel.ParentTemplate != null)
                    {
                        // moving choicebox question, check all other selected questions
                        List <BaseQuestionViewModel> selectedItems = questionViewModel.ParentTemplate.SelectedElements.ToList();
                        ActionTracker.TrackChangeQuestionsPosition(selectedItems, deltaTop, deltaLeft, 1, 1);

                        if (questionViewModel.ParentTemplate.GotSnapLines)
                        {
                            questionViewModel.ParentTemplate.CleanSnapLines();
                        }
                    }
                    else if (questionViewModel is ChoiceBoxViewModel)
                    {
                        if (((ChoiceBoxViewModel)questionViewModel).ParentGrid != null)
                        {
                            // moving choicebox child of grid question
                            ActionTracker.TrackChangeQuestionsPosition(new List <BaseQuestionViewModel>()
                            {
                                questionViewModel
                            }, deltaTop, deltaLeft, 1, 1);
                        }
                    }
                }

                if (questionViewModel.ParentTemplate != null)
                {
                    if (questionViewModel.ParentTemplate.GotSnapLines)
                    {
                        questionViewModel.ParentTemplate.CleanSnapLines();
                    }
                }
            }
            else if (this.DataContext is BubbleViewModel)
            {
                // move bubble
                BubbleViewModel bubbleViewModel = (BubbleViewModel)this.DataContext;

                double deltaTop  = this.bubbleStartTop - bubbleViewModel.Top;
                double deltaLeft = this.bubbleStartLeft - bubbleViewModel.Left;

                if (Math.Abs(deltaTop) > 0.01 || Math.Abs(deltaLeft) > 0.01)
                {
                    ActionTracker.TrackChangeBubble(new List <BubbleViewModel> {
                        bubbleViewModel
                    }, deltaTop, deltaLeft, 1, 1);
                }
            }
        }
Пример #7
0
        void UpdateHoveringTarget(ActionTracker tracker, GameObject new_target)
        {
            if (new_target == tracker.pevent.pointerEnter)
            {
                return;    /* already up-to-date */
            }
            /* pop off any hovered objects from the stack, as long as they are not parents of 'new_target' */
            while (tracker.pevent.hovered.Count > 0)
            {
                GameObject h = tracker.pevent.hovered[tracker.pevent.hovered.Count - 1];
                if (!h)
                {
                    tracker.pevent.hovered.RemoveAt(tracker.pevent.hovered.Count - 1);
                    continue;
                }
                if (new_target != null && new_target.transform.IsChildOf(h.transform))
                {
                    break;
                }
                tracker.pevent.hovered.RemoveAt(tracker.pevent.hovered.Count - 1);
                ExecuteEvents.Execute(h, tracker.pevent, ExecuteEvents.pointerExitHandler);
            }

            /* enter and push any new object going to 'new_target', in order from outside to inside */
            tracker.pevent.pointerEnter = new_target;
            if (new_target != null)
            {
                EnterAndPush(tracker.pevent, new_target.transform, tracker.pevent.hovered.Count == 0 ? transform :
                             tracker.pevent.hovered[tracker.pevent.hovered.Count - 1].transform);
            }
        }
Пример #8
0
    public void DecodeTrackers()
    {
        using (StreamReader r = new StreamReader(@"savegame.json"))
        {
            string   json     = r.ReadToEnd();
            Encoders encoders = JsonUtility.FromJson <Encoders>(json);

            GoldTracker goldTracker = FindObjectOfType <GoldTracker>();
            JsonUtility.FromJsonOverwrite(encoders.goldTracker, goldTracker);

            GameSetupScenarioTracker gameSetupScenarioTracker = FindObjectOfType <GameSetupScenarioTracker>();
            JsonUtility.FromJsonOverwrite(encoders.gameSetupScenarioTracker, gameSetupScenarioTracker);
            gameSetupScenarioTracker.OnLoad();

            UnlockTracker unlockTracker = FindObjectOfType <UnlockTracker>();
            JsonUtility.FromJsonOverwrite(encoders.unlockTracker, unlockTracker);

            PerkTracker perkTracker = FindObjectOfType <PerkTracker>();
            JsonUtility.FromJsonOverwrite(encoders.perkTracker, perkTracker);

            ActionTracker actionTracker = FindObjectOfType <ActionTracker>();
            JsonUtility.FromJsonOverwrite(encoders.actionTracker, actionTracker);

            RandomTracker randomTracker = FindObjectOfType <RandomTracker>();
            JsonUtility.FromJsonOverwrite(encoders.randomTracker, randomTracker);
            randomTracker.OnLoad();
        }
    }
Пример #9
0
        /// <summary>
        ///  workout what is a delete, anything that isn't in the target but is in the master
        ///  should be a delete.
        /// </summary>
        /// <param name="master"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private void IdentifyDeletes(string master, string target)
        {
            var missingFiles = MigrationIO.LeftOnlyFiles(master, target);

            var actionTracker = new ActionTracker(target);

            foreach (var file in missingFiles)
            {
                // work out the type of file...
                if (File.Exists(file.FullName))
                {
                    XElement node     = XElement.Load(file.FullName);
                    var      itemType = node.GetUmbracoType();
                    var      key      = node.NameFromNode();

                    // we need to find id's to handle deletes,
                    // and we need to check that the thing hasn't been renamed.
                    // so if it exsits only in master we need to double check its id
                    // doesn't still exist somewhere else on the install with the
                    // same id but a different name,

                    // we basically need some id hunting shizzel.
                    if (itemType != default(Type))
                    {
                        var fileKey = MigrationIDHunter.GetItemId(node);
                        if (!string.IsNullOrEmpty(fileKey))
                        {
                            if (MigrationIDHunter.FindInFiles(target, fileKey))
                            {
                                // the key exists somewhere else in the
                                // folder, so it's a rename of something
                                // we won't add this one to the delete pile.

                                // but we will need to signal somehow that
                                // the old name is wrong, so that on a full
                                // merge the two files don't get included.
                                actionTracker.AddAction(SyncActionType.Obsolete, file.FullName, itemType);

                                continue;
                            }
                        }
                    }

                    // if we can't workout what type of thing it is, we assume
                    // it's a file, then we can deal with it like a delete
                    // later on.
                    if (itemType == default(Type))
                    {
                        itemType = typeof(FileInfo);
                    }

                    actionTracker.AddAction(SyncActionType.Delete, key, itemType);
                }
            }

            actionTracker.SaveActions();
        }
Пример #10
0
        private void OnButtonDrag(ControllerAction action, ControllerSnapshot snapshot)
        {
            ActionTracker tracker = GetTracker(action);

            if (tracker.current_pressed != null && tracker.UpdateCurrentPoint(allow_out_of_bounds: true))
            {
                ExecuteEvents.Execute(tracker.current_pressed, tracker.pevent, ExecuteEvents.dragHandler);
            }
        }
Пример #11
0
 private void OnApplicationQuit()
 {
     if (state == GameState.INGAME)
     {
         ActionTracker tracker = playerObject.GetComponent <ActionTracker>();
         Debug.Log(tracker.actions.Count);
         sessionManager.getCurrentSession().actions.AddRange(tracker.actions);
         sessionManager.save();
     }
 }
Пример #12
0
 /// <summary>
 /// Closes tab
 /// </summary>
 private void OnCloseTab()
 {
     this.TabViewModels.Remove(this.SelectedTab);
     if (this.TabViewModels.Count > 0)
     {
         this.SelectedTab = this.TabViewModels.Last();
     }
     else
     {
         this.SelectedTab = null;
         ActionTracker.ClearCommands();
     }
 }
Пример #13
0
        private void OnButtonOver(ControllerAction action, ControllerSnapshot snapshot)
        {
            ActionTracker tracker = GetTracker(action);

            // handle enter and exit events (highlight)
            GameObject new_target = null;

            if (tracker.UpdateCurrentPoint())
            {
                new_target = tracker.pevent.pointerCurrentRaycast.gameObject;
            }

            UpdateHoveringTarget(tracker, new_target);
        }
Пример #14
0
    static void AddActionWindow()
    {
        if (editingEvent == null)
        {
            addActionClicked = false;
            Debug.LogWarning("The event you are trying to add to is null");
        }
        else if (editingEvent.eventName == null)
        {
            addActionClicked = false;
            Debug.LogWarning("The event you are trying to add to is null");
        }

        GUILayout.Label("Add Action", "boldLabel");


        List <string>      options = new List <string>();
        List <System.Type> types   = ActionTracker.FindActions();

        foreach (System.Type type in types)
        {
            options.Add(type.Name);
        }
        selectedNewAction = EditorGUILayout.Popup("Action to Add", selectedNewAction, options.ToArray());
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Cancel"))
        {
            addActionClicked = false;
        }
        if (GUILayout.Button("Add Action"))
        {
            addActionClicked = false;
            Action newAction = null;

            //TODO: automatically create the object?
            newAction = (Action)AssetDatabase.LoadAssetAtPath(EventSaver.TOOL_DATA_DIR + options[selectedNewAction] + ".asset", typeof(ScriptableObject));
            if (newAction == null)
            {
                Debug.LogError("Could not load asset at: " + EventSaver.TOOL_DATA_DIR + options[selectedNewAction]);
            }

            newAction = ScriptableObject.Instantiate(newAction);//DISCUSS: memory leak or auto-collected?
            editingEvent.AddAction(newAction);
            Debug.Log("Created Action: " + newAction.ToString());

            EventSaver.SaveEventAsObject(editingEvent);
        }
        GUILayout.EndHorizontal();
    }
Пример #15
0
    void Start()
    {
        vitals    = gameObject.GetComponent <Vitals>();
        inventory = gameObject.GetComponent <Inventory>();

        //General script, all players have this.
        movement = gameObject.GetComponentInParent <PlayerMovement>();

        //Player script, only the local player has this.
        controller = gameObject.GetComponentInParent <PlayerController>();
        tracker    = gameObject.GetComponentInParent <ActionTracker>();
        hud        = gameObject.GetComponent <PlayerHUD>();

        //Shadow script, only the opponent player (shadow) has this.
        replay = gameObject.GetComponentInParent <ActionReplay>();
    }
        /// <summary>
        /// Removes selected elements
        /// </summary>
        private void OnRemoveElement()
        {
            BaseQuestionViewModel[] removedElements = new BaseQuestionViewModel[this.SelectedElements.Count];
            int index = 0;

            foreach (BaseQuestionViewModel selectedItem in this.SelectedElements)
            {
                this.PageQuestions.Remove(selectedItem);
                removedElements[index++] = selectedItem;
            }

            this.SelectedElements.Clear();

            ActionTracker.TrackAction(new RemoveElementsAction(removedElements, this.PageQuestions));

            this.OnPropertyChanged(nameof(this.PropertiesContext));
        }
Пример #17
0
        private void OnButtonUp(ControllerAction action, ControllerSnapshot snapshot)
        {
            ActionTracker tracker = GetTracker(action);

            if (tracker.current_pressed != null)
            {
                bool in_bounds = tracker.UpdateCurrentPoint();

                ExecuteEvents.Execute(tracker.current_pressed, tracker.pevent, ExecuteEvents.endDragHandler);
                if (in_bounds)
                {
                    ExecuteEvents.ExecuteHierarchy(tracker.current_pressed, tracker.pevent, ExecuteEvents.dropHandler);
                }
                ExecuteEvents.Execute(tracker.current_pressed, tracker.pevent, ExecuteEvents.pointerUpHandler);

                tracker.current_pressed = null;
            }
        }
        /// <summary>
        /// Initialize commands
        /// </summary>
        private void InitCommands()
        {
            base.RemoveElementCommand = new RelayCommand(x => this.OnRemoveElement(), x => this.SelectedElements.Any());

            this.LoadTemplateImageCommand = new RelayCommand(x => this.OnLoadTemplateImage());
            this.DropPageImageCommand     = new RelayCommand(x => this.LoadTemplateImageFromFile((string)x));
            this.SelectAllElementsCommand = new RelayCommand(x => this.OnSelectAllElements(), x => this.PageQuestions.Any());
            this.SaveTemplateCommand      = new RelayCommand(x => this.OnSaveTemplate(), x => this.PageQuestions.Any());

            this.CorrectTemplateCommand  = new RelayCommand(x => this.OnCorrectTemplate(), x => this.PageQuestions.Any());
            this.FinalizeTemplateCommand = new RelayCommand(x => this.OnFinilizeTemplate(), x => !string.IsNullOrEmpty(this.TemplateId));

            this.CopyElementsCommand = new RelayCommand(x => this.OnCopyQuestions(), x => this.SelectedElements.Any());

            this.PasteElementsCommand = new RelayCommand(x =>
            {
                if (x == null)
                {
                    x = new Point(30, 30);
                }
                this.OnPasteQuestions((Point)x);
            }, x => this.copiedQuestionsBuffer.Any());

            this.FitPageWidthCommand  = new RelayCommand(x => this.OnFitPageWidth((double)x));
            this.FitPageHeightCommand = new RelayCommand(x => this.OnFitPageHeight((Size)x));
            this.ZoomInCommand        = new RelayCommand(x => this.ZoomLevel = Math.Min(this.ZoomLevel + 0.1, 4));
            this.ZoomOutCommand       = new RelayCommand(x => this.ZoomLevel = Math.Max(this.ZoomLevel - 0.1, 0.1));
            this.ZoomOriginalCommand  = new RelayCommand(x => this.ZoomLevel = 1);

            this.UndoCommand = new RelayCommand(o => ActionTracker.Undo(1), o => ActionTracker.CanUndo());
            this.RedoCommand = new RelayCommand(o => ActionTracker.Redo(1), o => ActionTracker.CanRedo());

            this.AlignBottomCommand = new RelayCommand(x => AlignmentHelper.AlignBottom(this.SelectedElements), x => this.SelectedElements.Count > 1);
            this.AlignTopCommand    = new RelayCommand(x => AlignmentHelper.AlignTop(this.SelectedElements), x => this.SelectedElements.Count > 1);
            this.AlignRightCommand  = new RelayCommand(x => AlignmentHelper.AlignRight(this.SelectedElements), x => this.SelectedElements.Count > 1);
            this.AlignLeftCommand   = new RelayCommand(x => AlignmentHelper.AlignLeft(this.SelectedElements), x => this.SelectedElements.Count > 1);

            this.ApplyFormattingCommand = new RelayCommand(x => this.OnApplyFormatting(), x => this.SelectedElements.Count == 1);
            this.ShrinkElementCommand   = new RelayCommand(x => this.OnShrinkQuestionCommand(), x => this.SelectedElements.Count > 0);

            this.MoveElementsHorizontal = new RelayCommand(x => this.OnMoveElementsHorizontal((double)x), x => this.SelectedElements.Count > 0);
            this.MoveElementsVertical   = new RelayCommand(x => this.OnMoveElementsVertical((double)x), x => this.SelectedElements.Count > 0);
        }
        /// <summary>
        /// Attempts to close active tab
        /// </summary>
        /// <returns>False if tab closing was cancelled by user, true otherwise</returns>
        private bool OnCloseTab()
        {
            if (this.SelectedTab.IsDirty)
            {
                if (this.SelectedTab is TemplateViewModel)
                {
                    MessageBoxResult dialogResult = DialogManager.ShowConfirmDirtyClosingDialog(
                        "This template has unsaved changes. Do you want to save them?");

                    if (dialogResult == MessageBoxResult.Cancel)
                    {
                        // cancel closing
                        return(false);
                    }
                    else if (dialogResult == MessageBoxResult.Yes)
                    {
                        // save
                        this.OnSaveTemplate();
                    }
                }
                else if (this.SelectedTab is ResultsViewModel)
                {
                }
            }

            if (this.SelectedTab is TemplateViewModel)
            {
                ActionTracker.ClearCommands();
            }

            this.TabViewModels.Remove(this.SelectedTab);
            if (this.TabViewModels.Count > 0)
            {
                this.SelectedTab = this.TabViewModels.Last();
            }
            else
            {
                this.SelectedTab = null;
            }

            return(true);
        }
Пример #20
0
        /// <summary>
        /// Thumb drag completed event handler
        /// </summary>
        private void ResizeThumbDragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (this.DataContext is BaseQuestionViewModel)
            {
                // resize question
                BaseQuestionViewModel questionViewModel = (BaseQuestionViewModel)this.DataContext;

                double deltaTop = this.startTop - questionViewModel.Top;
                double deltaLeft = this.startLeft - questionViewModel.Left;
                double widthKoef = this.startWidth / questionViewModel.Width;
                double heightKoef = this.startHeight / questionViewModel.Height;

                if (questionViewModel.ParentTemplate != null)
                {
                    List<BaseQuestionViewModel> selectedItems = questionViewModel.ParentTemplate.SelectedElements.ToList();
                    ActionTracker.TrackChangeQuestionsPosition(selectedItems, deltaTop, deltaLeft, widthKoef, heightKoef);
                }
                else if (questionViewModel is ChoiceBoxViewModel)
                {
                    var choiceBoxViewModel = (ChoiceBoxViewModel) questionViewModel;
                    List<BaseQuestionViewModel> selectedItems = choiceBoxViewModel.ParentGrid.ChoiceBoxes
                        .Cast<BaseQuestionViewModel>()
                        .ToList();
                    ActionTracker.TrackChangeQuestionsPosition(selectedItems, deltaTop, deltaLeft, widthKoef, heightKoef);
                }
            }
            else if (this.DataContext is BubbleViewModel)
            {
                // resize bubble
                BubbleViewModel bubbleViewModel = (BubbleViewModel)this.DataContext;
                List<BubbleViewModel> bubbles = bubbleViewModel.ParentQuestion.Bubbles.ToList();

                double deltaTop = this.bubbleStartTop - bubbles[0].Top;
                double deltaLeft = this.bubbleStartLeft - bubbles[0].Left;

                double widthKoef = this.bubbleStartWidth / bubbles[0].Width;
                double heightKoef = this.bubbleStartHeight / bubbles[0].Height;

                ActionTracker.TrackChangeBubble(bubbles, deltaTop, deltaLeft, widthKoef, heightKoef);
            }
        }
Пример #21
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            AudioManager.instance.playSound("game_end.wav");

            Player player = collision.gameObject.GetComponent <Player>();

            player.GetComponent <PlayerController>().enabled    = false;
            player.GetComponent <Rigidbody2D>().velocity        = Vector3.zero;
            player.GetComponent <Rigidbody2D>().angularVelocity = 0f;

            //Save Session
            ActionTracker tracker = player.GetComponent <ActionTracker>();
            Debug.Log(tracker.actions.Count);
            GameManager.instance.sessionManager.getCurrentSession().actions.AddRange(tracker.actions);
            GameManager.instance.sessionManager.save();

            EndGameMenu endMenu = GameObject.FindGameObjectWithTag("GameEndMenu").GetComponent <EndGameMenu>();

            Session oppSession  = GameManager.instance.sessionManager.getOpponentSession();
            Session currSession = GameManager.instance.sessionManager.getCurrentSession();

            if (oppSession == null)
            {
                endMenu.show(Result.COMPLETED, GameManager.instance.sessionManager.getCurrentSession().elapsedTime);
            }
            else
            {
                if (currSession.elapsedTime > oppSession.elapsedTime)
                {
                    endMenu.show(Result.DEFEAT, GameManager.instance.sessionManager.getCurrentSession().elapsedTime);
                }
                else
                {
                    endMenu.show(Result.VICTORY, GameManager.instance.sessionManager.getCurrentSession().elapsedTime);
                }
            }
        }
    }
        /// <summary>
        /// Top alignment
        /// </summary>
        /// <param name="items">Items to align</param>
        public static void AlignTop(ObservableCollection <BaseQuestionViewModel> items)
        {
            double minY = items[0].Top;

            foreach (BaseQuestionViewModel element in items)
            {
                if (minY > element.Top)
                {
                    minY = element.Top;
                }
            }

            List <double> changes = new List <double>(items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                changes.Add(items[i].Top - minY);
                items[i].Top = minY;
            }

            ActionTracker.TrackAlign(items.ToList(), null, changes);
        }
        /// <summary>
        /// Add new element via selection rectangle
        /// </summary>
        /// <param name="area">Element area</param>
        public void AddQuestion(Rect area)
        {
            string nextName = NamingManager.GetNextAvailableElementName(this.PageQuestions);

            BaseQuestionViewModel newQuestion;

            if (this.IsAddingChoiceBox)
            {
                newQuestion            = new ChoiceBoxViewModel(nextName, area);
                this.IsAddingChoiceBox = false;
            }
            else
            {
                newQuestion       = new GridViewModel(nextName, area);
                this.IsAddingGrid = false;
            }

            this.OnAddQuestion(newQuestion);
            newQuestion.IsSelected = true;

            ActionTracker.TrackAction(new AddElementsAction(new[] { newQuestion }, this.PageQuestions));
        }
        /// <summary>
        /// Left alignment
        /// </summary>
        /// <param name="items">Items to align</param>
        public static void AlignLeft(ObservableCollection <BaseQuestionViewModel> items)
        {
            double minX = items[0].Left;

            foreach (BaseQuestionViewModel element in items)
            {
                if (minX > element.Left)
                {
                    minX = element.Left;
                }
            }

            List <double> changes = new List <double>(items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                changes.Add(items[i].Left - minX);
                items[i].Left = minX;
            }

            ActionTracker.TrackAlign(items.ToList(), changes, null);
        }
        /// <summary>
        /// Right alignment
        /// </summary>
        /// <param name="items">Items to align</param>
        public static void AlignRight(ObservableCollection <BaseQuestionViewModel> items)
        {
            double maxX = items[0].Left + items[0].Width;

            foreach (BaseQuestionViewModel element in items)
            {
                if (element.Left + element.Width > maxX)
                {
                    maxX = element.Left + element.Width;
                }
            }

            List <double> changes = new List <double>(items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                changes.Add(items[i].Left - (maxX - items[i].Width));
                items[i].Left = maxX - items[i].Width;
            }

            ActionTracker.TrackAlign(items.ToList(), changes, null);
        }
        /// <summary>
        /// Bottom alignment
        /// </summary>
        /// <param name="items">Items to align</param>
        public static void AlignBottom(ObservableCollection <BaseQuestionViewModel> items)
        {
            double maxY = items[0].Top + items[0].Height;

            foreach (BaseQuestionViewModel element in items)
            {
                if (element.Top + element.Height > maxY)
                {
                    maxY = element.Top + element.Height;
                }
            }

            List <double> changes = new List <double>(items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                changes.Add(items[i].Top - (maxY - items[i].Height));
                items[i].Top = maxY - items[i].Height;
            }

            ActionTracker.TrackAlign(items.ToList(), null, changes);
        }
Пример #27
0
    public void EncodeTrackers()
    {
        GoldTracker              goldTracker              = FindObjectOfType <GoldTracker>();
        UnlockTracker            unlockTracker            = FindObjectOfType <UnlockTracker>();
        ActionTracker            actionTracker            = FindObjectOfType <ActionTracker>();
        RandomTracker            randomTracker            = FindObjectOfType <RandomTracker>();
        GameSetupScenarioTracker gameSetupScenarioTracker = FindObjectOfType <GameSetupScenarioTracker>();
        PerkTracker              perkTracker              = FindObjectOfType <PerkTracker>();

        Encoders encoders = new Encoders();

        encoders.goldTracker              = JsonUtility.ToJson(goldTracker);
        encoders.unlockTracker            = JsonUtility.ToJson(unlockTracker);
        encoders.actionTracker            = JsonUtility.ToJson(actionTracker);
        encoders.randomTracker            = JsonUtility.ToJson(randomTracker);
        encoders.perkTracker              = JsonUtility.ToJson(perkTracker);
        encoders.gameSetupScenarioTracker = JsonUtility.ToJson(gameSetupScenarioTracker);

        string json = JsonUtility.ToJson(encoders);

        System.IO.File.WriteAllText(@"savegame.json", json);
    }
Пример #28
0
 private void OnButtonEnter(ControllerAction action, ControllerSnapshot snapshot)
 {
     ActionTracker tracker = AddTracker(action);
 }