adapted tour and controls

This commit is contained in:
Chr1Z93 2024-09-19 11:20:40 +02:00
parent c20d747921
commit b99f018891
2 changed files with 25 additions and 27 deletions

View File

@ -5,7 +5,7 @@ do
local internal = {} local internal = {}
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
-- Base IDs for various tour card UI elements. Actual IDs will have _[playerColor] appended -- Base IDs for various tour card UI elements. Actual IDs will have _[playerColor] appended
local CARD_ID = "tourCard" local CARD_ID = "tourCard"
local LEFT_NARRATOR_ID = "tourNarratorImageLeft" local LEFT_NARRATOR_ID = "tourNarratorImageLeft"
local RIGHT_NARRATOR_ID = "tourNarratorImageRight" local RIGHT_NARRATOR_ID = "tourNarratorImageRight"
@ -14,7 +14,7 @@ do
local NEXT_BUTTON_ID = "tourNext" local NEXT_BUTTON_ID = "tourNext"
local STOP_BUTTON_ID = "tourStop" local STOP_BUTTON_ID = "tourStop"
-- Table centerpoint for the camera hook object. Camera handling is a bit erratic so it doesn't -- Table centerpoint for the camera hook object. Camera handling is a bit erratic so it doesn't
-- always land right where you think it's going to, but it's close -- always land right where you think it's going to, but it's close
local HOOK_CAMERA_HOME = { local HOOK_CAMERA_HOME = {
x = -30.2, x = -30.2,
@ -22,7 +22,7 @@ do
z = 0, z = 0,
} }
-- Default (0) position for the camera, as defined in the mod. If we don't recreate this position -- Default (0) position for the camera, as defined in the mod. If we don't recreate this position
-- EXACTLY when exiting the tour then camera controls get weird -- EXACTLY when exiting the tour then camera controls get weird
local DEFAULT_CAMERA_POS = { local DEFAULT_CAMERA_POS = {
position = { x = -22.26, y = -2.5, z = 5.26 }, position = { x = -22.26, y = -2.5, z = 5.26 },
@ -45,16 +45,15 @@ do
northeast = "600 300 0", northeast = "600 300 0",
southwest = "-600 -300 0", southwest = "-600 -300 0",
-- Used by the Diana and Wini cards referencing the bottom-right global controls, moved a little -- Used by the cards referencing the bottom-right panel, moved a little closer to them
-- closer to them southeast = "675 -365 0"
southeast = "730 -365 0"
} }
-- Tracks the current state of the tours. Keyed by player color to keep each player's tour -- Tracks the current state of the tours. Keyed by player color to keep each player's tour
-- separate, will hold the camera hook and current card. -- separate, will hold the camera hook and current card.
local tourState = {} local tourState = {}
-- Kicks off the tour by initializing the card and camera hook. A callback on the hook creation -- Kicks off the tour by initializing the card and camera hook. A callback on the hook creation
-- will then show the first card. -- will then show the first card.
---@param playerColor string Player color to start the tour for ---@param playerColor string Player color to start the tour for
TourManager.startTour = function(playerColor) TourManager.startTour = function(playerColor)
@ -62,12 +61,12 @@ do
currentCardIndex = 1 currentCardIndex = 1
} }
-- Camera gets really screwy when we finalize if we don't start settled in ThirdPerson at the -- Camera gets really screwy when we finalize if we don't start settled in ThirdPerson at the
-- default position before attaching to the hook. Unfortunately there are no callbacks for when -- default position before attaching to the hook. Unfortunately there are no callbacks for when
-- the movement is done, but the delay seems to handle it -- the movement is done, but the delay seems to handle it
Player[playerColor].setCameraMode("ThirdPerson") Player[playerColor].setCameraMode("ThirdPerson")
Player[playerColor].lookAt(DEFAULT_CAMERA_POS) Player[playerColor].lookAt(DEFAULT_CAMERA_POS)
-- Initial camera rotation is painfully slow. White and Orange players are likely oriented -- Initial camera rotation is painfully slow. White and Orange players are likely oriented
-- correctly, but need a longer start delay for Green and Red -- correctly, but need a longer start delay for Green and Red
local delay = 0.5 local delay = 0.5
if playerColor ~= "White" and playerColor ~= "Orange" then if playerColor ~= "White" and playerColor ~= "Orange" then
@ -81,7 +80,7 @@ do
end, delay) end, delay)
end end
-- Shows the next card in the tour script. This method is exposed (rather than being part of -- Shows the next card in the tour script. This method is exposed (rather than being part of
-- internal) because the XMLUI callbacks expect the method to be on the object directly. -- internal) because the XMLUI callbacks expect the method to be on the object directly.
---@param player tts__Player object to show the next card for, provided by XMLUI callback ---@param player tts__Player object to show the next card for, provided by XMLUI callback
function nextCard(player) function nextCard(player)
@ -96,7 +95,7 @@ do
end, 0.3) end, 0.3)
end end
-- Ends the tour and cleans up the camera. This method is exposed (rather than being part of -- Ends the tour and cleans up the camera. This method is exposed (rather than being part of
-- internal) because the XMLUI callbacks expect the method to be on the object directly. -- internal) because the XMLUI callbacks expect the method to be on the object directly.
---@param player tts__Player object to end the tour for, provided by XMLUI callback ---@param player tts__Player object to end the tour for, provided by XMLUI callback
function stopTour(player) function stopTour(player)
@ -133,7 +132,7 @@ do
lookPos = lookAtObj.getPosition() lookPos = lookAtObj.getPosition()
lookPos.y = TOUR_SCRIPT[cardIndex].distanceFromObj or 0 lookPos.y = TOUR_SCRIPT[cardIndex].distanceFromObj or 0
-- Since camera isn't directly above the hook, changing the Y affects the visual position of -- Since camera isn't directly above the hook, changing the Y affects the visual position of
-- whatever object we're trying to look at. This is an approximation, but close enough to -- whatever object we're trying to look at. This is an approximation, but close enough to
-- keep the object more centered -- keep the object more centered
lookPos.x = lookPos.x - lookPos.y / 2 lookPos.x = lookPos.x - lookPos.y / 2
elseif TOUR_SCRIPT[cardIndex].showPos ~= nil then elseif TOUR_SCRIPT[cardIndex].showPos ~= nil then
@ -148,7 +147,7 @@ do
Wait.time(function() Global.UI.show(internal.getUiId(CARD_ID, playerColor)) end, delay) Wait.time(function() Global.UI.show(internal.getUiId(CARD_ID, playerColor)) end, delay)
end end
-- Hides the current card being shown to a player. This can be in preparation for showing the -- Hides the current card being shown to a player. This can be in preparation for showing the
-- next card, or ending the tour. -- next card, or ending the tour.
---@param playerColor string Player color to hide the current card for ---@param playerColor string Player color to hide the current card for
internal.hideCard = function(playerColor) internal.hideCard = function(playerColor)
@ -156,7 +155,7 @@ do
end end
-- Cleans up all the various resources associated with the tour, and (hopefully) resets the -- Cleans up all the various resources associated with the tour, and (hopefully) resets the
-- camera to the default position. Camera handling is erratic, the final card in the script -- camera to the default position. Camera handling is erratic, the final card in the script
-- should include instructions for the player to fix it. -- should include instructions for the player to fix it.
---@param playerColor string Player color to clean up ---@param playerColor string Player color to clean up
internal.finalizeTour = function(playerColor) internal.finalizeTour = function(playerColor)
@ -198,10 +197,9 @@ do
end end
end end
-- Creates a small, transparent object which the camera will be attached to in order to move the -- Creates a small, transparent object which the camera will be attached to in order to move the user's view
-- user's view around the table. This should be called only at the beginning of the tour. Once -- around the table. This should be called only at the beginning of the tour. Once creation is complete
-- creation is complete the user's camera will be attached to the hook and the first card will be -- the user's camera will be attached to the hook and the first card will be shown.
-- shown.
---@param playerColor string Player color to create the hook for ---@param playerColor string Player color to create the hook for
internal.createCameraHook = function(playerColor) internal.createCameraHook = function(playerColor)
local hookData = { local hookData = {
@ -230,7 +228,7 @@ do
spawnObjectData({ data = hookData, callback_function = internal.onHookCreated }) spawnObjectData({ data = hookData, callback_function = internal.onHookCreated })
end end
-- Callback for creation of the camera hook object. Will attach the camera and show the current -- Callback for creation of the camera hook object. Will attach the camera and show the current
-- (presumably first) card. -- (presumably first) card.
---@param hook tts__Object Created object ---@param hook tts__Object Created object
internal.onHookCreated = function(hook) internal.onHookCreated = function(hook)
@ -243,7 +241,7 @@ do
internal.showCurrentCard(playerColor) internal.showCurrentCard(playerColor)
end end
-- Creates an XMLUI entry in Global for a player-specific tour card. Dynamically creating this -- Creates an XMLUI entry in Global for a player-specific tour card. Dynamically creating this
-- is somewhat complex, but ensures we can properly handle any player color. -- is somewhat complex, but ensures we can properly handle any player color.
---@param playerColor string Player color to create the card for ---@param playerColor string Player color to create the card for
internal.createTourCard = function(playerColor) internal.createTourCard = function(playerColor)

View File

@ -5,15 +5,15 @@
color="clear"/> color="clear"/>
</Defaults> </Defaults>
<!-- Buttons at the bottom right (height: n * 37 - 2) --> <!-- Buttons at the bottom right (height: n * width + spacing) -->
<VerticalLayout visibility="Admin" <VerticalLayout visibility="Admin"
color="#000000" color="#000000"
outlineSize="1 1" outlineSize="1 1"
outline="#303030" outline="#303030"
rectAlignment="LowerRight" rectAlignment="LowerRight"
width="35" width="38"
height="72" height="78"
offsetXY="-1 120" offsetXY="-1 123"
spacing="2"> spacing="2">
<Button class="navbar" <Button class="navbar"
icon="devourer" icon="devourer"
@ -31,8 +31,8 @@
outlineSize="1 1" outlineSize="1 1"
outline="#303030" outline="#303030"
rectAlignment="LowerRight" rectAlignment="LowerRight"
width="35" width="38"
height="35" height="38"
offsetXY="-1 85"> offsetXY="-1 85">
<Button class="navbar" <Button class="navbar"
icon="NavigationOverlayIcon" icon="NavigationOverlayIcon"