Jump to content

Recommended Posts

I'm the author of the Crafting Guide Mod. Before the update the mod was able to utilize DoRecipeClick function from custom ui to craft items. This stopped working for non-structure crafts after the crafting update and I can't figure out why. Placing a structure using this function still works though

if recipe_data ~= nil then
    local already_buffered = self.owner.replica.builder:IsBuildBuffered(recipe_data.recipe.name)
    local stay_open, error_msg = _G.DoRecipeClick(self.owner, recipe_data.recipe, self.skin_name)
    if not stay_open then
      self.owner:PushEvent("refreshcrafting") -- this is only really neede for free crafting

      if already_buffered or Profile:GetCraftingMenuBufferedBuildAutoClose() then
        self.owner.HUD:CloseCrafting()
      end
    end
    if error_msg and not TheNet:IsServerPaused() then
      _G.SendRPCToServer(_G.RPC.CannotBuild, error_msg)
    end
end

this code is used for create button

The problem is this snippet of the DoRecipeClick fn:

	if owner.components.playercontroller ~= nil then
            local iscontrolsenabled, ishudblocking = owner.components.playercontroller:IsEnabled()
            if not (iscontrolsenabled or ishudblocking) then
                --Ignore button click when controls are disabled
                --but not just because of the HUD blocking input
                return true
            end
        end

This will return false, as playercontroller:IsEnabled will return false,nil

Spoiler

function PlayerController:IsEnabled()
    if self.classified == nil or not self.classified.iscontrollerenabled:value() then
        return false
    elseif self.inst.HUD ~= nil and self.inst.HUD:HasInputFocus() then
		return false, self.inst.HUD:IsCraftingOpen() and TheFrontEnd.textProcessorWidget == nil
    end
    return true
end

 

You could try to hook into the inst.HUD:IsCraftingOpen() function and make it so that your widget returns true if it's there or hook any other function on the way.

Edit: A quick fix would be this:

Spoiler

AddClassPostConstruct("screens/playerhud",function(self)
    local old_IsCraftingOpen = self.IsCraftingOpen
    function self:IsCraftingOpen(...)
      	local activeScreen = TheFrontEnd:GetActiveScreen()
        if activeScreen and activeScreen.name == "Root" then
            return true
        else
            return old_IsCraftingOpen(self,...)
        end
    end
end)

 

 

Edited by Monti18
  • Like 1
7 hours ago, Monti18 said:

The problem is this snippet of the DoRecipeClick fn:


	if owner.components.playercontroller ~= nil then
            local iscontrolsenabled, ishudblocking = owner.components.playercontroller:IsEnabled()
            if not (iscontrolsenabled or ishudblocking) then
                --Ignore button click when controls are disabled
                --but not just because of the HUD blocking input
                return true
            end
        end

This will return false, as playercontroller:IsEnabled will return false,nil

  Reveal hidden contents


function PlayerController:IsEnabled()
    if self.classified == nil or not self.classified.iscontrollerenabled:value() then
        return false
    elseif self.inst.HUD ~= nil and self.inst.HUD:HasInputFocus() then
		return false, self.inst.HUD:IsCraftingOpen() and TheFrontEnd.textProcessorWidget == nil
    end
    return true
end

 

You could try to hook into the inst.HUD:IsCraftingOpen() function and make it so that your widget returns true if it's there or hook any other function on the way.

Edit: A quick fix would be this:

  Reveal hidden contents


AddClassPostConstruct("screens/playerhud",function(self)
    local old_IsCraftingOpen = self.IsCraftingOpen
    function self:IsCraftingOpen(...)
      	local activeScreen = TheFrontEnd:GetActiveScreen()
        if activeScreen and activeScreen.name == "Root" then
            return true
        else
            return old_IsCraftingOpen(self,...)
        end
    end
end)

 

 

Thank you so much! I'm definitely gonna implement this solution

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...