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; } }
private void HandleKeyDown(Event e) { if (e.keyCode != KeyCode.None) { if (e.alt || e.control || (e.keyCode >= KeyCode.F1 && e.keyCode <= KeyCode.F15)) { object key = Symbol.Intern(e.keyCode.ToString().ToLower()); if (e.alt) { if (e.control) { key = new Structure( "-", new Structure("-", Symbol.Intern("control"), Symbol.Intern("alt")), key); } else { key = new Structure("-", Symbol.Intern("alt"), key); } } else if (e.control) { key = new Structure("-", Symbol.Intern("control"), key); } KnowledgeBase.Global.IsTrue(new Structure("fkey_command", key)); return; } // Update last user activity time this.lastPlayerActivity.StoreExclusive(Time.time, true); switch (e.keyCode) { case KeyCode.Escape: this.input = this.formatted = this.commentary = ""; this.dialogAct = null; PauseManager.Paused = false; break; case KeyCode.Delete: case KeyCode.Backspace: if (this.input != "") { this.formatted = this.input = this.input.Substring(0, this.input.Length - 1); this.TryCompletionIfCompleteWord(); } break; case KeyCode.Tab: this.input = string.Format( "{0}{1}{2}", this.input, (this.input.EndsWith(" ") || (!string.IsNullOrEmpty(completion) && !char.IsLetterOrDigit(completion[0]))) ? "" : " ", this.completion); break; case KeyCode.Return: case KeyCode.KeypadEnter: if (this.dialogAct != null) { simController.QueueEvent("player_input", dialogAct); this.IsTrue("log_dialog_act", dialogAct); this.formatted = this.input = this.completion = this.commentary = ""; this.dialogAct = null; PauseManager.Paused = false; } Event.current.Use(); break; } } if (e.character > 0 && !e.alt && !e.control && e.character >= ' ') { this.AddToInput(e.character); } }