From 24d9c95507a8bd62ce4d0bddfcc13c0b7690d76b Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 24 Feb 2012 11:49:51 -0800 Subject: [PATCH] "Edit" and "Delete" added to the news feature. --- code/game/player/news.dm | 72 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/code/game/player/news.dm b/code/game/player/news.dm index b4c5cdd26e9..ec6bcb371ea 100644 --- a/code/game/player/news.dm +++ b/code/game/player/news.dm @@ -11,6 +11,10 @@ datum/news_topic_handler var/client/C = locate(href_list["client"]) if(href_list["action"] == "show_all_news") C.display_all_news_list() + else if(href_list["action"] == "remove") + C.remove_news(text2num(href_list["ID"])) + else if(href_list["action"] == "edit") + C.edit_news(text2num(href_list["ID"])) else if(href_list["action"] == "show_news") C.display_news_list() else if(href_list["action"] == "add_news") @@ -115,7 +119,7 @@ client/proc/display_news_list() output += "Nothing new!

" output += "Display All
" - if(src.holder && istype(src.holder, /obj/admins)) + if(src.holder) output += "Add Guidelines
" usr << browse(output, "window=news;size=600x400") @@ -125,6 +129,8 @@ client/proc/display_news_list() client/proc/display_all_news_list() var/list/news = load_news() + var/admin = (src.holder) + // load the list of news already read by this player var/path = savefile_path(src.mob) if(!fexists(path)) @@ -142,16 +148,19 @@ client/proc/display_all_news_list() var/date = time2text(N.date,"MM/DD") output += "[date] [N.title]
" output += "[N.body]
" - output += "authored by [N.author]
" + output += "authored by [N.author]" + if(admin && N.author == src.key) + output += " Delete Edit" + output += "
" output += "
" F["read_news"] << read_news - if(src.holder && istype(src.holder, /obj/admins)) + if(admin) output += "Add Guidelines
" usr << browse(output, "window=news;size=600x400") client/proc/add_news() - if(!istype(src.holder, /obj/admins)) + if(!src.holder) src << "You tried to modify the news, but you're not an admin!" return @@ -163,10 +172,61 @@ client/proc/add_news() make_news(title, body, key) - display_all_news_list() + spawn(1) + display_all_news_list() client/verb/read_news() set name = "Read News" set category = "OOC" set desc = "Read important news and updates" - display_all_news_list() \ No newline at end of file + display_all_news_list() + +client/proc/remove_news(ID as num) + if(src.holder) + src << "You tried to modify the news, but you're not an admin!" + return + + var/savefile/News = new("data/news.sav") + var/list/news + + News["news"] >> news + + for(var/datum/news/N in news) + if(N.ID == ID) + news.Remove(N) + + News["news"] << news + + spawn(1) + display_all_news_list() + +client/proc/edit_news(ID as num) + if(src.holder) + src << "You tried to modify the news, but you're not an admin!" + return + + var/savefile/News = new("data/news.sav") + var/list/news + + News["news"] >> news + + var/datum/news/found + for(var/datum/news/N in news) + if(N.ID == ID) + found = N + if(!found) src << "* An error occured, sorry." + + var/title = input(src.mob, "Select a title for the news", "Title") as null|text + if(!title) return + + var/body = input(src.mob, "Enter a body for the news", "Body") as null|message + if(!body) return + + found.title = title + found.body = body + + + News["news"] << news + + spawn(1) + display_all_news_list() \ No newline at end of file