Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- -- Image Path Function Test
- --
- -- Usage:
- -- * :debug or the -d command line switch to enter debug mdoe.
- -- * :lua wesnoth.image_test()
- --
- -- You may create an alias command as follows:
- -- * :alias image_test=lua wesnoth.image_test()
- --
- -- For more information about image path functions, see:
- -- http://wiki.wesnoth.org/ImagePathFunctionWML
- ---
- helper = wesnoth.require "lua/helper.lua"
- T = helper.set_wml_tag_metatable {}
- local image_test_dialog = {
- --maximum_width = 800,
- --maximum_height = 600,
- T.helptip { id="tooltip_large" }, -- mandatory field
- T.tooltip { id="tooltip_large" }, -- mandatory field
- T.grid {
- T.row {
- T.column {
- border = "all", border_size = 5,
- vertical_alignment = "top",
- horizontal_alignment = "left",
- T.label {
- definition = "title",
- label = "Image Test",
- }
- }
- },
- T.row {
- T.column {
- border = "all", border_size = 5,
- horizontal_alignment = "center",
- T.panel {
- id = "image_panel",
- T.grid {
- T.row {
- T.column {
- vertical_alignment = "center",
- horizontal_alignment = "center",
- T.image {
- id = "image"
- }
- },
- T.column {
- T.spacer { height = 288 }
- }
- },
- T.row {
- T.column {
- T.spacer { width = 288 }
- },
- T.column {
- T.spacer {}
- }
- }
- }
- }
- }
- },
- T.row {
- T.column {
- grow_factor = 1,
- horizontal_grow = true,
- T.grid {
- T.row {
- T.column {
- grow_factor = 0,
- horizontal_grow = false,
- border = "all", border_size = 5,
- T.label {
- label = "Path:"
- }
- },
- T.column {
- grow_factor = 1,
- horizontal_grow = true,
- border = "all", border_size = 5,
- T.text_box {
- id = "path",
- }
- },
- T.column {
- grow_factor = 0,
- horizontal_grow = false,
- border = "all", border_size = 5,
- T.button {
- id = "show",
- label = "Show"
- }
- }
- },
- T.row {
- T.column {
- T.spacer {}
- },
- T.column {
- T.spacer {}
- },
- T.column {
- horizontal_grow = false,
- border = "all", border_size = 5,
- T.button {
- id = "clear",
- label = "Clear"
- }
- }
- }
- }
- }
- },
- T.row {
- T.column {
- T.spacer { width = 1024 }
- }
- },
- T.row {
- T.column {
- border = "all", border_size = 5,
- horizontal_alignment = "right",
- T.button {
- id = "cancel",
- label = "Close",
- }
- }
- }
- }
- }
- -- Preserve the last value set on the dialog between runs in the same session.
- local path = "items/gold-coins-large.png" ..
- "~BLIT(units/orcs/grunt-die-7.png~FL(horiz)~O(85%))" ..
- "~BLIT(projectiles/hatchet-2.png~CS(-200,-200,-200))" ..
- "~BLIT(halo/misc/leadership-flare-3.png)"
- function wesnoth.image_test()
- local function do_show_image()
- path = wesnoth.get_dialog_value("path")
- wesnoth.set_dialog_value(path, "image")
- end
- local function do_clear()
- wesnoth.set_dialog_value("", "path")
- do_show_image()
- end
- local function preshow()
- wesnoth.set_dialog_value(path, "path")
- wesnoth.set_dialog_value(path, "image")
- wesnoth.set_dialog_callback(do_show_image, "show")
- wesnoth.set_dialog_callback(do_clear, "clear")
- wesnoth.set_dialog_canvas(1, {
- T.rectangle {
- x = 0,
- y = 0,
- w = "(width)",
- h = "(height)",
- fill_color = "0,0,0,64"
- } }, "image_panel")
- end
- local function postshow()
- path = wesnoth.get_dialog_value("path")
- end
- local res
- repeat
- -- Keep displaying the dialog until it is closed by means other than
- -- pressing Enter, capturing path box updates on postshow accordingly.
- res = wesnoth.show_dialog(image_test_dialog, preshow, postshow)
- until res ~= -1
- end
Advertisement
Add Comment
Please, Sign In to add comment