Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Friendly reminder that this is only an example of code that should be read and analyzed so that you understand the core concepts behind it
- --Pasting it on top of your code will not fix whatever issue you're having :P
- function love.load()
- --Decoration
- width = 25
- spacing = 5
- curSlot = 1 --Selected slot
- numOfSlots = 8 --Total slots size
- slotsInUse = 8 --By default, each slot is in use
- love.window.setMode((width+spacing)*numOfSlots+spacing, spacing*2+width)
- end
- function love.draw()
- for i = 1, numOfSlots do
- love.graphics.setColor(.5, .5, .5, 1) --Sets default slot color
- if i > slotsInUse then --Sets inactive slot color
- love.graphics.setColor(.25, .25, .25, 1)
- end
- if curSlot == i then --Sets highlighted slot color
- love.graphics.setColor(.75, .75, .25, 1)
- end
- love.graphics.rectangle("fill", spacing + (i-1)*(width + spacing), spacing, width, width) --Draw slot
- --This is just the make-shift item representation via colored balls
- love.graphics.setColor(.75, .1, 0, 1)
- if i <= slotsInUse then
- love.graphics.setColor(.1, .75, 0, 1)
- end
- love.graphics.circle("fill", spacing + (i-1)*(width + spacing)+width/2, spacing+width/2, width/4, 32)
- love.graphics.setLineWidth(2)
- if curSlot == i then
- love.graphics.setColor(.3, 1, 0, 1)
- end
- love.graphics.circle("line", spacing + (i-1)*(width + spacing)+width/2, spacing+width/2, width/4, 32)
- if curSlot == i then --Highlight slot
- love.graphics.setColor(.25, .25, 0, 1)
- love.graphics.setLineWidth(5)
- love.graphics.rectangle("line", spacing + (i-1)*(width + spacing), spacing, width, width)
- end
- end
- end
- function love.wheelmoved(x, y)
- if y ~= 0 then
- y = y < 0 and -1 or 1
- if slotsInUse == 0 then
- curSlot = false
- elseif curSlot == false and slotsInUse >= 1 then
- curSlot = 1 --If no slot was selected, make it start at 1
- else
- curSlot = curSlot + y --Moves the selected slot up or down depending on the mouse wheel movement
- if curSlot > slotsInUse then --This makes the slot selection wrap around if you reach the end
- curSlot = 1
- elseif curSlot < 1 then
- curSlot = slotsInUse
- end
- end
- end
- end
- function love.keypressed(key)
- local number = false
- --This is a cheap way of checking if the key pressed is 1, 2, 3... or kp1, kp2, kp3...
- if string.len(key) == 3 and string.sub(key, 1, 2) == "kp" and tonumber(string.sub(key, -1, -1)) then
- number = tonumber(string.sub(key, -1, -1))
- elseif tonumber(key) then
- number = tonumber(key)
- end
- if number and number >= 0 and number <= numOfSlots then
- slotsInUse = number
- if number == 0 then
- curSlot = false
- elseif curSlot == false and number > 0 then
- curSlot = 1
- elseif curSlot > slotsInUse then
- curSlot = slotsInUse
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement