forked from Sokomine/yl_speak_up
show log on each dialog; allow to toggle between full and trade log
This commit is contained in:
parent
8ef9aeb5db
commit
56b832d9d1
@ -76,17 +76,22 @@ yl_speak_up.input_show_log = function(player, formname, fields)
|
|||||||
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
|
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if(fields.back) then
|
if(fields.show_trade_log) then
|
||||||
-- back to the normal trade list
|
yl_speak_up.show_fs(player, "show_log", {log_type = "trade"})
|
||||||
|
elseif(fields.show_full_log) then
|
||||||
|
yl_speak_up.show_fs(player, "show_log", {log_type = "full"})
|
||||||
|
elseif(fields.back_to_trade) then
|
||||||
yl_speak_up.show_fs(player, "trade_list")
|
yl_speak_up.show_fs(player, "trade_list")
|
||||||
return
|
elseif(fields.back_to_talk) then
|
||||||
|
yl_speak_up.show_fs(player, "talk")
|
||||||
end
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- helper function for get_fs_show_log
|
-- helper function for get_fs_show_log
|
||||||
-- text: list of string
|
-- text: list of string
|
||||||
yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, same_lines, entry_type)
|
yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, same_lines, entry_type, log_type)
|
||||||
local line = {}
|
local line = {}
|
||||||
-- split the line up so that it can actually be read
|
-- split the line up so that it can actually be read
|
||||||
local multiline = minetest.wrap_text(last_line, 75, true)
|
local multiline = minetest.wrap_text(last_line, 75, true)
|
||||||
@ -122,6 +127,9 @@ yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, sa
|
|||||||
table.insert(line, '#00FFFF') -- cyan
|
table.insert(line, '#00FFFF') -- cyan
|
||||||
elseif(entry_type and entry_type == "Trade:") then
|
elseif(entry_type and entry_type == "Trade:") then
|
||||||
table.insert(line, '#00BBFF') -- darker cyan
|
table.insert(line, '#00BBFF') -- darker cyan
|
||||||
|
elseif(log_type and log_type == 'trade') then
|
||||||
|
-- don't show this line if only trade lines are beeing asked for
|
||||||
|
return
|
||||||
elseif(entry_type and entry_type == "error:") then
|
elseif(entry_type and entry_type == "error:") then
|
||||||
table.insert(line, '#FF4444') -- bright red
|
table.insert(line, '#FF4444') -- bright red
|
||||||
else
|
else
|
||||||
@ -133,7 +141,7 @@ yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, sa
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- TODO: make use of log_type and toggle between trade entries and full log?
|
-- allow to toggle between trade entries and full log
|
||||||
yl_speak_up.get_fs_show_log = function(player, log_type)
|
yl_speak_up.get_fs_show_log = function(player, log_type)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||||
@ -142,14 +150,27 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
|
|||||||
return "size[5,1]label[0,0;Error: You do not own this NPC.]"
|
return "size[5,1]label[0,0;Error: You do not own this NPC.]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local log_type_desc = "Full"
|
||||||
|
local log_type_switch = "show_trade_log;Show trade log"
|
||||||
|
local back_link = "back_to_talk;Back to talk"
|
||||||
|
if(log_type == "trade") then
|
||||||
|
log_type_desc = "Trade"
|
||||||
|
log_type_switch = "show_full_log;Show full log"
|
||||||
|
back_link = "back_to_trade;Back to trade"
|
||||||
|
end
|
||||||
local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM..
|
local file, err = io.open(yl_speak_up.worldpath..yl_speak_up.log_path..DIR_DELIM..
|
||||||
"log_"..tostring(n_id)..".txt", "r")
|
"log_"..tostring(n_id)..".txt", "r")
|
||||||
local formspec = {'size[18,12]'..
|
local formspec = {'size[18,12]'..
|
||||||
'button[0.5,11.1;17,0.8;back;Back]'..
|
'button[0.5,11.1;17,0.8;',
|
||||||
'label[4.5,0.5;Log of ',
|
back_link,
|
||||||
|
']'..
|
||||||
|
'label[4.5,0.5;'..log_type_desc..' Log of ',
|
||||||
minetest.formspec_escape(tostring(dialog.n_npc)..
|
minetest.formspec_escape(tostring(dialog.n_npc)..
|
||||||
" [ID: "..tostring(n_id).."]"),
|
" [ID: "..tostring(n_id).."]"),
|
||||||
']',
|
']',
|
||||||
|
'button[0.5,0.1;3,0.8;',
|
||||||
|
log_type_switch,
|
||||||
|
']',
|
||||||
'tablecolumns[' ..
|
'tablecolumns[' ..
|
||||||
'color;text,align=left;'.. -- the date
|
'color;text,align=left;'.. -- the date
|
||||||
'color;text,align=center;'.. -- name of the player
|
'color;text,align=center;'.. -- name of the player
|
||||||
@ -182,7 +203,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
|
|||||||
same_lines = same_lines + 1
|
same_lines = same_lines + 1
|
||||||
else
|
else
|
||||||
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines,
|
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines,
|
||||||
last_entry_type)
|
last_entry_type, log_type)
|
||||||
-- store information about the next line
|
-- store information about the next line
|
||||||
same_lines = 0
|
same_lines = 0
|
||||||
last_line = this_line
|
last_line = this_line
|
||||||
@ -193,7 +214,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
|
|||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
-- cover the last line
|
-- cover the last line
|
||||||
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines, last_entry_type)
|
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines, last_entry_type, log_type)
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
-- reverse the order so that new entries are on top (newer entries are more intresting)
|
-- reverse the order so that new entries are on top (newer entries are more intresting)
|
||||||
|
@ -31,6 +31,12 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if(fields.show_log) then
|
||||||
|
-- show a log
|
||||||
|
yl_speak_up.show_fs(player, "show_log", {log_type = "full"})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- mobs_redo based NPC may follow their owner, stand or wander around
|
-- mobs_redo based NPC may follow their owner, stand or wander around
|
||||||
local new_move_order = ""
|
local new_move_order = ""
|
||||||
if(fields.order_stand) then
|
if(fields.order_stand) then
|
||||||
@ -648,6 +654,13 @@ yl_speak_up.get_fs_talkdialog_add_edit_buttons = function(
|
|||||||
if(not(may_edit_npc)) then
|
if(not(may_edit_npc)) then
|
||||||
return {h = h, formspec = formspec}
|
return {h = h, formspec = formspec}
|
||||||
end
|
end
|
||||||
|
-- button "show log" for those who can edit the NPC (entering edit mode is not required)
|
||||||
|
text = minetest.formspec_escape(
|
||||||
|
"[Log] Show me your log.")
|
||||||
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
|
"show_log",
|
||||||
|
text, text,
|
||||||
|
true, nil, nil, pname_for_old_fs)
|
||||||
-- Offer to enter edit mode if the player has the npc_talk_owner priv OR is allowed to edit the NPC.
|
-- Offer to enter edit mode if the player has the npc_talk_owner priv OR is allowed to edit the NPC.
|
||||||
-- The npc_master priv allows to edit all NPC.
|
-- The npc_master priv allows to edit all NPC.
|
||||||
if(not(edit_mode)) then
|
if(not(edit_mode)) then
|
||||||
|
@ -49,7 +49,7 @@ yl_speak_up.input_trade_list = function(player, formname, fields)
|
|||||||
|
|
||||||
if(fields.show_log) then
|
if(fields.show_log) then
|
||||||
-- show a log
|
-- show a log
|
||||||
yl_speak_up.show_fs(player, "show_log")
|
yl_speak_up.show_fs(player, "show_log", {log_type = "trade"})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
|||||||
true, nil, nil, pname_for_old_fs)
|
true, nil, nil, pname_for_old_fs)
|
||||||
-- button "show log" for those who can edit the NPC (entering edit mode is not required)
|
-- button "show log" for those who can edit the NPC (entering edit mode is not required)
|
||||||
text = minetest.formspec_escape(
|
text = minetest.formspec_escape(
|
||||||
"[Log] Show me who gave you which orders and who bought what.")
|
"[Log] Show me who bought what.")
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
"show_log",
|
"show_log",
|
||||||
text, text,
|
text, text,
|
||||||
|
Loading…
Reference in New Issue
Block a user