--[[ Mod: TES3UI TextInput Author: Hrnchamd]]--localthis={}functionthis.init()this.id_menu=tes3ui.registerID("example:MenuTextInput")this.id_input=tes3ui.registerID("example:MenuTextInput_Text")this.id_ok=tes3ui.registerID("example:MenuTextInput_Ok")this.id_cancel=tes3ui.registerID("example:MenuTextInput_Cancel")end-- Create window and layout. Called by onCommand.functionthis.createWindow()-- Return if window is already openif(tes3ui.findMenu(this.id_menu)~=nil)thenreturnend-- Create window and framelocalmenu=tes3ui.createMenu{id=this.id_menu,fixedFrame=true}-- To avoid low contrast, text input windows should not use menu transparency settingsmenu.alpha=1.0-- Create layoutlocalinput_label=menu:createLabel{text="Rename your item"}input_label.borderBottom=5localinput_block=menu:createBlock{}input_block.width=300input_block.autoHeight=trueinput_block.childAlignX=0.5-- centre content alignmentlocalborder=input_block:createThinBorder{}border.width=300border.height=30border.childAlignX=0.5border.childAlignY=0.5localinput=border:createTextInput{id=this.id_input}input.text=this.item.name-- initial textinput.borderLeft=5input.borderRight=5input.widget.lengthLimit=31-- TextInput custom propertiesinput.widget.eraseOnFirstKey=truelocalbutton_block=menu:createBlock{}button_block.widthProportional=1.0-- width is 100% parent widthbutton_block.autoHeight=truebutton_block.childAlignX=1.0-- right content alignmentlocalbutton_cancel=button_block:createButton{id=this.id_cancel,text=tes3.findGMST("sCancel").value}localbutton_ok=button_block:createButton{id=this.id_ok,text=tes3.findGMST("sOK").value}-- Eventsbutton_cancel:register(tes3.uiEvent.mouseClick,this.onCancel)menu:register(tes3.uiEvent.keyEnter,this.onOK)-- only works when text input is not capturedinput:register(tes3.uiEvent.keyEnter,this.onOK)button_ok:register(tes3.uiEvent.mouseClick,this.onOK)-- Final setupmenu:updateLayout()tes3ui.enterMenuMode(this.id_menu)tes3ui.acquireTextInput(input)-- automatically reset when menu is closedend-- OK button callback.functionthis.onOK(e)localmenu=tes3ui.findMenu(this.id_menu)if(menu)then-- Copy text *before* the menu is destroyedlocalname=menu:findChild(this.id_input).texttes3ui.leaveMenuMode()menu:destroy()tes3.messageBox{message=this.item.name.." renamed to "..name}this.item.name=nameendend-- Cancel button callback.functionthis.onCancel(e)localmenu=tes3ui.findMenu(this.id_menu)if(menu)thentes3ui.leaveMenuMode()menu:destroy()endend-- Keydown callback.functionthis.onCommand(e)localt=tes3.getPlayerTarget()if(t)thent=t.object.baseObjectort.object-- Select actor base objectif(t.name)thenthis.item=tthis.createWindow()endendendevent.register(tes3.event.initialized,this.init)event.register(tes3.event.keyDown,this.onCommand,{filter=tes3.scanCode["/"]})-- "/" key