Add game components 246-268; data.DrawSlot, Canvas.TextVeil
Health, mana and experience bars, quarter hearts, lives, a spinning coin counter, score board, stage timer, minimap with fog, compass, hotbar, paper-doll equipment, skill tree, skill buttons with cooldown wipes, status effects, a boss bar, damage numbers, quest log and tracker, party frames, character sheet, level-up screen and shop. data exports DrawSlot so every slot looks alike; pixel adds TextVeil for dissolving text. Messages the font cannot draw are fixed and TestMessagesHaveGlyphs holds every message to the font.
This commit is contained in:
42 files changed
+3260
-26
No files matched your search
+4
-4
@@ -38,12 +38,12 @@ func Inventory(c *ui.Context, text string, items []Item, selected *int, o Invent
|
||||
panic(fmt.Sprintf("data: Inventory slot %d of %d", *selected, len(items)))
|
||||
}
|
||||
old := *selected
|
||||
shell, base, st, _ := pixel.Pad(c, text, cols, len(items), slotSize, slotSize, selected, o.Disabled)
|
||||
shell, base, st, _ := pixel.Pad(c, text, cols, len(items), SlotSize, SlotSize, selected, o.Disabled)
|
||||
b := ui.Local(base, bagKey{}, func() bag { return bag{} })
|
||||
res := InventoryResult{Element: shell, Changed: *selected != old}
|
||||
px, py, _ := base.PointerPosition()
|
||||
at := func() int {
|
||||
col, row := int(px/k.Dot())/slotSize, int(py/k.Dot())/slotSize
|
||||
col, row := int(px/k.Dot())/SlotSize, int(py/k.Dot())/SlotSize
|
||||
if px < 0 || py < 0 || col >= cols || row*cols+col >= len(items) {
|
||||
return -1
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func Inventory(c *ui.Context, text string, items []Item, selected *int, o Invent
|
||||
default:
|
||||
b.dead = false
|
||||
}
|
||||
base.Description(itemName(items[*selected]))
|
||||
base.Description(items[*selected].String())
|
||||
drag := -1
|
||||
if b.held && b.over != b.from {
|
||||
drag = b.from
|
||||
@@ -79,7 +79,7 @@ func Inventory(c *ui.Context, text string, items []Item, selected *int, o Invent
|
||||
if i == drag {
|
||||
it = Item{}
|
||||
}
|
||||
slot(g, i%cols*slotSize, i/cols*slotSize, it, 0, i == *selected)
|
||||
DrawSlot(g, i%cols*SlotSize, i/cols*SlotSize, it, ItemSlotOptions{Selected: i == *selected})
|
||||
}
|
||||
// The dragged item rides with the pointer.
|
||||
if drag >= 0 && shown[drag].Sprite != nil {
|
||||
|
||||
+24
-18
@@ -28,43 +28,49 @@ type ItemSlotOptions struct {
|
||||
// ItemSlot shows an item, count, rarity edge and cooldown.
|
||||
func ItemSlot(c *ui.Context, it Item, o ItemSlotOptions) *ui.Element {
|
||||
k := pixel.K(c)
|
||||
if !(o.Cooldown >= 0 && o.Cooldown <= 1) {
|
||||
panic(fmt.Sprintf("data: Cooldown %v outside 0–1", o.Cooldown))
|
||||
}
|
||||
return ui.Box(c).Role(ui.RoleImage).Label(itemName(it)).Size(k.D(slotSize), k.D(slotSize)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
slot(k.Canvas(p, r), 0, 0, it, o.Cooldown, o.Selected)
|
||||
o.check()
|
||||
return ui.Box(c).Role(ui.RoleImage).Label(it.String()).Size(k.D(SlotSize), k.D(SlotSize)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
DrawSlot(k.Canvas(p, r), 0, 0, it, o)
|
||||
})
|
||||
}
|
||||
|
||||
const slotSize = 22
|
||||
func (o ItemSlotOptions) check() {
|
||||
if !(o.Cooldown >= 0 && o.Cooldown <= 1) {
|
||||
panic(fmt.Sprintf("data: Cooldown %v outside 0–1", o.Cooldown))
|
||||
}
|
||||
}
|
||||
|
||||
// itemName reads an item with its count.
|
||||
func itemName(it Item) string {
|
||||
// SlotSize is a slot's side in dots.
|
||||
const SlotSize = 22
|
||||
|
||||
// String reads an item with its count: "Potion ×3".
|
||||
func (it Item) String() string {
|
||||
if it.Count > 1 {
|
||||
return it.Name + " ×" + strconv.Itoa(it.Count)
|
||||
}
|
||||
return it.Name
|
||||
}
|
||||
|
||||
// slot draws a slot with its top-left at x, y.
|
||||
func slot(g pixel.Canvas, x, y int, it Item, cool float64, chosen bool) {
|
||||
// DrawSlot paints a slot, top left at x, y.
|
||||
func DrawSlot(g pixel.Canvas, x, y int, it Item, o ItemSlotOptions) {
|
||||
o.check()
|
||||
edge := pixel.Edge
|
||||
if it.Sprite != nil {
|
||||
edge = it.Rarity.Slot()
|
||||
}
|
||||
if chosen {
|
||||
g.Rect(x, y, slotSize, slotSize, pixel.Accent)
|
||||
if o.Selected {
|
||||
g.Rect(x, y, SlotSize, SlotSize, pixel.Accent)
|
||||
}
|
||||
g.Rect(x+1, y+1, slotSize-2, slotSize-2, edge)
|
||||
g.Rect(x+2, y+2, slotSize-4, slotSize-4, pixel.Well)
|
||||
g.Rect(x+1, y+1, SlotSize-2, SlotSize-2, edge)
|
||||
g.Rect(x+2, y+2, SlotSize-4, SlotSize-4, pixel.Well)
|
||||
if sp := it.Sprite; sp != nil {
|
||||
g.Sprite(x+2+(slotSize-4-sp.W)/2, y+2+(slotSize-4-sp.H)/2, sp, 0, pixel.Ink, 1)
|
||||
g.Sprite(x+2+(SlotSize-4-sp.W)/2, y+2+(SlotSize-4-sp.H)/2, sp, 0, pixel.Ink, 1)
|
||||
}
|
||||
if h := int(cool * (slotSize - 4)); h > 0 {
|
||||
g.Veil(x+2, y+2, slotSize-4, h, pixel.Shade, 10)
|
||||
if h := int(o.Cooldown * (SlotSize - 4)); h > 0 {
|
||||
g.Veil(x+2, y+2, SlotSize-4, h, pixel.Shade, 10)
|
||||
}
|
||||
if it.Count > 1 {
|
||||
n := strconv.Itoa(it.Count)
|
||||
g.Micro(x+slotSize-2-pixel.MicroWidth(n), y+slotSize-8, n, pixel.Ink, 1)
|
||||
g.Micro(x+SlotSize-2-pixel.MicroWidth(n), y+SlotSize-8, n, pixel.Ink, 1)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user