浏览代码

Fix Lua binding for Localization and Database subsystems.
Fix Lua version of the localization demo.

Yao Wei Tjong 姚伟忠 10 年之前
父节点
当前提交
934c640835

+ 1 - 1
Source/Urho3D/LuaScript/pkgs/Database/Database.pkg

@@ -8,7 +8,7 @@ enum DBAPI
 
 class Database : public Object
 {
-    DbConnection* Connect(const String& connectionString);
+    DbConnection* Connect(const String connectionString);
     void Disconnect(DbConnection* connection);
     bool IsPooling() const;
     unsigned GetPoolSize() const;

+ 5 - 5
Source/Urho3D/LuaScript/pkgs/Resource/Localization.pkg

@@ -4,15 +4,15 @@ class Localization : public Object
 {
     int GetNumLanguages() const;
     int GetLanguageIndex() const;
-    int GetLanguageIndex(const String &language);
+    int GetLanguageIndex(const String language);
     String GetLanguage();
     String GetLanguage(int index);
+    void SetLanguage(const String language);
     void SetLanguage(int index);
-    void SetLanguage(const String &language);
-    String Get(const String &id);
+    String Get(const String id);
     void Reset();
-    void LoadJSON(const JSONValue &source);
-    void LoadJSONFile(const String &name);
+    void LoadJSON(const JSONValue& source);
+    void LoadJSONFile(const String name);
 
     tolua_readonly tolua_property__get_set int numLanguages;
     tolua_readonly tolua_property__get_set int languageIndex;

+ 8 - 8
Source/Urho3D/Resource/Localization.cpp

@@ -43,7 +43,7 @@ Localization::~Localization()
 {
 }
 
-int Localization::GetLanguageIndex(const String &language)
+int Localization::GetLanguageIndex(const String& language)
 {
     if (language.Empty())
     {
@@ -108,7 +108,7 @@ void Localization::SetLanguage(int index)
     }
 }
 
-void Localization::SetLanguage(const String &language)
+void Localization::SetLanguage(const String& language)
 {
     if (language.Empty())
     {
@@ -129,7 +129,7 @@ void Localization::SetLanguage(const String &language)
     SetLanguage(index);
 }
 
-String Localization::Get(const String &id)
+String Localization::Get(const String& id)
 {
     if (id.Empty())
         return String::EMPTY;
@@ -176,14 +176,14 @@ void Localization::LoadJSON(const JSONValue& source)
             const String& string = j->second_.GetString();
             if (string.Empty())
             {
-                LOGWARNING("Localization::LoadJSON(source): translation is empty, string ID=\"" + id +
-                    "\", language=\"" + lang + "\"");
+                LOGWARNING(
+                    "Localization::LoadJSON(source): translation is empty, string ID=\"" + id + "\", language=\"" + lang + "\"");
                 continue;
             }
             if (strings_[StringHash(lang)][StringHash(id)] != String::EMPTY)
             {
-                LOGWARNING("Localization::LoadJSON(source): override translation, string ID=\"" + id +
-                    "\", language=\"" + lang + "\"");
+                LOGWARNING(
+                    "Localization::LoadJSON(source): override translation, string ID=\"" + id + "\", language=\"" + lang + "\"");
             }
             strings_[StringHash(lang)][StringHash(id)] = string;
             if (!languages_.Contains(lang))
@@ -194,7 +194,7 @@ void Localization::LoadJSON(const JSONValue& source)
     }
 }
 
-void Localization::LoadJSONFile(const String &name)
+void Localization::LoadJSONFile(const String& name)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     JSONFile* jsonFile = cache->GetResource<JSONFile>(name);

+ 8 - 5
Source/Urho3D/Resource/Localization.h

@@ -38,12 +38,15 @@ public:
     Localization(Context* context);
     /// Destruct. Free all resources.
     virtual ~Localization();
+
     /// Return the number of languages.
     int GetNumLanguages() const { return (int)languages_.Size(); }
+
     /// Return the index number of current language. The index is determined by the order of loading.
     int GetLanguageIndex() const { return languageIndex_; }
+
     /// Return the index number of language. The index is determined by the order of loading.
-    int GetLanguageIndex(const String &language);
+    int GetLanguageIndex(const String& language);
     /// Return the name of current language.
     String GetLanguage();
     /// Return the name of language.
@@ -51,15 +54,15 @@ public:
     /// Set current language.
     void SetLanguage(int index);
     /// Set current language.
-    void SetLanguage(const String &language);
+    void SetLanguage(const String& language);
     /// Return a string in the current language. Returns String::EMPTY if id is empty. Returns id if translation is not found and logs a warning.
-    String Get(const String &id);
+    String Get(const String& id);
     /// Clear all loaded strings.
     void Reset();
     /// Load strings from JSONValue.
-    void LoadJSON(const JSONValue &source);
+    void LoadJSON(const JSONValue& source);
     /// Load strings from JSONFile. The file should be UTF8 without BOM.
-    void LoadJSONFile(const String &name);
+    void LoadJSONFile(const String& name);
 
 private:
     /// Language names.

+ 7 - 7
bin/Data/LuaScripts/40_Localization.lua

@@ -9,10 +9,10 @@ require "LuaScripts/Utilities/Sample"
 function Start()
     -- Execute the common startup for samples
     SampleStart()
-    
+
     -- Enable OS cursor
     input.mouseVisible = true
-    
+
     -- Load strings from JSON files and subscribe to the change language event
     InitLocalizationSystem()
 
@@ -63,14 +63,14 @@ function CreateGUI()
     window:AddChild(b)
     b:SetStyle("Button")
     b.minHeight = 24
-    
+
     local t = b:CreateChild("Text", "ButtonTextChangeLang")
     -- The showing text value will automatically change when language is changed
     t.autoLocalizable = true
     -- The text value used as a string identifier in this mode.
     -- Remember that a letter case of the id and of the lang name is important.
     t.text = "Press this button"
-    
+
     t:SetAlignment(HA_CENTER, VA_CENTER)
     t:SetStyle("Text")
     SubscribeToEvent(b, "Released", "HandleChangeLangButtonPressed")
@@ -82,17 +82,17 @@ function CreateGUI()
     t = b:CreateChild("Text", "ButtonTextQuit")
     t:SetAlignment(HA_CENTER, VA_CENTER)
     t:SetStyle("Text")
-    
+
     -- Manually set text in the current language
     t.text = localization:Get("quit")
-    
+
     SubscribeToEvent(b, "Released", "HandleQuitButtonPressed")
 end
 
 function CreateScene()
     scene_ = Scene:new()
     scene_:CreateComponent("Octree")
-    
+
     local zone = scene_:CreateComponent("Zone")
     zone.boundingBox = BoundingBox:new(-1000.0, 1000.0)
     zone.ambientColor = Color:new(0.5, 0.5, 0.5)