Norbyte / bg3se

Baldur's Gate 3 Script Extender
Other
1.11k stars 68 forks source link

Add the ability to draw icons and textures in ImGui menus #388

Closed WarZone762 closed 4 months ago

WarZone762 commented 5 months ago

Initial draft for drawing icons and textures in ImGui menus.

Overview

Add 2 lua functions, AddImage and AddIcon, for drawing textures and icons from their IDs.

Showcase

Code used:

W = Ext.IMGUI.NewWindow("Image and Icon Showcase")

W:AddText("A Random Noise Texture")
T = W:AddImage("019e6e85-0a62-7987-2196-0e77f7e107a8", 128, 256, 0, 0, 0.5, 1)
SWidth = W:AddSlider("Width")
SWidth.Value = { 128, 0, 0, 0 }
SWidth.Max = { 512, 0, 0, 0 }
SWidth.OnChange = function(_, x) T.Width = x[1] end
SHeight = W:AddSlider("Height")
SHeight.Value = { 256, 0, 0, 0 }
SHeight.Max = { 512, 0, 0, 0 }
SHeight.OnChange = function(_, x) T.Height = x[1] end
SU1 = W:AddSlider("U1")
SU1.Value = { 0, 0, 0, 0 }
SU1.OnChange = function(_, x) T.U1 = x[1] end
SV1 = W:AddSlider("V1")
SV1.Value = { 0, 0, 0, 0 }
SV1.OnChange = function(_, x) T.V1 = x[1] end
SU2 = W:AddSlider("U2")
SU2.Value = { 0.5, 0, 0, 0 }
SU2.OnChange = function(_, x) T.U2 = x[1] end
SV2 = W:AddSlider("V2")
SV2.Value = { 1, 0, 0, 0 }
SV2.OnChange = function(_, x) T.V2 = x[1] end

Icons = {}

local templates = Ext.Template.GetAllRootTemplates();
for _, v in pairs(templates) do
    if #Icons >= 20 then break end
    if v.TemplateType == "item" then
        table.insert(Icons, v)
    end
end

for _, v in pairs(Icons) do
    W:AddIcon(v.Icon)
    W:AddText(v.Name).SameLine = true
end

https://github.com/Norbyte/bg3se/assets/25852324/1c930a44-831b-45df-89d9-2f657d6665d2