Beispiel #1
0
    public void InitializeButtons()
    {
        Localization loc = GameManager.instance.localization;

        foreach (GameObject b in instantiatedButtons)
        {
            Destroy(b);
        }

        foreach (KeyValuePair <int, EventManager.GameAction> gameAction in gameEvent.choices)
        {
            GameObject button          = Instantiate(buttonExample, buttonExample.transform.parent);
            Button     buttonComponent = button.GetComponentInChildren <Button>();
            Text       txt             = button.GetComponentInChildren <Text>();
            Tooltip    tt = button.GetComponentInChildren <Tooltip>();

            txt.text           = loc.GetLineFromCategory("choice", "event" + gameEvent.id + "_" + gameAction.Key);
            tt.isFirstLineBold = false;

            List <EventManager.GameEffect> fxs = gameAction.Value.GetGameEffects();

            // Remove untranslatable actions like DECLARE_EVENT
            fxs.RemoveAll(o => skippedActions.Contains(o.intention));

            foreach (EventManager.GameEffect action in fxs)
            {
                if (action.intention.Length <= 0)
                {
                    continue;
                }
                tt.AddLocalizedLine(
                    new Tooltip.Entry(
                        action.intention,
                        "scriptAction",
                        action.ttColor,
                        action.parameters
                        )
                    );
            }
            if (fxs.Count <= 0)
            {
                tt.AddLocalizedLine(
                    new Localization.Line(
                        "scriptAction",
                        "none"
                        )
                    );
            }

            // On choice click
            buttonComponent.onClick.AddListener(delegate {
                try {
                    gameEvent.ExecuteChoice(gameAction.Key);
                }
                catch (System.Exception e) {
                    Logger.Error("Skipped event error : " + e.ToString() + ". This should NOT happen. Check the event syntax on.");
                }
                subWindow.SetActive(false);
                if (GameManager.instance.player.options.GetBool(Options.Option.animatedCitizens))
                {
                    displayer.Unstage();
                }
                try {
                    FindObjectOfType <TooltipGO>().Disable();
                }
                catch {
                    // Sometimes the tooltip destroys too early
                    // This is okay
                }
                GameManager.instance.UnPause();
                GetComponent <Image>().enabled = false;
                StopAllCoroutines();
            });

            instantiatedButtons.Add(button);

            button.SetActive(true);
        }
    }