Beispiel #1
0
    private bool NotebookTabIsOpen(NotebookTab tab)
    {
        NotebookUI        notebook = GameManager.Instance.NotebookUI;
        NotebookTabPicker picker   = notebook.TabPicker;

        return(notebook.IsOpen && picker.CurrentTab == tab);
    }
Beispiel #2
0
    private ConditionalHighlight[] HighlightItemPicker(NotebookTab targetTab, ItemID targetItem, string nameFilter)
    {
        NotebookUI notebook = GameManager.Instance.NotebookUI;

        // Get all pickers in the given tab
        ItemPicker[] pickers = notebook.TabPicker.GetTabRoot(targetTab).GetComponentsInChildren <ItemPicker>(true);
        // Find a picker whose name contains the filter
        ItemPicker picker = Array.Find(pickers, p => p.name.IndexOf(nameFilter, StringComparison.OrdinalIgnoreCase) >= 0);

        return(HighlightItemPicker(picker, targetItem));
    }
Beispiel #3
0
    private bool NotebookItemPicked(NotebookTab targetTab, ItemID targetItem, string nameFilter)
    {
        NotebookUI notebook = GameManager.Instance.NotebookUI;

        // Get all pickers in the given tab
        ItemPicker[] pickers = notebook.TabPicker.GetTabRoot(targetTab).GetComponentsInChildren <ItemPicker>(true);
        // Find a picker whose name contains the filter
        ItemPicker picker = Array.Find(pickers, p => p.name.IndexOf(nameFilter, StringComparison.OrdinalIgnoreCase) >= 0);

        return(picker.SelectedItem == targetItem && notebook.IsOpen && notebook.TabPicker.CurrentTab == targetTab);
    }
Beispiel #4
0
    public virtual void Setup()
    {
        UIParent = GetComponentInParent <NotebookUI>();

        // Log a warning if no UI parent is found
        if (UIParent == null)
        {
            Debug.LogWarning(GetType() + ": expecting a component of type 'NotebookUI' attached to one of its parents, " +
                             "but no such component was found.  Did you place the object in the heirarchy correctly?", gameObject);
        }
    }
Beispiel #5
0
    private ConditionalHighlight HighlightNotebookButton()
    {
        NotebookUI    notebook       = GameManager.Instance.NotebookUI;
        RectTransform notebookButton = FindRectTransform("NotebookButton");

        // Highlight the notebook button while notebook is not open
        return(new ConditionalHighlight()
        {
            predicate = () => !notebook.IsOpen,
            target = () => notebookButton
        });
    }
Beispiel #6
0
    private ConditionalHighlight HighlightNotebookTabButton(NotebookTab tab)
    {
        NotebookUI    notebook  = GameManager.Instance.NotebookUI;
        RectTransform tabButton = notebook.TabPicker.GetTabSelectButton(tab).GetComponent <RectTransform>();

        // Return a highlight that will be active while the tab is not picked
        return(new ConditionalHighlight()
        {
            predicate = () => notebook.TabPicker.CurrentTab != tab,
            target = () => tabButton
        });
    }
Beispiel #7
0
    private ConditionalHighlight HighlightHighlightButton()
    {
        // Cache some useful values
        NotebookUI notebook = GameManager.Instance.NotebookUI;
        ResearchEncyclopediaArticleInputField inputField = notebook.GetComponentInChildren <ResearchEncyclopediaArticleInputField>(true);
        RectTransform highlightPicker = FindRectTransformInChildren(notebook.TabPicker.GetTabRoot(NotebookTab.Research), "HighlightPicker");

        return(new ConditionalHighlight()
        {
            predicate = () => !inputField.IsHighlighting,
            target = () => highlightPicker
        });
    }
Beispiel #8
0
    public void FreezeUntilConceptCanvasExpanded(bool expanded)
    {
        NotebookUI       notebook = GameManager.Instance.NotebookUI;
        ConceptsCanvasUI canvas   = notebook.GetComponentInChildren <ConceptsCanvasUI>(true);

        FreezingScheduler.FreezeUntilConditionIsMet(() => NotebookTabIsOpen(NotebookTab.Concepts) && canvas.IsExpanded == expanded);
        HighlightingScheduler.SetHighlights(HighlightNotebookButton(),
                                            HighlightNotebookTabButton(NotebookTab.Concepts),
                                            new ConditionalHighlight()
        {
            predicate = () => canvas.IsExpanded != expanded,
            target    = () => canvas.FoldoutToggle.transform as RectTransform
        });
    }
Beispiel #9
0
    private bool ResourceRequestWasSubmitted(ItemID requestedItem, int requestQuantity)
    {
        // Grab a bunch of references to various scripts in the Notebook
        NotebookUI notebook = GameManager.Instance.NotebookUI;
        ReviewedResourceRequestDisplay reviewDisplay = notebook.GetComponentInChildren <ReviewedResourceRequestDisplay>(true);
        ReviewedResourceRequest        review        = reviewDisplay.LastReviewConfirmed;

        // If there is a review that was just confirmed then check if it was the correct request
        if (review != null)
        {
            ResourceRequest request = review.Request;
            return(request.ItemRequested == requestedItem && request.QuantityRequested == requestQuantity);
        }
        else
        {
            return(false);
        }
    }
Beispiel #10
0
    public void Initialize(Item item, bool displayPrice, ItemSelectedHandler itemSelectedHandler)
    {
        this.item             = item;
        this.itemImage.sprite = item.Icon;
        this.ItemName.text    = this.item.ItemID.Data.Name.Get(global::ItemName.Type.Colloquial);

        // Display the price
        PriceRoot.SetActive(displayPrice);
        if (displayPrice)
        {
            PriceText.text = item.Price.ToString();
        }

        // Check if the selected handler is null. If not then add it to the event
        if (itemSelectedHandler != null)
        {
            this.onSelected += itemSelectedHandler;
        }

        RequestButton.onClick.AddListener(() =>
        {
            if (GameManager.Instance)
            {
                // Reference the notebook ui
                NotebookUI notebookUI = GameManager.Instance.NotebookUI;
                // Tab picker reference
                NotebookTabPicker tabPicker = notebookUI.TabPicker;

                // Create the bookmark to navigate to
                Bookmark bookmark = new Bookmark(string.Empty, new BookmarkData(tabPicker.name, NotebookTab.Concepts));
                // Create a request to prefill in the notebook
                ResourceRequest request = new ResourceRequest()
                {
                    QuantityRequested = 1,
                    ItemRequested     = item.ItemID
                };

                notebookUI.NavigateToBookmark(bookmark);
                notebookUI.FillResourceRequest(request);
            }
        });
    }
Beispiel #11
0
    private void FreezeUntilHighlightAbsent(ItemID item, int articleIndex, TextHighlight targetHighlight)
    {
        NotebookUI notebook = GameManager.Instance.NotebookUI;
        ResearchEncyclopediaArticleInputField inputField = notebook.GetComponentInChildren <ResearchEncyclopediaArticleInputField>(true);

        // Get the list of all highlights in this encyclopedia article
        List <TextHighlight> highlights = notebook
                                          .Data.Research.GetEntry(item)
                                          .GetArticleData(articleIndex).Highlights;

        FreezingScheduler.FreezeUntilConditionIsMet(() =>
        {
            // Get an index of any highlight that overlaps the target highlight
            int indexOfMatch = highlights.FindIndex(current => targetHighlight.Overlap(current));
            // Freeze until no overlapping highlights found and notebook is open to research tab
            return(indexOfMatch < 0 && notebook.IsOpen && notebook.TabPicker.CurrentTab == NotebookTab.Research);
        });
        HighlightingScheduler.SetHighlights(HighlightNotebookButton(),
                                            HighlightNotebookTabButton(NotebookTab.Research),
                                            HighlightEraseButton());
    }
Beispiel #12
0
    private void FreezeUntilHighlightPresent(ItemID item, int articleIndex, TextHighlight targetHighlight)
    {
        // Cache some useful values
        NotebookUI notebook = GameManager.Instance.NotebookUI;

        // Get the list of all highlights in this encyclopedia article
        List <TextHighlight> highlights = notebook
                                          .Data.Research.GetEntry(item)
                                          .GetArticleData(articleIndex).Highlights;

        FreezingScheduler.FreezeUntilConditionIsMet(() =>
        {
            // Get index of a highlight that this highlight contains
            int indexOfMatch = highlights.FindIndex(current => current.Contains(targetHighlight));
            // Freeze until highlight is found and notebook is open to research tab
            return(indexOfMatch >= 0 && notebook.IsOpen && notebook.TabPicker.CurrentTab == NotebookTab.Research);
        });
        HighlightingScheduler.SetHighlights(HighlightNotebookButton(),
                                            HighlightNotebookTabButton(NotebookTab.Research),
                                            HighlightHighlightButton());
    }
Beispiel #13
0
    private void FreezeUntilResourceRequestSubmitted(ItemID requestedItem, int requestQuantity)
    {
        // Grab a bunch of references to various scripts in the Notebook
        NotebookUI                     notebook              = GameManager.Instance.NotebookUI;
        ConceptsUI                     concepts              = notebook.GetComponentInChildren <ConceptsUI>(true);
        ResourceRequestEditor          requestEditor         = notebook.ResourceRequestEditor;
        ReviewedResourceRequestDisplay reviewDisplay         = notebook.GetComponentInChildren <ReviewedResourceRequestDisplay>(true);
        TMP_InputField                 quantityInput         = requestEditor.QuantityInput;
        ItemDropdown                   itemRequestedDropdown = requestEditor.ItemRequestedDropdown;

        // Freeze conversation until correct review was confirmed
        FreezingScheduler.FreezeUntilConditionIsMet(() => ResourceRequestWasSubmitted(requestedItem, requestQuantity), HighlightingScheduler.ClearHighlights);
        HighlightingScheduler.SetHighlights(HighlightNotebookButton(),
                                            HighlightNotebookTabButton(NotebookTab.Concepts),
                                            HighlightItemDropdown(itemRequestedDropdown, requestedItem)[0],
                                            HighlightItemDropdown(itemRequestedDropdown, requestedItem)[1],
                                            HighlightInputField(quantityInput, requestQuantity.ToString()),
                                            new ConditionalHighlight()
        {
            predicate = () => !reviewDisplay.gameObject.activeInHierarchy,
            target    = () => concepts.RequestButton.transform as RectTransform
        });
    }