-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an Auto Craft checkbox to enable/disable auto crafting
- Loading branch information
1 parent
54c79f3
commit 822599d
Showing
3 changed files
with
179 additions
and
28 deletions.
There are no files selected for viewing
27 changes: 24 additions & 3 deletions
27
interface/scripted/recipeCrafterMFM/recipeCrafterMFM.config.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
[ | ||
[ | ||
{ "op": "test", "path": "/gui/craft", "inverse": true }, | ||
{ "op": "add", "path": "/gui/craft", "value": {} } | ||
{ "op": "test", "path": "/gui/toggleAutoCraft", "inverse": true }, | ||
{ "op": "add", "path": "/gui/toggleAutoCraft", "value": {} } | ||
], | ||
[ | ||
{ "op": "remove", "path": "/gui/craft" } | ||
{ "op": "test", "path": "/gui/lblAutoCraft", "inverse": true }, | ||
{ "op": "add", "path": "/gui/lblAutoCraft", "value": {} } | ||
], | ||
[ | ||
{ "op": "replace", "path": "/gui/toggleAutoCraft", "value": { | ||
"type": "button", | ||
"checkable" : true, | ||
"base" : "/interface/crafting/checkboxnocheck.png", | ||
"baseImageChecked" : "/interface/crafting/checkboxcheck.png", | ||
"checked" : false, | ||
"position" : [45, 7] | ||
} | ||
}, | ||
{ "op": "replace", "path": "/gui/lblAutoCraft", "value": { | ||
"type" : "label", | ||
"position" : [55, 7], | ||
"hAnchor" : "left", | ||
"value" : "AUTO CRAFT" | ||
} | ||
}, | ||
{ "op": "add", "path": "/scriptWidgetCallbacks/-", "value": "toggleAutoCraft" }, | ||
{ "op": "replace", "path": "/scripts", "value": [ "/interface/scripted/recipeCrafterMFM/recipeCrafterMFMFUgui.lua" ] } | ||
] | ||
] |
83 changes: 83 additions & 0 deletions
83
interface/scripted/recipeCrafterMFM/recipeCrafterMFMFUgui.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require "/scripts/MFM/entityQueryAPI.lua" | ||
require "/interface/scripted/recipeCrafterMFM/recipeCrafterMFMgui.lua" | ||
|
||
local autoCraftStateUpdated = false; | ||
local entityId = nil; | ||
local settings = { | ||
autoCraftState = false | ||
}; | ||
|
||
TOGGLE_AUTOCRAFT_NAME = "toggleAutoCraft"; | ||
|
||
function init() | ||
EntityQueryAPI.init() | ||
entityId = pane.containerEntityId() | ||
autoCraftStateUpdated = false; | ||
RecipeCrafterMFMGui.init() | ||
hideCraftButtonIfAutoCraftEnabled() | ||
end | ||
|
||
function update(dt) | ||
updateAutoCraftState() | ||
RecipeCrafterMFMGui.update(dt) | ||
end | ||
|
||
--------------------------------------------------------------------- | ||
|
||
function getAutoCraftState() | ||
if(storage) then | ||
return storage.autoCraftState | ||
else | ||
return settings.autoCraftState | ||
end | ||
end | ||
|
||
function setAutoCraftState(val) | ||
if(storage) then | ||
storage.autoCraftState = toEnable | ||
else | ||
settings.autoCraftState = toEnable | ||
end | ||
hideCraftButtonIfAutoCraftEnabled() | ||
end | ||
|
||
function toggleAutoCraft() | ||
if(entityId == nil) then | ||
return | ||
end | ||
local toEnable = widget.getChecked(TOGGLE_AUTOCRAFT_NAME) | ||
setAutoCraftState(toEnable) | ||
hideCraftButtonIfAutoCraftEnabled() | ||
world.sendEntityMessage(entityId, "setAutoCraftState", toEnable) | ||
end | ||
|
||
function hideCraftButtonIfAutoCraftEnabled() | ||
if(getAutoCraftState()) then | ||
widget.setVisible("craft", false) | ||
else | ||
widget.setVisible("craft", true) | ||
end | ||
end | ||
|
||
function updateAutoCraftState() | ||
if(autoCraftStateUpdated) then | ||
return | ||
end | ||
local handle = function() | ||
local result = EntityQueryAPI.requestData(entityId, "getAutoCraftState", 0, nil) | ||
if(result ~= nil) then | ||
return true, result | ||
end | ||
return false, nil | ||
end | ||
|
||
local onCompleted = function(result) | ||
local autoCraftState = result.autoCraftState | ||
setAutoCraftState(autoCraftState) | ||
hideCraftButtonIfAutoCraftEnabled() | ||
widget.setChecked(TOGGLE_AUTOCRAFT_NAME, autoCraftState) | ||
autoCraftStateUpdated = true | ||
end | ||
|
||
EntityQueryAPI.addRequest("RGMFMFUGui.updateAutoCraftState", handle, onCompleted) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters