Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Character Sheet for Gloomhaven Scoundrel
- --Most the code was writen by Mr.Stump - To him I am greatful!
- --Saves the count value into a table (data_to_save) then encodes it into the Tabletop save
- function onSave()
- local data_to_save = {
- saved_countXP = countXP,
- saved_countGold = countGold,
- saved_ref_checkboxes = ref_checkboxes
- }
- saved_data = JSON.encode(data_to_save)
- return saved_data
- end
- function onLoad(saved_data)
- --Checks if there is a saved data. If there is, it gets the saved value for 'count'
- --saved_data = ''
- if saved_data != '' then
- local loaded_data = JSON.decode(saved_data)
- countXP = loaded_data.saved_countXP
- countGold = loaded_data.saved_countGold
- ref_checkboxes = loaded_data.saved_ref_checkboxes
- else
- --If there wasn't saved data, the default value is set to 0.
- countXP = 0
- countGold = 0
- ref_checkboxes = {
- --Notes Section
- {pos={0.211,0.1,0.386}, state=false},
- {pos={0.257,0.1,0.386}, state=false},
- {pos={0.302,0.1,0.386}, state=false},
- {pos={0.409,0.1,0.386}, state=false},
- {pos={0.455,0.1,0.386}, state=false},
- {pos={0.500,0.1,0.386}, state=false},
- {pos={0.606,0.1,0.386}, state=false},
- {pos={0.652,0.1,0.386}, state=false},
- {pos={0.697,0.1,0.386}, state=false},
- {pos={0.211,0.1,0.445}, state=false},
- {pos={0.257,0.1,0.445}, state=false},
- {pos={0.302,0.1,0.445}, state=false},
- {pos={0.409,0.1,0.445}, state=false},
- {pos={0.455,0.1,0.445}, state=false},
- {pos={0.500,0.1,0.445}, state=false},
- {pos={0.606,0.1,0.445}, state=false},
- {pos={0.652,0.1,0.445}, state=false},
- {pos={0.697,0.1,0.445}, state=false},
- --Perks Section
- {pos={0.163,0.1,-0.801}, state=false},
- {pos={0.212,0.1,-0.801}, state=false},
- {pos={0.163,0.1,-0.726}, state=false},
- {pos={0.163,0.1,-0.651}, state=false},
- {pos={0.163,0.1,-0.527}, state=false},
- {pos={0.163,0.1,-0.403}, state=false},
- {pos={0.212,0.1,-0.403}, state=false},
- {pos={0.163,0.1,-0.276}, state=false},
- {pos={0.212,0.1,-0.276}, state=false},
- {pos={0.163,0.1,-0.198}, state=false},
- {pos={0.163,0.1,-0.123}, state=false},
- {pos={0.212,0.1,-0.123}, state=false},
- {pos={0.163,0.1,-0.002}, state=false},
- {pos={0.163,0.1,0.076}, state=false},
- {pos={0.163,0.1,0.183}, state=false},
- }
- end
- --Tables for all the button paramiters
- --Creates the checkboxes using the data from ref_checkboxes table
- -- button index 0-32 are used here
- createCheckboxes()
- --Creates the paramaters used to build the XP, Gold and other labels buttons
- generateButtonParamiters()
- --Updates the counter labels
- b_displayXP.label = tostring(countXP)
- b_displayGold.label = tostring(countGold)
- -- Creates labels for XP, Gold and others
- self.createButton(b_displayXP) --index is 33
- self.createButton(b_plusXP)
- self.createButton(b_minusXP)
- self.createButton(b_plus5XP)
- self.createButton(b_minus5XP)
- self.createButton(b_displayGold) --index is 38
- self.createButton(b_plusGold)
- self.createButton(b_minusGold)
- self.createButton(b_plus5Gold)
- self.createButton(b_minus5Gold)
- self.createButton(label_update_parameters)
- self.createButton(label_name_parameters) --index is 44
- self.createButton(label_items_parameters) --index is 45
- --Function to pull in character name and items
- updateSheet()
- end
- --Activates when + is hit. Adds 1 to 'count' then updates the display button.
- function increaseXP()
- countXP = countXP + 1
- updateDisplayXP()
- end
- --Activates when - is hit. Subtracts 1 from 'count' then updates the display button.
- function decreaseXP()
- --Prevents count from going below 0
- if countXP > 0 then
- countXP = countXP - 1
- updateDisplayXP()
- end
- end
- --Activates when + is hit. Adds 5 to 'count' then updates the display button.
- function increase5XP()
- countXP = countXP + 5
- updateDisplayXP()
- end
- --Activates when - is hit. Subtracts 5 from 'count' then updates the display button.
- function decrease5XP()
- --Prevents count from going below 0
- if countXP > 4 then
- countXP = countXP - 5
- else
- countXP = 0
- end
- updateDisplayXP()
- end
- --function that updates the XP Counter display. Triggered whenever 'countxp' is changed
- function updateDisplayXP()
- --b_displayXP.label = tostring(countXP)
- --self.editButton(b_displayXP)
- self.editButton({index = 33, label = tostring(countXP)})
- end
- --Activates when + is hit. Adds 1 to 'count' then updates the display button.
- function increaseGold()
- countGold = countGold + 1
- updateDisplayGold()
- end
- --Activates when - is hit. Subtracts 1 from 'count' then updates the display button.
- function decreaseGold()
- --Prevents count from going below 0
- if countGold > 0 then
- countGold = countGold - 1
- updateDisplayGold()
- end
- end
- --Activates when + is hit. Adds 5 to 'count' then updates the display button.
- function increase5Gold()
- countGold = countGold + 5
- updateDisplayGold()
- end
- --Activates when - is hit. Subtracts 5 from 'count' then updates the display button.
- function decrease5Gold()
- --Prevents count from going below 0
- if countGold > 4 then
- countGold = countGold - 5
- else
- countGold = 0
- end
- updateDisplayGold()
- end
- --function that updates the Gold Counter display.
- function updateDisplayGold()
- --b_displayGold.label = tostring(countGold)
- --self.editButton(b_displayGold)
- self.editButton({index = 38, label = tostring(countGold)})
- end
- function updateSheet()
- local name = self.getName()
- self.editButton({index = 44, label = tostring(name)})
- local items = self.getDescription()
- self.editButton({index = 45, label = tostring(items)})
- end
- function createCheckboxes()
- --print('createCheckboxes funcatoin has been called')
- for i, boxData in ipairs(ref_checkboxes) do
- --Set up the function trigger
- local funcName = "checkbox"..i
- local func = function() toggleCheck(i) end
- self.setVar(funcName, func)
- --Set the X
- local label = ""
- print(tostring(label))
- if boxData.state == true then label = "X" end
- --Make the button
- self.createButton({
- click_function = funcName, function_owner = self, label = label,
- position =boxData.pos, width = 150, height = 150, font_size = 145,
- scale = {0.1,0.1,0.1}
- })
- end
- end
- function toggleCheck(i)
- if ref_checkboxes[i].state == true then
- self.editButton({index=i-1, label=""})
- ref_checkboxes[i].state = false
- else
- self.editButton({index=i-1, label="X"})
- ref_checkboxes[i].state = true
- end
- end
- function generateButtonParamiters()
- -- Sets all the paramiters for the XP counter
- -- Sets XYZ center position for all buttons
- xpXPos = -0.3
- xpYPos = 0.1
- xpZPos = -0.35
- lableScale = 0.20
- b_displayXP = {
- index = 0, click_function="none", function_owner = self, label = '',
- position = {xpXPos,xpYPos,xpZPos}, width = 0, height = 0,
- font_size = 500, scale = {lableScale,lableScale,lableScale}
- }
- b_plusXP = {
- click_function = 'increaseXP', function_owner = self, label = '+1',
- position = {xpXPos + 0.15,xpYPos, xpZPos + 0.05}, width = 150,
- height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- b_minusXP = {
- click_function = 'decreaseXP', function_owner = self, label = '-1',
- position = {xpXPos + -0.15,xpYPos, xpZPos + 0.05}, width = 150,
- height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- b_plus5XP = {
- click_function = 'increase5XP', function_owner = self, label = '+5',
- position = {xpXPos + 0.15,xpYPos, xpZPos + -0.07}, width = 150,
- height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- b_minus5XP = {
- click_function = 'decrease5XP', function_owner = self, label = '-5',
- position = {xpXPos + -0.15,xpYPos, xpZPos + -0.07}, width = 150,
- height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- -- Sets all the paramiters for the Gold counter
- -- Sets XYZ center position for all buttons
- goldXPos = -0.3
- goldYPos = 0.1
- goldZPos = -0.05
- b_displayGold = {
- click_function="none", function_owner = self, label = '',
- position = {goldXPos,goldYPos,goldZPos}, width = 0, height = 0,
- font_size = 500, scale = {lableScale,lableScale,lableScale}
- }
- b_plusGold = {
- click_function = 'increaseGold', function_owner = self, label = '+1',
- position = {goldXPos + 0.15,goldYPos, goldZPos + 0.05}, width = 150,
- height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- b_minusGold = {
- click_function = 'decreaseGold', function_owner = self, label = '-1',
- position = {goldXPos + -0.15,goldYPos, goldZPos + 0.05}, width = 150,
- height = 300, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- b_plus5Gold = {
- click_function = 'increase5Gold', function_owner = self, label = '+5',
- position = {goldXPos + 0.15,goldYPos, goldZPos + -0.07}, width = 150,
- height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- b_minus5Gold = {
- click_function = 'decrease5Gold', function_owner = self, label = '-5',
- position = {goldXPos + -0.15,goldYPos, goldZPos + -0.07}, width = 150,
- height = 230, font_size = 100, scale = {lableScale,lableScale,lableScale}
- }
- --Label to update character name and iteam list
- label_update_parameters = {
- click_function="updateSheet", function_owner=self, label='Update',
- position={-0.74,0.15,-0.96}, rotation={0,0,0}, height=60, width=420,
- font_size=100, scale = {0.15,0.15,0.15}
- }
- -- Label for character name
- label_name_parameters = {
- click_function="none", function_owner=self, label='',
- position={-0.3,0.15,-0.72}, rotation={0,0,0}, height=0, width=0,
- font_size=100, scale = {0.3,0.3,0.3}
- }
- --When alingment left works use position={-0.7,0.15,0.2}
- label_items_parameters = {
- click_function="none", function_owner=self, label='',
- position={-0.3,0.15,0.4}, rotation={0,0,0}, height=0, width=0,
- font_size=100, scale = {0.3,0.3,0.3},
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement