Advertisement
Guest User

names.lua

a guest
Jun 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. --rename items or units
  2. --[====[
  3.  
  4. names
  5. =====
  6. Rename units or items. Usage:
  7.  
  8. :-help: print this help message
  9. :-if a first name is desired press f, leave blank to clear current first name
  10. :-if viewing an artifact you can rename it
  11. :-if viewing a unit you can rename them
  12. ]====]
  13. local gui = require 'gui'
  14. local dlg = require 'gui.dialogs'
  15. local widgets = require 'gui.widgets'
  16. local utils = require 'utils'
  17. local vw
  18. local trg
  19. local choices
  20.  
  21. validArgs = validArgs or utils.invert({
  22. 'help',
  23. })
  24. local args = utils.processArgs({...}, validArgs)
  25. if args.help then
  26. print(
  27. [[names.lua
  28. arguments:
  29. -help
  30. print this help message
  31. if a first name is desired press f, leave blank to clear current first name
  32. if viewing an artifact you can rename it
  33. if viewing a unit you can rename them
  34. ]])
  35. return
  36. end
  37. namescr = defclass(namescr, gui.Screen)
  38. namescr.focus_path = 'names'
  39. function namescr:init()
  40. if not dfhack.gui.getViewscreenByType(df.viewscreen_layer_choose_language_namest)==true then
  41. self:addviews{
  42. widgets.Label{
  43. view_id='namescr',
  44. frame = {b=4, l=1},
  45. text = {
  46. {text = "Press f to Change First Name"},NEWLINE,
  47. {text = "Press Esc to Set Name and Exit"},
  48. },
  49. }
  50. }
  51. vw = dfhack.gui.getCurViewscreen()
  52. if df.viewscreen_itemst:is_instance(vw.parent) then
  53. fact = vw.parent.item.general_refs[0].artifact_id
  54. trg = df.artifact_record.find(fact)
  55. elseif df.viewscreen_dungeon_monsterstatusst:is_instance(vw.parent) then
  56. uid = vw.parent.unit.id
  57. trg = df.unit.find(uid)
  58. elseif df.global.ui_advmode.menu==1 then
  59. local t_look=df.global.ui_look_list.items[df.global.ui_look_cursor]
  60. if t_look.type==2 then
  61. trg=t_look.unit
  62. end
  63. end
  64. choices = df.viewscreen_setupadventurest:new()
  65. choices.page = 7
  66. local tn = choices.adventurer
  67. utils.assign(tn.name, trg.name)
  68. gui.simulateInput(choices, 'A_CUST_NAME')
  69. vw = dfhack.gui.getViewscreenByType(df.viewscreen_layer_choose_language_namest)
  70. elseif dfhack.gui.getViewscreenByType(df.viewscreen_layer_choose_language_namest)==true then
  71. qerror('names screen already displayed')
  72. end
  73. return vw,trg
  74. end
  75. function namescr:setName()
  76. for k = 0,6 do
  77. trg.name.words[k] = vw.name.words[k]
  78. trg.name.parts_of_speech[k] = vw.name.parts_of_speech[k]
  79. trg.name.language = vw.name.language
  80. trg .name.has_name = vw.name.has_name
  81. end
  82. end
  83. function namescr:setFirst()
  84. local str = ''
  85. dlg.showInputPrompt("Set First Name?","First: ",COLOR_WHITE,'',
  86. function(str)
  87. if str==nil then
  88. self:callback("setFirst")
  89. else
  90. vw.name.first_name = str
  91. trg.name.first_name = str
  92. end
  93. end)
  94. return str
  95. end
  96. function namescr:onRenderBody(dc)
  97. self._native.parent:render()
  98. end
  99. function namescr:onInput(keys)
  100. if keys.SELECT then
  101. self:setName()
  102. end
  103. if keys.CUSTOM_F then
  104. self:setFirst()
  105. if not str==nil then
  106. trg.name.first_name = str
  107. end
  108. end
  109. if keys.LEAVESCREEN then
  110. self:setName()
  111. self:dismiss()
  112. dfhack.screen.dismiss(self._native.parent)
  113. end
  114. return
  115. gui.simulateInput(self._native.parent, keys)
  116. end
  117. namescr():show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement