Skip to content

Widgets will not open after CC when wrapping CC DataContext #577

@NinthPlane

Description

@NinthPlane

I have attempted solutions to common problems

Yes

I have checked that my game version is supported

Yes

OS

Windows 11

Platform

Steam

Description

When wrapping the CharacterCreation (gui::DCCharacterCreation) DataContext, most widgets no longer open once completing or cancelling the CC. For example, all the buttons in the main menu, opening the inventory etc.

Otherwise, it appears to work well. I am able to use the wrapped context in the xaml files and get stuff done.

Indications

I am developing a mod and no other mods are active.

Diagnostic Files

BG3 Diagnostic Data.txt

Steps to Reproduce

  1. Load game with mod
  2. Enable mod
  3. Start a new game
  4. Complete or cancel the CC (defaults are fine)
  5. Try to open the inventory or click a button in the main menu

Attached is a minimal repro:
BG3SE_RegisterTypeBug_4a6b3765-9af7-3f03-c23b-4bdd41738959.zip

The script in question (I have noted other issues that occur):

function GetWidget(name)
    if not Ext.UI.GetRoot() then
        return
    end

    local root = Ext.UI.GetRoot():Child(1):Child(1)
    if not root then
        return
    end

    local count = root.ChildrenCount
    if count < 1 then
        return
    end

    for i = 1, count do
        local child = root:Child(i)
        if child == nil then
            return child
        end
        if child.Name == name or child.Name == name .. "_c" then
            return child
        end
    end
end

function GetCharacterCreation()
    return GetWidget("CharacterCreation")
end

local changeCallback = function(context, value)
    print("Value changed: ", value)
end

local tick = 0

local registered = false
local instantiated = false

-- Get the following error if registration done in bootstrap.
-- Wrapped context type 'gui::DCCharacterCreation' does not exist
-- bg3se::lua::State::LoadScript(): Failed to execute script: [string "BG3SE_RegisterTypeBug/BootstrapClient.lua"]:36: Invalid wrapped context type 'gui::DCCharacterCreation'
-- stack traceback:
--         [C++ Code]: in field 'RegisterType'
--         BG3SE_RegisterTypeBug/BootstrapClient.lua:36: in main chunk
--         [C++ Code]: in field 'Include'
--         builtin://Libs/ModLoader.lua:77: in method 'LoadBootstrap'
--         builtin://BuiltinLibrary.lua:31: in function <builtin://BuiltinLibrary.lua:30>
-- Ext.UI.RegisterType("BG3SE_RegisterTypeBug_CharacterCreation", { CustomList = { Type = "Collection" } }, "gui::DCCharacterCreation")

Ext.Events.Tick:Subscribe(function (e)
    local cc = GetCharacterCreation()

    -- Not in CC.
    if not cc then
        return
    end

    -- From here on, we are in the CC view.

    -- Delaying the registration/instation prevents UI breaking in CC. Delay is much longer than it needs to be.
    -- The delay does not change the bug outside of CC.
    if not registered and tick > 120 then
        -- Get the following warnings, even on first registration:
        -- Registering type 'INotifyPropertyChanged' when it already exists in the registry? Might be problematic
        -- Registering type 'String' when it already exists in the registry? Might be problematic
        -- Registering type 'Ptr<BaseComponent>' when it already exists in the registry? Might be problematic
        Ext.UI.RegisterType("BG3SE_RegisterTypeBug_CharacterCreation", { MyStringProperty = { Type = "String", WriteCallback = changeCallback } }, "gui::DCCharacterCreation")
        registered = true
        print("Type Registered!")
    end

    if not instantiated and tick > 240 then
        -- Once beyond the CC in the tutorial, most widgets no longer work.
        cc.DataContext = Ext.UI.Instantiate("se::BG3SE_RegisterTypeBug_CharacterCreation", cc.DataContext)
        instantiated = true
        print("Type Instantiated!")
    end

    tick = tick + 1
end)

Expected Behavior

Once out of the CC, widgets should open and stay open like normal.

Actual Behavior

Once out of the CC, widgets do not open. Some seem to open for a split second and then immediately close again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions