Version 2.2.1 - updated market, text editor, bot

This commit is contained in:
OTCv8
2020-04-02 06:47:02 +02:00
parent 932165111d
commit ed8162a9d5
20 changed files with 263 additions and 163 deletions

View File

@@ -366,7 +366,8 @@ function initCallbacks()
onAppear = botCreatureAppear,
onDisappear = botCreatureDisappear,
onPositionChange = botCreaturePositionChange,
onHealthPercentChange = botCraetureHealthPercentChange
onHealthPercentChange = botCraetureHealthPercentChange,
onTurn = botCreatureTurn
})
connect(LocalPlayer, {
@@ -414,7 +415,8 @@ function terminateCallbacks()
onAppear = botCreatureAppear,
onDisappear = botCreatureDisappear,
onPositionChange = botCreaturePositionChange,
onHealthPercentChange = botCraetureHealthPercentChange
onHealthPercentChange = botCraetureHealthPercentChange,
onTurn = botCreatureTurn
})
disconnect(LocalPlayer, {
@@ -559,3 +561,8 @@ function botChannelEvent(channelId, name, event)
if botExecutor == nil then return false end
safeBotCall(function() botExecutor.callbacks.onChannelEvent(channelId, name, event) end)
end
function botCreatureTurn(creature, direction)
if botExecutor == nil then return false end
safeBotCall(function() botExecutor.callbacks.onTurn(creature, direction) end)
end

View File

@@ -59,7 +59,8 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, relo
onChannelList = {},
onOpenChannel = {},
onCloseChannel = {},
onChannelEvent = {}
onChannelEvent = {},
onTurn = {}
}
-- basic functions & classes
@@ -311,6 +312,11 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, relo
callback(channelId, name, event)
end
end,
onTurn = function(creature, direction)
for i, callback in ipairs(context._callbacks.onTurn) do
callback(creature, direction)
end
end,
}
}
end

View File

@@ -146,6 +146,10 @@ context.onChannelEvent = function(callback)
return context.callback("onChannelEvent", callback)
end
-- onTurn -- callback = function(creature, direction)
context.onTurn = function(callback)
return context.callback("onTurn", callback)
end
-- CUSTOM CALLBACKS

View File

@@ -166,7 +166,7 @@ Config.setup = function(dir, widget, configExtension, callback)
end
widget.add.onClick = function()
context.UI.SinglelineEditorWindow("config_name", function(name)
context.UI.SinglelineEditorWindow("config_name", {title="Enter config name"}, function(name)
name = name:gsub("%s+", "_")
if name:len() == 0 or name:len() >= 30 or name:find("/") or name:find("\\") then
return context.error("Invalid config name")
@@ -185,8 +185,7 @@ Config.setup = function(dir, widget, configExtension, callback)
widget.edit.onClick = function()
local name = context.storage._configs[dir].selected
if not name then return end
context.UI.MultilineEditorWindow("Config editor - " .. name .. " in " .. dir,
Config.loadRaw(dir, name), function(newValue)
context.UI.MultilineEditorWindow(Config.loadRaw(dir, name), {title="Config editor - " .. name .. " in " .. dir}, function(newValue)
local data = Config.parse(newValue)
Config.save(dir, name, data, configExtension)
refresh()

View File

@@ -4,12 +4,31 @@ if type(context.UI) ~= "table" then
end
local UI = context.UI
UI.SinglelineEditorWindow = function(text, callback)
return modules.game_textedit.singlelineEditor(text, callback)
UI.EditorWindow = function(text, options, callback)
--[[
Available options:
title = text
description = text
multiline = true / false
width = number
validation = text (regex)
examples = {{name, text}, {name, text}}
]]--
local window = modules.game_textedit.edit(text, options, callback)
window.botWidget = true
return window
end
UI.MultilineEditorWindow = function(description, test, callback)
return modules.game_textedit.multilineEditor(description, test, callback)
UI.SinglelineEditorWindow = function(text, options, callback)
options = options or {}
options.multiline = false
return UI.EditorWindow(text, options, callback)
end
UI.MultilineEditorWindow = function(text, options, callback)
options = options or {}
options.multiline = true
return UI.EditorWindow(text, options, callback)
end
UI.ConfirmationWindow = function(title, question, callback)

View File

@@ -29,7 +29,7 @@ BotConfig < Panel
anchors.top: prev.bottom
anchors.left: parent.left
text: Add
width: 59
width: 56
height: 20
Button
@@ -37,7 +37,7 @@ BotConfig < Panel
anchors.top: prev.top
anchors.horizontalCenter: parent.horizontalCenter
text: Edit
width: 59
width: 56
height: 20
Button
@@ -45,5 +45,5 @@ BotConfig < Panel
anchors.top: prev.top
anchors.right: parent.right
text: Remove
width: 59
width: 56
height: 20

View File

@@ -22,6 +22,7 @@ BotIcon < UIWidget
margin-top: 0
size: 48 48
phantom: true
optimized: true
UIWidget
id: status