如何在Tabletop Simulator左侧侧边栏添加脚本按钮作为新工具项?
关于Tabletop Simulator左侧侧边栏添加自定义按钮的问题
目前Tabletop Simulator官方确实没有开放直接在左侧原生侧边栏添加自定义按钮的接口,不管是通过Lua脚本还是XML自定义UI都做不到——你查文档没找到是对的,这部分原生UI功能没对外开放。
不过可以用几个替代方案实现类似效果,不占用桌面空间:
自定义UI模拟侧边栏
用XML创建一个固定在屏幕左侧的自定义面板,把设置按钮放在里面,视觉上和原生侧边栏位置重合,效果差不多。示例XML代码:<Panel id="CustomSidebar" position="0, 0, 0" width="100" height="600" background="#222222" alpha="0.9"> <Button id="PlayerSetupBtn" text="玩家配置" onClick="callScript('setupPlayers')" position="10, 20, 0" width="80" height="45"/> <Button id="ModeSwitchBtn" text="切换玩法" onClick="callScript('switchGameMode')" position="10, 75, 0" width="80" height="45"/> </Panel>对应的Lua脚本实现逻辑:
function setupPlayers() -- 这里写玩家人数设置的逻辑 print("玩家配置已执行") end function switchGameMode() -- 这里写玩法切换的逻辑 print("玩法模式已切换") end利用自定义菜单分类管理
虽然是下拉菜单,但可以把设置项分类整理,比散在桌面的按钮整洁很多,而且不占空间。示例XML代码:<CustomMenu> <MenuItem text="玩家设置" onClick="callScript('setupPlayers')"/> <MenuSeparator/> <MenuItem text="玩法模式"> <MenuItem text="休闲模式" onClick="callScript('setCasualMode')"/> <MenuItem text="竞技模式" onClick="callScript('setCompetitiveMode')"/> </MenuItem> <MenuSeparator/> <MenuItem text="重置游戏" onClick="callScript('resetGame')"/> </CustomMenu>桌面隐藏式按钮组
把按钮放在桌面左侧边缘,设置为仅hover时显示,平时隐藏不占空间。Lua脚本示例:local sidebarBtnGroup = {} -- 创建玩家设置按钮 local playerBtn = spawnObject({type="Button", position={-18, 1, 0}, scale={0.6,0.6,0.6}, color={0.2,0.2,0.2}}) playerBtn.createButton({ label="玩家设置", click_function="setupPlayers", function_owner=self, font_size=16 }) playerBtn.interactable = false table.insert(sidebarBtnGroup, playerBtn) -- 创建玩法切换按钮 local modeBtn = spawnObject({type="Button", position={-18, 1, -1}, scale={0.6,0.6,0.6}, color={0.2,0.2,0.2}}) modeBtn.createButton({ label="切换玩法", click_function="switchGameMode", function_owner=self, font_size=16 }) modeBtn.interactable = false table.insert(sidebarBtnGroup, modeBtn) -- 鼠标hover时显示按钮 function showSidebarBtns() for _, btn in ipairs(sidebarBtnGroup) do btn.interactable = true btn.setColor({1,1,1}) end end -- 鼠标离开时隐藏按钮 function hideSidebarBtns() for _, btn in ipairs(sidebarBtnGroup) do btn.interactable = false btn.setColor({0.2,0.2,0.2}) end end -- 给每个按钮绑定hover事件 for _, btn in ipairs(sidebarBtnGroup) do btn.setOnHoverEnter(self, "showSidebarBtns") btn.setOnHoverExit(self, "hideSidebarBtns") end
这几个方案都能满足你“不占用桌面空间、快速调用设置脚本”的需求,选最适合你模组风格的就行。
内容的提问来源于stack exchange,提问作者Alban Lusitanae
相关产品推荐
相关产品推荐

