Selected cursor chrome
This commit is contained in:
@@ -92,7 +92,7 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
||||
counter := map[string]int{}
|
||||
for _, pt := range toDraw {
|
||||
for z := 0; z <= s.ZIdx; z++ {
|
||||
if err := s.renderCell(pt, z, screen, counter); err != nil {
|
||||
if err := s.renderCell(int(pt.X), int(pt.Y), z, screen, counter); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -100,26 +100,53 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
||||
|
||||
//log.Printf("%#+v", counter)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Scenario) renderCell(pos IsoPt, z int, screen *ebiten.Image, counter map[string]int) error {
|
||||
sprites, err := s.area.SpritesForCell(int(pos.X), int(pos.Y), z)
|
||||
// Finally, draw cursor chrome
|
||||
spr, err := s.specials.Sprite(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
iso := ebiten.GeoM{}
|
||||
iso.Translate(-float64(s.Viewpoint.X), -float64(s.Viewpoint.Y))
|
||||
op := ebiten.DrawImageOptions{}
|
||||
op.GeoM = s.geoForCoords(int(s.selectedCell.X), int(s.selectedCell.Y), 0)
|
||||
op.GeoM.Translate(-cellWidthHalf, -cellHeightHalf)
|
||||
|
||||
pix := pos.ToCart()
|
||||
iso.Translate(pix.X, pix.Y)
|
||||
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sx, sy := op.GeoM.Apply(0, 0)
|
||||
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("(%.0f,%.0f)", s.selectedCell.X, s.selectedCell.Y), int(sx), int(sy))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Scenario) geoForCoords(x, y, z int) ebiten.GeoM {
|
||||
geo := ebiten.GeoM{}
|
||||
geo.Translate(-float64(s.Viewpoint.X), -float64(s.Viewpoint.Y))
|
||||
|
||||
pix := IsoPt{X: float64(x), Y: float64(y)}.ToCart()
|
||||
geo.Translate(pix.X, pix.Y)
|
||||
|
||||
// Taking the Z index away *seems* to draw the object in the correct place.
|
||||
// FIXME: There are some artifacts, investigate more
|
||||
iso.Translate(0.0, -float64(z*48.0)) // offset for Z index
|
||||
geo.Translate(0.0, -float64(z*48.0)) // offset for Z index
|
||||
|
||||
return geo
|
||||
}
|
||||
|
||||
func (s *Scenario) renderCell(x, y, z int, screen *ebiten.Image, counter map[string]int) error {
|
||||
sprites, err := s.area.SpritesForCell(x, y, z)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: iso.Scale(e.state.zoom, e.state.zoom) // apply current zoom factor
|
||||
iso := s.geoForCoords(x, y, z)
|
||||
|
||||
// FIXME: this fixed offset is found in jungtil.obj. Drawing with it
|
||||
// means we put everywhere where the iso->pix conversion expects, but
|
||||
// it's a bit nasty. Is there a better way?
|
||||
iso.Translate(-209, -332)
|
||||
|
||||
for _, spr := range sprites {
|
||||
// if _, ok := counter[spr.ID]; !ok {
|
||||
@@ -128,20 +155,11 @@ func (s *Scenario) renderCell(pos IsoPt, z int, screen *ebiten.Image, counter ma
|
||||
// counter[spr.ID] = counter[spr.ID] + 1
|
||||
op := ebiten.DrawImageOptions{GeoM: iso}
|
||||
|
||||
// FIXME: this fixed offset is found in jungtil.obj. Drawing with it
|
||||
// means we put everywhere where the iso->pix conversion expects, but
|
||||
// it's a bit nasty. Is there a better way?
|
||||
op.GeoM.Translate(float64(spr.Rect.Min.X-209), float64(spr.Rect.Min.Y-322))
|
||||
op.GeoM.Translate(float64(spr.Rect.Min.X), float64(spr.Rect.Min.Y))
|
||||
|
||||
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if z == 0 {
|
||||
x, y := op.GeoM.Apply(0, 0)
|
||||
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("(%d,%d)", int(pos.X), int(pos.Y)), int(x), int(y))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user