#pragma once
#include "skinnableframe.h"
#include "draggableimageview.h"
#include "vector.h"
#include "maplocation.h"
#include "mapuser.h"

class MapWindow :
	public SkinnableFrame
{
public:
	MapWindow(void);
	~MapWindow(void);
	int Create(HWND parent = 0);
	int SaveView(TCHAR * filename, TCHAR * format);
	
	void UpdateMap();
	void UpdateMapAround(MapUser * mu);
	void UpdateMapAround(MapLocation * mu);

	virtual void OnSize(int cx, int cy);
	virtual void OnClose() { Hide(); };
	virtual void OnCustomNotify(int id, Notification& n);
	virtual void OnButton(HWND h);

	// the map
	DraggableImageView mapview;
	Bitmap * map;
	Bitmap * original;
	int mv_edgex, mv_edgey; // to maintain appearance during resize

	// the other widgets
	TextBox NearbyUsers;
	Appearance FocusLocation;

	// the current focus
	MapLocation * focusml;

	// load the locations and all the users
	void LoadLocations();
	void DeepRefresh();

	// The locations widgets on the map
	Vector<MapLocation> locations;
	MapLocation * FindLocation(int LocationId);
	MapLocation * FindLocation(HWND h);
	void ShowLocation(int LocationId);
	void GlideToLocation(int LocationId);
	void ShowAllLocations();

	// The user icons on the map
	std::list<MapUser *> users;
	MapUser * FindUser(int UserId);
	MapUser * FindUser(HWND h);
	void UpdateUser(int UserId, int redraw = 1); // called when a user's state changes
	void UpdateUser(MapUser * mu, int redraw = 1); // called when a user's state changes
	MapUser * selectedUser; // the currently selected user
	void ShowUser(int userId);
	void SelectUser(int userId);
	void ClearSelection();
	void GlideToUser(int userId);

	void CreateBogusUser();
	void UpdateBogusUser(int locationId);

private:
	int NeedToLoadLocations;
};
