Sunday, April 4, 2010

Options Window

Since the beginning when I first conceived of the idea for the Scripts Plugin I've been trying to come up with a way to give us the ability to let the users interact with the script from the PlayOn window. My first attempt just confused our users, and the second attempt is just a band aid.

But I've been working on a way to let us have options on par with "normal" plugins. This came to head with a good link provided by hotTamale (script developer extraordinaire) here. It goes into great detail dealing with accessing C# options from Lua.

I'm getting tired so to cut it short I'll just leave you with what the new options code will (probably) look like:

  1. --[[Options
  2. --#code
  3. --load the assemblies
  4. luanet.load_assembly "System.Windows.Forms"
  5. luanet.load_assembly "System.Drawing"
  6. --assign the objects (#include controls can supplant this)
  7. Form = luanet.import_type "System.Windows.Forms.Form"
  8. Button = luanet.import_type "System.Windows.Forms.Button"
  9. TextBox = luanet.import_type "System.Windows.Forms.TextBox"
  10. Label = luanet.import_type "System.Windows.Forms.Label"
  11. Point = luanet.import_type "System.Drawing.Point"
  12. --create the objects
  13. frmDialog = Form()
  14. txtZip = TextBox()
  15. lblZip = Label()
  16. butClose = Button()
  17. butApply = Button()
  18. --controls
  19. lblZip.Text = "Zipcode: "
  20. lblZip.Location=Point(20,20)
  21. txtZip.Text = "90210"
  22. txtZip.Location=Point(50,20)
  23. txtZip.Width = 150
  24. butApply.Text = "Apply"
  25. butApply.Location=Point(250,180)
  26. --button click handler
  27. handler=butApply.MouseUp:Add(function(sender, data)
  28. --apply code here
  29. Log(txtZip.text)
  30. frmDialog:HideDialog()
  31. end)
  32. butClose.Text = "Close"
  33. butClose.Location=Point(280,180)
  34. --button click handler
  35. handler=butApply.MouseUp:Add(function(sender, data)
  36. --reset fields and hide window
  37. frmDialog:HideDialog()
  38. end)
  39. --form properties
  40. frmDialog.Text = "My Dialog Box"
  41. frmDialog.Width = 300;
  42. frmDialog.Height = 250;
  43. frmDialog.HelpButton = true
  44. frmDialog.MaximizeBox=false
  45. frmDialog.MinimizeBox=false
  46. --assign controls to our window
  47. frmDialog.Controls:Add(txtZip)
  48. frmDialog.Controls:Add(lblZip)
  49. frmDialog.Controls:Add(butClose)
  50. frmDialog.Controls:Add(butApply)
  51. frmDialog:ShowDialog()
  52. EndOptions]]--

No comments:

Post a Comment