shadowm

Untitled

Feb 12th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.06 KB | None | 0 0
  1. diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
  2. index 6becd19..7b1d2d0 100644
  3. --- a/src/scripting/lua.cpp
  4. +++ b/src/scripting/lua.cpp
  5. @@ -2999,6 +2999,51 @@ static int intf_set_dialog_markup(lua_State *L)
  6.  }
  7.  
  8.  /**
  9. + * Sets the visiblity of a widget in the current dialog.
  10. + * - Arg 1: boolean.
  11. + * - Args 2..n: path of strings and integers.
  12. + */
  13. +static int intf_set_dialog_visible(lua_State *L)
  14. +{
  15. +   // The GUI2 control visibility value type
  16. +   typedef gui2::tcontrol::tvisible tvisible;
  17. +
  18. +   tvisible::scoped_enum flag = tvisible::visible;
  19. +
  20. +   switch (lua_type(L, 1)) {
  21. +       case LUA_TBOOLEAN:
  22. +           flag = bool(lua_toboolean(L, 1))
  23. +               ? tvisible::visible
  24. +               : tvisible::invisible;
  25. +           break;
  26. +       case LUA_TSTRING:
  27. +           {
  28. +               const std::string& str = lua_tostring(L, 1);
  29. +               if(str == "visible") {
  30. +                   flag = tvisible::visible;
  31. +               } else if(str == "hidden") { // FIXME: broken
  32. +                   flag = tvisible::hidden;
  33. +               } else if(str == "invisible") {
  34. +                   flag = tvisible::invisible;
  35. +               } else {
  36. +                   return luaL_argerror(L, 1, "string must be one of: visible, hidden, invisible");
  37. +               }
  38. +           }
  39. +           break;
  40. +       default:
  41. +           return luaL_typerror(L, 1, "boolean or string");
  42. +   }
  43. +
  44. +   gui2::twidget *w = find_widget(L, 2, true);
  45. +   gui2::tcontrol *c = dynamic_cast<gui2::tcontrol *>(w);
  46. +   if (!c) return luaL_argerror(L, lua_gettop(L), "unsupported widget");
  47. +
  48. +   c->set_visible(flag);
  49. +
  50. +   return 0;
  51. +}
  52. +
  53. +/**
  54.   * Sets a canvas on a widget of the current dialog.
  55.   * - Arg 1: integer.
  56.   * - Arg 2: WML table.
  57. @@ -3624,6 +3669,7 @@ LuaKernel::LuaKernel(const config &cfg)
  58.         { "set_dialog_canvas",        &intf_set_dialog_canvas        },
  59.         { "set_dialog_markup",        &intf_set_dialog_markup        },
  60.         { "set_dialog_value",         &intf_set_dialog_value         },
  61. +       { "set_dialog_visible",       &intf_set_dialog_visible       },
  62.         { "set_music",                &intf_set_music                },
  63.         { "set_terrain",              &intf_set_terrain              },
  64.         { "set_variable",             &intf_set_variable             },
Advertisement
Add Comment
Please, Sign In to add comment