shadowm

Untitled

Mar 31st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. ---
  2. -- Image Path Function Test
  3. --
  4. -- Usage:
  5. --   * :debug or the -d command line switch to enter debug mdoe.
  6. --   * :lua wesnoth.image_test()
  7. --
  8. -- You may create an alias command as follows:
  9. --   * :alias image_test=lua wesnoth.image_test()
  10. --
  11. -- For more information about image path functions, see:
  12. --   http://wiki.wesnoth.org/ImagePathFunctionWML
  13. ---
  14.  
  15. helper = wesnoth.require "lua/helper.lua"
  16. T = helper.set_wml_tag_metatable {}
  17.  
  18. local image_test_dialog = {
  19.     --maximum_width = 800,
  20.     --maximum_height = 600,
  21.  
  22.     T.helptip { id="tooltip_large" }, -- mandatory field
  23.     T.tooltip { id="tooltip_large" }, -- mandatory field
  24.  
  25.     T.grid {
  26.         T.row {
  27.             T.column {
  28.                 border = "all", border_size = 5,
  29.                 vertical_alignment = "top",
  30.                 horizontal_alignment = "left",
  31.                 T.label {
  32.                     definition = "title",
  33.                     label = "Image Test",
  34.                 }
  35.             }
  36.         },
  37.         T.row {
  38.             T.column {
  39.                 border = "all", border_size = 5,
  40.                 horizontal_alignment = "center",
  41.                 T.panel {
  42.                     id = "image_panel",
  43.                     T.grid {
  44.                         T.row {
  45.                             T.column {
  46.                                 vertical_alignment = "center",
  47.                                 horizontal_alignment = "center",
  48.                                 T.image {
  49.                                     id = "image"
  50.                                 }
  51.                             },
  52.                             T.column {
  53.                                 T.spacer { height = 288 }
  54.                             }
  55.                         },
  56.                         T.row {
  57.                             T.column {
  58.                                 T.spacer { width = 288 }
  59.                             },
  60.                             T.column {
  61.                                 T.spacer {}
  62.                             }
  63.                         }
  64.                     }
  65.                 }
  66.             }
  67.         },
  68.         T.row {
  69.             T.column {
  70.                 grow_factor = 1,
  71.                 horizontal_grow = true,
  72.                 T.grid {
  73.                     T.row {
  74.                         T.column {
  75.                             grow_factor = 0,
  76.                             horizontal_grow = false,
  77.                             border = "all", border_size = 5,
  78.                             T.label {
  79.                                 label = "Path:"
  80.                             }
  81.                         },
  82.                         T.column {
  83.                             grow_factor = 1,
  84.                             horizontal_grow = true,
  85.                             border = "all", border_size = 5,
  86.                             T.text_box {
  87.                                 id = "path",
  88.                             }
  89.                         },
  90.                         T.column {
  91.                             grow_factor = 0,
  92.                             horizontal_grow = false,
  93.                             border = "all", border_size = 5,
  94.                             T.button {
  95.                                 id = "show",
  96.                                 label = "Show"
  97.                             }
  98.                         }
  99.                     },
  100.                     T.row {
  101.                         T.column {
  102.                             T.spacer {}
  103.                         },
  104.                         T.column {
  105.                             T.spacer {}
  106.                         },
  107.                         T.column {
  108.                             horizontal_grow = false,
  109.                             border = "all", border_size = 5,
  110.                             T.button {
  111.                                 id = "clear",
  112.                                 label = "Clear"
  113.                             }
  114.                         }
  115.                     }
  116.                 }
  117.             }
  118.         },
  119.         T.row {
  120.             T.column {
  121.                 T.spacer { width = 1024 }
  122.             }
  123.         },
  124.         T.row {
  125.             T.column {
  126.                 border = "all", border_size = 5,
  127.                 horizontal_alignment = "right",
  128.                 T.button {
  129.                     id = "cancel",
  130.                     label = "Close",
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
  136.  
  137. -- Preserve the last value set on the dialog between runs in the same session.
  138. local path = "items/gold-coins-large.png" ..
  139.         "~BLIT(units/orcs/grunt-die-7.png~FL(horiz)~O(85%))" ..
  140.         "~BLIT(projectiles/hatchet-2.png~CS(-200,-200,-200))" ..
  141.         "~BLIT(halo/misc/leadership-flare-3.png)"
  142.  
  143. function wesnoth.image_test()
  144.     local function do_show_image()
  145.         path = wesnoth.get_dialog_value("path")
  146.         wesnoth.set_dialog_value(path, "image")
  147.     end
  148.  
  149.     local function do_clear()
  150.         wesnoth.set_dialog_value("", "path")
  151.         do_show_image()
  152.     end
  153.  
  154.     local function preshow()
  155.         wesnoth.set_dialog_value(path, "path")
  156.         wesnoth.set_dialog_value(path, "image")
  157.  
  158.         wesnoth.set_dialog_callback(do_show_image, "show")
  159.         wesnoth.set_dialog_callback(do_clear,      "clear")
  160.  
  161.         wesnoth.set_dialog_canvas(1, {
  162.             T.rectangle {
  163.                 x = 0,
  164.                 y = 0,
  165.                 w = "(width)",
  166.                 h = "(height)",
  167.                 fill_color = "0,0,0,64"
  168.             } }, "image_panel")
  169.     end
  170.  
  171.     local function postshow()
  172.         path = wesnoth.get_dialog_value("path")
  173.     end
  174.  
  175.     local res
  176.     repeat
  177.         -- Keep displaying the dialog until it is closed by means other than
  178.         -- pressing Enter, capturing path box updates on postshow accordingly.
  179.         res = wesnoth.show_dialog(image_test_dialog, preshow, postshow)
  180.     until res ~= -1
  181. end
Advertisement
Add Comment
Please, Sign In to add comment