コード例 #1
0
ファイル: NLPrompt.cs プロジェクト: Tubbz-alt/MKULTRA-1
    internal void OnGUI()
    {
        // You'd want this to be called by a MouseMove event, but it's not supported in game,
        // and in any case, we probably need to keep updating because of potential object movement.
        if (contextMenu == null)
        {
            UpdateMouseSelection();
        }

        GUI.depth = 0;
        var e = Event.current;

        switch (e.type)
        {
        case EventType.MouseDown:
            //typingPromptStartTime = Time.time;
            contextMenu = MakeMenu(MouseSelection);
            lastPlayerActivity.StoreExclusive(Time.time, true);
            break;

        case EventType.MouseUp:
            if (contextMenu != null && MouseSelection != null)
            {
                var guiScreenRect = MouseSelection.GUIScreenRect();
                if (guiScreenRect.HasValue)
                {
                    var selection = contextMenu.SelectedAction(guiScreenRect.Value.Center());
                    if (selection != null)
                    {
                        simController.QueueEvent("player_input", selection);
                    }
                }
            }

            lastPlayerActivity.StoreExclusive(Time.time, true);
            contextMenu = null;
            break;

        case EventType.KeyDown:
            if (GUI.GetNameOfFocusedControl() == "")
            {
                HandleKeyDown(e);
                if (!e.alt && !e.control)
                {
                    TryCompletionIfCompleteWord();
                }
            }
            break;

        case EventType.Repaint:
            DrawGUI();
            break;
        }
    }
コード例 #2
0
ファイル: NLPrompt.cs プロジェクト: Tubbz-alt/MKULTRA-1
 internal void Start()
 {
     lastPlayerActivity = KnowledgeBase.Global.ELRoot.StoreNonExclusive(Symbol.Intern("last_player_activity"));
     lastPlayerActivity.StoreExclusive(-1, true);
     elRoot               = this.KnowledgeBase().ELRoot;
     haloElNode           = elRoot / Symbol.Intern("halo");
     mouseSelectionELNode = elRoot / Symbol.Intern("perception") / Symbol.Intern("mouse_selection");
     talkingToElNode      = elRoot / Symbol.Intern("social_state") / Symbol.Intern("talking_to");
     MouseSelection       = null;
 }
コード例 #3
0
ファイル: NLPrompt.cs プロジェクト: Tubbz-alt/MKULTRA-1
    private void TryCompletion()
    {
        // Update the mouse selection, so Prolog can get at it.
        mouseSelectionELNode.StoreExclusive(MouseSelection, true);

        var  completionVar     = new LogicVariable("Output");
        var  dialogActVar      = new LogicVariable("DialogAct");
        bool completionSuccess = false;

        try
        {
            completionSuccess = this.IsTrue("input_completion", input, completionVar, dialogActVar);
        }
        catch (InferenceStepsExceededException e)
        {
            Debug.LogError("Completion took too many steps for input: " + input);
            Debug.LogException(e);
        }
        if (completionSuccess)
        {
            completion = (string)completionVar.Value;
            dialogAct  = Term.CopyInstantiation(dialogActVar.Value);
            if (this.IsTrue("well_formed_dialog_act", dialogAct))
            {
                formatted = completion == "" ?
                            string.Format("<b><color=lime>{0}</color></b>", input)
                    : string.Format("<color=lime>{0}{1}<i>{2}</i></color>",
                                    input,
                                    (input.EndsWith(" ") || input.EndsWith("'") ||
                                     !char.IsLetterOrDigit(completion[0]))
                                    ? "" : " ",
                                    completion);

                var da = dialogAct as Structure;
                if (da != null && da.Arity > 1)
                {
                    var a         = da.Argument <GameObject>(1);
                    var addressee = (a == gameObject) ? "myself" : a.name;
                    commentary = string.Format("{0} to {1}\n{2}", da.Functor, addressee,
                                               ISOPrologWriter.WriteToString(dialogActVar.Value));
                    formatted = string.Format("{1} (speaking to {0})", addressee, formatted);
                }
                else
                {
                    commentary = ISOPrologWriter.WriteToString(dialogActVar.Value);
                }
            }
            else
            {
                // Input is grammatical but not well formed.
                formatted = completion == "" ?
                            string.Format("<b><color=yellow>{0}</color></b>", input)
                    : string.Format("<color=yellow>{0}{1}</color><color=grey><i>{2}</i></color>",
                                    input,
                                    (input.EndsWith(" ") || !char.IsLetterOrDigit(completion[0])) ? "" : " ",
                                    completion);
                if (completion == "")
                {
                    commentary = string.Format(
                        "This input is grammatical, but doesn't make sense to me\n{0}",
                        ISOPrologWriter.WriteToString(dialogActVar.Value));
                }
                else
                {
                    commentary = "This is grammatical but nonsensical\n" + ISOPrologWriter.WriteToString(dialogActVar.Value);
                }
            }
        }
        else
        {
            var lastWordOfInput = LastWordOfInput;
            if (lastWordOfInput != "" && Prolog.Prolog.IsPrefixOfDistinctLexicalItem(lastWordOfInput))
            {
                FormatInputWithoutColorCoding();
            }
            else
            {
                FormatRejectionOfInput();
            }
        }
    }