소스 검색

Console remembers the last used interpreter if there are more than one.
Editor persists the last used command interpreter in configuration file.

Yao Wei Tjong 姚伟忠 11 년 전
부모
커밋
6c7db54e4b

+ 10 - 0
Bin/Data/Scripts/Editor.as

@@ -127,6 +127,7 @@ void LoadConfig()
     XMLElement inspectorElem = configElem.GetChild("attributeinspector");
     XMLElement inspectorElem = configElem.GetChild("attributeinspector");
     XMLElement viewElem = configElem.GetChild("view");
     XMLElement viewElem = configElem.GetChild("view");
     XMLElement resourcesElem = configElem.GetChild("resources");
     XMLElement resourcesElem = configElem.GetChild("resources");
+    XMLElement consoleElem = configElem.GetChild("console");
 
 
     if (!cameraElem.isNull)
     if (!cameraElem.isNull)
     {
     {
@@ -225,6 +226,12 @@ void LoadConfig()
         if (viewElem.HasAttribute("gridcolor")) gridColor = viewElem.GetColor("gridcolor");
         if (viewElem.HasAttribute("gridcolor")) gridColor = viewElem.GetColor("gridcolor");
         if (viewElem.HasAttribute("gridsubdivisioncolor")) gridSubdivisionColor = viewElem.GetColor("gridsubdivisioncolor");
         if (viewElem.HasAttribute("gridsubdivisioncolor")) gridSubdivisionColor = viewElem.GetColor("gridsubdivisioncolor");
     }
     }
+
+    if (!consoleElem.isNull)
+    {
+        // Console does not exist yet at this point, so store the string in a global variable
+        if (consoleElem.HasAttribute("commandinterpreter")) consoleCommandInterpreter = consoleElem.GetAttribute("commandinterpreter");
+    }
 }
 }
 
 
 void SaveConfig()
 void SaveConfig()
@@ -241,6 +248,7 @@ void SaveConfig()
     XMLElement inspectorElem = configElem.CreateChild("attributeinspector");
     XMLElement inspectorElem = configElem.CreateChild("attributeinspector");
     XMLElement viewElem = configElem.CreateChild("view");
     XMLElement viewElem = configElem.CreateChild("view");
     XMLElement resourcesElem = configElem.CreateChild("resources");
     XMLElement resourcesElem = configElem.CreateChild("resources");
+    XMLElement consoleElem = configElem.CreateChild("console");
 
 
     cameraElem.SetFloat("nearclip", viewNearClip);
     cameraElem.SetFloat("nearclip", viewNearClip);
     cameraElem.SetFloat("farclip", viewFarClip);
     cameraElem.SetFloat("farclip", viewFarClip);
@@ -307,6 +315,8 @@ void SaveConfig()
     viewElem.SetColor("gridcolor", gridColor);
     viewElem.SetColor("gridcolor", gridColor);
     viewElem.SetColor("gridsubdivisioncolor", gridSubdivisionColor);
     viewElem.SetColor("gridsubdivisioncolor", gridSubdivisionColor);
 
 
+    consoleElem.SetAttribute("commandinterpreter", console.commandInterpreter);
+
     config.Save(File(configFileName, FILE_WRITE));
     config.Save(File(configFileName, FILE_WRITE));
 }
 }
 
 

+ 2 - 0
Bin/Data/Scripts/Editor/EditorUI.as

@@ -8,6 +8,7 @@ Menu@ recentSceneMenu;
 Window@ mruScenesPopup;
 Window@ mruScenesPopup;
 Array<QuickMenuItem@> quickMenuItems;
 Array<QuickMenuItem@> quickMenuItems;
 FileSelector@ uiFileSelector;
 FileSelector@ uiFileSelector;
+String consoleCommandInterpreter;
 
 
 const ShortStringHash UI_ELEMENT_TYPE("UIElement");
 const ShortStringHash UI_ELEMENT_TYPE("UIElement");
 const ShortStringHash WINDOW_TYPE("Window");
 const ShortStringHash WINDOW_TYPE("Window");
@@ -924,6 +925,7 @@ void CreateConsole()
 {
 {
     Console@ console = engine.CreateConsole();
     Console@ console = engine.CreateConsole();
     console.defaultStyle = uiStyle;
     console.defaultStyle = uiStyle;
+    console.commandInterpreter = consoleCommandInterpreter;
     console.numBufferedRows = 100;
     console.numBufferedRows = 100;
     console.autoVisibleOnError = true;
     console.autoVisibleOnError = true;
 }
 }

+ 22 - 1
Source/Engine/Engine/Console.cpp

@@ -83,6 +83,7 @@ Console::Console(Context* context) :
 
 
     SetNumRows(DEFAULT_CONSOLE_ROWS);
     SetNumRows(DEFAULT_CONSOLE_ROWS);
 
 
+    SubscribeToEvent(interpreters_, E_ITEMSELECTED, HANDLER(Console, HandleInterpreterSelected));
     SubscribeToEvent(lineEdit_, E_TEXTFINISHED, HANDLER(Console, HandleTextFinished));
     SubscribeToEvent(lineEdit_, E_TEXTFINISHED, HANDLER(Console, HandleTextFinished));
     SubscribeToEvent(lineEdit_, E_UNHANDLEDKEY, HANDLER(Console, HandleLineEditKey));
     SubscribeToEvent(lineEdit_, E_UNHANDLEDKEY, HANDLER(Console, HandleLineEditKey));
     SubscribeToEvent(E_SCREENMODE, HANDLER(Console, HandleScreenMode));
     SubscribeToEvent(E_SCREENMODE, HANDLER(Console, HandleScreenMode));
@@ -253,9 +254,17 @@ bool Console::PopulateInterpreter()
     if (!receivers || receivers->Empty())
     if (!receivers || receivers->Empty())
         return false;
         return false;
 
 
+    Vector<String> names;
     for (HashSet<Object*>::ConstIterator iter = receivers->Begin(); iter != receivers->End(); ++iter)
     for (HashSet<Object*>::ConstIterator iter = receivers->Begin(); iter != receivers->End(); ++iter)
+        names.Push((*iter)->GetTypeName());
+    Sort(names.Begin(), names.End());
+
+    unsigned selection = M_MAX_UNSIGNED;
+    for (unsigned i = 0; i < names.Size(); ++i)
     {
     {
-        const String& name = (*iter)->GetTypeName();
+        const String& name = names[i];
+        if (name == commandInterpreter_)
+            selection = i;
         Text* text = new Text(context_);
         Text* text = new Text(context_);
         text->SetStyle("ConsoleText");
         text->SetStyle("ConsoleText");
         text->SetText(name);
         text->SetText(name);
@@ -268,9 +277,21 @@ bool Console::PopulateInterpreter()
     interpreters_->SetEnabled(enabled);
     interpreters_->SetEnabled(enabled);
     interpreters_->SetFocusMode(enabled ? FM_FOCUSABLE_DEFOCUSABLE : FM_NOTFOCUSABLE);
     interpreters_->SetFocusMode(enabled ? FM_FOCUSABLE_DEFOCUSABLE : FM_NOTFOCUSABLE);
 
 
+    if (selection == M_MAX_UNSIGNED)
+    {
+        selection = 0;
+        commandInterpreter_ = names[selection];
+    }
+    interpreters_->SetSelection(selection);
+
     return true;
     return true;
 }
 }
 
 
+void Console::HandleInterpreterSelected(StringHash eventType, VariantMap& eventData)
+{
+    commandInterpreter_ = static_cast<Text*>(interpreters_->GetSelectedItem())->GetText();
+}
+
 void Console::HandleTextFinished(StringHash eventType, VariantMap& eventData)
 void Console::HandleTextFinished(StringHash eventType, VariantMap& eventData)
 {
 {
     using namespace TextFinished;
     using namespace TextFinished;

+ 8 - 0
Source/Engine/Engine/Console.h

@@ -56,6 +56,8 @@ public:
     void Toggle();
     void Toggle();
     /// Automatically set console to visible when receiving an error log message.
     /// Automatically set console to visible when receiving an error log message.
     void SetAutoVisibleOnError(bool enable) { autoVisibleOnError_ = enable; }
     void SetAutoVisibleOnError(bool enable) { autoVisibleOnError_ = enable; }
+    /// Set the command interpreter.
+    void SetCommandInterpreter(const String& interpreter) { commandInterpreter_ = interpreter; }
     /// Set number of buffered rows.
     /// Set number of buffered rows.
     void SetNumBufferedRows(unsigned rows);
     void SetNumBufferedRows(unsigned rows);
     /// Set number of displayed rows.
     /// Set number of displayed rows.
@@ -77,6 +79,8 @@ public:
     bool IsVisible() const;
     bool IsVisible() const;
     /// Return true when console is set to automatically visible when receiving an error log message.
     /// Return true when console is set to automatically visible when receiving an error log message.
     bool IsAutoVisibleOnError() const { return autoVisibleOnError_; }
     bool IsAutoVisibleOnError() const { return autoVisibleOnError_; }
+    /// Return the last used command interpreter.
+    const String& GetCommandInterpreter() const { return commandInterpreter_; }
     /// Return number of buffered rows.
     /// Return number of buffered rows.
     unsigned GetNumBufferedRows() const;
     unsigned GetNumBufferedRows() const;
     /// Return number of displayed rows.
     /// Return number of displayed rows.
@@ -95,6 +99,8 @@ public:
 private:
 private:
     /// Populate the command line interpreters that could handle the console command.
     /// Populate the command line interpreters that could handle the console command.
     bool PopulateInterpreter();
     bool PopulateInterpreter();
+    /// Handle interpreter being selected on the drop down list.
+    void HandleInterpreterSelected(StringHash eventType, VariantMap& eventData);
     /// Handle enter pressed on the line edit.
     /// Handle enter pressed on the line edit.
     void HandleTextFinished(StringHash eventType, VariantMap& eventData);
     void HandleTextFinished(StringHash eventType, VariantMap& eventData);
     /// Handle unhandled key on the line edit for scrolling the history.
     /// Handle unhandled key on the line edit for scrolling the history.
@@ -116,6 +122,8 @@ private:
     SharedPtr<UIElement> commandLine_;
     SharedPtr<UIElement> commandLine_;
     /// Interpreter drop down list.
     /// Interpreter drop down list.
     SharedPtr<DropDownList> interpreters_;
     SharedPtr<DropDownList> interpreters_;
+    /// Last used command interpreter.
+    String commandInterpreter_;
     /// Line edit.
     /// Line edit.
     SharedPtr<LineEdit> lineEdit_;
     SharedPtr<LineEdit> lineEdit_;
     /// Command history.
     /// Command history.

+ 3 - 0
Source/Engine/LuaScript/pkgs/Engine/Console.pkg

@@ -6,6 +6,7 @@ class Console : public Object
     void SetVisible(bool enable);
     void SetVisible(bool enable);
     void Toggle();
     void Toggle();
     void SetAutoVisibleOnError(bool enable);
     void SetAutoVisibleOnError(bool enable);
+    void SetCommandInterpreter(const String& interpreter);
     void SetNumBufferedRows(unsigned rows);
     void SetNumBufferedRows(unsigned rows);
     void SetNumRows(unsigned rows);
     void SetNumRows(unsigned rows);
     void SetNumHistoryRows(unsigned rows);
     void SetNumHistoryRows(unsigned rows);
@@ -17,6 +18,7 @@ class Console : public Object
     LineEdit* GetLineEdit() const;
     LineEdit* GetLineEdit() const;
     bool IsVisible() const;
     bool IsVisible() const;
     bool IsAutoVisibleOnError() const;
     bool IsAutoVisibleOnError() const;
+    const String& GetCommandInterpreter() const;
     unsigned GetNumBufferedRows() const;
     unsigned GetNumBufferedRows() const;
     unsigned GetNumRows() const;
     unsigned GetNumRows() const;
     void CopySelectedRows() const;
     void CopySelectedRows() const;
@@ -30,6 +32,7 @@ class Console : public Object
     tolua_readonly tolua_property__get_set LineEdit* lineEdit;
     tolua_readonly tolua_property__get_set LineEdit* lineEdit;
     tolua_property__is_set bool visible;
     tolua_property__is_set bool visible;
     tolua_property__is_set bool autoVisibleOnError;
     tolua_property__is_set bool autoVisibleOnError;
+    tolua_property__get_set String commandInterpreter;
     tolua_property__get_set unsigned numBufferedRows;
     tolua_property__get_set unsigned numBufferedRows;
     tolua_property__get_set unsigned numRows;
     tolua_property__get_set unsigned numRows;
     tolua_property__get_set unsigned numHistoryRows;
     tolua_property__get_set unsigned numHistoryRows;

+ 2 - 0
Source/Engine/Script/EngineAPI.cpp

@@ -46,6 +46,8 @@ static void RegisterConsole(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Console", "bool get_visible() const", asMETHOD(Console, IsVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "bool get_visible() const", asMETHOD(Console, IsVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "void set_autoVisibleOnError(bool)", asMETHOD(Console, SetAutoVisibleOnError), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "void set_autoVisibleOnError(bool)", asMETHOD(Console, SetAutoVisibleOnError), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "bool get_autoVisibleOnError() const", asMETHOD(Console, IsAutoVisibleOnError), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "bool get_autoVisibleOnError() const", asMETHOD(Console, IsAutoVisibleOnError), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Console", "void set_commandInterpreter(const String&in)", asMETHOD(Console, SetCommandInterpreter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Console", "const String& get_commandInterpreter() const", asMETHOD(Console, GetCommandInterpreter), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "void set_numBufferedRows(uint)", asMETHOD(Console, SetNumBufferedRows), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "void set_numBufferedRows(uint)", asMETHOD(Console, SetNumBufferedRows), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "uint get_numBufferedRows() const", asMETHOD(Console, GetNumBufferedRows), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "uint get_numBufferedRows() const", asMETHOD(Console, GetNumBufferedRows), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "void set_numRows(uint)", asMETHOD(Console, SetNumRows), asCALL_THISCALL);
     engine->RegisterObjectMethod("Console", "void set_numRows(uint)", asMETHOD(Console, SetNumRows), asCALL_THISCALL);