Added feature to get descriptions of HUD elements

This commit is contained in:
Wofsauge committed 2021-06-19 23:47:19 +02:00
1 parent b0a12ea770
commit 4b1ebfc1c8
8 files changed
+259 -25

No files matched your search

+40
View File
@@ -800,6 +800,46 @@ function EID:tableToCraftingIconsMerged(craftTable)
end
function EID:handleHUDElement(hudElement)
local alteredHudElement = {}
for k,v in pairs(hudElement) do
alteredHudElement[k] = v
end
local screenSize = EID:GetScreenSize()
for _,v in ipairs(hudElement.anchors) do
if v == "TOP" then
if EID.MCMLoaded then
alteredHudElement.y = hudElement.y + EID.MCMHudOffset * 2
end
elseif v == "LEFT" then
if EID.MCMLoaded then
alteredHudElement.x = hudElement.x + EID.MCMHudOffset * 2
end
elseif v == "BOTTOM" then
alteredHudElement.y = screenSize.Y*2 - alteredHudElement.y - alteredHudElement.height
if EID.MCMLoaded then
alteredHudElement.y = alteredHudElement.y - EID.MCMHudOffset * 2
end
elseif v == "RIGHT" then
alteredHudElement.x = screenSize.X*2 - alteredHudElement.x - alteredHudElement.width
if EID.MCMLoaded then
alteredHudElement.x = alteredHudElement.x - EID.MCMHudOffset * 2
end
end
end
return alteredHudElement
end
function EID:GetScreenSize()
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 Vector(rx*2 + 13*26, ry*2 + 7*26)
end
-- Creates a copy of a KColor object. This prevents overwriting existing
function EID:copyKColor(colorObj)
return KColor(colorObj.Red, colorObj.Green, colorObj.Blue, colorObj.Alpha)
+12
View File
@@ -158,6 +158,16 @@ EID.UserConfig = {
-- Default = 7
["BagOfCraftingResults"] = 7,
---------Mouse Controls-----------
-- Toggles HUD descriptions based on the mouse position
-- Default = "false"
["EnableMouseControls"] = "false",
-- Toggles the custom mouse cursor
-- Default = "true"
["ShowCursor"] = "true",
-------------MISC---------------
-- Changes the number of Results shown for the additional Spindown dice description
@@ -236,6 +246,8 @@ EID.DefaultConfig = {
["DisplayBagOfCrafting"] = "always",
["BagOfCraftingResults"] = 7,
["SpindownDiceResults"] = 3,
["UseMouseControls"] = "false",
["ShowCursor"] = "true",
["ErrorMessage"] = "[Effect not defined]",
["TextColor"] = "ColorEIDText",
["ErrorColor"] = "ColorEIDError",
+53 -1
View File
@@ -21,6 +21,57 @@ EID.SpindownDiceSkipIDs = {
[718]=true
}
EID.HUDElements = {
["Active1"] = {x = 20,y = 5, width = 65, height = 65, anchors={"TOP","LEFT"}, descriptionObj = function()
local id = EID.player:GetActiveItem(ActiveSlot.SLOT_PRIMARY)
if id == 0 then return nil end
return EID:getDescriptionObj(5, 100, id)
end},
["Active2"] = {x = -5,y = 0, width = 35, height = 35, anchors={"TOP","LEFT"}, descriptionObj = function()
local id = EID.player:GetActiveItem(ActiveSlot.SLOT_SECONDARY)
if id == 0 then return nil end
return EID:getDescriptionObj(5, 100, id)
end},
["Trinket1"] = {x = 50,y = 0, width = 55, height = 65, anchors={"BOTTOM","LEFT"}, descriptionObj = function()
local id = EID.player:GetTrinket(0)
if id == 0 then return nil end
return EID:getDescriptionObj(5, 350, id)
end},
["Trinket2"] = {x = 0,y = 40, width = 55, height = 65, anchors={"BOTTOM","LEFT"}, descriptionObj = function()
local id = EID.player:GetTrinket(1)
if id == 0 then return nil end
return EID:getDescriptionObj(5, 350, id)
end},
["Pocket1"] = {x = 0,y = 5, width = 250, height = 40, anchors={"BOTTOM","RIGHT"}, descriptionObj = function()
local id = EID.player:GetCard(0)
if id ~= 0 then return EID:getDescriptionObj(5, 300, id) end
id = EID.player:GetPill(0)
if id ~= 0 then return EID:getDescriptionObj(5, 70, id) end
return nil
end},
["Pocket2"] = {x = 0,y = 40, width = 30, height = 30, anchors={"BOTTOM","RIGHT"}, descriptionObj = function()
local id = EID.player:GetCard(1)
if id ~= 0 then return EID:getDescriptionObj(5, 300, id) end
id = EID.player:GetPill(1)
if id ~= 0 then return EID:getDescriptionObj(5, 70, id) end
return nil
end},
["Pocket3"] = {x = 0,y = 70, width = 30, height = 25, anchors={"BOTTOM","RIGHT"}, descriptionObj = function()
local id = EID.player:GetCard(2)
if id ~= 0 then return EID:getDescriptionObj(5, 300, id) end
id = EID.player:GetPill(2)
if id ~= 0 then return EID:getDescriptionObj(5, 70, id) end
return nil
end},
["Pocket4"] = {x = 0,y = 95, width = 30, height = 20, anchors={"BOTTOM","RIGHT"}, descriptionObj = function()
local id = EID.player:GetCard(3)
if id ~= 0 then return EID:getDescriptionObj(5, 300, id) end
id = EID.player:GetPill(3)
if id ~= 0 then return EID:getDescriptionObj(5, 70, id) end
return nil
end}
}
-- Specific strings that will be replaced with something else. This is used to convert Shortcuts into internal markup.
EID.TextReplacementPairs = {
{"!!!", "{{Warning}}"}, -- Turn 3 Exclamations into Warning
@@ -35,6 +86,7 @@ EID.TextReplacementPairs = {
{"\8\189", "{{Bomb}}"}, -- Legacy BOMB
{"{{Hashtag}}", "ǂ"}, -- Hashtag
{"{{CR}}", "{{ColorReset}}"}, -- Shortcut for Color Resetting
{"{{EthernalHeart}}", "{{EternalHeart}}"} -- fix spelling error
}
--Format: [SHORTCUT]= {Animationname, Frame, Width, Height, LeftOffset [Default: -1], TopOffset [Default: 0], SpriteObject [Default: EID.InlineIconSprite]}
@@ -61,7 +113,7 @@ EID.InlineIcons = {
-- Hearts
["Heart"] = {"hearts", 0, 9, 9},
["HalfHeart"] = {"hearts", 1, 9, 9},
["EthernalHeart"] = {"hearts", 2, 9, 9},
["EternalHeart"] = {"hearts", 2, 9, 9},
["EmptyHeart"] = {"hearts", 3, 9, 9},
["BlendedHeart"] = {"hearts", 4, 9, 9},
["BoneHeart"] = {"hearts", 5, 9, 9},
+2
View File
@@ -102,6 +102,8 @@ EID:addColor("ColorBlackBlink", nil, function(color)
local function onDebugRender(t)
EID:renderHUDLocationIndicators()
for i,v in ipairs(Isaac.FindByType(5,10,3,true,false)) do
if v:GetData()["EID_Description"] == nil then
v:GetData()["EID_Description"] = "Test specific description#Init seed: ".. v.InitSeed
+42 -2
View File
@@ -45,6 +45,10 @@ local ArrowSprite = Sprite()
ArrowSprite:Load("gfx/eid_transform_icons.anm2", true)
ArrowSprite:Play("Arrow", false)
local hudBBSprite = Sprite()
hudBBSprite:Load("gfx/eid_transform_icons.anm2", true)
hudBBSprite:Play("boundingBox")
------- Load all modules and other stuff ------
require("mod_config_menu")
@@ -403,6 +407,33 @@ function EID:renderIndicator(entity)
end
end
function EID:renderHUDLocationIndicators()
local mousePos = Input.GetMousePosition(false)
Isaac.RenderScaledText("Mouse pos X:"..mousePos.X.." Y:"..mousePos.Y, 100, 10, 0.5, 0.5, 1 ,1 ,1 ,1 )
Isaac.RenderScaledText("HUD Adjustment Preview!", 200, 10, 1, 1, 1 ,0.25 ,0.25 ,1 )
for k, v in pairs(EID.HUDElements) do
local hudElement = EID:handleHUDElement(v)
hudBBSprite.Scale = Vector(hudElement.width/2, hudElement.height/2)
hudBBSprite.Color = Color(1, 1, 1, EID.Config["Transparency"], 0, 0, 0)
hudBBSprite:Render(Vector(hudElement.x/2, hudElement.y/2), nullVector, nullVector)
Isaac.RenderScaledText(k, hudElement.x/2, hudElement.y/2, 0.5, 0.5, 1, 1, 1 ,1)
end
end
function EID:handleHoverHUD()
local mousePos = Input.GetMousePosition(false)
if EID.Config["ShowCursor"] then
EID.IconSprite:Play("Cursor")
EID:renderIcon(EID.IconSprite, mousePos.X/2, mousePos.Y/2)
end
for k, v in pairs(EID.HUDElements) do
local hudElement = EID:handleHUDElement(v)
if hudElement.x <= mousePos.X and (hudElement.x + hudElement.width) >= mousePos.X and hudElement.y <= mousePos.Y and (hudElement.y + hudElement.height) >= mousePos.Y then
return hudElement.descriptionObj() or nil
end
end
return nil
end
---------------------------------------------------------------------------
---------------------------On Update Function------------------------------
@@ -502,8 +533,17 @@ local function onRender(t)
EID.lastDescriptionEntity = nil
EID.lastDist = 10000
local searchGroups = {}
local sourcePos = EID.player.Position
table.insert(searchGroups, Isaac.FindInRadius(EID.player.Position, tonumber(EID.Config["MaxDistance"])*40, searchPartitions))
if EID.Config["EnableMouseControls"] then
local hudDescription = EID:handleHoverHUD()
if hudDescription then
EID:printDescription(hudDescription)
return
end
end
table.insert(searchGroups, Isaac.FindInRadius(sourcePos, tonumber(EID.Config["MaxDistance"])*40, searchPartitions))
for k,_ in pairs(EID.effectList) do
table.insert(searchGroups, Isaac.FindByType(EntityType.ENTITY_EFFECT, k, -1, true, false))
end
@@ -511,7 +551,7 @@ local function onRender(t)
for _, entitySearch in ipairs(searchGroups) do
for i, entity in ipairs(entitySearch) do
if EID:hasDescription(entity) and entity.FrameCount > 0 then
local diff = entity.Position:__sub(EID.player.Position)
local diff = entity.Position:__sub(sourcePos)
if diff:Length() < EID.lastDist then
EID.lastDescriptionEntity = entity
EID.lastDist = diff:Length()
+84 -21
View File
@@ -1,42 +1,57 @@
-- MOD CONFIG MENU Compatibility
local MCMLoaded, MCM = pcall(require, "scripts.modconfig")
EID.MCMCompat_isDisplayingEIDTab = false
EID.MCMCompat_isDisplayingEIDTab = ""
local MCMCompat_isDisplayingDummyMCMObj = false
local MCMCompat_oldPermanentObj = false
EID.MCMLoaded = MCMLoaded
local colorNameArray = {}
EID.MCMHudOffset = ModConfigMenu.Config["General"].HudOffset
function EID:renderMCMDummyDescription()
if MCMLoaded then
local mcmHudOffset = ModConfigMenu.Config["General"].HudOffset
if mcmHudOffset == nil and ScreenHelper then
mcmHudOffset = ScreenHelper.GetOffset()
end
EID:addTextPosModifier("MCM_HudOffset", Vector(mcmHudOffset * 2, mcmHudOffset))
if MCM.IsVisible and EID.permanentDisplayTextObj == nil and EID.MCMCompat_isDisplayingEIDTab then
local function renderDummyDesc()
MCMCompat_oldPermanentObj = EID.permanentDisplayTextObj
local demoDescObj = EID:getDescriptionObj(5, 100, 33)
demoDescObj.Name = "Demo Object Name"
demoDescObj.Transformation = "Demo Transformation"
demoDescObj.Description = "A very cool description as a demonstration of the power of EID!#\1 This is also a cool line#This line loves you {{Heart}}"
EID:displayPermanentText(demoDescObj)
MCMCompat_isDisplayingDummyMCMObj = true
EID:buildColorArray()
elseif not MCM.IsVisible and MCMCompat_isDisplayingDummyMCMObj then
end
local function clearRenderDummyDesc()
if MCMCompat_oldPermanentObj == nil then
EID:hidePermanentText()
else
EID.permanentDisplayTextObj = MCMCompat_oldPermanentObj
end
EID.MCMCompat_isDisplayingEIDTab = false
MCMCompat_oldPermanentObj = nil
MCMCompat_isDisplayingDummyMCMObj = false
end
function EID:renderMCMDummyDescription()
if MCMLoaded then
EID.MCMHudOffset = ModConfigMenu.Config["General"].HudOffset
if EID.MCMHudOffset == nil and ScreenHelper then
EID.MCMHudOffset = ScreenHelper.GetOffset()
end
EID:addTextPosModifier("MCM_HudOffset", Vector(EID.MCMHudOffset * 2, EID.MCMHudOffset))
if MCM.IsVisible and EID.MCMCompat_isDisplayingEIDTab ~= "" then
if EID.MCMCompat_isDisplayingEIDTab == "Mouse" and EID.Config["EnableMouseControls"] then
clearRenderDummyDesc()
EID:renderHUDLocationIndicators()
elseif EID.MCMCompat_isDisplayingEIDTab == "Visuals" and EID.permanentDisplayTextObj == nil then
renderDummyDesc()
end
MCMCompat_isDisplayingDummyMCMObj = true
EID:buildColorArray()
elseif not MCM.IsVisible and MCMCompat_isDisplayingDummyMCMObj then
clearRenderDummyDesc()
EID.MCMCompat_isDisplayingEIDTab = ""
colorNameArray = {}
end
end
end
function EID:buildColorArray()
colorNameArray = {}
for k,v in pairs(EID.InlineColors) do
@@ -85,7 +100,7 @@ if MCMLoaded then
Minimum = 1,
Maximum = #(EID.Languages),
Display = function()
EID.MCMCompat_isDisplayingEIDTab = false;
EID.MCMCompat_isDisplayingEIDTab = "";
return "Language: " .. displayLanguage[AnIndexOf(EID.Languages, EID.Config["Language"])]
end,
OnChange = function(currentNum)
@@ -308,7 +323,7 @@ if MCMLoaded then
return EID.Config["DisplayItemInfo"]
end,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = false;
EID.MCMCompat_isDisplayingEIDTab = "";
local onOff = "False"
if EID.Config["DisplayItemInfo"] then
onOff = "True"
@@ -644,7 +659,7 @@ if MCMLoaded then
Minimum = 1,
Maximum = #fontTypes,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = true;
EID.MCMCompat_isDisplayingEIDTab = "Visuals";
return "Font Type: " .. EID.Config["FontType"]
end,
OnChange = function(currentNum)
@@ -824,9 +839,60 @@ if MCMLoaded then
end
}
)
---------------------------------------------------------------------------
-----------------------------Mouse Controls--------------------------------
MCM.AddText("EID", "Mouse", function() return "! THIS FEATURE IS IN EARLY DEVELOPMENT !" end)
MCM.AddSpace("EID", "Mouse")
MCM.AddText("EID", "Mouse", function() return "MCM -> General -> Hud Offset" end)
MCM.AddText("EID", "Mouse", function() return "to adjust Hud Offset" end)
MCM.AddSpace("EID", "Mouse")
-- Enable mouse controls
MCM.AddSetting(
"EID",
"Mouse",
{
Type = ModConfigMenu.OptionType.BOOLEAN,
CurrentSetting = function()
return EID.Config["EnableMouseControls"]
end,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = "Mouse";
local onOff = "False"
if EID.Config["EnableMouseControls"] then
onOff = "True"
end
return "Enable Mouse controls: " .. onOff
end,
OnChange = function(currentBool)
EID.Config["EnableMouseControls"] = currentBool
end,
Info = {"If enabled, allows to hover over certain HUD elements to get descriptions"}
}
)
-- Enable mouse controls
MCM.AddSetting(
"EID",
"Mouse",
{
Type = ModConfigMenu.OptionType.BOOLEAN,
CurrentSetting = function()
return EID.Config["ShowCursor"]
end,
Display = function()
local onOff = "False"
if EID.Config["ShowCursor"] then
onOff = "True"
end
return "Show Cursor: " .. onOff
end,
OnChange = function(currentBool)
EID.Config["ShowCursor"] = currentBool
end,
}
)
---------------------------------------------------------------------------
---------------------------------Visuals-----------------------------------
---------------------------------Colors-----------------------------------
-- Text Color
MCM.AddSetting(
@@ -840,7 +906,7 @@ if MCMLoaded then
Minimum = 0,
Maximum = 1000,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = true;
EID.MCMCompat_isDisplayingEIDTab = "Visuals";
return "Descriptions: " .. string.gsub(EID.Config["TextColor"], "Color", "").. " ("..AnIndexOf(colorNameArray, EID.Config["TextColor"]).."/"..#colorNameArray..")"
end,
OnChange = function(currentNum)
@@ -863,7 +929,6 @@ if MCMLoaded then
Minimum = 0,
Maximum = 1000,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = true;
return "Names: " .. string.gsub(EID.Config["ItemNameColor"], "Color", "").. " ("..AnIndexOf(colorNameArray, EID.Config["ItemNameColor"]).."/"..#colorNameArray..")"
end,
OnChange = function(currentNum)
@@ -886,7 +951,6 @@ if MCMLoaded then
Minimum = 0,
Maximum = 1000,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = true;
return "Transformations: " .. string.gsub(EID.Config["TransformationColor"], "Color", "").. " ("..AnIndexOf(colorNameArray, EID.Config["TransformationColor"]).."/"..#colorNameArray..")"
end,
OnChange = function(currentNum)
@@ -909,7 +973,6 @@ if MCMLoaded then
Minimum = 0,
Maximum = 1000,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = true;
return "Errors: " .. string.gsub(EID.Config["ErrorColor"], "Color", "").. " ("..AnIndexOf(colorNameArray, EID.Config["ErrorColor"]).."/"..#colorNameArray..")"
end,
OnChange = function(currentNum)
+26 -1
View File
@@ -1,5 +1,5 @@
<AnimatedActor>
<Info CreatedBy="Unknown" CreatedOn="29.05.2021 01:01:14" Version="29" Fps="30"/>
<Info CreatedBy="Unknown" CreatedOn="17.06.2021 22:02:47" Version="30" Fps="30"/>
<Content>
<Spritesheets>
<Spritesheet Path="eid_transform_icons.png" Id="0"/>
@@ -257,5 +257,30 @@
<NullAnimations/>
<Triggers/>
</Animation>
<Animation Name="boundingBox" FrameNum="1" Loop="false">
<RootAnimation>
<Frame XPosition="0" YPosition="0" XScale="100" YScale="100" Delay="1" Visible="true" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
</RootAnimation>
<LayerAnimations>
<LayerAnimation LayerId="0" Visible="true">
<Frame XPosition="0" YPosition="0" XPivot="0" YPivot="0" XCrop="80" YCrop="16" Width="1" Height="1" XScale="100" YScale="100" Delay="1" Visible="true" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
</LayerAnimation>
</LayerAnimations>
<NullAnimations/>
<Triggers/>
</Animation>
<Animation Name="Cursor" FrameNum="2" Loop="false">
<RootAnimation>
<Frame XPosition="0" YPosition="0" XScale="100" YScale="100" Delay="1" Visible="true" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
</RootAnimation>
<LayerAnimations>
<LayerAnimation LayerId="0" Visible="true">
<Frame XPosition="0" YPosition="0" XPivot="0" YPivot="0" XCrop="64" YCrop="0" Width="16" Height="16" XScale="100" YScale="100" Delay="1" Visible="true" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
<Frame XPosition="0" YPosition="0" XPivot="6" YPivot="0" XCrop="80" YCrop="0" Width="16" Height="16" XScale="100" YScale="100" Delay="1" Visible="true" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
</LayerAnimation>
</LayerAnimations>
<NullAnimations/>
<Triggers/>
</Animation>
</Animations>
</AnimatedActor>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB