Area Display announces the text areas of the map to the players who walk into them.
It takes over the textarea area type of the Areas API: while this plugin is loaded,
entering a text area shows its text as an area notice instead of the plain text the Areas
API draws on its own, so a player never gets both. Entering or leaving a text area runs
the PlayerEnteredTextArea and PlayerLeftTextArea hooks.
Staff create text areas with the Text Area mode of the Area Tool, which this plugin
replaces with one that also has a display style and a one-time switch. Right clicking
inside of an existing text area applies both to it. An area keeps them in its style and
once fields, next to its text.
A notice is drawn in a display style. Three come with the plugin: 'fade', a title that
fades in and out and is the default; 'typewriter', text that is typed out letter by letter
with a quiet sound; and 'cinematic', a caption between the letterbox bars of the
Cinematics plugin, which falls back to 'fade' when that plugin is not loaded. More are
added with AreaDisplay:register_style.
The same area is not announced again until the 'area_display_cooldown' config has passed.
A one-time area is shown to a player only once: the server remembers it in the data table
of the player (Player:set_player_data, under 'seen_areas'). Players turn the notices off
with the 'area_display' client setting when the Settings plugin is loaded.
The AdjustAreaDisplay hook lets other plugins change a notice before it is shown, for
example to put the in-game time into its text. The server shows a notice of its own with
AreaDisplay:show, client code with AreaDisplay:add.
The look comes from the theme, which the plugin fills in from its OnThemeLoaded handler:
the 'area_display_duration', 'area_display_fade_time', 'area_display_type_interval' and
'area_display_type_volume' options, the 'area_display_text' color, the 'area_display_type'
sound and the 'area_display_title' and 'area_display_typewriter' fonts.
Summary
Hooks
build_tool_mode).Methods
Hooks
Implements hook AddAreaToolModes
Replaces the Text Area mode of the Area Tool with the one of this plugin (see
build_tool_mode). The mode is passed through mode_list:Add, which fills in its defaults
and merges its convars into the tool, and then takes the place of the first Text Area mode
in the list; any other Text Area mode is removed, so that a code refresh does not leave
more than one behind. The mode stays at the end of the list if the Areas API has not added
its own.
Parameters
- mode_list Map the Area.tool_modes table; modes are added with mode_list:Add
AreaDisplay:ClientSettingChanged(id, value, _old_value)
client plugins/areadisplay/plugin/cl_hooks.lua:40Implements hook ClientSettingChanged
Takes the notices off the screen when the local player turns them off.
Parameters
- id String setting id
- value Any new value of the setting
- _old_value Any previous value of the setting
Implements hook FLHUDPaint
Announces the areas that were entered while the HUD was hidden and draws the notices that are on screen. The hook only runs while the local player is alive and the HUD is shown.
Parameters
- cur_time Number current CurTime()
- scrw Number screen width
- scrh Number screen height
Implements hook OnThemeLoaded
Sets the options, the color, the sound and the fonts of the area notices on the theme that was loaded.
Parameters
- current_theme ThemeBase
AreaDisplay:PlayerEnteredTextArea(_actor, area, _cur_time)
client plugins/areadisplay/plugin/cl_hooks.lua:80Implements hook PlayerEnteredTextArea
Announces the text area that the local player has entered.
Parameters
- _actor Player the player who entered the area
- area Map the area that was entered
- _cur_time Number CurTime at the moment of entering
Implements hook PlayerInitialized
Announces the text areas the local player is standing in when their client has finished loading. The Areas API reports an area once, at the moment the player enters it, and for a player who joins inside of one that is before their client is able to receive anything, so the area at the spawn point would never be announced. By the time this hook runs the areas have arrived from the server; the notice is kept as pending until the local player can see it.
AreaDisplay:PlayerLeftTextArea(_actor, area, _cur_time)
client plugins/areadisplay/plugin/cl_hooks.lua:89Implements hook PlayerLeftTextArea
Forgets the text area that the local player has left, if it was still waiting to be announced.
Parameters
- _actor Player the player who left the area
- area Map the area that was left
- _cur_time Number CurTime at the moment of leaving
Implements hook RegisterClientSettings
Registers the 'area_display' client setting, which turns the area notices on and off.
Methods
Shows an area notice to the local player. Nothing is shown while the notices are turned off or the local player cannot see them, or when a notice of the same area is on screen.
AreaDisplay:add('City 17')
AreaDisplay:add({ text = 'Sector 7', style = 'typewriter', duration = 4 })
Parameters
- info String/Map text or language phrase of the notice, or a table with the fields: text, style (ID of a display style, the default style if left out or not registered), color (Color of the text, the 'area_display_text' theme color by default), duration (seconds the notice stays once it has appeared, the 'area_display_duration' theme option by default) and area_id (ID of the area the notice belongs to)
- area Map optional, defaults to
nilthe area that is being announced, passed on to the hook
Returns
- Map the notice, or nil if nothing is shown
See also
Announces an area to the local player. An area that was announced less than 'area_display_cooldown' seconds ago is skipped. A one-time area is not shown right away: the server is asked first, and shows it if the player has not seen it before. If the local player cannot see notices at the moment, the area is announced once they can, unless they leave it first.
Parameters
- area Map the area, with the
id,text,styleandoncefields - force Boolean optional, defaults to
falseshow the notice regardless of the cooldown and of the area being a one-time one
Returns
- Boolean true if the notice has been shown, false otherwise
See also
Takes every notice off the screen and forgets the pending areas.
Draws the notices that are on screen and drops the ones that are over. Notices of the same style are stacked below one another.
Parameters
- cur_time Number current CurTime()
- scrw Number screen width
- scrh Number screen height
Returns a display style.
Parameters
- id String style ID
Returns
- Map the style, or nil if it is not registered
Finds a text area by its ID.
Parameters
- id String area ID
Returns
- Map the area, or nil if there is no text area with that ID
Finds the text area that a position is inside of.
Parameters
- pos Vector position to check, 16 units are added to its height as the Areas API does for players
Returns
- Map the first text area that contains the position, or nil if there is none
See also
Finds every text area that a position is inside of.
Parameters
- pos Vector position to check, 16 units are added to its height as the Areas API does for players
Returns
- List<Map> the text areas that contain the position, empty if there are none
Announces the areas that were entered while the local player could not see notices.
Returns the opacity of a notice at a point in time.
Parameters
- display Map the notice
- cur_time Number CurTime() to get the opacity at
Returns
- Number opacity from 0 to 255, or nil if the notice is over
Turns a value into the ID of a registered display style.
Parameters
- id Any style ID to check
Returns
- String the ID if such a style is registered, otherwise the ID of the default style
Returns every registered display style.
Returns
- Map styles keyed by style ID
Checks whether a player has already been shown a one-time area.
Parameters
- actor Player
- area Map the area
Returns
- Boolean
Checks whether the local player has area notices turned on. They are always on when the Settings plugin is not loaded.
Returns
- Boolean
Checks whether a notice can be seen by the local player right now: they are initialized, alive and, when the Characters plugin is loaded, have a character.
Returns
- Boolean
Registers a display style: a way of putting an area notice on the screen. Register it from shared code, so that the server accepts it from the Area Tool. Registering an ID again replaces the style.
local style = { name = 'my_schema.area_styles.corner' }
if CLIENT then
function style:draw(display, alpha, scrw, scrh, offset)
local font = Theme.get_font('text_normal')
local color = Theme.get_color('text'):alpha(alpha)
draw.SimpleText(display.text, font, 32, scrh - 64 - offset, color)
return util.font_size(font)
end
end
AreaDisplay:register_style('corner', style)
Parameters
- id String unique style ID, stored in the
stylefield of an area - data Map style definition: name (String phrase or text shown in the Area Tool, the ID by default) and the optional clientside functions is_available(style) (return false to have the default style used instead), start(style, display) (called when a notice is about to be shown, may change its
fade_in,holdandfade_outtimes; return false if the style shows the notice by other means and nothing is to be drawn) and draw(style, display, alpha, scrw, scrh, offset) (draws the notice at the given opacity from 0 to 255 and returns the height it took, which is the offset of the next notice of the same style)
Returns
- Map the registered style, or nil if the arguments are not valid
Sets whether a player has already been shown a one-time area. It is kept in the data table of the player, which is saved with their database record.
Parameters
- actor Player
- area Map the area
- seen Boolean optional, defaults to
truefalse to have the area shown to the player again
Shows an area notice to one player, several players or everyone. Clients that have the notices turned off, or whose player cannot see them at the moment, ignore it.
AreaDisplay:show(nil, 'The curfew has begun.')
AreaDisplay:show(target, { text = 'Sector 7', style = 'typewriter', duration = 4 })
Parameters
- targets Player/List<Player> who to show the notice to; everyone if nil. Players that are not valid any more are left out
- info String/Map text or language phrase of the notice, or a table with the fields that
AreaDisplay:addtakes on the client: text, style, color and duration
Returns
- Boolean true if the notice has been sent, false if it has no text
See also
Announces a text area to one player, several players or everyone, as if they had just entered it, but regardless of the cooldown and of the area being a one-time one.
Parameters
- targets Player/List<Player> who to announce the area to; everyone if nil. Players that are not valid any more are left out
- area Map the text area
Returns
- Boolean true if the request has been sent, false if the area is not valid