diff --git a/bossrushwavecounter/mcm.lua b/bossrushwavecounter/mcm.lua index d8dec2f..a5b2894 100644 --- a/bossrushwavecounter/mcm.lua +++ b/bossrushwavecounter/mcm.lua @@ -6,18 +6,18 @@ local resetSettings = false local category = "Wave Counter" MCM.UpdateCategory(category, { - Info = "A Simple Wave Counter For Boss Rush!", + Info = "一个简单的Boss Rush波次计数器!", }) MCM.AddSpace(category) -MCM.AddTitle(category, "Hold '/' and use the arrow keys") -MCM.AddTitle(category, "To move the counter, press '.'") -MCM.AddTitle(category, "To reset the counters position") +MCM.AddTitle(category, "按住 / 键,用方向键调整计数器位置") +MCM.AddTitle(category, "按 . 键重置计数器位置") +MCM.AddTitle(category, "计数器位置已重置") MCM.AddSpace(category) -local presetOptions = { "Default", "Found HUD", "Boss Bar" } -- For changing the preset +local presetOptions = { "默认", "Found HUD", "Boss血条" } -- For changing the preset MCM.AddSetting(category, { Type = ModConfigMenu.OptionType.NUMBER, @@ -29,7 +29,7 @@ MCM.AddSetting(category, { Maximum = 3, Display = function() - return "Preset: " .. presetOptions[variables.displayPreset] + return "预设位置: " .. presetOptions[variables.displayPreset] end, OnChange = function(i) @@ -38,11 +38,11 @@ MCM.AddSetting(category, { variables.verticalAdjustment = 0 end, - Info = { "Use a preset for the position of the counter" } + Info = { "使用预设位置摆放计数器" } }) MCM.AddSpace(category) -MCM.AddTitle(category, "Counter RGB Values") +MCM.AddTitle(category, "计数器文字颜色") MCM.AddSpace(category) -- RGB Values @@ -57,14 +57,14 @@ MCM.AddSetting(category, { Maximum = 255, Display = function() - return "Counter R : " .. variables.textR + return "颜色R(红): " .. variables.textR end, OnChange = function(i) variables.textR = i end, - Info = { "Change the Red Value in the counters text" } + Info = { "修改计数器文字中的红色值" } }) MCM.AddSetting(category, { @@ -78,14 +78,14 @@ MCM.AddSetting(category, { Maximum = 255, Display = function() - return "Counter G : " .. variables.textG + return "颜色G(绿): " .. variables.textG end, OnChange = function(i) variables.textG = i end, - Info = { "Change the Green Value in the counters text" } + Info = { "修改计数器文字中的绿色值" } }) MCM.AddSetting(category, { @@ -99,18 +99,18 @@ MCM.AddSetting(category, { Maximum = 255, Display = function() - return "Counter B : " .. variables.textB + return "颜色B(蓝): " .. variables.textB end, OnChange = function(i) variables.textB = i end, - Info = { "Change the Blue Value in the counters text" } + Info = { "修改计数器文字中的蓝色值" } }) MCM.AddSpace(category) -MCM.AddTitle(category, "UI Scaling") +MCM.AddTitle(category, "界面缩放") MCM.AddSpace(category) MCM.AddSetting(category, { @@ -124,14 +124,14 @@ MCM.AddSetting(category, { Maximum = 200, Display = function() - return "Bar Scale : " .. variables.barScale + return "进度条缩放: " .. variables.barScale end, OnChange = function(i) variables.barScale = i end, - Info = { "Change the scale at which the Bar Sprite should be rendered" } + Info = { "进度条贴图的渲染缩放" } }) MCM.AddSetting(category, { @@ -145,14 +145,14 @@ MCM.AddSetting(category, { Maximum = 200, Display = function() - return "Font Scale : " .. variables.textScale + return "字体缩放: " .. variables.textScale end, OnChange = function(i) variables.textScale = i end, - Info = { "Change the scale at which the Font should be rendered" } + Info = { "文字的渲染缩放" } }) MCM.AddSetting(category, { @@ -166,14 +166,14 @@ MCM.AddSetting(category, { Maximum = 20, Display = function() - return "Vertical Adjustment : " .. variables.textNudge + return "垂直微调: " .. variables.textNudge end, OnChange = function(i) variables.textNudge = i end, - Info = { "Nudge the Counter Text up or down" } + Info = { "上下微调计数器文字的位置" } }) MCM.AddSpace(category) @@ -186,7 +186,7 @@ MCM.AddSetting(category, { end, Display = function() - return "RESET ALL SETTINGS" + return "重置所有设置" end, OnChange = function(boolean) @@ -196,5 +196,5 @@ MCM.AddSetting(category, { save.saveData() end, - Info = { "RESET ALL SETTINGS TO DEFAULT" } + Info = { "将所有设置恢复为默认值" } }) diff --git a/main.lua b/main.lua index 296c94b..9bfc765 100755 --- a/main.lua +++ b/main.lua @@ -1,164 +1,191 @@ -local bossRushWaveCounter = RegisterMod("Boss Rush Wave Counter", 1) - -local variables = require("bossrushwavecounter.variables") -local save = require("bossrushwavecounter.save") -local utils = require("bossrushwavecounter.utils") - -save.modRef = bossRushWaveCounter - -if ModConfigMenu then - require("bossrushwavecounter.mcm") -end - --- All code written by Aaron Cohen - -local version = 1.12 -- change this number every time you update the mod so it will reset the saveX.dat files in case the way data handling is changed and not break the mod for previous users -local editMode = false -- to see if the player is editing the position of the counter - -local waveHasStarted = false -- to be able to know whether a wave is in progress -local currentNumberOfBosses = 0 -- the current number of bosses in the room -local inBossRush = false -- indicates if the current room is a boss rush room - --- Constants -local MAX_BOSS_RUSH_WAVES = 15 -- max number of boss rush waves - -function checkEditModeAdjustments() - if Input.IsButtonPressed(Keyboard.KEY_SLASH, 0) then - editMode = true - else - editMode = false - end - - if editMode == true then - if Input.IsButtonPressed(Keyboard.KEY_RIGHT, 0) then - variables.horizontalAdjustment = variables.horizontalAdjustment + 1 - elseif Input.IsButtonPressed(Keyboard.KEY_LEFT, 0) then - variables.horizontalAdjustment = variables.horizontalAdjustment - 1 - elseif Input.IsButtonPressed(Keyboard.KEY_UP, 0) then - variables.verticalAdjustment = variables.verticalAdjustment + 1 - elseif Input.IsButtonPressed(Keyboard.KEY_DOWN, 0) then - variables.verticalAdjustment = variables.verticalAdjustment - 1 - end - end - - if Input.IsButtonPressed(Keyboard.KEY_PERIOD, 0) then - variables.horizontalAdjustment = 0 - variables.verticalAdjustment = 0 - end -end - -function bossRushWaveCounter:loadData() - save.loadData() -end - -function bossRushWaveCounter:saveData() - save.saveData() -end - -function bossRushWaveCounter:checkBossRush() - if Game():GetRoom():GetType() == RoomType.ROOM_BOSSRUSH then - inBossRush = true - - -- reset stats for the counter if the player re-enters bossrush and it isn't complete - if variables.wave < MAX_BOSS_RUSH_WAVES then - bossRushWaveCounter:resetCounter() - end - else - inBossRush = false - end -end - -function bossRushWaveCounter:resetCounter() - variables.wave = 0 - waveHasStarted = false - currentNumberOfBosses = 0 -end - -function bossRushWaveCounter:update() - if inBossRush then - -- Check keyboard inputs for editing counter positions - checkEditModeAdjustments() - - local aliveBossesCount = Game():GetRoom():GetAliveBossesCount() - local waveInProgress = aliveBossesCount > 0 - - if aliveBossesCount - currentNumberOfBosses ~= 0 then - Isaac.DebugString("Number of alive bosses: " .. aliveBossesCount) - end - - if not waveHasStarted and waveInProgress then - Isaac.DebugString("Increase wave number") - waveHasStarted = true - variables.wave = variables.wave + 1 - end - - if waveHasStarted and not waveInProgress then - Isaac.DebugString("Wave has finished") - waveHasStarted = false - end - - currentNumberOfBosses = aliveBossesCount - end -end - -local waveBar = Sprite() -waveBar:Load("gfx/ui/waveBar.anm2", true) -waveBar:Play("Idle") - -local font = Font() -font:Load("font/terminus.fnt") - -local posx, posy = utils.getScreenSize() - -function bossRushWaveCounter:renderWave() - if editMode then - font:DrawString("Edit Mode", posx * 0.5, posy * 0.5, KColor(1, 0, 0, 1), 12, true) - end - - if inBossRush then - local waveBarV1 - local positionX = 0 - local positionYOffset = 0 - - -- presets: 1 = Default, 2 = Found HUD, 3 = Boss Bar - if variables.displayPreset == 1 then - waveBarV1 = Vector(390 + variables.horizontalAdjustment, 29 - variables.verticalAdjustment) - positionX = 390 + variables.horizontalAdjustment + ((variables.barScale / 100) * 6) - positionYOffset = 29 - elseif variables.displayPreset == 2 then - waveBarV1 = Vector(29 + variables.horizontalAdjustment, 237 - variables.verticalAdjustment) - positionX = 29 + variables.horizontalAdjustment + ((variables.barScale / 100) * 6) - positionYOffset = 237 - else - if Isaac.CountBosses() >= 1 then - waveBarV1 = Vector(136 + variables.horizontalAdjustment, 304 - variables.verticalAdjustment) - positionX = 136 + variables.horizontalAdjustment + ((variables.barScale / 100) * 6) - positionYOffset = 304 - else - waveBarV1 = Vector(posx * 0.5, 304 - variables.verticalAdjustment) - positionX = posx * 0.5 + ((variables.barScale / 100) * 6) - positionYOffset = 304 - end - end - - local text = variables.wave .. "/" .. MAX_BOSS_RUSH_WAVES - local positionY = positionYOffset + variables.textNudge - variables.verticalAdjustment - ((variables.barScale / 100) * 22) - local scaleX = 0.7 * (variables.textScale / 100) - local scaleY = 0.7 * (variables.textScale / 100) - local renderColor = KColor(variables.textR / 255, variables.textG / 255, variables.textB / 255, 1) - local boxWidth = 7 - local center = true - - waveBar.Scale = Vector(variables.barScale / 100, variables.barScale / 100) - waveBar:Render(waveBarV1, Vector(0, 0), Vector(0, 0)) - - font:DrawStringScaled(text, positionX, positionY, scaleX, scaleY, renderColor, boxWidth, center) - end -end - -bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, bossRushWaveCounter.loadData) -bossRushWaveCounter:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, bossRushWaveCounter.saveData) -bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, bossRushWaveCounter.resetCounter) -bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, bossRushWaveCounter.checkBossRush) -bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_UPDATE, bossRushWaveCounter.update) -bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_RENDER, bossRushWaveCounter.renderWave) +local bossRushWaveCounter = RegisterMod("Boss Rush Wave Counter", 1) + +local variables = require("bossrushwavecounter.variables") +local save = require("bossrushwavecounter.save") +local utils = require("bossrushwavecounter.utils") + +save.modRef = bossRushWaveCounter + +if ModConfigMenu then + require("bossrushwavecounter.mcm") +end + +-- All code written by Aaron Cohen + +local version = 1.12 -- change this number every time you update the mod so it will reset the saveX.dat files in case the way data handling is changed and not break the mod for previous users +local editMode = false -- to see if the player is editing the position of the counter + +local waveHasStarted = false -- to be able to know whether a wave is in progress +local currentNumberOfBosses = 0 -- the current number of bosses in the room +local inBossRush = false -- indicates if the current room is a boss rush room + +-- Constants +local MAX_BOSS_RUSH_WAVES = 15 -- max number of boss rush waves + +function checkEditModeAdjustments() + if Input.IsButtonPressed(Keyboard.KEY_SLASH, 0) then + editMode = true + else + editMode = false + end + + if editMode == true then + if Input.IsButtonPressed(Keyboard.KEY_RIGHT, 0) then + variables.horizontalAdjustment = variables.horizontalAdjustment + 1 + elseif Input.IsButtonPressed(Keyboard.KEY_LEFT, 0) then + variables.horizontalAdjustment = variables.horizontalAdjustment - 1 + elseif Input.IsButtonPressed(Keyboard.KEY_UP, 0) then + variables.verticalAdjustment = variables.verticalAdjustment + 1 + elseif Input.IsButtonPressed(Keyboard.KEY_DOWN, 0) then + variables.verticalAdjustment = variables.verticalAdjustment - 1 + end + end + + if Input.IsButtonPressed(Keyboard.KEY_PERIOD, 0) then + variables.horizontalAdjustment = 0 + variables.verticalAdjustment = 0 + end +end + +function bossRushWaveCounter:loadData() + save.loadData() +end + +function bossRushWaveCounter:saveData() + save.saveData() +end + +function bossRushWaveCounter:checkBossRush() + if Game():GetRoom():GetType() == RoomType.ROOM_BOSSRUSH then + inBossRush = true + + -- reset stats for the counter if the player re-enters bossrush and it isn't complete + if variables.wave < MAX_BOSS_RUSH_WAVES then + bossRushWaveCounter:resetCounter() + end + else + inBossRush = false + end +end + +function bossRushWaveCounter:resetCounter() + variables.wave = 0 + waveHasStarted = false + currentNumberOfBosses = 0 +end + +function bossRushWaveCounter:update() + if inBossRush then + -- Check keyboard inputs for editing counter positions + checkEditModeAdjustments() + + local aliveBossesCount = Game():GetRoom():GetAliveBossesCount() + local waveInProgress = aliveBossesCount > 0 + + if aliveBossesCount - currentNumberOfBosses ~= 0 then + Isaac.DebugString("Number of alive bosses: " .. aliveBossesCount) + end + + if not waveHasStarted and waveInProgress then + Isaac.DebugString("Increase wave number") + waveHasStarted = true + variables.wave = variables.wave + 1 + end + + if waveHasStarted and not waveInProgress then + Isaac.DebugString("Wave has finished") + waveHasStarted = false + end + + currentNumberOfBosses = aliveBossesCount + end +end + +local waveBar = Sprite() +waveBar:Load("gfx/ui/waveBar.anm2", true) +waveBar:Play("Idle") + +local font = Font() +font:Load("font/terminus.fnt") + +-- 中文字体(汉化版):用于"编辑模式"提示,优先相对路径,绝对路径兜底 +local function GetCurrentModPath() + if debug then + return string.sub(debug.getinfo(GetCurrentModPath).source, 2) .. "/../" + end + local _, err = pcall(require, "") + local _, basePathStart = string.find(err, "no file '", 1) + local _, modPathStart = string.find(err, "no file '", basePathStart) + local modPathEnd, _ = string.find(err, ".lua'", modPathStart) + local modPath = string.sub(err, modPathStart + 1, modPathEnd - 1) + modPath = string.gsub(modPath, "\\", "/") + modPath = string.gsub(modPath, "//", "/") + modPath = string.gsub(modPath, ":/", ":\\") + return modPath +end +local editFontPaths = { + "font/fusion-pixel/12.fnt", + GetCurrentModPath() .. "resources/font/fusion-pixel/12.fnt" +} +local editFont = Font() +for _, p in ipairs(editFontPaths) do + editFont:Load(p) + if editFont:IsLoaded() then + break + end +end + +local posx, posy = utils.getScreenSize() + +function bossRushWaveCounter:renderWave() + if editMode then + editFont:DrawStringScaledUTF8("编辑模式", posx * 0.5, posy * 0.5, 0.7, 0.7, KColor(1, 0, 0, 1), 0, true) + end + + if inBossRush then + local waveBarV1 + local positionX = 0 + local positionYOffset = 0 + + -- presets: 1 = Default, 2 = Found HUD, 3 = Boss Bar + if variables.displayPreset == 1 then + waveBarV1 = Vector(390 + variables.horizontalAdjustment, 29 - variables.verticalAdjustment) + positionX = 390 + variables.horizontalAdjustment + ((variables.barScale / 100) * 6) + positionYOffset = 29 + elseif variables.displayPreset == 2 then + waveBarV1 = Vector(29 + variables.horizontalAdjustment, 237 - variables.verticalAdjustment) + positionX = 29 + variables.horizontalAdjustment + ((variables.barScale / 100) * 6) + positionYOffset = 237 + else + if Isaac.CountBosses() >= 1 then + waveBarV1 = Vector(136 + variables.horizontalAdjustment, 304 - variables.verticalAdjustment) + positionX = 136 + variables.horizontalAdjustment + ((variables.barScale / 100) * 6) + positionYOffset = 304 + else + waveBarV1 = Vector(posx * 0.5, 304 - variables.verticalAdjustment) + positionX = posx * 0.5 + ((variables.barScale / 100) * 6) + positionYOffset = 304 + end + end + + local text = variables.wave .. "/" .. MAX_BOSS_RUSH_WAVES + local positionY = positionYOffset + variables.textNudge - variables.verticalAdjustment - ((variables.barScale / 100) * 22) + local scaleX = 0.7 * (variables.textScale / 100) + local scaleY = 0.7 * (variables.textScale / 100) + local renderColor = KColor(variables.textR / 255, variables.textG / 255, variables.textB / 255, 1) + local boxWidth = 7 + local center = true + + waveBar.Scale = Vector(variables.barScale / 100, variables.barScale / 100) + waveBar:Render(waveBarV1, Vector(0, 0), Vector(0, 0)) + + font:DrawStringScaled(text, positionX, positionY, scaleX, scaleY, renderColor, boxWidth, center) + end +end + +bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, bossRushWaveCounter.loadData) +bossRushWaveCounter:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, bossRushWaveCounter.saveData) +bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, bossRushWaveCounter.resetCounter) +bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, bossRushWaveCounter.checkBossRush) +bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_UPDATE, bossRushWaveCounter.update) +bossRushWaveCounter:AddCallback(ModCallbacks.MC_POST_RENDER, bossRushWaveCounter.renderWave) diff --git a/resources/font/fusion-pixel/12.fnt b/resources/font/fusion-pixel/12.fnt new file mode 100644 index 0000000..88c9c9b Binary files /dev/null and b/resources/font/fusion-pixel/12.fnt differ diff --git a/resources/font/fusion-pixel/12_0.png b/resources/font/fusion-pixel/12_0.png new file mode 100644 index 0000000..d243308 Binary files /dev/null and b/resources/font/fusion-pixel/12_0.png differ diff --git a/resources/font/fusion-pixel/12_1.png b/resources/font/fusion-pixel/12_1.png new file mode 100644 index 0000000..9400a14 Binary files /dev/null and b/resources/font/fusion-pixel/12_1.png differ diff --git a/resources/font/fusion-pixel/LICENSE-OFL b/resources/font/fusion-pixel/LICENSE-OFL new file mode 100644 index 0000000..dca7cb2 --- /dev/null +++ b/resources/font/fusion-pixel/LICENSE-OFL @@ -0,0 +1,97 @@ +此目录下的字体依照「SIL 开放字体许可证第 1.1 版」 授权,并进行格式转换而非原始文件 +分发,此文件用于保留版权信息。 + +Copyright (c) 2022, TakWolf (https://takwolf.com), +with Reserved Font Name 'Fusion Pixel'. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file