Преглед на файлове

Fixed an issue localized strings and an exception that would happen when language was changed and update method was called on a deallocated object
Fixed GUIButton default skin active state texture (it was null)

Marko Pintera преди 12 години
родител
ревизия
085a98cd70

+ 1 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -154,6 +154,7 @@ namespace BansheeEngine
 		GUIElementStyle buttonStyle;
 		GUIElementStyle buttonStyle;
 		buttonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonNormalTex));
 		buttonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonNormalTex));
 		buttonStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonHoverTex));
 		buttonStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonHoverTex));
+		buttonStyle.active.texture = buttonStyle.hover.texture;
 		buttonStyle.border.left = 5;
 		buttonStyle.border.left = 5;
 		buttonStyle.border.right = 5;
 		buttonStyle.border.right = 5;
 		buttonStyle.border.top = 5;
 		buttonStyle.border.top = 5;

+ 2 - 0
CamelotClient/Include/CmTestTextSprite.h

@@ -18,5 +18,7 @@ namespace CamelotFramework
 
 
 	private:
 	private:
 		BS::GUILabel* mLabel;
 		BS::GUILabel* mLabel;
+
+		void dbgBtn();
 	};
 	};
 }
 }

+ 13 - 0
CamelotClient/Source/CmTestTextSprite.cpp

@@ -17,10 +17,12 @@
 #include "BsGUILayout.h"
 #include "BsGUILayout.h"
 #include "BsGUISpace.h"
 #include "BsGUISpace.h"
 #include "BsGUIViewport.h"
 #include "BsGUIViewport.h"
+#include "BsGUIButton.h"
 #include "BsCamera.h"
 #include "BsCamera.h"
 #include "CmInput.h"
 #include "CmInput.h"
 #include "CmPlatform.h"
 #include "CmPlatform.h"
 #include "BsGUIContent.h"
 #include "BsGUIContent.h"
+#include "CmStringTable.h"
 
 
 using namespace BansheeEngine;
 using namespace BansheeEngine;
 
 
@@ -52,6 +54,11 @@ namespace CamelotFramework
 		dropDownElements.push_back(HString(L"Element #2"));
 		dropDownElements.push_back(HString(L"Element #2"));
 		dropDownElements.push_back(HString(L"Element #3"));
 		dropDownElements.push_back(HString(L"Element #3"));
 		area->getLayout().addElement(GUIListBox::create(*this, dropDownElements, GUILayoutOptions::fixed(50, 13)));
 		area->getLayout().addElement(GUIListBox::create(*this, dropDownElements, GUILayoutOptions::fixed(50, 13)));
+
+		GUIButton* button = GUIButton::create(*this, HString(L"dbgBtn"));
+		button->onClick.connect(boost::bind(&TestTextSprite::dbgBtn, this));
+		area->getLayout().addElement(button);
+
 		area->getLayout().addFlexibleSpace();
 		area->getLayout().addFlexibleSpace();
 	}
 	}
 
 
@@ -61,4 +68,10 @@ namespace CamelotFramework
 
 
 		mLabel->setContent(GUIContent(HString(L"")));
 		mLabel->setContent(GUIContent(HString(L"")));
 	}
 	}
+
+	void TestTextSprite::dbgBtn()
+	{
+		StringTable::instance().setString(L"dbgBtn", Language::Abkhazian, L"ALOALO");
+		StringTable::instance().setActiveLanguage(Language::Abkhazian);
+	}
 }
 }

+ 2 - 2
CamelotUtility/Include/CmHString.h

@@ -32,6 +32,8 @@ namespace CamelotFramework
 
 
 			mutable bool mIsDirty;
 			mutable bool mIsDirty;
 			mutable WString mCachedString;
 			mutable WString mCachedString;
+
+			void updateString();
 		};
 		};
 
 
 		explicit HString(const WString& identifierString);
 		explicit HString(const WString& identifierString);
@@ -45,7 +47,5 @@ namespace CamelotFramework
 		boost::signals::connection addOnStringModifiedCallback(boost::function<void()> callback) const;
 		boost::signals::connection addOnStringModifiedCallback(boost::function<void()> callback) const;
 	private:
 	private:
 		std::shared_ptr<StringData> mData;
 		std::shared_ptr<StringData> mData;
-
-		void updateString();
 	};
 	};
 }
 }

+ 19 - 19
CamelotUtility/Source/CmHString.cpp

@@ -16,13 +16,30 @@ namespace CamelotFramework
 			cm_deleteN(mParameters, mStringData->numParameters);
 			cm_deleteN(mParameters, mStringData->numParameters);
 	}
 	}
 
 
+	void HString::StringData::updateString()
+	{
+		LocalizedStringData* stringData = &StringTable::instance().getStringData(mStringData->commonData->identifier);
+
+		// If common data changed re-apply the connections
+		if(stringData->commonData != mStringData->commonData)
+		{
+			mUpdateConn.disconnect();
+			mUpdateConn = stringData->commonData->onStringDataModified.connect(boost::bind(&HString::StringData::updateString, this));
+		}
+
+		mStringData = stringData;
+		mIsDirty = true;
+
+		onStringModified();
+	}
+
 	HString::HString()
 	HString::HString()
 	{
 	{
 		mData = cm_shared_ptr<StringData>();
 		mData = cm_shared_ptr<StringData>();
 
 
 		mData->mStringData = &StringTable::instance().getStringData(L"");
 		mData->mStringData = &StringTable::instance().getStringData(L"");
 		mData->mParameters = cm_newN<WString>(mData->mStringData->numParameters);
 		mData->mParameters = cm_newN<WString>(mData->mStringData->numParameters);
-		mData->mUpdateConn = mData->mStringData->commonData->onStringDataModified.connect(boost::bind(&HString::updateString, this));
+		mData->mUpdateConn = mData->mStringData->commonData->onStringDataModified.connect(boost::bind(&HString::StringData::updateString, mData.get()));
 	}
 	}
 
 
 	HString::HString(const WString& identifierString)
 	HString::HString(const WString& identifierString)
@@ -31,7 +48,7 @@ namespace CamelotFramework
 
 
 		mData->mStringData = &StringTable::instance().getStringData(identifierString);
 		mData->mStringData = &StringTable::instance().getStringData(identifierString);
 		mData->mParameters = cm_newN<WString>(mData->mStringData->numParameters);
 		mData->mParameters = cm_newN<WString>(mData->mStringData->numParameters);
-		mData->mUpdateConn = mData->mStringData->commonData->onStringDataModified.connect(boost::bind(&HString::updateString, this));
+		mData->mUpdateConn = mData->mStringData->commonData->onStringDataModified.connect(boost::bind(&HString::StringData::updateString, mData.get()));
 	}
 	}
 
 
 	HString::HString(const HString& copy)
 	HString::HString(const HString& copy)
@@ -67,21 +84,4 @@ namespace CamelotFramework
 	{
 	{
 		return mData->onStringModified.connect(callback);
 		return mData->onStringModified.connect(callback);
 	}
 	}
-
-	void HString::updateString()
-	{
-		LocalizedStringData* stringData = &StringTable::instance().getStringData(mData->mStringData->commonData->identifier);
-
-		// If common data changed re-apply the connections
-		if(stringData->commonData != mData->mStringData->commonData)
-		{
-			mData->mUpdateConn.disconnect();
-			mData->mUpdateConn = stringData->commonData->onStringDataModified.connect(boost::bind(&HString::updateString, this));
-		}
-
-		mData->mStringData = stringData;
-		mData->mIsDirty = true;
-
-		mData->onStringModified();
-	}
 }
 }

+ 6 - 8
Localization.txt

@@ -4,11 +4,9 @@ Test HString:
  - Test changing string
  - Test changing string
  - Test removing string
  - Test removing string
 
 
- HString needs to be introduced in:
- - Label, Button, Toggle, Listbox
-   - Also needs a callback so those elements can be marked as dirty when it is changed
- - Context menu & menu bar
-   - How do I change this when HString is modified or language is changed?
-   - Allow the user to set custom menu name (name used only for display)
-     - Normally the name provided in menu path is used but user can set a localized string if he wants
- - Title bar & window names
+ Exception happens when changing languages
+
+ Update MenuBar, ContextMenu, ListBox and GUIDropDownBox so they handle HString properly
+  - GUIDropDownData also accepts an array of localized strings
+  - MenuBar/ContextMenu/ListBox need to properly fill that array and forward it
+  - That array is then used for naming of menu entries (if it exists, otherwise we just use the name from the menu string)