func Monsters(info []MonstInfo) { // G █ Name // // G is creatures graphic. // █ is the color representation of the health of the monster. // Name is the name of the creature. for y, monst := range info { t := text.New(string(monst.Graphics.Ch), monst.Graphics.Fg) Print( t, monsterInfo.XOffset, monsterInfo.YOffset+y, monsterInfo.Width, ) t = text.New("█", monst.Color()) Print( t, monsterInfo.XOffset+2, monsterInfo.YOffset+y, monsterInfo.Width, ) t = text.New(strings.Title(monst.Name), termbox.ColorWhite) Print( t, monsterInfo.XOffset+4, monsterInfo.YOffset+y, monsterInfo.Width, ) } }
func PrintLong(msg []string, yoffset int) { for y, m := range msg { t := text.New(m, termbox.ColorWhite) ui.Print(t, 0, y+yoffset, ui.Inventory.Width) } termbox.Flush() }
func printEnterSign() { width, height := termbox.Size() msgPos := width/2 + len(journeyStr)/2 t := text.New("↵", termbox.AttrBold) ui.Print(t, msgPos+1, height/2, 0) termbox.Flush() }
func printNameQuestion() { width, height := termbox.Size() offsetY := height/2 + 2 msgPos := width/2 - len(journeyStr)/2 t := text.New(nameStr, termbox.AttrBold) ui.Print(t, msgPos, offsetY, 0) }
func printJourney() { width, height := termbox.Size() msgPos := width/2 - len(journeyStr)/2 ui.ClearLineOffset(height/2, msgPos) t := text.New(journeyStr, termbox.AttrBold) ui.Print(t, msgPos, height/2, 0) }
func printName() { width, height := termbox.Size() offsetX := width/2 - len(nameStr)/2 offsetY := height/2 + 2 ui.ClearLineOffset(offsetY, offsetX) t := text.New(name, termbox.AttrBold+termbox.ColorBlack) ui.Print(t, offsetX+1, offsetY, 0) }
func (attacker *Creature) Battle(defender *Creature, a *area.Area) { t := text.New("", termbox.ColorWhite) if attacker.isHit(defender) { t.Text = attacker.damage(defender, a) } else { t.Text = attacker.hitFail(defender) t.Attr = termbox.ColorBlack } if attacker.dist() <= Hero.Sight { status.PrintTextln(t) } }
// Hp updates the hero health bar. // Health: 17/17 ===================== func Hp(curHp, maxHp int) { xOffset := 0 t := text.New("Health: ", termbox.ColorWhite) Print( t, healthBar.XOffset, healthBar.YOffset, healthBar.Width, ) // len("Health: ") xOffset += 8 t.Text = fmt.Sprintf("%d/%d", curHp, maxHp) t.Attr = termbox.ColorRed Print( t, healthBar.XOffset+xOffset, healthBar.YOffset, healthBar.Width, ) xOffset += len(t.Text) + 1 bar, err := barcli.New(maxHp) if err != nil { log.Println(err) } bar.IncN(curHp) filled, unfilled, err := bar.StringSize(20) if err != nil { log.Println(err) } t.Text = filled t.Attr = termbox.ColorGreen + termbox.AttrBold Print( t, healthBar.XOffset+xOffset, healthBar.YOffset, healthBar.Width, ) xOffset += len(filled) t.Text = unfilled t.Attr = termbox.ColorBlack + termbox.AttrBold Print( t, healthBar.XOffset+xOffset, healthBar.YOffset, healthBar.Width, ) }
func printLogo() { width, height := termbox.Size() logoH := 12 logoW := 82 for x := 0; x < logoW; x++ { for y := 0; y < logoH; y++ { t := text.New(string(logo[y*logoW+x]), termbox.ColorRed) ui.Print(t, width/2-logoW/2+x, height/2-15+y, 0) } } termbox.Flush() }
func printCategory(catStr string, items []*text.Text, rowOffset *int) { cat := text.New(catStr, termbox.ColorCyan+termbox.AttrBold) ui.Print(cat, 0, *rowOffset+ui.Inventory.YOffset, ui.Whole.Width) *rowOffset = *rowOffset + 1 // Items in that category. for _, t := range items { ui.Print(t, ui.Inventory.XOffset, *rowOffset+ui.Inventory.YOffset, ui.Whole.Width) *rowOffset = *rowOffset + 1 } // Empty line. *rowOffset = *rowOffset + 1 }
func addToCategory(i item.Itemer, categories map[string][]*text.Text) { t := text.New(InvText(i), InvAttr(i)) switch i.(type) { case *item.Weapon: categories["Weapons"] = append(categories["Weapons"], t) case *item.Tool: categories["Tools"] = append(categories["Tools"], t) case *item.Ring: categories["Rings"] = append(categories["Rings"], t) case *item.Potion: categories["Potions"] = append(categories["Potions"], t) default: categories["Unknown"] = append(categories["Unknown"], t) } }
// PrintText to status window. func PrintText(t *text.Text) { for { if line >= len(status) { status = append(status, []*text.Text{}) } if lineLen(status[line])+len(t.Text) < ui.Status.Width { status[line] = append(status[line], t) /// Might be wrong, should remove newline char as well? /// What should happen with multiple new lines? // If new line. if strings.ContainsRune(t.Text, '\n') { line++ } break } strLen := ui.Status.Width - lineLen(status[line]) status[line] = append(status[line], text.New(t.Text[:strLen], t.Attr)) line++ t.Text = t.Text[strLen:] } }
func ShowItemDetails(i item.Itemer, a *area.Area) bool { ui.Clear() // Print item title. msgs := makeDrawable(fmt.Sprintf("%c - %s", i.Hotkey(), i.Name())) PrintLong(msgs, 0) rows := len(msgs) // Print flavor text. msgs = makeDrawable(i.FlavorText()) PrintLong(msgs, rows) rows += len(msgs) // Print flavor text. msgs = makeDrawable(StringEffects(i.Effects())) PrintLong(msgs, rows) rows += len(msgs) actionStr := dropAction if item.IsEquipable(i) && !creature.Hero.IsEquipped(i) { actionStr += " You can (e)quip this " + strings.ToLower(i.Cat()) + "." } if creature.Hero.IsEquipped(i) { actionStr += " You can (r)emove this " + strings.ToLower(i.Cat()) + "." } if item.IsUsable(i) { actionStr += " You can (u)se this " + strings.ToLower(i.Cat()) + "." } msgs = makeDrawable(actionStr) for y, m := range msgs { t := text.New(m, termbox.ColorCyan) ui.Print(t, ui.Inventory.XOffset, y+rows, ui.Inventory.Width) } termbox.Flush() itemDetailLoop: for { switch detailsEvent := termbox.PollEvent(); detailsEvent.Type { case termbox.EventKey: if detailsEvent.Key == ui.CancelKey { break itemDetailLoop } switch string(detailsEvent.Ch) { case string(ui.DropItemKey): creature.Hero.DropItem(i.Hotkey(), a) return true case string(ui.EquipItemKey): NarrativeEquip(i.Hotkey()) return true case string(ui.UseItemKey): NarrativeUse(i.Hotkey()) return true case string(ui.UnEquipItemKey): NarrativeUnEquip(i.Hotkey()) return true } } } return false }
// Print takes a string, an attribute and adds it to the status buffer. func Print(str string, attr termbox.Attribute) { PrintText(text.New(str, attr)) }
// Println takes a string, an attribute and adds it to the status buffer // suffixed with a newline '\n'. func Println(str string, attr termbox.Attribute) { PrintText(text.New(fmt.Sprintln(str), attr)) }
// PrintTextln prints text to status window. func PrintTextln(t *text.Text) { PrintText(text.New(fmt.Sprintln(t.Text), t.Attr)) }
func invTitle(title string) { t := text.New(title, termbox.ColorWhite+termbox.AttrBold) ui.Print(t, 0, 0, ui.Whole.Width) }
func emptyInvMsg() { t := text.New(emptyInv, termbox.ColorWhite+termbox.AttrBold) ui.Print(t, 0, 0, ui.Whole.Width) }