Closed LuckyScamper closed 3 years ago
Thanks for the PR. After some thoughts I've decided that I dont need such localization solution. Myra needs localization solution, however probably I'll simply add something like this to MML:
However auto-subscribing to events through reflection is nice feature.
So can you remove the localization feature?
Are there any plans to update and merge this PR? Adding method names to the MML file declaration is really useful for my current project.
I'll take auto-subscribing to events, but localization probably will work like this: https://github.com/rds1983/Myra/issues/308 Thanks, @LuckyScamper!
Project.LoadFromXml now has extra functions which allow one to enter a class instance to serve as eventhandler.
Project.LoadFromXml(File.ReadAllText("UI/MainMenuScreen.xmmp"), this);
public void ContinueButton_Click(object sender, EventArgs e) { HasSceneEnded = true; }
in the xmmp you can enter public non-static methods that serve as the receipients for the events.
<Button Click="ContinueButton_Click" />
First, you have to enter the Func<string, string> in Project (static variable) which determines how a string is localized. In my own personal project I localize using .resx files and the following line of code is made to reflect that. However, other people may want to localize differently (SQLite, json, etc) so they can enter the lambda as they see fit.
This line of code should be implemented in the implementation of the Game class. There will not be any errors in your runtime if this isn't implemented, unless you are going to use the localize texts property.
Project.Localize = (key) => L18nManager.GetText(key);
Then, in xmmp
<Button Click="ContinueButton_Click" L18nTextKey="continue" />
Do note that L18nTextKey will in its set property override the Text property, so using this one alongside Text will likely not result in a desired outcome.
The following code: `(File.ReadAllText("UI/MainMenuScreen.xmmp"), this).Root;
Constants.GUIRenderer.Root = Project.LoadFromXml
to this:
Constants.GUIRenderer.Root = Project.LoadFromXml(File.ReadAllText("UI/MainMenuScreen.xmmp"), this).Root; UIRoot = Constants.GUIRenderer.Root;