Example #1
0
func categorizedInv(title string) (isEmpty bool) {
	// Make screen black.
	ui.Clear()

	// If inventory is empty, warn the user.
	if len(creature.Hero.Inventory) == 0 {
		emptyInvMsg()

		// Show the text and wait for any input.
		termbox.Flush()
		termbox.PollEvent()
		return true
	}

	// Print inventory title.
	invTitle(title)

	// categories contains the item texts sorted in item categories.
	// Sort items into categories.
	var categories = map[string][]*text.Text{}
	for _, pos := range item.Positions {
		if i, ok := creature.Hero.Inventory[pos]; ok {
			addToCategory(i, categories)
		}
	}

	// The ordering of the categories in the inventory.
	var order = []string{
		"Weapons",
		"Rings",
		"Potions",
		"Tools",
		"Unknown",
	}
	// Print categories and the items in that category to screen.
	// Rows written to screen.
	rowOffset := 0
	for _, cat := range order {
		items := categories[cat]
		// Ignore empty categories
		if len(items) == 0 {
			continue
		}

		// Item category.
		printCategory(cat, items, &rowOffset)
	}
	termbox.Flush()
	return false
}
Example #2
0
File: fov.go Project: karlek/reason
// DrawFOV draws a field of view around a creature as well as the creatures
// memory of already explored areas.
func (c Creature) DrawFOV(a *area.Area) {
	// Clear screen.
	ui.Clear()

	// Get viewport coordinate offset.
	camX, camY := camXY(c, a)

	// Draw already explored areas.
	a.DrawExplored(ui.Area, camX, camY)

	// Draw hero.
	a.Draw(c.X(), c.Y(), camX, camY, ui.Area)

	// Visible coordinates of character.
	cs := c.FOV(a)
	for p := range cs {
		// Set terrain as explored.
		a.Terrain[p.X][p.Y].IsExplored = true

		// TODO(_): refactor cam.
		a.Draw(p.X, p.Y, camX, camY, ui.Area)
	}
}
Example #3
0
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
}