Ability to add names to dialog boxes

http://forum.solarus-games.org/index.php/topic,1273.0.html
Thanks llamazing!
parent 065bd393
......@@ -1208,6 +1208,7 @@ you'll surely drown.
dialog{
id = "intro.greybeard.1",
text = [[
##Greybeard
Hello? Are you awake?
......
properties{
x = 0,
y = 0,
width = 256,
height = 144,
min_layer = 0,
max_layer = 2,
tileset = "zoria",
}
tile{
layer = 0,
x = 0,
y = 0,
width = 256,
height = 144,
pattern = "grass.soil",
}
npc{
layer = 0,
x = 128,
y = 61,
direction = 3,
subtype = 1,
sprite = "animals/beaver",
behavior = "dialog#intro.greybeard.1",
}
destination{
name = "destination",
layer = 0,
x = 128,
y = 101,
direction = 1,
}
npc{
layer = 0,
x = 128,
y = 117,
direction = 3,
subtype = 1,
sprite = "animals/beaver",
behavior = "dialog#intro.greybeard.1",
}
-- Lua script of map _test/dialog_box.
-- This script is executed every time the hero enters this map.
-- Feel free to modify the code below.
-- You can add more events and remove the ones you don't need.
-- See the Solarus Lua API documentation:
-- http://www.solarus-games.org/doc/latest
local map = ...
local game = map:get_game()
-- Event called at initialization time, as soon as this map is loaded.
function map:on_started()
-- You can initialize the movement and sprites of various
-- map entities here.
end
-- Event called after the opening transition effect of the map,
-- that is, when the player takes control of the hero.
function map:on_opening_transition_finished()
end
......@@ -2,6 +2,7 @@ map{ id = "0000", description = "Title screen hack" }
map{ id = "_stage/gandhi", description = "Gandhi room" }
map{ id = "_stage/greybeard_intro", description = "Greybeard intro" }
map{ id = "_stage/item_star", description = "Item star" }
map{ id = "_test/dialog_box", description = "Dialog box test" }
map{ id = "_unused/caves/cave", description = "Beach/forest connection" }
map{ id = "_unused/caves/dungeon_path", description = "Path to water dungeon" }
map{ id = "_unused/forest/forest", description = "Forest" }
......@@ -334,8 +335,9 @@ file{ path = "scripts/features.lua", author = "Christopho; Alex Gleason", licens
file{ path = "scripts/game_manager.lua", author = "Christopho; Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/initial_game.lua", author = "Christopho; Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/item_auto_assign.lua", author = "Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/language_manager.lua", author = "Christopho", license = "GPL-3.0-or-later" }
file{ path = "scripts/menus", author = "Alex Gleason; Christopho; Maxs", license = "GPL-3.0-or-later" }
file{ path = "scripts/menus/dialog_box.lua", author = "Christopho; Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/menus/dialog_box.lua", author = "Christopho; llamazing; Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/menus/end_card.lua", author = "Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/menus/end_credits.lua", author = "Alex Gleason", license = "GPL-3.0-or-later" }
file{ path = "scripts/menus/hud.lua", author = "Alex Gleason", license = "GPL-3.0-or-later" }
......
-- This script provides configuration information about text and languages.
--
-- Usage:
-- local language_manager = require("scripts/language_manager")
local language_manager = {}
local default_language = "en"
-- Returns the id of the default language.
function language_manager:get_default_language()
return default_language
end
-- Returns the font and font size to be used for dialogs
-- depending on the specified language (the current one by default).
function language_manager:get_dialog_font(language)
-- No font differences between languages (for now).
return "enter_command", 16
end
-- Returns the font and font size to be used to display text in menus
-- depending on the specified language (the current one by default).
function language_manager:get_menu_font(language)
-- No font differences between languages (for now).
return "enter_command", 16
end
-- Returns the font and font size to be used to display text on HUD icons
-- depending on the specified language (the current one by default).
function language_manager:get_hud_icons_font(language)
-- No font differences between languages (for now).
return "enter_command", 16
end
return language_manager
......@@ -4,6 +4,7 @@
-- require("scripts/menus/dialog_box")
require("scripts/multi_events")
local language_manager = require("scripts/language_manager")
-- Creates and sets up a dialog box for the specified game.
local function initialize_dialog_box_features(game)
......@@ -37,6 +38,9 @@ local function initialize_dialog_box_features(game)
full = false, -- Whether the 3 visible lines have shown all content.
need_letter_sound = false, -- Whether a sound should be played with the next character.
gradual = true, -- Whether text is displayed gradually.
is_name = nil, -- Whether name box is visible
is_name_on_right = nil, -- If true then name is drawn on right side of dialog box.
name_surface = nil, -- Text surface for name text
-- Graphics.
dialog_surface = nil,
......@@ -71,6 +75,14 @@ local function initialize_dialog_box_features(game)
font_size = font_size,
}
end
dialog_box.name = ""
dialog_box.name_surface = sol.text_surface.create{
horizontal_alignment = "left",
vertical_alignment = "top",
font = font,
color = {0, 0, 0},
font_size = font_size,
}
dialog_box.dialog_surface = sol.surface.create(sol.video.get_quest_size())
dialog_box.box_img = sol.surface.create("hud/dialog_box.png")
dialog_box.icons_img = sol.surface.create("hud/dialog_icons.png")
......@@ -104,6 +116,8 @@ local function initialize_dialog_box_features(game)
end
dialog_box.dialog = nil
dialog_box.info = nil
dialog_box.is_name = nil
dialog_box.is_name_on_right = nil
end)
-- Sets the style of the dialog box for subsequent dialogs.
......@@ -115,7 +129,7 @@ local function initialize_dialog_box_features(game)
dialog_box.style = style
if style == "box" then
-- Make the dialog box slightly transparent.
dialog_box.dialog_surface:set_opacity(216)
-- dialog_box.dialog_surface:set_opacity(216)
end
end
......@@ -179,7 +193,7 @@ local function initialize_dialog_box_features(game)
local y = (screen_height - 52)
if top then
y = 4
y = 16
end
self.box_dst_position = { x = x, y = y }
......@@ -322,6 +336,23 @@ local function initialize_dialog_box_features(game)
end
end
-- Check if name should be displayed
if self:has_more_lines() then
local is_empty, is_right, is_special, name = self.next_line:match"^%s*##(#?)(>?)([@&]?)(.*)"
if name then
self.is_name = is_empty=="" --3rd # hides name
self.is_name_on_right = is_right==">"
if is_special=="&" then --use savegame value
self.name_surface:set_text(game:get_value(name) or "")
elseif is_special=="@" then --use strings.dat value
self.name_surface:set_text(sol.language.get_string(name) or "")
else
self.name_surface:set_text(name)
end
self.next_line = self.line_it()
end
end
-- Prepare the 3 lines.
for i = 1, nb_visible_lines do
self.line_surfaces[i]:set_text("")
......@@ -500,6 +531,32 @@ local function initialize_dialog_box_features(game)
-- Draw a dark rectangle.
self.bg_sprite:draw(dst_surface, x, y)
-- Draw the name box.
if self.is_name then
local text_width = self.name_surface:get_size()
text_width = math.max(text_width, 12)
local right_offset = self.is_name_on_right and (188-text_width) or 0
self.box_img:draw_region( -- left side
204, 60, 4, 16, self.dialog_surface,
x + 12 + right_offset, y - 12
)
local x_offset = 0
while x_offset < text_width do
self.box_img:draw_region(
208, 60,
math.min(8, text_width - x_offset), 16,
self.dialog_surface,
x + 16 + x_offset + right_offset,
y - 12
)
x_offset = x_offset + 8
end
self.box_img:draw_region( -- right side
216, 60, 4, 16, self.dialog_surface,
x + 16 + text_width + right_offset, y - 12
)
self.name_surface:draw(self.dialog_surface, x + 16 + right_offset, y - 11)
end
-- Draw the text.
local text_x = x + (self.icon_index == nil and 8 or 16)
......
data/sprites/hud/dialog_box.png

128 Bytes | W: | H:

data/sprites/hud/dialog_box.png

178 Bytes | W: | H:

data/sprites/hud/dialog_box.png
data/sprites/hud/dialog_box.png
data/sprites/hud/dialog_box.png
data/sprites/hud/dialog_box.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment