Skip to content

Commit

Permalink
#194 units now working on flat projection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich2 committed Aug 16, 2022
1 parent 4cdfb59 commit 171dbe7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
11 changes: 5 additions & 6 deletions Tiling/ExsSrc/gOne/GOneGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ case class GOneGui(canv: CanvasPlatform, scenStart: OneScen, viewIn: HGView) ext
val urect = Rect(1.4, 1)

/** We could of used the mapHCen method and produced the units and the hexstrs graphics at the same time, but its easier to keep them separate. */
def units: Arr[PolygonCompound] = players.hcSomesMap { (hc, p) =>
def units: Arr[PolygonCompound] = players.hcSomesOptMap { (hc, p) => proj.transCoord(hc).map { pt =>
val str = ptScale.scaledStr(170, p.toString + "\n" + hc.strComma, 150, p.charStr + "\n" + hc.strComma, 60, p.charStr)
urect.scale(1.5).slate(hc.toPt2).fillDrawTextActive(p.colour, HPlayer(hc, p), str, 24, 2.0)
urect.scale(120).slate(pt).fillDrawTextActive(p.colour, HPlayer(hc, p), str, 24, 2.0)
}
}

/** [[TextGraphic]]s to display the [[HCen]] coordinate in the tiles that have no unit counters. */
Expand All @@ -41,11 +42,9 @@ case class GOneGui(canv: CanvasPlatform, scenStart: OneScen, viewIn: HGView) ext

/** Draws the tiles sides (or edges). */
def innerSidesDraw: LinesDraw = proj.innerSidesDraw()
//def innerSidesDraw: LinesDraw = gridSys.innerSidesDraw()

/** Draws the tiles sides (or edges). */
def outerSidesDraw: LinesDraw = proj.outerSidesDraw(2, Colour.Gold)
//gridSys.outerSidesDraw(Colour.Gold).slate(-focus).scale(cPScale)

/** This is the graphical display of the planned move orders. */
def moveGraphics: Arr[LineSegDraw] = moves.hcSomesMap { (hc, step) =>
Expand All @@ -62,7 +61,7 @@ case class GOneGui(canv: CanvasPlatform, scenStart: OneScen, viewIn: HGView) ext
}

/** The frame to refresh the top command bar. Note it is a ref so will change with scenario state. */
def thisTop(): Unit = reTop(Arr(bTurn) ++ proj.buttons ++ navButtons)
def thisTop(): Unit = reTop(Arr(bTurn) ++ proj.buttons)

mainMouseUp = (b, cl, _) => (b, selected, cl) match
{
Expand All @@ -83,7 +82,7 @@ case class GOneGui(canv: CanvasPlatform, scenStart: OneScen, viewIn: HGView) ext
thisTop()

def moveGraphics2: GraphicElems = moveGraphics.slate(-focus).scale(cPScale).flatMap(_.arrow)
def frame: GraphicElems = (tiles ++ units ++ hexStrs).slate(-focus).scale(cPScale) +% innerSidesDraw +% outerSidesDraw ++ moveGraphics2
def frame: GraphicElems = (tiles).slate(-focus).scale(cPScale) ++ units +% innerSidesDraw +% outerSidesDraw ++ moveGraphics2 ++ hexStrs
proj.getFrame = () => frame
proj.setStatusText = {str =>
statusText = str
Expand Down
11 changes: 11 additions & 0 deletions Tiling/src/prid/phex/HCenOptDGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ class HCenOptDGrid[A <: AnyRef](val unsafeArr: Array[A]) extends AnyVal with TCe
build.buffToBB(buff)
}

/** [[HCen]] with Some optMap. map the Some values of this HcenArrOpt, with the respective [[HCen]] coordinate to type B, the first type parameter
* B. Returns an immutable Array based collection of type ArrT, the second type parameter. */
def hcSomesOptMap[B, ArrB <: SeqImut[B]](f: (HCen, A) => Option[B])(implicit grider: HGridSys, build: ArrBuilder[B, ArrB]): ArrB =
{ val buff = build.newBuff()
grider.foreach { hc =>
val a: A = unsafeArr(grider.arrIndex(hc))
if (a != null) { f(hc, a).foreach(build.buffGrow(buff, _)) }
}
build.buffToBB(buff)
}

/** Maps the Somes of this [[HCenOptDGrid]] and the Some values of a second HCenArrOpt. Returns an immutable Array based collection of type ArrC, the
* second type parameter. */
def some2sMap[B <: AnyRef, C, ArrC <: SeqImut[C]](optArrB: HCenOptDGrid[B])(f: (A, B) => C)(implicit grider: HGridSys, build: ArrBuilder[C, ArrC]): ArrC =
Expand Down
30 changes: 29 additions & 1 deletion Tiling/src/prid/phex/HSysProjectionFlat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,33 @@ final case class HSysProjectionFlat(gridSys: HGridSys, panel: Panel) extends HSy
setStatusText(tilePScaleStr)
}

override val buttons: Arr[PolygonCompound] = Arr(zoomIn, zoomOut)
def focusAdj(uniStr: String)(f: (Vec2, Double) => Vec2): PolygonCompound = clickButton(uniStr) { butt =>
val delta = butt(1, 10, 100, 0)
focus = f(focus, cPScale * delta / 40)
panel.repaint(getFrame())
setStatusText(focus.strSemi(2, 2))
}

def focusLeft: PolygonCompound = focusAdj("\u2190") { (v, d) =>
val newX: Double = (v.x - d).max(gridSys.left)
Vec2(newX, v.y)
}

def focusRight: PolygonCompound = focusAdj("\u2192") { (v, d) =>
val newX: Double = (v.x + d).min(gridSys.right)
Vec2(newX, v.y)
}

def focusUp: PolygonCompound = focusAdj("\u2191") { (v, d) =>
val newY: Double = (v.y + d).min(gridSys.top)
Vec2(v.x, newY)
}

def focusDown: PolygonCompound = focusAdj("\u2193") { (v, d) =>
val newY: Double = (v.y - d).max(gridSys.bottom)
Vec2(v.x, newY)
}

val buttons: Arr[PolygonCompound] = Arr(zoomIn, zoomOut, focusLeft, focusRight, focusUp, focusDown)
//override val buttons: Arr[PolygonCompound] = Arr(zoomIn, zoomOut)
}

0 comments on commit 171dbe7

Please sign in to comment.