|
| 1 | +package tracker |
| 2 | + |
| 3 | +import ( |
| 4 | + "image" |
| 5 | + "image/color" |
| 6 | + "log" |
| 7 | + "strconv" |
| 8 | + |
| 9 | + "github.com/hajimehoshi/ebiten" |
| 10 | + "github.com/hajimehoshi/ebiten/ebitenutil" |
| 11 | + "github.com/hajimehoshi/ebiten/text" |
| 12 | +) |
| 13 | + |
| 14 | +func (tracker *Tracker) Draw(screen *ebiten.Image) { |
| 15 | + op := ebiten.DrawImageOptions{} |
| 16 | + drawState := func(state bool, sheet *ebiten.Image) { |
| 17 | + for k := range tracker.items { |
| 18 | + if tracker.items[k].Enabled != state { |
| 19 | + continue |
| 20 | + } |
| 21 | + |
| 22 | + pos := tracker.items[k].Rect().Min.Add(tracker.pos) |
| 23 | + op.GeoM.Reset() |
| 24 | + op.GeoM.Translate(float64(pos.X), float64(pos.Y)) |
| 25 | + |
| 26 | + if err := screen.DrawImage( |
| 27 | + sheet.SubImage(tracker.items[k].SheetRect()).(*ebiten.Image), |
| 28 | + &op, |
| 29 | + ); err != nil { |
| 30 | + log.Fatal(err) |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + _ = screen.DrawImage(tracker.background, nil) |
| 36 | + if tracker.kbInputStateIsAny(inputStateItemKPZoneInput, inputStateItemInput) { |
| 37 | + _ = screen.DrawImage(tracker.backgroundHelp, nil) |
| 38 | + if tracker.input.activeKPZone > 0 { |
| 39 | + tracker.drawActiveItemSlot(screen, tracker.input.activeKPZone) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + // Do two loops to avoid texture switches. |
| 44 | + drawState(false, tracker.sheetDisabled) |
| 45 | + drawState(true, tracker.sheetEnabled) |
| 46 | + |
| 47 | + tracker.drawDungeons(screen) |
| 48 | + tracker.drawCapacities(screen) |
| 49 | + tracker.drawInputState(screen) |
| 50 | + tracker.drawHints(screen) |
| 51 | +} |
| 52 | +func (tracker *Tracker) drawActiveItemSlot(screen *ebiten.Image, slot int) { |
| 53 | + if slot <= 0 || slot > 9 { |
| 54 | + return |
| 55 | + } |
| 56 | + |
| 57 | + slot = []int{ // make maths ez |
| 58 | + 0, |
| 59 | + 6, 7, 8, |
| 60 | + 3, 4, 5, |
| 61 | + 0, 1, 2, |
| 62 | + }[slot] |
| 63 | + |
| 64 | + edge := gridSize * 3 |
| 65 | + pos := image.Point{ |
| 66 | + (slot % 3) * edge, |
| 67 | + (slot / 3) * edge, |
| 68 | + } |
| 69 | + size := image.Point{126, 126} |
| 70 | + |
| 71 | + if slot == 2 { // KP 9 |
| 72 | + pos.Y = 0 |
| 73 | + size.X = gridSize |
| 74 | + size.Y = 4*gridSize + (gridSize / 2) |
| 75 | + } else if slot == 8 { // KP 3 |
| 76 | + pos.Y = 4*gridSize + (gridSize / 2) |
| 77 | + size.X = gridSize |
| 78 | + size.Y = pos.Y |
| 79 | + } |
| 80 | + |
| 81 | + ebitenutil.DrawRect( |
| 82 | + screen, |
| 83 | + float64(pos.X), float64(pos.Y), |
| 84 | + float64(size.X), float64(size.Y), |
| 85 | + color.RGBA{0xFF, 0xFF, 0xFF, 0x50}, |
| 86 | + ) |
| 87 | +} |
| 88 | + |
| 89 | +func (tracker *Tracker) drawDungeons(screen *ebiten.Image) { |
| 90 | + for k := range tracker.items { |
| 91 | + if !tracker.items[k].IsMedallion { |
| 92 | + continue |
| 93 | + } |
| 94 | + |
| 95 | + rect := tracker.items[k].Rect() |
| 96 | + x, y := rect.Min.X, rect.Max.Y |
| 97 | + text.Draw(screen, tracker.items[k].DungeonText(), tracker.fontSmall, x, y, color.White) |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +func (tracker *Tracker) drawCapacities(screen *ebiten.Image) { |
| 102 | + for k := range tracker.items { |
| 103 | + var count int |
| 104 | + switch { |
| 105 | + case tracker.items[k].HasCapacity(): |
| 106 | + count = tracker.items[k].Capacity() |
| 107 | + case tracker.items[k].IsCountable(): |
| 108 | + count = tracker.items[k].Count |
| 109 | + default: |
| 110 | + continue |
| 111 | + } |
| 112 | + |
| 113 | + if !tracker.items[k].Enabled { |
| 114 | + continue |
| 115 | + } |
| 116 | + |
| 117 | + rect := tracker.items[k].Rect() |
| 118 | + x, y := rect.Min.X, rect.Max.Y |
| 119 | + |
| 120 | + // HACK, display skull count centered on the right slot |
| 121 | + if tracker.items[k].Name == "Gold Skulltula Token" { |
| 122 | + x, y = rect.Min.X+gridSize+marginLeft, rect.Min.Y+marginTop+(gridSize/2) |
| 123 | + if count == 100 { |
| 124 | + x -= 5 |
| 125 | + } else if count < 10 { |
| 126 | + x += 5 |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + str := strconv.Itoa(count) |
| 131 | + text.Draw(screen, str, tracker.font, x, y, color.White) |
| 132 | + } |
| 133 | +} |
0 commit comments