// Path: src/game/NodeMap.java
// public static enum Status {
// 	Unknown,
// 	Visible, Open,
// 	Defeated;
// }
// 
// Path: src/gui/WidgetText.java
// public enum TextAlign {
// 	Right,
// 	Left,
// 	Center;
// }


import java.awt.Color;
import java.awt.Graphics;
import game.NodeMap.Node.Status;
import gui.*;
import gui.WidgetText.TextAlign;
import util.*;
import input.*;
import java.util.List;
import java.util.Collections;
import java.util.Comparator;
import java.util.ArrayList;
package game;




public class NodeMapView extends WidgetRect {
	private interface IAction {
		public void onSelect();
		public void onDeselect();
		public void onClick(NodeMap.Node nd);
	}
	
	/***************************************/
	/***************************************/
	/***************************************/
	private class CutoffCornerWidget extends WidgetRect {
		// a---b
		// |   |
		// c---d
		public CutoffCornerWidget(int a, int b, int c, int d) {
			mA = a; mB = b; mC = c; mD = d;
		}
		public void onRender(RenderTarget t) {
			Rect r = getRect();
			Graphics g = t.getContext();
			int h = r.getHeight();
			int[] xs = {r.getX()+h*mA, r.getX()+r.getWidth()-h*mB, r.getX()+r.getWidth()-h*mD, r.getX()+h*mC};
			int[] ys = {r.getY(), r.getY(), r.getY()+h, r.getY()+h};
			g.setColor(getColor());
			g.fillPolygon(xs, ys, 4);
		}
		private int mA, mB, mC, mD;
	}

	private class ActionPanOrSelectNode implements IAction {
		private void scrollify(Widget w, final Vec dir) {
			w.onMouseDown.connect(new MouseEvent.Listener() {
				public void onMouseEvent(MouseEvent e) {
					mScroll = dir;
				}
			});
			w.onMouseUp.connect(new MouseEvent.Listener() {
				public void onMouseEvent(MouseEvent e) {
					mScroll = new Vec(0, 0);
				}
			});
		}
		public ActionPanOrSelectNode() {
			mWidget = new Widget() {
				public void onRender(RenderTarget t) {
					mOriginOffset = mOriginOffset.add(mScroll);
				}
			};
			mWidget.setSize(new UDim(0, 0, 1, 1));
			mWidget.setActive(false);
			mWidget.setParent(NodeMapView.this);
			mWidget.setVisible(false);
			//
			WidgetImage scrollRight = new WidgetImage();
			scrollRight.setPos(new UDim(-64, -64, 1, 0.5f));
			scrollRight.setSize(new UDim(64, 128));
			scrollRight.setParent(mWidget);
			scrollRight.setImage(ResourceLoader.LoadImage("scroll-right.png"));
			scrollify(scrollRight, new Vec(-MAP_SCROLL_SPEED, 0));
			//
			WidgetImage scrollLeft = new WidgetImage();
			scrollLeft.setPos(new UDim(0, -64, 0, 0.5f));
			scrollLeft.setSize(new UDim(64, 128));
			scrollLeft.setParent(mWidget);
			scrollLeft.setImage(ResourceLoader.LoadImage("scroll-left.png"));
			scrollify(scrollLeft, new Vec(MAP_SCROLL_SPEED, 0));
			//
			WidgetImage scrollDown = new WidgetImage();
			scrollDown.setPos(new UDim(-64, -64, 0.5f, 1));
			scrollDown.setSize(new UDim(128, 64));
			scrollDown.setParent(mWidget);
			scrollDown.setImage(ResourceLoader.LoadImage("scroll-down.png"));
			scrollify(scrollDown, new Vec(0, -MAP_SCROLL_SPEED));
			//
			WidgetImage scrollup = new WidgetImage();
			scrollup.setPos(new UDim(-64, 0, 0.5f, 0));
			scrollup.setSize(new UDim(128, 64));
			scrollup.setParent(mWidget);
			scrollup.setImage(ResourceLoader.LoadImage("scroll-up.png"));
			scrollify(scrollup, new Vec(0, MAP_SCROLL_SPEED));
			//inv button
			//
			CutoffCornerWidget inventoryButton = new CutoffCornerWidget(0, 0, 1, 0);
			inventoryButton.setSize(new UDim(150, 30));
			inventoryButton.setPos(new UDim(-150, 0, 1, 0));
			inventoryButton.setColor(HEADER_COLOR);
			inventoryButton.setParent(NodeMapView.this);
			WidgetLabel invtext = new WidgetLabel();
			invtext.setSize(new UDim(0, 0, 1, 1));
			invtext.setBackground(false);
			invtext.setActive(false);
			invtext.setTextColor(HEADER_TEXT_COLOR);
			invtext.setText("INVENTORY");
			invtext.setParent(inventoryButton);
			inventoryButton.onMouseDown.connect(new MouseEvent.Listener() {
				public void onMouseEvent(MouseEvent e) {
					setAction(mActionInventory);
				}
			});
		}
		public void onSelect() {
			showGui();
		}
		public void onDeselect() {
			hideGui();
		}
		public void onClick(NodeMap.Node nd) {
// Path: src/game/NodeMap.java
// public static enum Status {
// 	Unknown,
// 	Visible, Open,
// 	Defeated;
// }
// 
// Path: src/gui/WidgetText.java
// public enum TextAlign {
// 	Right,
// 	Left,
// 	Center;
// }


// Path: src/game/NodeMapView.java
import java.awt.Color;
import java.awt.Graphics;
import game.NodeMap.Node.Status;
import gui.*;
import gui.WidgetText.TextAlign;
import util.*;
import input.*;
import java.util.List;
import java.util.Collections;
import java.util.Comparator;
import java.util.ArrayList;

package game;




public class NodeMapView extends WidgetRect {
	private interface IAction {
		public void onSelect();
		public void onDeselect();
		public void onClick(NodeMap.Node nd);
	}
	
	/***************************************/
	/***************************************/
	/***************************************/
	private class CutoffCornerWidget extends WidgetRect {
		// a---b
		// |   |
		// c---d
		public CutoffCornerWidget(int a, int b, int c, int d) {
			mA = a; mB = b; mC = c; mD = d;
		}
		public void onRender(RenderTarget t) {
			Rect r = getRect();
			Graphics g = t.getContext();
			int h = r.getHeight();
			int[] xs = {r.getX()+h*mA, r.getX()+r.getWidth()-h*mB, r.getX()+r.getWidth()-h*mD, r.getX()+h*mC};
			int[] ys = {r.getY(), r.getY(), r.getY()+h, r.getY()+h};
			g.setColor(getColor());
			g.fillPolygon(xs, ys, 4);
		}
		private int mA, mB, mC, mD;
	}

	private class ActionPanOrSelectNode implements IAction {
		private void scrollify(Widget w, final Vec dir) {
			w.onMouseDown.connect(new MouseEvent.Listener() {
				public void onMouseEvent(MouseEvent e) {
					mScroll = dir;
				}
			});
			w.onMouseUp.connect(new MouseEvent.Listener() {
				public void onMouseEvent(MouseEvent e) {
					mScroll = new Vec(0, 0);
				}
			});
		}
		public ActionPanOrSelectNode() {
			mWidget = new Widget() {
				public void onRender(RenderTarget t) {
					mOriginOffset = mOriginOffset.add(mScroll);
				}
			};
			mWidget.setSize(new UDim(0, 0, 1, 1));
			mWidget.setActive(false);
			mWidget.setParent(NodeMapView.this);
			mWidget.setVisible(false);
			//
			WidgetImage scrollRight = new WidgetImage();
			scrollRight.setPos(new UDim(-64, -64, 1, 0.5f));
			scrollRight.setSize(new UDim(64, 128));
			scrollRight.setParent(mWidget);
			scrollRight.setImage(ResourceLoader.LoadImage("scroll-right.png"));
			scrollify(scrollRight, new Vec(-MAP_SCROLL_SPEED, 0));
			//
			WidgetImage scrollLeft = new WidgetImage();
			scrollLeft.setPos(new UDim(0, -64, 0, 0.5f));
			scrollLeft.setSize(new UDim(64, 128));
			scrollLeft.setParent(mWidget);
			scrollLeft.setImage(ResourceLoader.LoadImage("scroll-left.png"));
			scrollify(scrollLeft, new Vec(MAP_SCROLL_SPEED, 0));
			//
			WidgetImage scrollDown = new WidgetImage();
			scrollDown.setPos(new UDim(-64, -64, 0.5f, 1));
			scrollDown.setSize(new UDim(128, 64));
			scrollDown.setParent(mWidget);
			scrollDown.setImage(ResourceLoader.LoadImage("scroll-down.png"));
			scrollify(scrollDown, new Vec(0, -MAP_SCROLL_SPEED));
			//
			WidgetImage scrollup = new WidgetImage();
			scrollup.setPos(new UDim(-64, 0, 0.5f, 0));
			scrollup.setSize(new UDim(128, 64));
			scrollup.setParent(mWidget);
			scrollup.setImage(ResourceLoader.LoadImage("scroll-up.png"));
			scrollify(scrollup, new Vec(0, MAP_SCROLL_SPEED));
			//inv button
			//
			CutoffCornerWidget inventoryButton = new CutoffCornerWidget(0, 0, 1, 0);
			inventoryButton.setSize(new UDim(150, 30));
			inventoryButton.setPos(new UDim(-150, 0, 1, 0));
			inventoryButton.setColor(HEADER_COLOR);
			inventoryButton.setParent(NodeMapView.this);
			WidgetLabel invtext = new WidgetLabel();
			invtext.setSize(new UDim(0, 0, 1, 1));
			invtext.setBackground(false);
			invtext.setActive(false);
			invtext.setTextColor(HEADER_TEXT_COLOR);
			invtext.setText("INVENTORY");
			invtext.setParent(inventoryButton);
			inventoryButton.onMouseDown.connect(new MouseEvent.Listener() {
				public void onMouseEvent(MouseEvent e) {
					setAction(mActionInventory);
				}
			});
		}
		public void onSelect() {
			showGui();
		}
		public void onDeselect() {
			hideGui();
		}
		public void onClick(NodeMap.Node nd) {
			if (nd.NStatus != NodeMap.Node.Status.Unknown) {