1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Added parameter passthrough to rendering module

This commit is contained in:
SimonFlapse 2019-06-09 13:31:44 +02:00
parent de77c9601a
commit f04b13f63a
3 changed files with 129 additions and 41 deletions

View File

@ -84,7 +84,7 @@ local function restart_cutscene(player_index, waypoints, start_index)
current_running.update = false
local character = current_running.character
game.print(character.position)
--game.print(character.position)
local end_waypoint = {
-- end waypoint
position = character.position,
@ -177,7 +177,7 @@ local reconnect_character =
function Public.terminate_cutscene(player_index, ticks)
local running_cutscene = running_cutscenes[player_index]
if not running_cutscene then
game.print("Error terminating!")
--game.print("Error terminating!")
return
end
ticks = ticks and ticks or 1
@ -196,7 +196,7 @@ handler = function(event)
local player_index = event.player_index
local waypoint_index = event.waypoint_index
game.print('Waypoint: ' .. waypoint_index)
--game.print('Waypoint: ' .. waypoint_index)
local running_cutscene = running_cutscenes[player_index]
if not running_cutscene then
@ -206,7 +206,7 @@ handler = function(event)
local update = running_cutscene.update
if update then
game.print('Updating!')
--game.print('Updating!')
restart_cutscene(player_index, update, waypoint_index)
return
end

View File

@ -1,9 +1,11 @@
local RS = require 'map_gen.shared.redmew_surface'
local Public = {}
--At zoom level 1 a tile is 32x32 pixels
--tile size is calculated by 32 * zoom level.
function Public.draw_text(original_resolution, original_zoom, player_zoom, offset, text, scale, ttl, player, draw_background)
function Public.draw_text(original_resolution, original_zoom, player_zoom, offset, text, scale, player, params, draw_background)
local height_scalar = player.display_resolution.height / original_resolution.height
local width_scalar = player.display_resolution.width / original_resolution.width
@ -26,24 +28,69 @@ function Public.draw_text(original_resolution, original_zoom, player_zoom, offse
local right_bottom = {x = 40, y = size * 0.75 / tile_scalar}
--offset.y = offset_y / height_scalar / tile_scalar
--game.print('left_top: ' .. serpent.block(left_top) .. ' | right_bottom: ' .. serpent.block(right_bottom))
Public.draw_rectangle(original_resolution, original_zoom, player_zoom, offset, left_top, right_bottom, ttl, nil, player)
local background_params = params.background
background_params = background_params or params
Public.draw_rectangle(original_resolution, original_zoom, player_zoom, offset, left_top, right_bottom, player, background_params)
end
local target = {x = player.position.x + offset_x, y = player.position.y + offset_y}
local color = params.color
color = color and color or {r = 255, g = 255, b = 255}
local font = params.font
local surface = params.surface
surface = surface or RS.get_surface()
local ttl = params.time_to_live
ttl = ttl and ttl or -1
local forces = params.forces
local players = params.players
players = players or {}
table.insert(players, player)
local visible = params.visible
visible = visible or true
local dog = params.draw_on_ground
dog = dog or false
local orientation = params.orientation
orientation = orientation or 0
local alignment = params.alignment
alignment = alignment or 'center'
local swz = params.scale_with_zoom
swz = swz or true
local oiam = params.only_in_alt_mode
oiam = oiam or false
rendering.draw_text {
text = {'', text},
color = {r = 255, g = 255, b = 255},
color = color,
target = target,
scale_with_zoom = true,
surface = game.surfaces[2],
scale_with_zoom = swz,
surface = surface,
time_to_live = ttl,
alignment = 'center',
players = {player},
scale = scale
alignment = alignment,
players = players,
scale = scale,
forces = forces,
visible = visible,
draw_on_ground = dog,
only_in_alt_mode = oiam,
orientation = orientation,
font = font
}
end
function Public.draw_multi_line_text(original_resolution, original_zoom, player_zoom, offset, texts, scale, ttl, player, draw_background)
function Public.draw_multi_line_text(original_resolution, original_zoom, player_zoom, offset, texts, scale, player, params, draw_background)
local height_scalar = player.display_resolution.height / original_resolution.height
local size = (0.0065 * player.display_resolution.height * scale) / (player_zoom * 32)
local tile_scalar = (original_zoom * 32) / (player_zoom * 32)
@ -51,17 +98,19 @@ function Public.draw_multi_line_text(original_resolution, original_zoom, player_
if draw_background then
local left_top = {x = -40, y = -size / tile_scalar / height_scalar}
local right_bottom = {x = 40, y = ((size * 1.5) / tile_scalar / height_scalar) * #texts}
Public.draw_rectangle(original_resolution, original_zoom, player_zoom, offset, left_top, right_bottom, ttl, nil, player)
local background_params = params.background
background_params = background_params or params
Public.draw_rectangle(original_resolution, original_zoom, player_zoom, offset, left_top, right_bottom, player, background_params)
draw_background = false
end
for i = 1, #texts do
Public.draw_text(original_resolution, original_zoom, player_zoom, offset, texts[i], scale, ttl, player, draw_background)
Public.draw_text(original_resolution, original_zoom, player_zoom, offset, texts[i], scale, player, params, draw_background)
offset.y = offset.y + (size * 1.5) / tile_scalar / height_scalar
end
end
function Public.draw_rectangle(original_resolution, original_zoom, player_zoom, offset, left_top, right_bottom, ttl, color, player)
function Public.draw_rectangle(original_resolution, original_zoom, player_zoom, offset, left_top, right_bottom, player, params)
local height_scalar = player.display_resolution.height / original_resolution.height
local width_scalar = player.display_resolution.width / original_resolution.width
--game.print('scalar: ' .. height_scalar .. ' | ' .. width_scalar)
@ -82,25 +131,58 @@ function Public.draw_rectangle(original_resolution, original_zoom, player_zoom,
--game.print('target_left: ' .. serpent.block(target_left))
--game.print('target_right: ' .. serpent.block(target_right))
if not color then
color = {}
end
local color = params.color
color = color and color or {}
local width = params.width
width = width and width or 0
local filled = params.filled
filled = filled and filled or true
local surface = params.surface
surface = surface or RS.get_surface()
local ttl = params.time_to_live
ttl = ttl and ttl or -1
local forces = params.forces
local players = params.players
players = players or {}
table.insert(players, player)
local visible = params.visible
visible = visible or true
local dog = params.draw_on_ground
dog = dog or false
local oiam = params.only_in_alt_mode
oiam = oiam or false
rendering.draw_rectangle {
color = color,
filled = true,
width = width,
filled = filled,
left_top = target_left,
right_bottom = target_right,
surface = game.surfaces[2],
surface = surface,
time_to_live = ttl,
players = {player}
forces = forces,
players = players,
visible = visible,
draw_on_ground = dog,
only_in_alt_mode = oiam
}
end
function Public.blackout(player, zoom, ttl, color)
local left_top = {x = -40, y = -22.5}
local right_bottom = {x = 40, y = 22.5}
Public.draw_rectangle({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 0}, left_top, right_bottom, ttl, color, player)
Public.draw_rectangle({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 0}, left_top, right_bottom, player, {color = color, time_to_live = ttl})
end
return Public

View File

@ -4,29 +4,33 @@ local Task = require 'utils.task'
local Cutscene = require 'features.cutscene.cutscene_controller'
local Rendering = require 'features.cutscene.renderings'
local RS = require 'map_gen.shared.redmew_surface'
local Color = require 'resources.color_presets'
local DiggyCutscene = {}
local function cutscene_function(player_index, waypoint_index, params)
local cases = {}
local player = game.players[player_index]
game.print('index: ' .. waypoint_index .. ' | position:' .. serpent.block(params.position) .. ' | trans_time: ' .. params.transition_time .. ' | ttw: ' .. params.time_to_wait .. ' | zoom: ' .. params.zoom)
local ttw = params.time_to_wait
local zoom = params.zoom
--game.print('index: ' .. waypoint_index .. ' | position:' .. serpent.block(params.position) .. ' | trans_time: ' .. params.transition_time .. ' | ttw: ' .. ttw .. ' | zoom: ' .. zoom)
cases[-1] = function()
player.clear_console()
player.gui.center.clear()
Rendering.blackout(player, params.zoom, params.time_to_wait + 1)
Rendering.draw_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = -16}, 'Diggy', 10, params.time_to_wait, player, false)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = -5}, {'Welcome to Diggy', '---------------------', 'This is a custom scenario developed by Redmew', 'Join us at www.redmew.com/discord'}, 5, params.time_to_wait, player, false)
Rendering.draw_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 10}, 'The following introduction will help you get started!', 3, params.time_to_wait, player, false)
Rendering.blackout(player, zoom, ttw + 1)
Rendering.draw_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = -16}, 'Diggy', 10, player, {time_to_live = ttw, color = Color.yellow}, false)
local multi_params = {time_to_live = ttw}
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = -5}, {'Welcome to Diggy', '---------------------', 'This is a custom scenario developed by Redmew', 'Join us at www.redmew.com/discord'}, 5, player, multi_params, multi_params, false)
Rendering.draw_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 10}, 'The following introduction will help you get started!', 3, player, {time_to_live = ttw}, false)
end
cases[0] = function()
Rendering.draw_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, 'This is the starting area', 2.5, params.time_to_wait, player, true)
Rendering.draw_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, 'This is the starting area', 2.5, player, {time_to_live = ttw}, true)
local entity = RS.get_surface().find_entities_filtered {name = 'stone-wall', limit = 1}
if entity[1] then
game.print('Found wall')
--game.print('Found wall')
local position = entity[1].position
waypoint = {
local waypoint = {
-- case 1
position = position,
transition_time = 120,
@ -35,16 +39,15 @@ local function cutscene_function(player_index, waypoint_index, params)
}
Cutscene.inject_waypoint(player_index, waypoint, 3, true)
end
end
cases[1] = function()
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, {'Expanding the mine is dangerous!', '', 'Walls are used to keep the cave roof from crushing us'}, 2.5, params.time_to_wait, player, true)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, {'Expanding the mine is dangerous!', '', 'Walls are used to keep the cave roof from crushing us'}, 2.5, player, {time_to_live = ttw}, true)
end
cases[2] = function()
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, {'The market provides extra supplies', '', 'You unlock new items when you level up'}, 2.5, params.time_to_wait, player, true)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, {'The market provides extra supplies', '', 'You unlock new items when you level up'}, 2.5, player, {time_to_live = ttw}, true)
end
cases[3] = function()
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, {"Cave ins happens frequently when you don't add supports", '', 'Different types of brick and concrete can reinforce our support pillars!'}, 2.5, params.time_to_wait, player, true)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, {"Cave ins happens frequently when you don't add supports", '', 'Different types of brick and concrete can reinforce our support pillars!'}, 2.5, player, {time_to_live = ttw}, true)
local position = RS.get_surface().find_entities_filtered {name = 'rock-big', limit = 1}[1].position
local waypoint = {
-- case 4
@ -56,13 +59,13 @@ local function cutscene_function(player_index, waypoint_index, params)
Cutscene.inject_waypoint(player_index, waypoint, 6)
end
cases[4] = function()
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, {'This world contains brittle rocks', '', 'Our tools are too powerful to preserve any resources from destroying them'}, 2.5, params.time_to_wait, player, true)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, {'This world contains brittle rocks', '', 'Our tools are too powerful to preserve any resources from destroying them'}, 2.5, player, {time_to_live = ttw}, true)
end
cases[5] = function()
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, {'The native population is lurking in the dark', '', 'Be wary when digging, always bring along some defences'}, 2.5, params.time_to_wait, player, true)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, {'The native population is lurking in the dark', '', 'Be wary when digging, always bring along some defences'}, 2.5, player, {time_to_live = ttw}, true)
end
cases[6] = function()
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, params.zoom, {x = 0, y = 18}, {'This concludes the introduction', '', 'Have fun and keep digging!'}, 2.5, params.time_to_wait, player, true)
Rendering.draw_multi_line_text({height = 1440, width = 2560}, 1, zoom, {x = 0, y = 18}, {'This concludes the introduction', '', 'Have fun and keep digging!'}, 2.5, player, {time_to_live = ttw}, true)
end
local case = cases[waypoint_index]
if case then
@ -125,9 +128,12 @@ local waypoints = {
Cutscene.register_cutscene_function('Diggy_Welcome', waypoints, Token.register(cutscene_function))
local start_cutscene = Token.register(function(params)
Cutscene.register_running_cutscene(params.event.player_index, 'Diggy_Welcome', 120)
end)
local start_cutscene =
Token.register(
function(params)
Cutscene.register_running_cutscene(params.event.player_index, 'Diggy_Welcome', 120)
end
)
function DiggyCutscene.register()
Event.add(