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
|
||||
return
|
||||
end
|
||||
if(fields.back) then
|
||||
-- back to the normal trade list
|
||||
if(fields.show_trade_log) then
|
||||
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")
|
||||
return
|
||||
elseif(fields.back_to_talk) then
|
||||
yl_speak_up.show_fs(player, "talk")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- helper function for get_fs_show_log
|
||||
-- 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 = {}
|
||||
-- split the line up so that it can actually be read
|
||||
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
|
||||
elseif(entry_type and entry_type == "Trade:") then
|
||||
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
|
||||
table.insert(line, '#FF4444') -- bright red
|
||||
else
|
||||
@ -133,7 +141,7 @@ yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, sa
|
||||
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)
|
||||
local pname = player:get_player_name()
|
||||
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.]"
|
||||
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..
|
||||
"log_"..tostring(n_id)..".txt", "r")
|
||||
local formspec = {'size[18,12]'..
|
||||
'button[0.5,11.1;17,0.8;back;Back]'..
|
||||
'label[4.5,0.5;Log of ',
|
||||
'button[0.5,11.1;17,0.8;',
|
||||
back_link,
|
||||
']'..
|
||||
'label[4.5,0.5;'..log_type_desc..' Log of ',
|
||||
minetest.formspec_escape(tostring(dialog.n_npc)..
|
||||
" [ID: "..tostring(n_id).."]"),
|
||||
']',
|
||||
'button[0.5,0.1;3,0.8;',
|
||||
log_type_switch,
|
||||
']',
|
||||
'tablecolumns[' ..
|
||||
'color;text,align=left;'.. -- the date
|
||||
'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
|
||||
else
|
||||
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
|
||||
same_lines = 0
|
||||
last_line = this_line
|
||||
@ -193,7 +214,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
|
||||
count = count + 1
|
||||
end
|
||||
-- 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()
|
||||
|
||||
-- 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
|
||||
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
|
||||
local new_move_order = ""
|
||||
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
|
||||
return {h = h, formspec = formspec}
|
||||
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.
|
||||
-- The npc_master priv allows to edit all NPC.
|
||||
if(not(edit_mode)) then
|
||||
|
@ -49,7 +49,7 @@ yl_speak_up.input_trade_list = function(player, formname, fields)
|
||||
|
||||
if(fields.show_log) then
|
||||
-- show a log
|
||||
yl_speak_up.show_fs(player, "show_log")
|
||||
yl_speak_up.show_fs(player, "show_log", {log_type = "trade"})
|
||||
return
|
||||
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)
|
||||
-- button "show log" for those who can edit the NPC (entering edit mode is not required)
|
||||
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,
|
||||
"show_log",
|
||||
text, text,
|
||||
|
Loading…
Reference in New Issue
Block a user