Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --#textdomain wesnoth-NX-RPG
- _ = wesnoth.textdomain "wesnoth-NX-RPG"
- --This dialogue pops up when you move to pick up an item
- function wml_actions.inventory_item(cfg)
- local image_and_description = T.grid { T.row { T.column { vertical_alignment = "center",
- horizontal_alignment = "center",
- border = "all",
- border_size = 5,
- T.image { id = "image_name" } },
- T.column { horizontal_alignment = "left",
- border = "all",
- border_size = 5,
- T.scroll_label { id = "item_description" } }
- } }
- local buttonbox = T.grid { T.row { T.column { T.button { id = "take_button", return_value = 1 } },
- T.column { T.spacer { width = 10 } },
- T.column { T.button { id = "leave_button", return_value = 2 } }
- } }
- local item_dialog = { T.helptip { id="tooltip_large" }, -- mandatory field
- T.tooltip { id="tooltip_large" }, -- mandatory field
- maximum_height = 320,
- maximum_width = 480,
- T.grid { -- Title, will be the object name
- T.row { T.column { horizontal_alignment = "left",
- grow_factor = 1, -- this one makes the title bigger and golden
- border = "all",
- border_size = 5,
- T.label { definition = "title", id = "item_name" } } },
- -- Image and item description
- T.row { T.column { image_and_description } }, -- grid teminator
- -- Effect description
- T.row { T.column { horizontal_alignment = "left",
- border = "all",
- border_size = 5,
- T.label { wrap = true, id = "item_effect" } } }, -- how to format?
- -- button box
- T.row { T.column { buttonbox } }
- }
- }
- local function item_preshow()
- -- here set all widget starting values
- wesnoth.set_dialog_value ( cfg.name, "item_name" )
- wesnoth.set_dialog_value ( cfg.image or "", "image_name" )
- wesnoth.set_dialog_value ( cfg.description, "item_description" )
- wesnoth.set_dialog_value ( cfg.action, "item_effect" )
- wesnoth.set_dialog_value ( _"Use and add to inventory" or helper.wml_error( "Missing take_string= key in [item_dialog]" ), "take_button" )
- wesnoth.set_dialog_value ( _"Put back down" or helper.wml_error( "Missing leave_string= key in [item_dialog]" ), "leave_button" )
- end
- local function sync()
- local function item_postshow()
- -- here get all widget values
- end
- local return_value = wesnoth.show_dialog( item_dialog, item_preshow, item_postshow )
- return { return_value = return_value }
- end
- local return_table = wesnoth.synchronize_choice(sync)
- if return_table.return_value == 1 or return_table.return_value == -1 then
- if cfg.status == "personal" then
- local u_id = wesnoth.get_variable("unit.id")
- local i_index = wesnoth.get_variable(u_id .. "." .. cfg.section .. ".length")
- var_path = u_id .. "." .. cfg.section .. "[" .. i_index .. "]" --(u_id.%s[%i]):format(cfg.section, i_index)
- wesnoth.set_variable(u_id .. ".inventory.picked_" .. cfg.id, "yes")
- elseif cfg.status == "shared" then
- local i_index = wesnoth.get_variable("shared_inventory." .. cfg.section .. ".length")
- var_path = "shared_inventory." .. cfg.section .. "[" .. i_index .. "]"
- wesnoth.set_variable("shared_inventory.inventory.picked_" .. cfg.id, "yes")
- end
- wesnoth.set_variable(var_path .. ".name", cfg.name)
- wesnoth.set_variable(var_path .. ".id", cfg.id)
- wesnoth.set_variable(var_path .. ".image", cfg.image)
- wesnoth.set_variable(var_path .. ".description", cfg.description)
- wesnoth.set_variable(var_path .. ".status", cfg.status)
- local item_action = helper.get_child(cfg, "command")
- local remove_action = helper.get_child(cfg, "remove_command")
- wesnoth.set_variable(var_path .. ".command", item_action.__literal)
- wesnoth.set_variable(var_path .. ".remcommand", remove_action.__literal)
- wesnoth.set_variable("continue_with_code", "yes")
- var_path = nil
- end
- end
- -- This brings up the custom inventory control window
- function wml_actions.inventory_controller(cfg)
- local item_list = T.listbox { id = "inventory_list",
- definition = "default",
- T.list_definition { T.row { T.column { vertical_grow = "true",
- horizontal_grow = "true",
- T.toggle_panel { T.grid { T.row { T.column { grow_factor = 0,
- horizontal_alignment = "left",
- border = "all",
- border_size = 5,
- T.toggle_button { id = "checkbox",
- definition = "default",
- linked_group = "checkbox" } },
- T.column { grow_factor = 1,
- horizontal_grow = "true",
- border = "all",
- border_size = 5,
- T.image { id = "image",
- definition = "default" } },
- T.column { grow_factor = 1,
- horizontal_grow = "true",
- border = "all",
- border_size = 5,
- T.label { id = "name",
- definition = "default",
- linked_group = "name" } } } } } } } } }
- --T.list_data { temp_list_data } }
- local main_window = { T.helptip { id="tooltip_large" }, -- mandatory field
- T.tooltip { id="tooltip_large" }, -- mandatory field
- window_height = 600,
- window_width = 700,
- T.grid { T.row { growth_factor = 0,
- T.column { grow_factor = 1,
- horizontal_alignment = "left",
- border = "all",
- border_size = 5,
- T.label { definition = "title",
- label = _"Inventory" } },
- T.column { T.spacer { definition = "default" } },
- T.column { T.spacer { definition = "default" } } },
- T.row { T.column { T.grid { T.row { item_list } } },
- T.column { T.spacer { definition = "default" } },
- T.column { T.spacer { definition = "default" } } },
- T.row { T.column { vertical_alignment = "center",
- horizontal_alignment = "center",
- border = "all",
- border_size = 5,
- T.image { id = image } },
- T.column { vertical_alignment = "top",
- horizontal_alignment = "center",
- border = "all",
- border_size = 5,
- T.label { id = "description" } },
- T.column { T.grid { T.row { T.column { T.button { id = "switch_button", return_value = 3 } } },
- T.row { T.column { T.button { id = "leave_chest_button", return_value = 2 } } },
- T.row { T.column { T.button { id = "ok_button", return_value = 1 } } } } } }
- } }
- local function item_preshow()
- temp_list_data = { name = { }, image = { } }
- function inventory_category_scan(section)
- u_id = wesnoth.get_variable("unit.id")
- i = 0
- repeat
- table .insert(temp_list_data.name, i , wesnoth.get_variable( u_id .. section .. "[" .. i .. "].name"))
- table .insert(temp_list_data.image, i , wesnoth.get_variable( u_id .. section .. "[" .. i .. "].image"))
- i = i + 1
- until i == wesnoth.get_variable( u_id .. section .. ".length")
- end
- inventory_category_scan(items)
- inventory_category_scan(weapons)
- inventory_category_scan(potions)
- wesnoth.set_dialog_value ( "DESCRIPTION PLACEHOLDER", "description" )
- wesnoth.set_dialog_value ( "Switch items", "switch_button" )
- wesnoth.set_dialog_value ( "Leave in chest", "leave_chest_button" )
- wesnoth.set_dialog_value ( "Exit", "ok_button" )
- end
- local function sync()
- local function item_postshow()
- end
- local return_value = wesnoth.show_dialog( main_window, item_preshow, item_postshow )
- return { return_value = return_value }
- end
- local return_table = wesnoth.synchronize_choice(sync)
- end
Add Comment
Please, Sign In to add comment