Guest User

Untitled

a guest
Apr 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. --#textdomain wesnoth-NX-RPG
  2. _ = wesnoth.textdomain "wesnoth-NX-RPG"
  3.  
  4. --This dialogue pops up when you move to pick up an item
  5. function wml_actions.inventory_item(cfg)
  6. local image_and_description = T.grid { T.row { T.column { vertical_alignment = "center",
  7. horizontal_alignment = "center",
  8. border = "all",
  9. border_size = 5,
  10. T.image { id = "image_name" } },
  11. T.column { horizontal_alignment = "left",
  12. border = "all",
  13. border_size = 5,
  14. T.scroll_label { id = "item_description" } }
  15. } }
  16.  
  17. local buttonbox = T.grid { T.row { T.column { T.button { id = "take_button", return_value = 1 } },
  18. T.column { T.spacer { width = 10 } },
  19. T.column { T.button { id = "leave_button", return_value = 2 } }
  20. } }
  21.  
  22. local item_dialog = { T.helptip { id="tooltip_large" }, -- mandatory field
  23. T.tooltip { id="tooltip_large" }, -- mandatory field
  24. maximum_height = 320,
  25. maximum_width = 480,
  26. T.grid { -- Title, will be the object name
  27. T.row { T.column { horizontal_alignment = "left",
  28. grow_factor = 1, -- this one makes the title bigger and golden
  29. border = "all",
  30. border_size = 5,
  31. T.label { definition = "title", id = "item_name" } } },
  32. -- Image and item description
  33. T.row { T.column { image_and_description } }, -- grid teminator
  34. -- Effect description
  35. T.row { T.column { horizontal_alignment = "left",
  36. border = "all",
  37. border_size = 5,
  38. T.label { wrap = true, id = "item_effect" } } }, -- how to format?
  39. -- button box
  40. T.row { T.column { buttonbox } }
  41. }
  42. }
  43.  
  44. local function item_preshow()
  45. -- here set all widget starting values
  46. wesnoth.set_dialog_value ( cfg.name, "item_name" )
  47. wesnoth.set_dialog_value ( cfg.image or "", "image_name" )
  48. wesnoth.set_dialog_value ( cfg.description, "item_description" )
  49. wesnoth.set_dialog_value ( cfg.action, "item_effect" )
  50. wesnoth.set_dialog_value ( _"Use and add to inventory" or helper.wml_error( "Missing take_string= key in [item_dialog]" ), "take_button" )
  51. wesnoth.set_dialog_value ( _"Put back down" or helper.wml_error( "Missing leave_string= key in [item_dialog]" ), "leave_button" )
  52. end
  53.  
  54. local function sync()
  55. local function item_postshow()
  56. -- here get all widget values
  57. end
  58.  
  59. local return_value = wesnoth.show_dialog( item_dialog, item_preshow, item_postshow )
  60.  
  61. return { return_value = return_value }
  62. end
  63.  
  64. local return_table = wesnoth.synchronize_choice(sync)
  65. if return_table.return_value == 1 or return_table.return_value == -1 then
  66. if cfg.status == "personal" then
  67. local u_id = wesnoth.get_variable("unit.id")
  68. local i_index = wesnoth.get_variable(u_id .. "." .. cfg.section .. ".length")
  69. var_path = u_id .. "." .. cfg.section .. "[" .. i_index .. "]" --(u_id.%s[%i]):format(cfg.section, i_index)
  70.  
  71. wesnoth.set_variable(u_id .. ".inventory.picked_" .. cfg.id, "yes")
  72.  
  73. elseif cfg.status == "shared" then
  74. local i_index = wesnoth.get_variable("shared_inventory." .. cfg.section .. ".length")
  75. var_path = "shared_inventory." .. cfg.section .. "[" .. i_index .. "]"
  76.  
  77. wesnoth.set_variable("shared_inventory.inventory.picked_" .. cfg.id, "yes")
  78. end
  79. wesnoth.set_variable(var_path .. ".name", cfg.name)
  80. wesnoth.set_variable(var_path .. ".id", cfg.id)
  81. wesnoth.set_variable(var_path .. ".image", cfg.image)
  82. wesnoth.set_variable(var_path .. ".description", cfg.description)
  83. wesnoth.set_variable(var_path .. ".status", cfg.status)
  84.  
  85. local item_action = helper.get_child(cfg, "command")
  86. local remove_action = helper.get_child(cfg, "remove_command")
  87.  
  88. wesnoth.set_variable(var_path .. ".command", item_action.__literal)
  89. wesnoth.set_variable(var_path .. ".remcommand", remove_action.__literal)
  90.  
  91. wesnoth.set_variable("continue_with_code", "yes")
  92.  
  93. var_path = nil
  94. end
  95. end
  96.  
  97. -- This brings up the custom inventory control window
  98. function wml_actions.inventory_controller(cfg)
  99. local item_list = T.listbox { id = "inventory_list",
  100. definition = "default",
  101. T.list_definition { T.row { T.column { vertical_grow = "true",
  102. horizontal_grow = "true",
  103. T.toggle_panel { T.grid { T.row { T.column { grow_factor = 0,
  104. horizontal_alignment = "left",
  105. border = "all",
  106. border_size = 5,
  107. T.toggle_button { id = "checkbox",
  108. definition = "default",
  109. linked_group = "checkbox" } },
  110. T.column { grow_factor = 1,
  111. horizontal_grow = "true",
  112. border = "all",
  113. border_size = 5,
  114. T.image { id = "image",
  115. definition = "default" } },
  116. T.column { grow_factor = 1,
  117. horizontal_grow = "true",
  118. border = "all",
  119. border_size = 5,
  120. T.label { id = "name",
  121. definition = "default",
  122. linked_group = "name" } } } } } } } } }
  123. --T.list_data { temp_list_data } }
  124.  
  125. local main_window = { T.helptip { id="tooltip_large" }, -- mandatory field
  126. T.tooltip { id="tooltip_large" }, -- mandatory field
  127. window_height = 600,
  128. window_width = 700,
  129. T.grid { T.row { growth_factor = 0,
  130. T.column { grow_factor = 1,
  131. horizontal_alignment = "left",
  132. border = "all",
  133. border_size = 5,
  134. T.label { definition = "title",
  135. label = _"Inventory" } },
  136. T.column { T.spacer { definition = "default" } },
  137. T.column { T.spacer { definition = "default" } } },
  138. T.row { T.column { T.grid { T.row { item_list } } },
  139. T.column { T.spacer { definition = "default" } },
  140. T.column { T.spacer { definition = "default" } } },
  141. T.row { T.column { vertical_alignment = "center",
  142. horizontal_alignment = "center",
  143. border = "all",
  144. border_size = 5,
  145. T.image { id = image } },
  146. T.column { vertical_alignment = "top",
  147. horizontal_alignment = "center",
  148. border = "all",
  149. border_size = 5,
  150. T.label { id = "description" } },
  151. T.column { T.grid { T.row { T.column { T.button { id = "switch_button", return_value = 3 } } },
  152. T.row { T.column { T.button { id = "leave_chest_button", return_value = 2 } } },
  153. T.row { T.column { T.button { id = "ok_button", return_value = 1 } } } } } }
  154. } }
  155.  
  156. local function item_preshow()
  157. temp_list_data = { name = { }, image = { } }
  158. function inventory_category_scan(section)
  159. u_id = wesnoth.get_variable("unit.id")
  160. i = 0
  161.  
  162. repeat
  163. table .insert(temp_list_data.name, i , wesnoth.get_variable( u_id .. section .. "[" .. i .. "].name"))
  164. table .insert(temp_list_data.image, i , wesnoth.get_variable( u_id .. section .. "[" .. i .. "].image"))
  165.  
  166. i = i + 1
  167. until i == wesnoth.get_variable( u_id .. section .. ".length")
  168. end
  169.  
  170. inventory_category_scan(items)
  171. inventory_category_scan(weapons)
  172. inventory_category_scan(potions)
  173.  
  174. wesnoth.set_dialog_value ( "DESCRIPTION PLACEHOLDER", "description" )
  175. wesnoth.set_dialog_value ( "Switch items", "switch_button" )
  176. wesnoth.set_dialog_value ( "Leave in chest", "leave_chest_button" )
  177. wesnoth.set_dialog_value ( "Exit", "ok_button" )
  178. end
  179.  
  180. local function sync()
  181. local function item_postshow()
  182. end
  183.  
  184. local return_value = wesnoth.show_dialog( main_window, item_preshow, item_postshow )
  185.  
  186. return { return_value = return_value }
  187. end
  188.  
  189. local return_table = wesnoth.synchronize_choice(sync)
  190. end
Add Comment
Please, Sign In to add comment