Lua - gui.text() and gui.Alert() - strongly type the anchor parameters as a string, will still except 0, 1, 2, or 3 as it did previously, for which it will interpret them as string automatically

This commit is contained in:
adelikat 2014-02-17 01:57:25 +00:00
parent 45c6b9f095
commit 63e8702242
1 changed files with 17 additions and 22 deletions

View File

@ -123,7 +123,7 @@ namespace BizHawk.Client.EmuHawk
bool alert, bool alert,
object background = null, object background = null,
object forecolor = null, object forecolor = null,
object anchor = null) string anchor = null)
{ {
if (!alert) if (!alert)
{ {
@ -140,31 +140,26 @@ namespace BizHawk.Client.EmuHawk
var a = 0; var a = 0;
if (anchor != null) if (!string.IsNullOrEmpty(anchor))
{ {
int dummy; switch (anchor)
if (int.TryParse(anchor.ToString(), out dummy) == false)
{ {
if (anchor.ToString().ToLower() == "topleft") case "0":
{ case "topleft":
a = 0; a = 0;
} break;
else if (anchor.ToString().ToLower() == "topright") case "1":
{ case "topright":
a = 1; a = 1;
} break;
else if (anchor.ToString().ToLower() == "bottomleft") case "2":
{ case "bottomleft":
a = 2; a = 2;
} break;
else if (anchor.ToString().ToLower() == "bottomright") case "3":
{ case "bottomright":
a = 3; a = 3;
} break;
}
else
{
a = LuaInt(anchor);
} }
} }
else else
@ -195,7 +190,7 @@ namespace BizHawk.Client.EmuHawk
"alert", "alert",
"Functions the same as gui.text() but shows the message in the alert font" "Functions the same as gui.text() but shows the message in the alert font"
)] )]
public void Alert(int x, int y, string message, object anchor = null) public void Alert(int x, int y, string message, string anchor = null)
{ {
DoGuiText(x, y, message, true, null, null, anchor); // TODO: refactor DoGuiText to take luaStr as string and refactor DoGuiText(x, y, message, true, null, null, anchor); // TODO: refactor DoGuiText to take luaStr as string and refactor
} }
@ -557,7 +552,7 @@ namespace BizHawk.Client.EmuHawk
string message, string message,
object background = null, object background = null,
object forecolor = null, object forecolor = null,
object anchor = null) string anchor = null)
{ {
DoGuiText(x, y, message, false, background, forecolor, anchor); DoGuiText(x, y, message, false, background, forecolor, anchor);
} }