Beispiel #1
0
        public ListItemUi AddDialogOption(Dialog.DialogOption option, bool scrollAllTheWayDown)
        {
            if (!initialized)
            {
                Init();
            }
            ListItemUi li = null;

            switch (option)
            {
            case Dialog.Choice c: AddDialogOption_Choice(c, out li, option); break;

            case Dialog.Text t: AddDialogOption_Text(t, out li, option); break;

            case Dialog.Command cmd: AddDialogOption_Command(cmd, out li, option); break;
            }
            if (li != null)
            {
                Dialog.Text txt = option as Dialog.Text;
                if (txt != null)
                {
                    li.TextAlignment = txt.anchorText;
                }
            }
            if (scrollAllTheWayDown && !goingToScrollAllTheWayDown)
            {
                goingToScrollAllTheWayDown = true;
                // we want scroll all the way down, and can't control when the UI updates enough to realize it can scroll
                Proc.Delay(100, () => {
                    goingToScrollAllTheWayDown = false; scrollRect.verticalNormalizedPosition = 0;
                });
                // 100ms (1/10th of a second) is not bad for UI lag, and should be enough time for the UI to update itself
            }
            return(li);
        }
    public void ParseCommand(string command)
    {
        if (!initialized)
        {
            Init();
        }
        tokenizer.Tokenize(command);
        string             cmd = tokenizer.GetResolvedToken(0, GetScriptScope()).ToString();
        Action <Tokenizer> commandToExecute;

        if (commandListing.TryGetValue(cmd, out commandToExecute))
        {
            commandToExecute.Invoke(tokenizer);
        }
        else
        {
            tokenizer.AddError("unknown command \'" + cmd + "\'");
        }
        if (tokenizer.errors.Count > 0)
        {
            for (int i = 0; i < tokenizer.errors.Count; ++i)
            {
                ListItemUi li = AddDialogOption(new Dialog.Text {
                    text = tokenizer.errors[i].ToString()
                }, true);
                li.text.color = Color.red;
            }
            tokenizer.errors.Clear();
        }
    }
Beispiel #3
0
        public void ShowError(string errorMessage)
        {
            ListItemUi li = AddDialogOption(new Dialog.Text {
                text = errorMessage
            }, true);

            li.TextColor = Color.red;
        }
Beispiel #4
0
        private void PossiblyAddParseCommandOutputToDialog(Dialog.DialogOption option)
        {
            if (Print_commandOutput.Length == 0)
            {
                return;
            }
            string     str = Print_commandOutput.ToString();
            ListItemUi li  = listUi.AddItem(option, str, null, prefab_textUi);

            Print_commandOutput.Clear();
        }
 public void InitializeListUi()
 {
     listUi = GetComponentInChildren <ListUi>();
     if (scrollRect == null)
     {
         scrollRect = GetComponentInChildren <ScrollRect>();
     }
     prefab_buttonUi = listUi.prefab_item;
     prefab_textUi   = Instantiate(prefab_buttonUi.gameObject).GetComponent <ListItemUi>();
     Destroy(prefab_textUi.GetComponent <Button>());
     Destroy(prefab_textUi.GetComponent <Image>());
 }
Beispiel #6
0
        private void AddDialogOption_Command(Dialog.Command cmd, out ListItemUi listItem, Dialog.DialogOption option)
        {
            //NonStandard.Show.Log("executing command "+cmd.command);
            Tokenizer tok = new Tokenizer();

            Commander.Instance.ParseCommand(new Instruction(cmd.command, option), Print, out tok);
            if (tok?.HasError() ?? false)
            {
                Print(Col.r() + tok.GetErrorString());
            }
            PossiblyAddParseCommandOutputToDialog(option);
            listItem = null;
        }
 public void ShowCloseDialogButton()
 {
     if (!initialized)
     {
         Init();
     }
     if (closeDialogButton != null)
     {
         Destroy(closeDialogButton.gameObject);
     }
     closeDialogButton = AddDialogOption(new Dialog.Choice {
         text = "\n<close dialog>\n", command = "hide", anchorText = TextAnchor.MiddleCenter
     }, true);
     currentChoices.Remove(closeDialogButton);
 }
Beispiel #8
0
        private void AddDialogOption_Choice(Dialog.Choice c, out ListItemUi listItem, Dialog.DialogOption option)
        {
            ListItemUi li = null;

            li = listItem = listUi.AddItem(option, DialogManager.Instance.GetScriptScope().Format(c.text), () => {
                //NonStandard.Show.Log("------- "+c.command);
                Tokenizer tok = new Tokenizer();
                Commander.Instance.ParseCommand(new Instruction(c.command, li), Print, out tok);
                //NonStandard.Show.Log("/////// " + c.command);
                if (tok?.HasError() ?? false)
                {
                    Print(tok.GetErrorString());
                }
                PossiblyAddParseCommandOutputToDialog(option);
            }, prefab_buttonUi);
            currentChoices.Add(li);
        }
    public ListItemUi AddDialogOption(Dialog.DialogOption option, bool scrollAllTheWayDown)
    {
        if (!initialized)
        {
            Init();
        }
        ListItemUi li = null;

        do
        {
            Dialog.Text t = option as Dialog.Text;
            if (t != null)
            {
                li = listUi.AddItem(option, scriptedVariableScope.Format(t.text), null, prefab_textUi);
                break;
            }
            Dialog.Choice c = option as Dialog.Choice;
            if (c != null)
            {
                li = listUi.AddItem(option, scriptedVariableScope.Format(c.text), () => ParseCommand(c.command), prefab_buttonUi);
                currentChoices.Add(li);
                break;
            }
            Dialog.Command cmd = option as Dialog.Command;
            if (cmd != null)
            {
                ParseCommand(cmd.command);
                break;
            }
        }while (false);
        if (li != null)
        {
            li.text.alignment = option.anchorText;
        }
        if (scrollAllTheWayDown && !goingToScrollAllTheWayDown)
        {
            goingToScrollAllTheWayDown = true;
            // we want scroll all the way down, and can't control when the UI updates enough to realize it can scroll
            NonStandard.Clock.setTimeout(() => {
                goingToScrollAllTheWayDown = false; scrollRect.verticalNormalizedPosition = 0;
            }, 100);
            // 100ms (1/10th of a second) is not bad for UI lag, and should be enough time for the UI to update itself
        }
        return(li);
    }
Beispiel #10
0
        public ListItemUi AddItem(GameObject itemObject)
        {
            if (items == null)
            {
                items = new List <GameObject>();
            }
            if (inventoryUi != null)
            {
                ListItemUi result = inventoryUi.GetListItemUi(itemObject); if (result != null)
                {
                    return(result);
                }
            }
            items.Add(itemObject);
            InventoryItem item = itemObject.GetComponent <InventoryItem>();

            if (item != null)
            {
                item.AddToInventory(this);
            }
            itemObject.SetActive(false);
            Vector3 playerLoc     = Global.GetComponent <Character.CharacterProxy>().transform.position;
            Vector3 localPosition = itemObject.transform.position - playerLoc;

            itemObject.transform.SetParent(transform);
            itemObject.transform.localPosition = localPosition;
            //Show.Log("POS IN" + localPosition);
            string name = item != null ? item.itemName : null;

            if (string.IsNullOrEmpty(name))
            {
                name = itemObject.name;
            }
            onAddItem.Invoke(itemObject);
            if (inventoryUi == null)
            {
                return(null);
            }
            return(inventoryUi.AddItem(itemObject, name, () => {
                RemoveItem(itemObject);
            }));
        }
Beispiel #11
0
    public ListItemUi AddMember(GameObject memberObject)
    {
        //Show.Log("adding member " + memberObject);
        if (members == null)
        {
            members = new List <GameObject>();
        }
        // make sure this character adds to the communal inventory! (assuming there is one)
        TeamMember teamMember = memberObject.GetComponent <TeamMember>();

        if (teamMember == null)
        {
            teamMember = memberObject.AddComponent <TeamMember>();
        }
        // add them to the roster
        if (members.IndexOf(memberObject) < 0)
        {
            members.Add(memberObject);
            teamMember.onJoinTeam?.Invoke(this);
            CharacterRoot cr = memberObject.GetComponent <CharacterRoot>();
            if (cr)
            {
                EventBind.IfNotAlready(cr.activateFunction, this, ActivateTeamMember);
            }
        }
        if (members.Count > 1)
        {
            if (prev)
            {
                prev.gameObject.SetActive(true);
            }
            if (next)
            {
                next.gameObject.SetActive(true);
            }
            if (team)
            {
                team.gameObject.SetActive(true);
            }
        }
        if (rosterUi != null)
        {
            ListItemUi result = rosterUi.GetListItemUi(memberObject);
            if (result != null)
            {
                //Show.Log("already ui");
                return(result);
            }
        }
        string name = teamMember != null ? teamMember.name : null;

        if (string.IsNullOrEmpty(name))
        {
            name = memberObject.name;
        }

        Interact3dItem i3i = teamMember.GetComponent <Interact3dItem>();
        //void ActivateTeamMember() {
        //	CharacterControlManager ccm = Global.Get<CharacterControlManager>();
        //	ccm.SetCharacter(memberObject);
        //	i3i.showing = false;
        //}
        Action activateMember = () => ActivateTeamMember(memberObject);

        if (i3i != null)
        {
            i3i.OnInteract             = activateMember;
            i3i.Text                   = "switch";
            i3i.internalState.alwaysOn = true;
        }
        if (rosterUi == null)
        {
            Show.Log("missing roster UI");
            return(null);
        }
        return(rosterUi.AddItem(memberObject, name, activateMember));
    }
Beispiel #12
0
 private void AddDialogOption_Text(Dialog.Text t, out ListItemUi listItem, Dialog.DialogOption option)
 {
     listItem = listUi.AddItem(option, DialogManager.Instance.GetScriptScope().Format(t.text), null, prefab_textUi);
 }