~widelands-dev/widelands/split_up_liblogic_1_libraries

« back to all changes in this revision

Viewing changes to data/scripting/richtext_scenarios.lua

Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
include "scripting/richtext.lua"
 
2
 
1
3
-- RST
2
 
--
3
 
 
 
4
-- .. _richtext_scenarios.lua:
 
5
--
 
6
-- richtext_scenarios.lua
 
7
-- ----------------------
 
8
--
 
9
-- Functions to simplify text formatting in scenarios and make it consistent.
 
10
-- Most of these functions are simple wrapper functions for our :ref:`richtext system <wlrichtext>`.
 
11
-- This file will include :ref:`richtext.lua` for you for additional formatting functions.
4
12
 
5
13
-- RST
6
14
-- .. function:: speech(img, clr, title, text)
20
23
--
21
24
--    :arg img: name of the image to use for this speaker
22
25
--    :arg clr: a valid 6 char hex color to use for the name of this speaker
 
26
--    :arg title: Title of this text. Use empty string if you don't want any.
 
27
--    :arg text: The text itself.
23
28
--    :returns: the formatted text.
24
 
--
25
 
function speech(img, clr, g_title, g_text)
26
 
   local title, text = g_title, g_text
27
 
   if not text then
28
 
      title = nil
29
 
      text = g_title
 
29
 
 
30
function speech(img, clr, title, text)
 
31
   if title ~= "" then
 
32
      title = h1(clr, title)
30
33
   end
31
34
 
32
35
   -- Surround the text with translatable ","
33
36
   text = (_'“%s”'):format(text)
34
37
 
35
 
   local s = ""
36
 
   if title then
37
 
      s = rt("<p font-size=20 font-weight=bold font-face=serif " ..
38
 
         ("font-color=%s>"):format(clr) .. title ..
39
 
         "</p><p font-size=8> <br></p>"
40
 
      )
41
 
   end
42
 
 
43
 
   return s .. rt(("image=%s"):format(img), p(text))
 
38
   return title .. li_image(img, p(text))
 
39
end
 
40
 
 
41
 
 
42
-- RST
 
43
-- .. function:: paragraphdivider()
 
44
--
 
45
--    Closes a paragraph and opens a new paragraph. Use this when you format a string with the speech function
 
46
--    and need to divide the speech into multiple paragraphs.
 
47
--
 
48
--    :returns: close_p() .. open_p()
 
49
 
 
50
function paragraphdivider()
 
51
   return close_p() .. open_p()
44
52
end
45
53
 
46
54
 
54
59
--
55
60
--    :returns: a rich text object that contains the formatted
56
61
--       objective text.
57
 
--
 
62
 
58
63
function objective_text(heading, body)
59
 
   return rt(h2(heading) .. p(body))
 
64
   return h2(heading) .. p(body)
60
65
end
61
66
 
62
67
 
63
68
-- RST
 
69
-- .. function:: new_objectives(...)
 
70
--
 
71
--    Append an objective text with a header to a dialog box in a nice fashion.
 
72
--    For displaying objectives with an extra title when an advisor is talking
64
73
--
65
74
--    Provides nice formatting for objective texts.
 
75
--    The following arguments will be parsed:
 
76
--
 
77
--       - number: the number of objectives described in the body
 
78
--       - body: the objective text, e.g. created with function objective_text(heading, body)
66
79
--
67
80
--    :returns: a rich text object that contains the formatted
68
81
--       objective text & title.
69
 
--
 
82
 
70
83
function new_objectives(...)
71
84
   local sum = 0
72
 
   local s = ""
 
85
   local text = ""
73
86
   for idx,obj in ipairs{...} do
74
 
      s = s .. obj.body
 
87
      text = text .. obj.body
75
88
      sum = sum + obj.number
76
89
   end
77
 
   return rt("<p font-size=10> <br></p>" ..
78
 
      "<p font=serif font-size=18 font-weight=bold font-color=D1D1D1>"
79
 
      .. ngettext("New Objective", "New Objectives", sum) .. "</p>") .. s
 
90
   return h1(ngettext("New Objective", "New Objectives", sum)) .. text
80
91
end