Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mod = RegisterMod("Lemegeton Item List", 1)
- local json = require("json")
- local renderItems = false
- local game = Game()
- local row = 0
- local updateTheList = false
- local listWasUpdated = false
- local showedMessage = false
- local renderMessage = false
- local timer = 0
- local alpha = 1
- local POSITION_LEFT = 1.26
- local POSITION_CENTER = 1.6
- local POSITION_RIGHT = 2.23
- local LemegetonItems = {}
- local clearedItems = {}
- local itemSprite = Sprite()
- itemSprite:Load("gfx/item.anm2", true)
- itemSprite:Play("Idle", true)
- for i=1, 24 do
- itemSprite:SetLayerFrame(i, 1)
- end
- local paper = Sprite()
- paper:Load("gfx/bg paper.anm2", true)
- paper:Play("Idle", true)
- local setting = {
- Scale = 0.85,
- Position = POSITION_LEFT,
- Opacity = 1
- }
- if ModConfigMenu then
- local function AnIndexOf(t, val)
- for k, v in ipairs(t) do
- if v == val then
- return k
- end
- end
- return 1
- end
- local modName = "Lemegeton Item List"
- -- avoid duplicating settings
- ModConfigMenu.RemoveCategory(modName)
- ModConfigMenu.UpdateCategory(modName, {
- Info = "Lemegeton Item List settings"
- })
- ModConfigMenu.AddTitle(modName, "Settings", " ")
- local paperPositions = {POSITION_LEFT, POSITION_CENTER, POSITION_RIGHT}
- ModConfigMenu.AddSetting(
- modName,
- "Settings",
- {
- Type = ModConfigMenu.OptionType.NUMBER,
- CurrentSetting = function()
- return AnIndexOf(paperPositions, setting.Position)
- end,
- Minimum = 1,
- Maximum = #paperPositions,
- Display = function()
- local pos
- if setting.Position == POSITION_LEFT then
- pos = "Left"
- elseif setting.Position == POSITION_CENTER then
- pos = "Center"
- elseif setting.Position == POSITION_RIGHT then
- pos = "Right"
- end
- return "List position: " .. pos
- end,
- OnChange = function(currentNum)
- setting.Position = paperPositions[currentNum]
- mod:SaveData(json.encode(setting))
- end,
- Info = {"Change the position of the item list (choose between left, center and right)"}
- }
- )
- --[[ModConfigMenu.AddSetting(modName, "Settings", {
- Type = ModConfigMenu.OptionType.KEYBIND_KEYBOARD,
- CurrentSetting = keybind,
- Default = Keyboard.KEY_G,
- Display = "Not working yet",
- --Display = "Open List: " .. keybind,
- OnChange = function(key)
- keybind = key
- end,
- Info = "Press " .. keybind .. " to open a list of items acquired with Lemegeton."
- })--]]
- local scalesArray = {0.75, 0.8, 0.85, 0.9, 0.95, 1}
- ModConfigMenu.AddSetting(
- modName,
- "Settings",
- {
- Type = ModConfigMenu.OptionType.NUMBER,
- CurrentSetting = function()
- return AnIndexOf(scalesArray, setting.Scale)
- end,
- Minimum = 1,
- Maximum = 6,
- Display = function()
- return "Size: " .. setting.Scale
- end,
- OnChange = function(currentNum)
- setting.Scale = scalesArray[currentNum]
- mod:SaveData(json.encode(setting))
- end,
- Info = {"Change the size of the Lemegeton items list"}
- }
- )
- local opacityArray = {0, 1, 2}
- ModConfigMenu.AddSetting(
- modName,
- "Settings",
- {
- Type = ModConfigMenu.OptionType.NUMBER,
- CurrentSetting = function()
- return AnIndexOf(opacityArray, setting.Opacity)
- end,
- Minimum = 1,
- Maximum = 3,
- Display = function()
- local opacity
- if setting.Opacity == 0 then
- opacity = "Visible"
- elseif setting.Opacity == 1 then
- opacity = "Semi visible"
- elseif setting.Opacity == 2 then
- opacity = "Barely visible"
- end
- return "Opacity: " .. opacity
- end,
- OnChange = function(currentNum)
- setting.Opacity = opacityArray[currentNum]
- mod:SaveData(json.encode(setting))
- end,
- Info = {"Change the opacity of the Lemegeton items list"}
- }
- )
- end
- local function GetScreenSize() --Made by Kilburn
- local room = game:GetRoom()
- local pos = room:WorldToScreenPosition(Vector(0,0)) - room:GetRenderScrollOffset() - game.ScreenShakeOffset
- local rx = pos.X + 60 * 26 / 40
- local ry = pos.Y + 140 * (26 / 40)
- return rx*2 + 13*26, ry*2 + 7*26
- end
- local function updateList()
- clearedItems = {}
- for i=1, #LemegetonItems do
- if LemegetonItems[i] ~= nil then
- local pos = (#clearedItems % 24) + 1
- clearedItems[pos] = LemegetonItems[i]
- end
- end
- end
- local function updateLemegetonList()
- local wisps = Isaac.FindByType(EntityType.ENTITY_FAMILIAR, FamiliarVariant.ITEM_WISP)
- for i=1, #wisps do
- if wisps[i].FrameCount == 0 then
- local wispItem = wisps[i].SubType
- LemegetonItems[#LemegetonItems + 1] = wispItem
- updateList()
- end
- end
- end
- function mod:gameStart(fromSave)
- if (mod:HasData()) then
- setting = json.decode(mod:LoadData())
- end
- if fromSave then
- updateLemegetonList()
- else
- LemegetonItems = {}
- end
- end
- mod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, mod.gameStart)
- function mod:newRoom()
- if #LemegetonItems > 0 then
- updateList()
- end
- end
- mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, mod.newRoom)
- local function renderItem() --Render the items
- local sx, sy = GetScreenSize()
- local ypos = sy - sy/1.35
- local xpos = sx - sx/setting.Position
- local itemScale = Vector(setting.Scale, setting.Scale)
- local paperScale = Vector(setting.Scale+0.09, setting.Scale)
- local sprPos = Vector(xpos + 55, ypos + 25)
- paper:Render(Vector(xpos + 60, ypos + 30), Vector.Zero, Vector.Zero)
- paper.Scale = paperScale
- paper:SetFrame(setting.Opacity)
- if updateTheList and not listWasUpdated then
- updateList()
- listWasUpdated = true
- end
- for index=1, #clearedItems do
- local icon = Isaac.GetItemConfig():GetCollectible(clearedItems[index]).GfxFileName
- itemSprite:ReplaceSpritesheet(index, icon)
- itemSprite:SetLayerFrame(index, 0) --Make the item visible
- end
- if #clearedItems < 24 then
- for i = (#clearedItems+1) , 24 do
- itemSprite:SetLayerFrame(i, 1) --Make the empty item spaces invisible
- end
- end
- itemSprite:LoadGraphics()
- itemSprite.Scale = itemScale
- itemSprite:Render(sprPos, Vector.Zero, Vector.Zero)
- end
- function mod:render()
- if renderItems then
- renderItem()
- end
- if renderMessage and timer ~= 0 then
- local sx, sy = GetScreenSize()
- Isaac.RenderScaledText("Press the map button to see your current wisp items!", sx-sx/1.24, sy-sy/3, 0.98, 0.98, 1, 0, 1, timer/100)
- end
- end
- mod:AddCallback(ModCallbacks.MC_POST_RENDER, mod.render)
- function mod:playerupdate(player)
- if timer > 0 then
- timer = timer - 1
- end
- if player:HasCollectible(CollectibleType.COLLECTIBLE_LEMEGETON) and not showedMessage then
- renderMessage = true
- timer = 160
- showedMessage = true
- end
- if #LemegetonItems > 0 then
- if Input.IsActionPressed(ButtonAction.ACTION_MAP, player.ControllerIndex) then
- if listWasUpdated then
- updateTheList = false
- else updateTheList = true end
- renderItems = true
- else
- listWasUpdated = false
- updateTheList = false
- renderItems = false
- end
- end
- end
- mod:AddCallback(ModCallbacks.MC_POST_PLAYER_UPDATE, mod.playerupdate)
- function mod:wispDeath(fam) --Remove the item wisp from the list when it dies
- if fam.Variant == FamiliarVariant.ITEM_WISP then
- for i=1, #LemegetonItems do
- if LemegetonItems[i] == fam.SubType then
- LemegetonItems[i] = nil
- updateList()
- return
- end
- end
- end
- end
- mod:AddCallback(ModCallbacks.MC_POST_ENTITY_REMOVE, mod.wispDeath, EntityType.ENTITY_FAMILIAR)
- function mod:onLemegeton(_, _, _) --Add the item wisp to the list when it spawns
- updateLemegetonList()
- end
- mod:AddCallback(ModCallbacks.MC_USE_ITEM, mod.onLemegeton, CollectibleType.COLLECTIBLE_LEMEGETON)
Advertisement
Add Comment
Please, Sign In to add comment