This commit is contained in:
2023-08-19 19:21:17 +08:00
parent 36dfa79e0d
commit 76b7abf06b
111 changed files with 12062 additions and 867 deletions

Binary file not shown.

View File

@@ -0,0 +1 @@
<Atlas><Texture filename="modicon.tex" /><Elements><Element name="modicon.tex" u1="0.00390625" u2="0.99609375" v1="0.00390625" v2="0.99609375" /></Elements></Atlas>

View File

@@ -0,0 +1,94 @@
name = "Smart Minisign"
description = [[Can draw by itself
会自己画画的小木牌
v1.14 可以换皮肤(Support Skin)
v1.10 兼容盐箱(SaltBox)
v1.08 兼容mod物品 提供了一个API 允许其他mod调用]]
author = "小班花 mamjun1"
version = "1.1.5"
forumthread = ""
api_version = 10
priority = -99999
dst_compatible = true
dont_starve_compatible = false
reign_of_giants_compatible = false
all_clients_require_mod = true
icon_atlas = "modicon.xml"
icon = "modicon.tex"
configuration_options =
{
{
name = "Icebox",
label = "Icebox",
hover = "Minisign for icebox/允许冰箱添加小木牌",
options =
{
{description = "No(关闭)", data = false},
{description = "Yes(打开)", data = true},
},
default = false,
},
{
name = "ChangeSkin",
label = "ChangeSkin",
hover = "Minisign can change skin/允许小木牌切换皮肤",
options =
{
{description = "Yes(是)", data = true},
{description = "No(否)", data = false},
},
default = true,
},
{
name = "DragonflyChest",
label = "DragonflyChest",
hover = "Minisign for DragonflyChest/允许龙鳞箱子添加小木牌",
options =
{
{description = "No(关闭)", data = false},
{description = "Yes(打开)", data = true},
},
default = false,
},
{
name = "SaltBox",
label = "SaltBox",
hover = "Minisign for SaltBox/允许盐箱添加小木牌",
options =
{
{description = "No(关闭)", data = false},
{description = "Yes(打开)", data = true},
},
default = false,
},
{
name = "BundleItems",
label = "BundleItems",
hover = "Show the item in bundle/显示包裹里面的物品",
options =
{
{description = "No(关闭)", data = false},
{description = "Yes(打开)", data = true},
},
default = false,
},
{
name = "Digornot",
label = "CanbeDug",
hover = "Can be Dug/是否可以被挖",
options =
{
{description = "No(关闭)", data = false},
{description = "Yes(打开)", data = true},
},
default = false,
},
}

View File

@@ -0,0 +1,173 @@
--You have to learn to draw by yourself
Assets = {}
GLOBAL.TUNING.HUAMINISIGN_BUNDLE = GetModConfigData("BundleItems")
GLOBAL.TUNING.HUAMINISIGN_DIG = GetModConfigData("Digornot")
GLOBAL.TUNING.HUAMINISIGN_SKIN = GetModConfigData("ChangeSkin")
---inventoryitem
local inventoryItemAtlasLookup = {}
local function GetAtlas(imagename)
local atlas = inventoryItemAtlasLookup[imagename]
if atlas then
return atlas
end
local base_atlas = "images/inventoryimages1.xml"
atlas = GLOBAL.TheSim:AtlasContains(base_atlas, imagename) and base_atlas or "images/inventoryimages2.xml"
inventoryItemAtlasLookup[imagename] = atlas
return atlas
end
AddClassPostConstruct( "components/inventoryitem_replica", function(self, inst)
local old_SetAtlas = self.SetAtlas
function self:SetAtlas(atlasname)
if old_SetAtlas ~= nil then
old_SetAtlas(self,atlasname)
end
self._huastrings = atlasname ~= nil and GLOBAL.resolvefilepath(atlasname) or ""
end
function self:GetHuaAtlas()
return self._huastrings ~= nil and
self._huastrings ~= "" and
self._huastrings or
self:GetAtlas()
end
end)
----================为了删掉上个旧版本写错的木牌===
local function onloadpostpass(inst, newents, savedata)
if savedata ~= nil then
if savedata.huachest ~= nil and newents[savedata.huachest] ~= nil then
inst:DoTaskInTime(0, inst.Remove)
end
end
end
AddPrefabPostInit("minisign", function(inst)
if not GLOBAL.TheWorld.ismastersim then
return inst
end
local oldOnLoadPostPass = inst.OnLoadPostPass
inst.OnLoadPostPass = function(inst, newents, savedata)
if oldOnLoadPostPass ~= nil then
oldOnLoadPostPass(inst, newents, savedata)
end
onloadpostpass(inst, newents, savedata)
end
end)
-----------------修复垃圾代码完成=============================
local function draw(inst)
if not GLOBAL.TheWorld.ismastersim then
return inst
end
inst:AddComponent("smart_minisign")
end
AddPrefabPostInit("treasurechest", draw)
if GetModConfigData("DragonflyChest") == true then
AddPrefabPostInit("dragonflychest", draw)
end
if GetModConfigData("Icebox") == true then
AddPrefabPostInit("icebox", draw)
end
if GetModConfigData("SaltBox") == true then
AddPrefabPostInit("saltbox", draw)
end
--读取所有已加载的mod
local enabledmods = GLOBAL.ModManager.enabledmods
local thisname = env.modname
--hook一下加载prefabs 加载完prefabs在检索数据
local oldRegisterPrefabs = GLOBAL.ModManager.RegisterPrefabs
GLOBAL.ModManager.RegisterPrefabs = function(self)
oldRegisterPrefabs(self)
for i,modname in ipairs(enabledmods) do
local mod = GLOBAL.ModManager:GetMod(modname)
--检索 modmain里注册的资源
if mod.Assets then
local modatlas = {}
local modatlas_build = {}
--检索所有的贴图
for k,v in ipairs (mod.Assets) do
if v.type == "ATLAS" then
table.insert(modatlas,v.file)
elseif v.type == "ATLAS_BUILD" then
table.insert(modatlas_build,v.file)
end
end
--判断是否有对应的ATLAS_BUILD
for k,v in ipairs(modatlas) do
local notfind = true
for x,y in ipairs(modatlas_build) do
if v == y then
notfind = false
break
end
end
if notfind then
--没有就插入
--因为注册的时候会自动搜索路径,所以自己注册的时候要还原回原来的路径
v = string.gsub(v,"%.%./mods/[^/]+/","",1)
table.insert(Assets,Asset("ATLAS_BUILD",v,256))
end
end
end
--检索 prefabs 里注册的资源
if mod.Prefabs then
for n,prefab in pairs(mod.Prefabs) do
local modatlas = {}
local modatlas_build = {}
--检索所有的贴图
if prefab.assets then
for k,v in pairs (prefab.assets) do
if v.type == "ATLAS" then
table.insert(modatlas,v.file)
elseif v.type == "ATLAS_BUILD" then
table.insert(modatlas_build,v.file)
end
end
end
--判断是否有对应的ATLAS_BUILD
for k,v in ipairs(modatlas) do
local notfind = true
for x,y in ipairs(modatlas_build) do
if v == y then
notfind = false
break
end
end
if notfind then
--没有就插入
v = string.gsub(v,"%.%./mods/[^/]+/","",1)
table.insert(Assets,Asset("ATLAS_BUILD",v,256))
end
end
end
end
end
--注册资源
GLOBAL.RegisterPrefabs(GLOBAL.Prefab("MOD_SMARTSIGNOTHER",nil,Assets,nil,true))
GLOBAL.TheSim:LoadPrefabs({"MOD_SMARTSIGNOTHER"})
table.insert(self.loadedprefabs,"MOD_SMARTSIGNOTHER")
end
GLOBAL.TUNING.SMART_SIGN_DRAW_ENABLE = true
GLOBAL.SMART_SIGN_DRAW = draw
--示例代码
--[[
if TUNING.SMART_SIGN_DRAW_ENABLE then
SMART_SIGN_DRAW(inst)
end
]]--

View File

@@ -0,0 +1,145 @@
local showbundle = TUNING.HUAMINISIGN_BUNDLE
local changeskin = TUNING.HUAMINISIGN_SKIN
local candig = TUNING.HUAMINISIGN_DIG
local function newminisign(inst,self)
if inst.components.drawable then
inst.components.drawable.candraw = false
end
if inst.components.workable then
if not candig then
inst:RemoveComponent("workable")
else
inst.components.workable:SetOnFinishCallback(function()
self.nohuaminisign = true
inst:Remove()
end)
end
end
if inst.components.burnable then
inst:RemoveComponent("burnable")
end
if inst.components.propagator then
inst:RemoveComponent("propagator")
end
end
local Smart_Minisign = Class(function(self, inst)
self.inst = inst
self.nohuaminisign = false
self.sign = nil
self.onclose = nil
inst:ListenForEvent("onclose", function(...) self:OnClose() end)
inst:DoTaskInTime(0.1,function (inst) --load or build
if not self.nohuaminisign then
self:SpawnSign()
self:OnClose()
end
end)
self._onremove = function(pet)
self.sign = nil
end
if inst.components.burnable ~= nil then --remove the fx after burnt
local onburnt = inst.components.burnable.onburnt or nil
inst.components.burnable.onburnt = function()
if onburnt ~= nil then
onburnt(inst)
end
if self.sign ~= nil then
self.sign:Remove()
end
end
end
end)
function Smart_Minisign:SpawnSign()
local inst = self.inst
if inst:HasTag("burnt") then --of course not
return
end
if self.sign ~= nil then --only one
return
end
local sign = SpawnPrefab("minisign")
self:LinkSign(sign)
end
function Smart_Minisign:LinkSign(minisign)
self.sign = minisign
self.inst:AddChild(minisign)
minisign.Transform:SetPosition(0, 0, 0)
self.inst:ListenForEvent("onremove", self._onremove, minisign)
minisign.persists = false
newminisign(minisign,self)
end
function Smart_Minisign:OnClose()
local inst = self.inst
if self.sign ~= nil and inst.components.container~= nil then
local container = inst.components.container
for i = 1, container:GetNumSlots() do
local item = container:GetItemInSlot(i)
if item ~= nil and item.replica.inventoryitem ~= nil then
if changeskin and item.prefab == "minisign_item" then --以旧换新
self.sign:Remove()
local sign = SpawnPrefab("minisign", item.linked_skinname, item.skin_id )
self:LinkSign(sign)
end
local image = item.replica.inventoryitem:GetImage()
local build = item.replica.inventoryitem:GetHuaAtlas()
--for bundle
if showbundle and item.components.unwrappable ~= nil and item.components.unwrappable.itemdata then
for i, v in ipairs(item.components.unwrappable.itemdata) do
if v then
local copy = SpawnPrefab(v.prefab)
if copy then
if copy.replica.inventoryitem ~= nil then
image = copy.replica.inventoryitem:GetImage()
build = copy.replica.inventoryitem:GetHuaAtlas()
end
copy:Remove()
break
end
end
end
end
self.sign.AnimState:OverrideSymbol("SWAP_SIGN", build, image)
if item.inv_image_bg and item.inv_image_bg.atlas then
self.sign.AnimState:OverrideSymbol("SWAP_SIGN_BG", resolvefilepath(item.inv_image_bg.atlas), item.inv_image_bg.image)
else
self.sign.AnimState:ClearOverrideSymbol("SWAP_SIGN_BG")
end
break
end
if i == container:GetNumSlots() and item == nil then
self.sign.AnimState:ClearOverrideSymbol("SWAP_SIGN")
self.sign.AnimState:ClearOverrideSymbol("SWAP_SIGN_BG")
end
end
end
end
function Smart_Minisign:OnSave()
return
{
nohuaminisign = self.nohuaminisign,
sign = self.sign ~= nil and self.sign:GetSaveRecord() or nil
}
end
function Smart_Minisign:OnLoad(data)
if data then
if data.nohuaminisign ~= nil then
self.nohuaminisign = data.nohuaminisign
end
if data.sign ~= nil then
local sign = SpawnSaveRecord(data.sign)
self:LinkSign(sign)
end
end
end
return Smart_Minisign