Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m_CurrentText = nil
- m_sCurrentTurn = nil
- function onPlayerTurnStart(player_color_start, player_color_previous)
- m_sCurrentTurn = player_color_start
- end
- function onSave()
- local sGUID = nil
- if m_CurrentText ~= nil then
- sGUID = m_CurrentText.getGUID()
- end
- return JSON.encode({sGUIDtext = sGUID})
- end
- function onLoad(save_state)
- --Create buttons
- local button_parameters = {}
- button_parameters.rotation = {0.0, 0.0, 0.0}
- button_parameters.width = 900
- button_parameters.height = 320
- button_parameters.function_owner = self
- --Accept Offer button
- button_parameters.position = {-3.06, 0.1, 0.48}
- button_parameters.label = 'Accept Offer'
- button_parameters.click_function = 'respAccept'
- button_parameters.font_size = 150
- self.createButton( button_parameters )
- local SavedData = JSON.decode(save_state)
- if SavedData ~= nil then
- if SavedData.sGUIDtext ~= nil then
- m_CurrentText = getObjectFromGUID(SavedData.sGUIDtext)
- end
- end
- end
- function respAccept(Board, sPlayer) displayResponse('I Accept!', sPlayer) end
- function displayResponse(sText, sPlayer)
- --clear old text
- if m_CurrentText ~= nil then
- m_CurrentText.destruct()
- end
- --spawn new response text
- local vPos = self.getPosition()
- --orient the text according to the orientation of the board
- local vRot = {90.0, 180 + self.getRotation().y, 0.0} --yeah, I think this is weird too
- if vRot[2] > 360.0 then
- vRot[2] = vRot[2] - 360.0
- end
- --rotate the text towards the active player -> see if we have to flip it to make it better readable for the active player
- local bFlip = false
- if m_sCurrentTurn ~= nil then
- local fRotationDiff = Player[m_sCurrentTurn].getPlayerHand().rot_y - self.getRotation()[2]
- if fRotationDiff < 0 then
- fRotationDiff = 360.0 + fRotationDiff
- end
- if fRotationDiff > 270.0 or fRotationDiff < 90.0 then
- bFlip = true
- end
- end
- --position the text above the board
- local fR = math.rad(vRot[2])
- local fSpace = 3.5
- if bFlip then
- vRot[2] = vRot[2] + 180.0
- fSpace = 2.2
- end
- vPos.x = vPos.x + (math.sin(fR) * fSpace)
- vPos.y = vPos.y + 0.2 --lift the text so it will not be covered by anything on the board
- vPos.z = vPos.z + (math.cos(fR) * fSpace)
- local params = {
- type = '3DText',
- position = vPos,
- rotation = vRot, --neither this nor setRotation/setRotationSmooth works ... only .rotate?!
- callback_owner = self,
- callback = 'newTextCallback',
- params = { sText = sText,
- sPlayer = sPlayer,
- iFontSize = 110,
- vRotation = vRot
- }
- }
- m_CurrentText = spawnObject(params)
- end
- --[[ This actually is needed because rotating a text is super weird. It only works in the callback of the object with the text tool ]]--
- function newTextCallback(TextObj, p)
- TextObj.TextTool.setValue(p.sText)
- TextObj.TextTool.setFontColor(getColor(p.sPlayer))
- TextObj.TextTool.setFontSize(p.iFontSize)
- TextObj.setRotation(p.vRotation)
- end
- function clearText()
- if m_CurrentText ~= nil then
- m_CurrentText.destruct()
- end
- end
- function getColor(sPlayer)
- if sPlayer == 'Orange' then
- return {['r']=1.0, ['g']=0.544700563, ['b']=0.188231677}
- elseif sPlayer == 'Red' then
- return {['r']=0.7921569, ['g']=0.0, ['b']=0.0}
- elseif sPlayer == 'White' then
- return {['r']=0.99649936, ['g']=1.0, ['b']=0.996506333}
- elseif sPlayer == 'Purple' then
- return {['r']=0.5528258, ['g']=0.164702222, ['b']=1.0}
- elseif sPlayer == 'Blue' then
- return {['r']=0.149015814, ['g']=0.419941843, ['b']=0.8235495}
- elseif sPlayer == 'Green' then
- return {['r']=0.201173037, ['g']=0.8549019, ['b']=0.188231409}
- elseif sPlayer == 'Black' then
- return {['r']=0.0, ['g']=0.0, ['b']=0.0}
- else
- return {['r']=1.0, ['g']=0.8, ['b']=0.0}
- end
- end
- --reset the response text when the turn is ended
- function onPlayerTurnEnd(player_color_end, player_color_next)
- clearText()
- end
- --reset the response when the board is moved
- function onPickUp(player_color)
- clearText()
- end
- --reset the response when the board is removed
- function onDestroy()
- clearText()
- end
Add Comment
Please, Sign In to add comment