File: richtext_scenarios.lua

package info (click to toggle)
widelands 2%3A1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684,084 kB
  • sloc: cpp: 196,737; ansic: 19,395; python: 8,515; sh: 1,734; xml: 700; makefile: 46; lisp: 25
file content (108 lines) | stat: -rw-r--r-- 3,153 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
include "scripting/richtext.lua"

-- RST
-- .. _richtext_scenarios.lua:
--
-- richtext_scenarios.lua
-- ----------------------
--
-- Functions to simplify text formatting in scenarios and make it consistent.
-- Most of these functions are simple wrapper functions for our :ref:`richtext system <wlrichtext>`.
-- This file will include :ref:`richtext.lua` for you for additional formatting functions.
--
-- To make these functions available include this file at the beginning
-- of a script via:
--
-- .. code-block:: lua
--
--    include "scripting/richtext_scenarios.lua"
--

-- RST
-- .. function:: speech(img, clr, title, text)
--
--    Formats a text as spoken by one person in a scenario. Use it as follows:
--
--    .. code-block:: lua
--
--        function jundlina(title, text)
--           return speech("map:princess.png", "2F9131", title, text)
--        end
--
--    :arg img: name of the image to use for this speaker
--    :type img: :class:`string`
--    :arg clr: A valid 6 char hex color to use for the name of this speaker.
--              Best practice is to use `styles.color()` to get a color value from the style
--              manager whenever possible.
--    :type clr: :class:`string`
--    :arg title: Title of this text. Use empty string if you don't want any.
--    :type title: :class:`string`
--    :arg text: The text itself.
--    :type text: :class:`string`
--
--    :returns: the formatted text.

function speech(img, clr, title, text)
   if title ~= "" then
      title = h1(clr, title)
   end

   -- Surround the text with translatable “quotes”
   push_textdomain("widelands")
   text = (_("“%s”")):format(text)
   pop_textdomain()

   return title .. li_image(img, p(text))
end


-- RST
-- .. function:: paragraphdivider()
--
--    Closes a paragraph and opens a new paragraph. Use this when you format
--    a :ref:`richtext<richtext.lua>` string and need to divide it into multiple paragraphs. Just concatenate
--    this function with the Lua string concatenation operator ``..``
--
--    :returns: close_p() .. open_p()
--
--    Example:
--
--    .. code-block:: lua
--
--       include "scripting/richtext.lua"
--       include "scripting/richtext_scenarios.lua"
--       include "scripting/messages.lua"
--
--       local text = p("This is the first paragraph"
--                      .. paragraphdivider() ..
--                      "This is the second paragraph"
--                     )
--
--       campaign_message_box({title = "Window title",
--                             body = text,
--                             w = 200,
--                             h = 150,
--                             position = "top"})
--

function paragraphdivider()
   return close_p() .. open_p()
end


-- RST
-- .. function:: objective_text(heading, body)
--
--    Provides nice formatting for objective texts.
--
--    :arg heading: The heading
--    :type heading: :class:`string`
--    :arg body: The text
--    :type body: :class:`string`
--
--    :returns: a rich text object that contains the formatted
--       objective text.

function objective_text(heading, body)
   return h2(heading) .. p(body)
end