From f029e3646042dbefed1870aba528facc28b17a4d Mon Sep 17 00:00:00 2001 From: wofsauge Date: Mon, 31 Aug 2020 20:46:35 +0200 Subject: [PATCH] Added Character replacement functions and fixed bulletpoint rendering --- eid_api.lua | 43 +++++++++++++++++++++- eid_debugging.lua | 5 ++- main.lua | 93 +++++++++++++++++++---------------------------- 3 files changed, 82 insertions(+), 59 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 2297d560..182fdf09 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -64,24 +64,65 @@ function EID:getModDescription(list, id) return (list) and (list[id]) end +function EID:replaceMarkupStrings(text) + text = string.gsub(text, "!!!", "ǃ") -- Turn 3 Exclamations into Warning + text = string.gsub(text, "\1", "↑") -- Legacy Up Arrow + text = string.gsub(text, "\2", "↓") -- Legacy Down Arrow + text = string.gsub(text, "\3", "ǃ") -- Legacy Warning + text = string.gsub(text, "\6", "\2HEART\2") -- Legacy Heart + text = string.gsub(text, "\5", "\2KEY\2") -- Legacy Key + text = string.gsub(text, "\015", "\2COIN\2") -- Legacy Coin + text = string.gsub(text, "\8\189", "\2BOMB\2") -- Legacy BOMB + return text +end + +--Returns +EID:bulletIcons={"↑","↓","!","ǃ"} +function EID:getBulletpointIcon(text) + for i,v in ipairs(EID:bulletIcons) do + local iconPos = string.find(text,v) + if iconPos == 1 or iconPos == 2 then + return v + end + end + return '\007' +end + --needs to be called in a render Callback -- args: string, Vector(int, int), Vector(float,float), KColor obj, bool function EID:renderString(str, position, scale, kcolor, centered) EID.font:DrawStringScaledUTF8(str, position.X, position.Y, scale.X ,scale.Y ,kcolor ,EID.font:GetStringWidthUTF8(str), centered) end +-- Get KColor object of "Entity Name" texts function EID:getNameColor() return KColor(EIDConfig["ItemNameColor"][1] , EIDConfig["ItemNameColor"][2], EIDConfig["ItemNameColor"][3],EIDConfig["Transparency"],0,0,0) end +-- Get KColor object of "Description" texts function EID:getTextColor() return KColor(EIDConfig["TextColor"][1] , EIDConfig["TextColor"][2], EIDConfig["TextColor"][3],EIDConfig["Transparency"],0,0,0) end +-- Get KColor object of "Transformation" texts function EID:getTransformationColor() return KColor(EIDConfig["TransformationColor"][1] , EIDConfig["TransformationColor"][2], EIDConfig["TransformationColor"][3],EIDConfig["Transparency"],0,0,0) end +-- Get KColor object of "Error" texts function EID:getErrorColor() return KColor(EIDConfig["ErrorColor"][1] , EIDConfig["ErrorColor"][2], EIDConfig["ErrorColor"][3],EIDConfig["Transparency"],0,0,0) -end \ No newline at end of file +end + +-- check if an entity is part of the describable entities +function EID:hasDescription(entity) + local isAllowed = false + if EIDConfig["EnableEntityDescriptions"] then + isAllowed = isAllowed or (__eidEntityDescriptions[entity.Type.."."..entity.Variant.."."..entity.SubType]~=nil --[[or type(entity:GetData()["EID_Description"]) ~= type(nil)]]) + end + isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_COLLECTIBLE and EIDConfig["DisplayItemInfo"]) + isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TRINKET and EIDConfig["DisplayTrinketInfo"]) + isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TAROTCARD and EIDConfig["DisplayCardInfo"]) + isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_PILL and EIDConfig["DisplayPillInfo"]) + return entity.Type == EntityType.ENTITY_PICKUP and isAllowed and entity.SubType>0 +end diff --git a/eid_debugging.lua b/eid_debugging.lua index 2d1e41c5..7fd0882e 100644 --- a/eid_debugging.lua +++ b/eid_debugging.lua @@ -1,5 +1,5 @@ local charsToDebug = { -"!!! EID DEBUG MODE ACTIVATED !!!", -- Header +EID:replaceMarkupStrings("!!! EID DEBUG MODE ACTIVATED !!!"), -- Header "ABCDEFGHIJKLMNOPQRSTUVWXYZ", -- Caps letters "abcdefghijklmnopqrstuvwxyz1234567890", -- small letters + numbers "western: Áá Àà Ââ Āā Ää Ãã Åå Ææ Éé Èè Êê Ēē Ëë Íí Ìì Îî Īī Ïï ", -- @@ -8,7 +8,8 @@ local charsToDebug = { "cyrillic 1: Аа Бб Вв Гг Дд Ее Ёё Жж Зз Ии Йй Кк Лл Мм Нн Оо", "cyrillic 2: Пп Рр Сс Тт Уу Фф Хх Цц Чч Шш Щщ Ъъ Ыы Ьь Ээ Юю Яя", "polish: Ąą Ćć Ęę Łł Ńń Óó Śś Źź Żż", -"custom icons: ↑Positive ↓Negative \007bulletpoint ! ǃ ---- Legacy: \1 = Up \2 = Down \3 = Warning ! \6 = health \5 Key \015 = Coin \8\189 = Bomb", +"custom icons: ↑Positive ↓Negative \007bulletpoint !Exclamation ǃWarning !!!shortcut", +EID:replaceMarkupStrings("legacy icon Markup: \\1:\1Positive \\2:\2Negative \\3:\3Warning ! \\6:\6 heart \\5:\5 Key \\015:\015 Coin \\8\\189:\8\189 Bomb"), "emotes: ☆★〠♠♣♥♦♤♧♡♢☀☂♨♪♭♯♂♀", } diff --git a/main.lua b/main.lua index 2683e03e..c2cf103a 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,21 @@ EID = RegisterMod( "External Item Descriptions" ,1 ); local itemConfig = Isaac.GetItemConfig() +local lineHeight = 11 +local isDisplayingText= false +local lastDescriptionEntity= nil +local hideDescToggle= false + +local IconSprite = Sprite() +IconSprite:Load("gfx/icons.anm2", true) + +local ArrowSprite = Sprite() +ArrowSprite:Load("gfx/icons.anm2", true) +ArrowSprite:Play("Arrow",false) + +local CardSprite = Sprite() +CardSprite:Load("gfx/cardfronts.anm2", true) + require("eid_config") require("mod_config_menu") require("descriptions.ab+."..EIDConfig["Language"]) @@ -22,49 +37,34 @@ EID.font:SetMissingCharacter(2) if not EID.font:IsLoaded() then Isaac.DebugString("EID - ERROR: Could not load font from '"..modPath.."resources/font/default.fnt".."'") end - - --Makes textscale smaller, when using detailed english descriptions if EIDConfig["Language"]=="en_us_detailed" and EIDConfig["Scale"] > 0.5 then EIDConfig["Scale"] = 0.5 end -local lineHeight = 11 -local isDisplayingText= false -local lastDescriptionEntity= nil -local IconSprite = Sprite() -IconSprite:Load("gfx/icons.anm2", true) - -local ArrowSprite = Sprite() -ArrowSprite:Load("gfx/icons.anm2", true) -ArrowSprite:Play("Arrow",false) - -local CardSprite = Sprite() -CardSprite:Load("gfx/cardfronts.anm2", true) --------------------------------------------------------------------------- -------------------------Handle Sacrifice Room----------------------------- local SacrificeCounter = 1 -if EIDConfig["DisplaySacrificeInfo"] then +if EIDConfig["DisplaySacrificeInfo"] then - function onNewFloor() - SacrificeCounter = 1 - end - EID:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, onNewFloor) + function onNewFloor() + SacrificeCounter = 1 + end + EID:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, onNewFloor) - function onDamage(_,entity,_,flag,source) - if Game():GetRoom():GetType()==RoomType.ROOM_SACRIFICE and source.Type==0 and flag == DamageFlag.DAMAGE_SPIKES then - if SacrificeCounter<12 then - SacrificeCounter= SacrificeCounter+1 - end - end - end - EID:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, onDamage,EntityType.ENTITY_PLAYER) + function onDamage(_,entity,_,flag,source) + if Game():GetRoom():GetType() == RoomType.ROOM_SACRIFICE and source.Type == 0 and flag == DamageFlag.DAMAGE_SPIKES then + if SacrificeCounter<12 then + SacrificeCounter= SacrificeCounter+1 + end + end + end + EID:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, onDamage,EntityType.ENTITY_PLAYER) end - --------------------------------------------------------------------------- ---------------------------Printing Functions------------------------------ local itemTypes= {"null","passive","active","familiar","trinket"} @@ -160,9 +160,9 @@ function printTrinketDescription(desc,typ) printBulletPoints(Description,padding) end -function printBulletPoints(Description,padding) +function printBulletPoints(description, padding) local textboxWidth=tonumber(EIDConfig["TextboxWidth"]) - for line in string.gmatch(Description, '([^#]+)') do + for line in string.gmatch(description, '([^#]+)') do local array={} local text = "" for word in string.gmatch(line, '([^ ]+)') do @@ -176,24 +176,20 @@ function printBulletPoints(Description,padding) table.insert(array, text) local textColor = EID:getTextColor() for i, v in ipairs(array) do - if i== 1 then - if string.sub(v, 2, 2)=="↑" or string.sub(v, 2, 2)=="↓" or string.sub(v, 2, 2)=="!" then - EID:renderString("!"..string.sub(v,3,string.len(v)), Vector(EIDConfig["XPosition"],padding), Vector(EIDConfig["Scale"],EIDConfig["Scale"]), textColor, false) - else - EID:renderString("\007"..v, Vector(EIDConfig["XPosition"],padding), Vector(EIDConfig["Scale"],EIDConfig["Scale"]), textColor, false) - end - else - EID:renderString(" "..v, Vector(EIDConfig["XPosition"],padding), Vector(EIDConfig["Scale"],EIDConfig["Scale"]), textColor, false) + local bpIcon = " " -- no bulletpoint + if i == 1 then + bpIcon = EID:getBulletpointIcon(v) end + EID:renderString(bpIcon..EID:replaceMarkupStrings(v), Vector(EIDConfig["XPosition"],padding), Vector(EIDConfig["Scale"],EIDConfig["Scale"]), textColor, false) padding = padding +lineHeight*EIDConfig["Scale"] end end end -function printTransformation(S) +function printTransformation(transformationString) local str="Custom"; for i = 0, #transformations-1 do - if (tonumber(S)==i) then + if (tonumber(transformationString)==i) then str = tostring(transformations[i+1]) end end @@ -261,17 +257,6 @@ end --------------------------------------------------------------------------- ---------------------------On Render Function------------------------------ -local hideDescToggle= false - --- check if an entity is part of the describable entities -local function isEntityAllowed(entity) - local isAllowed = false - isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_COLLECTIBLE and EIDConfig["DisplayItemInfo"]) - isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TRINKET and EIDConfig["DisplayTrinketInfo"]) - isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TAROTCARD and EIDConfig["DisplayCardInfo"]) - isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_PILL and EIDConfig["DisplayPillInfo"]) - return entity.Type == EntityType.ENTITY_PICKUP and isAllowed and entity.SubType>0 -end local function onRender(t) isDisplayingText= false @@ -285,13 +270,9 @@ local function onRender(t) if hideDescToggle then return end for i, entity in ipairs(Isaac.GetRoomEntities()) do - local isModEntityDesc = false - if EIDConfig["EnableEntityDescriptions"] and (__eidEntityDescriptions[entity.Type.."."..entity.Variant.."."..entity.SubType]~=nil --[[or type(entity:GetData()["EID_Description"]) ~= type(nil)]]) then - isModEntityDesc= true - end if Game():GetRoom():GetType()==RoomType.ROOM_DICE and entity.Type==1000 and entity.Variant== 76 then closestDice= entity end - if isModEntityDesc or isEntityAllowed(entity) then + if EID:hasDescription(entity) then local diff = entity.Position:__sub(player.Position); if diff:Length() < dist then closest = entity;