Exemplo n.º 1
0
Arquivo: ui.go Projeto: num5/steven
func uiFooter(scene *scene.Type) {
	scene.AddDrawable(
		ui.NewText("Steven - "+stevenVersion(), 5, 5, 255, 255, 255).Attach(ui.Bottom, ui.Left),
	)
	scene.AddDrawable(
		ui.NewText("Not affiliated with Mojang/Minecraft", 5, 5, 255, 200, 200).Attach(ui.Bottom, ui.Right),
	)
}
Exemplo n.º 2
0
func createItemIcon(item *ItemStack, scene *scene.Type, x, y float64) *ui.Container {
	mdl := getModel(item.Type.Name())

	container := ui.NewContainer(x, y, 32, 32)
	if mdl == nil || mdl.builtIn == builtInGenerated {
		var tex render.TextureInfo
		if mdl == nil {
			tex = render.GetTexture("missing_texture")

			img := ui.NewImage(tex, 0, 0, 32, 32, 0, 0, 1, 1, 255, 255, 255)
			img.AttachTo(container)
			scene.AddDrawable(img.Attach(ui.Top, ui.Left))
		} else {
			for i := 0; i < 9; i++ {
				v := fmt.Sprintf("layer%d", i)
				if _, ok := mdl.textureVars[v]; !ok {
					break
				}
				tex = mdl.lookupTexture("#" + v)

				img := ui.NewImage(tex, 0, 0, 32, 32, 0, 0, 1, 1, 255, 255, 255)
				img.AttachTo(container)
				scene.AddDrawable(img.Attach(ui.Top, ui.Left))
			}
		}
	} else if mdl.builtIn == builtInFalse {
		var blk Block
		if bt, ok := item.Type.(*blockItem); ok {
			blk = bt.block
		}
		u := modelToUI(mdl, blk)
		u.AttachTo(container)
		scene.AddDrawable(u.Attach(ui.Top, ui.Left))
	}
	if dam, ok := item.Type.(ItemDamagable); ok && dam.Damage() > 0 {
		val := 1.0 - (float64(dam.Damage()) / float64(dam.MaxDamage()))
		bar := ui.NewImage(render.GetTexture("solid"), 0, 0, 32*val, 2, 0, 0, 1, 1,
			int(255*(1.0-val)), int(255*val), 0,
		)
		bar.SetLayer(2)
		bar.AttachTo(container)
		scene.AddDrawable(bar.Attach(ui.Bottom, ui.Left))
	}
	if item.Count > 1 {
		txt := ui.NewText(fmt.Sprint(item.Count), -2, -2, 255, 255, 255).
			Attach(ui.Bottom, ui.Right)
		txt.AttachTo(container)
		txt.SetLayer(2)
		scene.AddDrawable(txt)
	}
	return container
}
Exemplo n.º 3
0
func (playerInventory) Draw(s *scene.Type, inv *Inventory) {
	full := Client.activeInventory == Client.playerInventory

	if !full {
		// Slots 36-44 are the hotbar
		Client.hotbarScene.Hide()
		Client.hotbarScene = scene.New(true)
		hs := Client.hotbarScene
		for i := invPlayerHotbarOffset; i < invPlayerHotbarOffset+9; i++ {
			if inv.Items[i] == nil {
				continue
			}
			item := inv.Items[i]
			container := createItemIcon(item, hs, 6+40*float64(i-36), 6).
				Attach(ui.Top, ui.Left)
			container.AttachTo(Client.hotbar)
		}
		return
	}

	background := ui.NewImage(
		render.GetTexture("gui/container/inventory"),
		0, 0, 176*2, 166*2,
		0, 0, 176/256.0, 166/256.0,
		255, 255, 255,
	)
	s.AddDrawable(background.Attach(ui.Middle, ui.Center))

	check := ui.NewContainer(0, 0, 176*2, 166*2)
	s.AddDrawable(check.Attach(ui.Middle, ui.Center))
	check.HoverFunc = func(over bool) {
		invScreen.inWindow = over
	}

	var slotPositions = [45][2]float64{
		0: {144, 36}, // Craft-out
		// Craft-In
		1: {88, 26},
		2: {106, 26},
		3: {88, 44},
		4: {106, 44},
		// Armor
		5: {8, 8},
		6: {8, 26},
		7: {8, 44},
		8: {8, 62},
	}
	for i := 9; i <= 35; i++ {
		x := i % 9
		y := (i / 9) - 1
		slotPositions[i] = [2]float64{
			8 + 18*float64(x), 84 + 18*float64(y),
		}
	}
	for i := 0; i < 9; i++ {
		slotPositions[i+36] = [2]float64{
			8 + 18*float64(i), 142,
		}
	}

	solid := render.GetTexture("solid")

	for i, pos := range slotPositions {
		i := i
		ctn := ui.NewContainer(pos[0]*2, pos[1]*2, 32, 32)
		ctn.AttachTo(background)
		s.AddDrawable(ctn)

		item := inv.Items[i]
		if item != nil {
			container := createItemIcon(item, s, pos[0]*2, pos[1]*2)
			container.AttachTo(background)
		} else if i >= 5 && i <= 8 {
			tex := render.GetTexture([]string{
				"items/empty_armor_slot_helmet",
				"items/empty_armor_slot_chestplate",
				"items/empty_armor_slot_leggings",
				"items/empty_armor_slot_boots",
			}[i-5])
			img := ui.NewImage(tex, pos[0]*2, pos[1]*2, 32, 32, 0, 0, 1, 1, 255, 255, 255)
			img.AttachTo(background)
			s.AddDrawable(img)
		}

		highlight := ui.NewImage(solid, pos[0]*2, pos[1]*2, 32, 32, 0, 0, 1, 1, 255, 255, 255)
		highlight.SetA(0)
		highlight.AttachTo(background)
		highlight.SetLayer(25)
		s.AddDrawable(highlight)

		ctn.HoverFunc = func(over bool) {
			if over {
				highlight.SetA(100)
				invScreen.activeSlot = i
			} else {
				highlight.SetA(0)
				if i == invScreen.activeSlot {
					invScreen.activeSlot = -1
				}
			}
		}
	}
}
Exemplo n.º 4
0
Arquivo: ui.go Projeto: num5/steven
func (sl *slider) add(s *scene.Type) {
	s.AddDrawable(sl.back)
	s.AddDrawable(sl.slider)
}