stom66

EditableNotecard.lua

Jan 8th, 2021 (edited)
1,186
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onLoad(save_data)
  2.     --set the default text to match the object description
  3.     text = self.getDescription()
  4.  
  5.     --update the XML Input field once the asset has finished loading
  6.     Wait.condition(
  7.         function() updateXml() end,
  8.         function() return self.loading_custom == false end
  9.     )
  10. end
  11.  
  12. function updateXml()
  13.     --calculate the vertical offset needed for the InputField
  14.     local size     = self.getBounds().size
  15.     local scale    = self.getScale()
  16.     local z_offset = ((self.getCustomObject().thickness * 100) - (self.getBounds().offset.y * 200)) / -2 -1
  17.  
  18.     --size, in percent, of the image that should be covered by the input field
  19.     local inputSize = 90
  20.  
  21.     --main xml styling
  22.     local xml = {
  23.         {
  24.             tag = "InputField",
  25.             attributes = {
  26.                 --edit the style of your input field here
  27.                 caretBlinkRate      = 0.85,
  28.                 caretColor          = "#323232",
  29.                 caretWidth          = 1,
  30.                 characterLimit      = 0,
  31.                 characterValidation = "None",
  32.                 color               = "#00000000", --8-digit hex code, last 2 are alpha. change to ff to see the background
  33.                 fontSize            = 45,
  34.                 lineType            = "MultiLineNewLine",
  35.                 placeholder         = "Click here to edit the text",
  36.                 rectAlignment       = "MiddleCenter",
  37.                 rotation            = "0 0 180",
  38.                 scale               = "0.5 0.5 0.5",
  39.                 selectionColor      = "rgba(0.65,0.8,1,0.75)",
  40.                 textColor           = "#cccccc",
  41.                 --don't edit the following fields, adjust size by changing "inputSize" above
  42.                 id                  = "field",
  43.                 onEndEdit           = "xml_endEdit",
  44.                 text                = text,
  45.                 position            = "0 0 "..z_offset,
  46.                 width               = size.x * (inputSize * 2) / scale.x,
  47.                 preferredWidth      = size.x * (inputSize * 2) / scale.x,
  48.                 height              = size.z * (inputSize * 2) / scale.z,
  49.                 preferredHeight     = size.z * (inputSize * 2) / scale.z,
  50.             }
  51.         }
  52.     }
  53.     self.UI.setXmlTable(xml)
  54. end
  55.  
  56. function xml_endEdit(player, value, id)
  57.     self.setDescription(value)
  58. end
RAW Paste Data