//Aaron Horne -- 3/26/02 -- MERCS
#pragma once


#define MWNEWSMANAGER_MAX_NUMBER_OF_MISSIONS_TO_REVEAL_ON    5

namespace MechWarrior4
{

	class MWNewsPlug : public Stuff::Plug
	{
	private:
		//data
		Stuff::MString  m_audioClip;//the audio clip file -- located in /content/audio/news
		Stuff::MString  m_title;//the title of the news -- usually the same as the name of the page
		int   m_stringID; //the index into script strings of the full text of the news story
		int   m_availableFlag;//set if the clip is available
		int   m_revealOnCycle;//cycle number to reveal this news on -- not required -- default to 1000
		int   m_revealOnMission[MWNEWSMANAGER_MAX_NUMBER_OF_MISSIONS_TO_REVEAL_ON]; //can have 0-5 of these, if none are used then use revealOnCycle
	
	public:
		Adept::ResourceID
			m_newsListID;

		//constructors
		MWNewsPlug(Stuff::MemoryStream *stream);
		~MWNewsPlug();

		//serialization
		static void
			ConstructStream (MemoryStream *stream,Stuff::Page *page);
		//void
		//	WriteToText (Stuff::NotationFile& file);
		void
			Save (MemoryStream *stream);

		//accessors
		inline Stuff::MString GetAudioClip(void)  {Check_Object(this); return m_audioClip;}
		inline Stuff::MString GetTitle(void)      {Check_Object(this); return m_title;}
		inline int GetStringIndex(void)           {Check_Object(this); return MWNewsPlug::m_stringID;}
		inline int GetAvailableFlag(void)         {Check_Object(this); return MWNewsPlug::m_availableFlag;}
		inline int GetRevealOnCycle(void)         {Check_Object(this); return MWNewsPlug::m_revealOnCycle;}
		inline int GetRevealOnMission(int index)  {Check_Object(this); return MWNewsPlug::m_revealOnMission[index];}

		inline void SetAudioClip(Stuff::MString val)         {Check_Object(this); m_audioClip = val;}
		inline void SetTitle(Stuff::MString val)             {Check_Object(this); m_title = val;}
		inline void SetStringIndex(int val)                  {Check_Object(this); MWNewsPlug::m_stringID = val;}
		inline void SetAvailableFlag(int val)                {Check_Object(this); MWNewsPlug::m_availableFlag = val;}
		inline void SetRevealOnCycle(int val)                {Check_Object(this); MWNewsPlug::m_revealOnCycle = val;}
		inline void SetRevealOnMission(int index, int val)  {Check_Object(this); MWNewsPlug::m_revealOnMission[index] = val;}
	};


	typedef Receiver__ClassData				MWNewsManager__ClassData;
	typedef Receiver__Message				MWNewsManager__Message;

	class MWNewsManager : public Adept::Receiver
	{
	private:


	public:
		static void InitializeClass();
		static void TerminateClass();

		//##########################################################################
		// Inheritance support
		//
		typedef MWNewsManager__ClassData              ClassData;
		typedef MWNewsManager__Message                Message;


		static void ConstructNewsManagerStream(Stuff::MemoryStream *stream,NotationFile *notation_file);

		static MWNewsManager *MakeNewMWNewsManager(const char *mwnewsmanager_name);
		static MWNewsManager *MakeNewMWNewsManager(Adept::ResourceID mwnews_id);
		//static MWNewsManager *MakeNewMWNewsManager(const ResourceID& newsmanager_resource_id);

		void Save(MemoryStream *stream);
		//void WriteToText(const char *file_name);

		MWNewsManager(Stuff::MemoryStream *stream);

		void 
			UpdateForNewCycle (void);   //*Note: to delete news, you have to do it permanently.  If you just try make it unavailable it it will make itself available on the next pass.

		MWNewsPlug
			*FindNews (MString news_title,bool case_sensitive = true);

		MWNewsPlug 
			*FindNews (int display_index);

		void
			GetAvailableNews (int **data, int &size);

		~MWNewsManager();

		Stuff::ChainOf<MWNewsPlug*> m_newsChain;


		static MWNewsManager *Instance; //necessary?


		static MWNewsManager* GetInstance() 
		{
			return reinterpret_cast<MWNewsManager *>( GlobalPointers::GetGlobalPointer(MWNewsManagerGlobalPointerIndex));
		};

		//void RevealNews (int news_id); //set inside
		//void HideNews (int news_id);

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Shared Data support
		//
		static ClassData *DefaultData;

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Test Support
		//
		void TestInstance() const;



	};
}