parent
							
								
									fb244dc2b9
								
							
						
					
					
						commit
						45e6558d90
					
				@ -1,62 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.gui.interaction; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.gamecore.input.InputSystem; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.algo.Coord; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.constraints.vect.Vect; | 
					 | 
				
			||||||
import mightypork.rogue.world.PlayerControl; | 
					 | 
				
			||||||
import mightypork.rogue.world.gui.MapView; | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class MIPClickPathfWalk implements MapInteractionPlugin { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private static final int BTN = 0; // left
 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void update(MapView view, PlayerControl pc, double delta) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if(pc.getPlayerEntity().pos.isMoving()) return; | 
					 | 
				
			||||||
		if (InputSystem.isMouseButtonDown(BTN)) { | 
					 | 
				
			||||||
			 | 
					 | 
				
			||||||
			troToNav(view, pc, InputSystem.getMousePos()); | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onClick(MapView view, PlayerControl player, Vect mouse, int button, boolean down) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (down || button != BTN) return false; | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		return troToNav(view, player, mouse); | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private boolean troToNav(MapView view, PlayerControl player, Vect mouse) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		final Coord clicked = view.toWorldPos(mouse); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		Tile t = player.getLevel().getTile(clicked); | 
					 | 
				
			||||||
		if (!t.isWalkable() || !t.isExplored()) return false; | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		player.navigateTo(clicked); | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onKey(MapView view, PlayerControl player, int key, boolean down) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onStepEnd(MapView mapView, PlayerControl player) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -0,0 +1,102 @@ | 
				
			|||||||
 | 
					package mightypork.rogue.world.gui.interaction; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.input.InputSystem; | 
				
			||||||
 | 
					import mightypork.gamecore.util.math.Calc.Deg; | 
				
			||||||
 | 
					import mightypork.gamecore.util.math.Polar; | 
				
			||||||
 | 
					import mightypork.gamecore.util.math.algo.Coord; | 
				
			||||||
 | 
					import mightypork.gamecore.util.math.algo.Sides; | 
				
			||||||
 | 
					import mightypork.gamecore.util.math.constraints.vect.Vect; | 
				
			||||||
 | 
					import mightypork.rogue.world.PlayerControl; | 
				
			||||||
 | 
					import mightypork.rogue.world.gui.MapView; | 
				
			||||||
 | 
					import mightypork.rogue.world.tile.Tile; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class MIPMouse implements MapInteractionPlugin { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private static final int BTN = 0; // left
 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void update(MapView view, PlayerControl pc, double delta) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (pc.getPlayerEntity().pos.hasPath()) return; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							final Vect pos = InputSystem.getMousePos(); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							if (InputSystem.isMouseButtonDown(BTN)) { | 
				
			||||||
 | 
								if (mouseWalk(view, pc, pos)) return; | 
				
			||||||
 | 
								if (troToNav(view, pc, pos)) return; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean onClick(MapView view, PlayerControl pc, Vect mouse, int button, boolean down) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (!down && button == BTN) { | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								final Coord pos = view.toWorldPos(mouse); | 
				
			||||||
 | 
								final Tile t = pc.getLevel().getTile(pos); | 
				
			||||||
 | 
								if (t.onClick()) return true; | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								if (troToNav(view, pc, mouse)) return true; | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private boolean troToNav(MapView view, PlayerControl pc, Vect mouse) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							final Coord clicked = view.toWorldPos(mouse); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							final Tile t = pc.getLevel().getTile(clicked); | 
				
			||||||
 | 
							if (!t.isWalkable() || !t.isExplored()) return false; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							pc.navigateTo(clicked); | 
				
			||||||
 | 
							return true; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						private boolean mouseWalk(MapView view, PlayerControl pc, Vect pos) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							final Coord plpos = pc.getCoord(); | 
				
			||||||
 | 
							final Coord clicked = view.toWorldPos(pos); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							final Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y); | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							final int dir = Deg.round90(p.getAngleDeg()) / 90; | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							switch (dir) { | 
				
			||||||
 | 
								case 0: | 
				
			||||||
 | 
									return pc.tryGo(Sides.E); | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
								case 1: | 
				
			||||||
 | 
									return pc.tryGo(Sides.S); | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
								case 2: | 
				
			||||||
 | 
									return pc.tryGo(Sides.W); | 
				
			||||||
 | 
									 | 
				
			||||||
 | 
								case 3: | 
				
			||||||
 | 
									return pc.tryGo(Sides.N); | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean onKey(MapView view, PlayerControl player, int key, boolean down) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public boolean onStepEnd(MapView mapView, PlayerControl player) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return false; | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
					} | 
				
			||||||
@ -1,83 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.gui.interaction; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.gamecore.input.InputSystem; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.Calc.Deg; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.Polar; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.algo.Coord; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.constraints.vect.Vect; | 
					 | 
				
			||||||
import mightypork.rogue.world.PlayerControl; | 
					 | 
				
			||||||
import mightypork.rogue.world.gui.MapView; | 
					 | 
				
			||||||
import mightypork.rogue.world.tile.Tile; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class MIPMouseWalk implements MapInteractionPlugin { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void update(MapView view, PlayerControl pc, double delta) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (InputSystem.isMouseButtonDown(0)) { | 
					 | 
				
			||||||
			// walk by holding btn
 | 
					 | 
				
			||||||
			tryWalk(view, pc, InputSystem.getMousePos()); | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onClick(MapView view, PlayerControl pc, Vect mouse, int button, boolean down) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (!down || button != 0) return false; | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		tryWalk(view, pc, mouse); | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	private void tryWalk(MapView view, PlayerControl pc, Vect pos) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (pc.getPlayerEntity().pos.isMoving()) return; | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		final Coord plpos = pc.getCoord(); | 
					 | 
				
			||||||
		final Coord clicked = view.toWorldPos(pos); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		final Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y); | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		final int dir = Deg.round90(p.getAngleDeg()) / 90; | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		switch (dir) { | 
					 | 
				
			||||||
			case 0: | 
					 | 
				
			||||||
				pc.goEast(); | 
					 | 
				
			||||||
				break; | 
					 | 
				
			||||||
			 | 
					 | 
				
			||||||
			case 1: | 
					 | 
				
			||||||
				pc.goSouth(); | 
					 | 
				
			||||||
				break; | 
					 | 
				
			||||||
			 | 
					 | 
				
			||||||
			case 2: | 
					 | 
				
			||||||
				pc.goWest(); | 
					 | 
				
			||||||
				break; | 
					 | 
				
			||||||
			 | 
					 | 
				
			||||||
			case 3: | 
					 | 
				
			||||||
				pc.goNorth(); | 
					 | 
				
			||||||
				break; | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onKey(MapView world, PlayerControl player, int key, boolean down) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onStepEnd(MapView view, PlayerControl pc) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if(!InputSystem.isMouseButtonDown(0)) return false; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		tryWalk(view, pc, InputSystem.getMousePos()); | 
					 | 
				
			||||||
		return true; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
@ -1,44 +0,0 @@ | 
				
			|||||||
package mightypork.rogue.world.gui.interaction; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.algo.Coord; | 
					 | 
				
			||||||
import mightypork.gamecore.util.math.constraints.vect.Vect; | 
					 | 
				
			||||||
import mightypork.rogue.world.PlayerControl; | 
					 | 
				
			||||||
import mightypork.rogue.world.WorldProvider; | 
					 | 
				
			||||||
import mightypork.rogue.world.gui.MapView; | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class MIPTileClick implements MapInteractionPlugin { | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onStepEnd(MapView wv, PlayerControl player) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onClick(MapView wv, PlayerControl player, Vect mouse, int button, boolean down) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		if (!down && button == 0) { | 
					 | 
				
			||||||
			Coord pos = wv.toWorldPos(mouse); | 
					 | 
				
			||||||
			player.clickTile(pos); | 
					 | 
				
			||||||
			System.out.println("~"); | 
					 | 
				
			||||||
			return true; | 
					 | 
				
			||||||
		} | 
					 | 
				
			||||||
		 | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public boolean onKey(MapView wv, PlayerControl player, int key, boolean down) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
		return false; | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
	 | 
					 | 
				
			||||||
	@Override | 
					 | 
				
			||||||
	public void update(MapView mapView, PlayerControl pc, double delta) | 
					 | 
				
			||||||
	{ | 
					 | 
				
			||||||
	} | 
					 | 
				
			||||||
} | 
					 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue