mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Fixed some of the requested changes
* Made add_task and update_task have consistent arguments * Removed default task title and body * Task list resized to fit to 10 items
This commit is contained in:
@@ -43,8 +43,6 @@ local task_id = Tasks.add_task(game.player.force.name, nil, game.player.name)
|
|||||||
function Tasks.add_task(force_name, player_name, task_title, task_body)
|
function Tasks.add_task(force_name, player_name, task_title, task_body)
|
||||||
-- Get a new task id
|
-- Get a new task id
|
||||||
local task_id = tostring(force_tasks._uid)
|
local task_id = tostring(force_tasks._uid)
|
||||||
task_title = task_title or 'New Task'
|
|
||||||
task_body = task_body or 'Do x or y'
|
|
||||||
force_tasks._uid = force_tasks._uid + 1
|
force_tasks._uid = force_tasks._uid + 1
|
||||||
|
|
||||||
-- Get the existing tasks for this force
|
-- Get the existing tasks for this force
|
||||||
@@ -67,8 +65,8 @@ function Tasks.add_task(force_name, player_name, task_title, task_body)
|
|||||||
TaskData:set(task_id, {
|
TaskData:set(task_id, {
|
||||||
task_id = task_id,
|
task_id = task_id,
|
||||||
force_name = force_name,
|
force_name = force_name,
|
||||||
title = task_title,
|
title = task_title or '',
|
||||||
body = task_body,
|
body = task_body or '',
|
||||||
last_edit_name = player_name or '<server>',
|
last_edit_name = player_name or '<server>',
|
||||||
last_edit_time = game.tick,
|
last_edit_time = game.tick,
|
||||||
currently_editing = editing
|
currently_editing = editing
|
||||||
@@ -93,20 +91,20 @@ end
|
|||||||
|
|
||||||
--[[-- Update the message and last edited information for a task
|
--[[-- Update the message and last edited information for a task
|
||||||
@tparam string task_id the uid of the task that you want to update
|
@tparam string task_id the uid of the task that you want to update
|
||||||
@tparam string message_title the message title that you want to have for the task
|
@tparam string player_name the name of the player who made the edit
|
||||||
@tparam string message_body the message body that you want to have for the task
|
@tparam string task_title the message title that you want to have for the task
|
||||||
@tparam[opt='server'] string player_name the name of the player who made the edit
|
@tparam string task_body the message body that you want to have for the task
|
||||||
|
|
||||||
@usage-- Updating the message for on a task
|
@usage-- Updating the message for on a task
|
||||||
Task.update_task(task_id, 'We need more iron!', game.player.name)
|
Task.update_task(task_id, 'We need more iron!', game.player.name)
|
||||||
|
|
||||||
]]
|
]]
|
||||||
function Tasks.update_task(task_id, message_title, message_body, player_name)
|
function Tasks.update_task(task_id, player_name, task_title, task_body)
|
||||||
TaskData:update(task_id, function(_, task)
|
TaskData:update(task_id, function(_, task)
|
||||||
task.last_edit_name = player_name or '<server>'
|
task.last_edit_name = player_name
|
||||||
task.last_edit_time = game.tick
|
task.last_edit_time = game.tick
|
||||||
task.title = message_title
|
task.title = task_title
|
||||||
task.body = message_body
|
task.body = task_body
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ local task_list =
|
|||||||
}
|
}
|
||||||
scroll_pane.style.horizontally_stretchable = true
|
scroll_pane.style.horizontally_stretchable = true
|
||||||
scroll_pane.style.padding = 0
|
scroll_pane.style.padding = 0
|
||||||
scroll_pane.style.maximal_height = 300
|
scroll_pane.style.maximal_height = 280
|
||||||
|
|
||||||
local flow =
|
local flow =
|
||||||
scroll_pane.add {
|
scroll_pane.add {
|
||||||
@@ -292,8 +292,7 @@ local task_view_footer =
|
|||||||
local title_label =
|
local title_label =
|
||||||
footer.add {
|
footer.add {
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "title",
|
name = "title"
|
||||||
caption = "New task"
|
|
||||||
}
|
}
|
||||||
title_label.style.padding = 4
|
title_label.style.padding = 4
|
||||||
title_label.style.font = "default-bold"
|
title_label.style.font = "default-bold"
|
||||||
@@ -301,8 +300,7 @@ local task_view_footer =
|
|||||||
local body_label =
|
local body_label =
|
||||||
footer.add {
|
footer.add {
|
||||||
type = "label",
|
type = "label",
|
||||||
name = "body",
|
name = "body"
|
||||||
caption = "Do x or y"
|
|
||||||
}
|
}
|
||||||
body_label.style.padding = 4
|
body_label.style.padding = 4
|
||||||
body_label.style.single_line = false
|
body_label.style.single_line = false
|
||||||
@@ -321,7 +319,7 @@ local message_pattern = "(.-)\n(.*)"
|
|||||||
-- @tparam string str message data
|
-- @tparam string str message data
|
||||||
local function parse_message(str)
|
local function parse_message(str)
|
||||||
-- Trimm the spaces of the string
|
-- Trimm the spaces of the string
|
||||||
local trimmed = (string.gsub(str, "^%s*(.-)%s*$", "%1"))
|
local trimmed = string.gsub(str, "^%s*(.-)%s*$", "%1")
|
||||||
local message = { title = "", body = "" }
|
local message = { title = "", body = "" }
|
||||||
local title, body = string.match(trimmed, message_pattern)
|
local title, body = string.match(trimmed, message_pattern)
|
||||||
if not title then
|
if not title then
|
||||||
@@ -379,7 +377,7 @@ edit_task_confirm_button =
|
|||||||
PlayerIsEditing:set(player, false)
|
PlayerIsEditing:set(player, false)
|
||||||
local new_message = element.parent.parent[task_message_textfield.name].text
|
local new_message = element.parent.parent[task_message_textfield.name].text
|
||||||
local parsed = parse_message(new_message)
|
local parsed = parse_message(new_message)
|
||||||
Tasks.update_task(selected, parsed.title, parsed.body, player.name)
|
Tasks.update_task(selected, player.name, parsed.title, parsed.body)
|
||||||
Tasks.set_editing(selected, player.name, nil)
|
Tasks.set_editing(selected, player.name, nil)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user