Пример #1
0
// Draw draws this to the target region.
func (b *Button) Draw(r Region, delta float64) {
	if b.isNew || b.isDirty() || forceDirty {
		b.isNew = false
		if b.disabled {
			b.currentTex = render.RelativeTexture(render.GetTexture("gui/widgets"), 256, 256).
				Sub(0, 46, 200, 20)
		} else {
			off := 66
			if b.hovered {
				off += 20
			}
			b.currentTex = render.RelativeTexture(render.GetTexture("gui/widgets"), 256, 256).
				Sub(0, off, 200, 20)
		}
		b.data = b.data[:0]

		cw, ch := b.Size()
		sx, sy := r.W/cw, r.H/ch
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X, r.Y, 4*sx, 4*sy, 0, 0, 2/200.0, 2/20.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X+r.W-4*sx, r.Y, 4*sx, 4*sy, 198/200.0, 0, 2/200.0, 2/20.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X, r.Y+r.H-6*sy, 4*sx, 6*sy, 0, 17/20.0, 2/200.0, 3/20.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X+r.W-4*sx, r.Y+r.H-6*sy, 4*sx, 6*sy, 198/200.0, 17/20.0, 2/200.0, 3/20.0).Bytes()...)

		w := (r.W/sx)/2 - 4
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(2, 0, 196, 2), r.X+4*sx, r.Y, r.W-8*sx, 4*sy, 0, 0, w/196.0, 1.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(2, 17, 196, 3), r.X+4*sx, r.Y+r.H-6*sy, r.W-8*sx, 6*sy, 0, 0, w/196.0, 1.0).Bytes()...)

		h := (r.H/sy)/2 - 5
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(0, 2, 2, 15), r.X, r.Y+4*sy, 4*sx, r.H-10*sy, 0.0, 0.0, 1.0, h/16.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(198, 2, 2, 15), r.X+r.W-4*sx, r.Y+4*sy, 4*sx, r.H-10*sy, 0.0, 0.0, 1.0, h/16.0).Bytes()...)

		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(2, 2, 196, 15), r.X+4*sx, r.Y+4*sy, r.W-8*sx, r.H-10*sy, 0.0, 0.0, w/196.0, h/16.0).Bytes()...)
	}
	render.UIAddBytes(b.data)
}
Пример #2
0
func genSunModel() {
	if sunModel != nil {
		sunModel.Free()
		moonModel.Free()
		sunModel = nil
		moonModel = nil
	}
	const size = 50
	tex := render.GetTexture("environment/sun")
	sunModel = render.NewModelCollection([][]*render.ModelVertex{
		{
			{X: 0, Y: -size, Z: -size, TextureX: 0, TextureY: 1, Texture: tex, R: 255, G: 255, B: 255, A: 255},
			{X: 0, Y: size, Z: -size, TextureX: 0, TextureY: 0, Texture: tex, R: 255, G: 255, B: 255, A: 255},
			{X: 0, Y: -size, Z: size, TextureX: 1, TextureY: 1, Texture: tex, R: 255, G: 255, B: 255, A: 255},
			{X: 0, Y: size, Z: size, TextureX: 1, TextureY: 0, Texture: tex, R: 255, G: 255, B: 255, A: 255},
		},
	}, render.SunModels)

	moon := render.GetTexture("environment/moon_phases")
	mpx, mpy := float64(moonPhase%4)*(1/4.0), float64(moonPhase/4)*(1/2.0)
	moonModel = render.NewModelCollection([][]*render.ModelVertex{
		{
			{X: 0, Y: -size, Z: -size, TextureX: mpx, TextureY: mpy + (1 / 2.0), Texture: moon, R: 255, G: 255, B: 255, A: 255},
			{X: 0, Y: size, Z: -size, TextureX: mpx, TextureY: mpy, Texture: moon, R: 255, G: 255, B: 255, A: 255},
			{X: 0, Y: -size, Z: size, TextureX: mpx + (1 / 4.0), TextureY: mpy + (1 / 2.0), Texture: moon, R: 255, G: 255, B: 255, A: 255},
			{X: 0, Y: size, Z: size, TextureX: mpx + (1 / 4.0), TextureY: mpy, Texture: moon, R: 255, G: 255, B: 255, A: 255},
		},
	}, render.SunModels)
}
Пример #3
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()))
		barShadow := ui.NewImage(render.GetTexture("solid"), 0, 2, 28, 4, 0, 0, 1, 1,
			0, 0, 0,
		)
		barShadow.SetLayer(2)
		barShadow.AttachTo(container)
		scene.AddDrawable(barShadow.Attach(ui.Bottom, ui.Center))
		bar := ui.NewImage(render.GetTexture("solid"), 0, 0, 28*val, 2, 0, 0, 1, 1,
			int(255*(1.0-val)), int(255*val), 0,
		)
		bar.SetLayer(2)
		bar.AttachTo(barShadow)
		scene.AddDrawable(bar.Attach(ui.Top, 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
}
Пример #4
0
func initBlocks() {
	missingModel := findStateModel("steven", "missing_block")
	// Flatten the ids
	for _, bs := range blockSetsByID {
		if bs == nil {
			continue
		}
		for i, b := range bs.Blocks {
			br := reflect.ValueOf(b).Elem()
			br.FieldByName("Index").SetInt(int64(i))
			br.FieldByName("StevenID").SetUint(uint64(len(allBlocks)))
			allBlocks = append(allBlocks, b)
			if len(allBlocks) > math.MaxUint16 {
				panic("ran out of ids, time to do this correctly :(")
			}
			data := b.toData()
			if data != -1 {
				blocks[(bs.ID<<4)|data] = b
			}
			// Liquids have custom rendering
			if l, ok := b.(*blockLiquid); ok {
				if l.Lava {
					l.Tex = render.GetTexture("blocks/lava_still")
				} else {
					l.Tex = render.GetTexture("blocks/water_still")
				}
				continue
			}
			if !b.Renderable() {
				continue
			}

			if model := findStateModel(b.Plugin(), b.ModelName()); model != nil {
				if variants := model.variant(b.ModelVariant()); variants != nil {
					br.FieldByName("BlockVariants").Set(
						reflect.ValueOf(variants),
					)
					continue
				}
				if variants := model.matchPart(bs, b); variants != nil {
					br.FieldByName("BlockVariants").Set(
						reflect.ValueOf(variants),
					)
					continue
				}
				console.Text("Missing block variant (%s) for %s", b.ModelVariant(), b)
			} else {
				console.Text("Missing block model for %s", b)
			}
			br.FieldByName("BlockVariants").Set(
				reflect.ValueOf(missingModel.variant("normal")),
			)

		}
	}
}
Пример #5
0
func newGameMenu() screen {
	gm := &gameMenu{
		scene: scene.New(true),
	}

	gm.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 480, 0, 0, 1, 1, 0, 0, 0)
	gm.background.SetA(160)
	gm.scene.AddDrawable(gm.background.Attach(ui.Top, ui.Left))

	disconnect, txt := newButtonText("Disconnect", 0, 50, 400, 40)
	gm.scene.AddDrawable(disconnect.Attach(ui.Center, ui.Middle))
	gm.scene.AddDrawable(txt)
	disconnect.AddClick(func() { Client.network.SignalClose(errManualDisconnect) })

	rtg, txt := newButtonText("Return to game", 0, -50, 400, 40)
	gm.scene.AddDrawable(rtg.Attach(ui.Center, ui.Middle))
	gm.scene.AddDrawable(txt)
	rtg.AddClick(func() { setScreen(nil) })

	option, txt := newButtonText("Options", 0, 0, 400, 40)
	gm.scene.AddDrawable(option.Attach(ui.Center, ui.Middle))
	gm.scene.AddDrawable(txt)
	option.AddClick(func() { setScreen(newOptionMenu(newGameMenu)) })

	uiFooter(gm.scene)
	return gm
}
Пример #6
0
func (b *blockBreakComponent) Update() {
	if b.model != nil {
		b.model.Free()
	}
	bounds := chunkMap.Block(b.Location.X, b.Location.Y, b.Location.Z).CollisionBounds()
	tex := render.GetTexture(fmt.Sprintf("blocks/destroy_stage_%d", b.stage))

	var verts []*render.StaticVertex
	for _, bo := range bounds {
		// Slightly bigger than the block to prevent clipping
		bo = bo.Grow(0.01, 0.01, 0.01)
		verts = appendBox(verts,
			bo.Min.X(), bo.Min.Y(), bo.Min.Z(),
			bo.Max.X()-bo.Min.X(), bo.Max.Y()-bo.Min.Y(), bo.Max.Z()-bo.Min.Z(),
			[6]render.TextureInfo{
				tex, tex, tex, tex, tex, tex,
			})
	}
	b.model = render.NewStaticModel([][]*render.StaticVertex{verts})

	b.model.Matrix[0] = mgl32.Translate3D(
		float32(b.Location.X),
		-float32(b.Location.Y),
		float32(b.Location.Z),
	)
}
Пример #7
0
func (c *ChatUI) Add(msg format.AnyComponent) {
	format.ConvertLegacy(msg)
	copy(c.Lines[0:chatHistoryLines-1], c.Lines[1:])
	c.Lines[chatHistoryLines-1] = msg
	f := ui.NewFormattedWidth(msg, 5, chatHistoryLines*18+1, maxLineWidth-10).Attach(ui.Top, ui.Left)
	f.AttachTo(c.container)
	line := &chatLine{
		text:       f,
		fade:       3.0,
		background: ui.NewImage(render.GetTexture("solid"), 0, chatHistoryLines*18, maxLineWidth, f.Height, 0, 0, 1, 1, 0, 0, 0),
	}
	line.background.AttachTo(c.container)
	line.background.SetA(77)
	c.parts = append(c.parts, line)
	Client.scene.AddDrawable(line.background)
	Client.scene.AddDrawable(f)
	ff := f
	for _, f := range c.parts {
		f.text.SetY(f.text.Y() - 18*float64(ff.Lines))
		f.background.SetY(f.background.Y() - 18*float64(ff.Lines))
	}
	if c.enteringText {
		ff.SetY(ff.Y() - 18)
		line.background.SetY(line.background.Y() - 18)
	}
}
Пример #8
0
func newRespawnScreen() *respawnScreen {
	rs := &respawnScreen{
		scene: scene.New(true),
	}

	rs.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 480, 0, 0, 1, 1, 0, 0, 0)
	rs.background.SetA(160)
	rs.scene.AddDrawable(rs.background.Attach(ui.Top, ui.Left))

	rs.scene.AddDrawable(
		ui.NewText("Respawn:", 0, -20, 255, 255, 255).Attach(ui.Center, ui.Middle),
	)

	respawn, txt := newButtonText("Respawn", -205, 20, 400, 40)
	rs.scene.AddDrawable(respawn.Attach(ui.Center, ui.Middle))
	rs.scene.AddDrawable(txt)
	respawn.AddClick(func() {
		setScreen(nil)
		Client.network.Write(&protocol.ClientStatus{ActionID: 0})
	})

	disconnect, txt := newButtonText("Disconnect", 205, 20, 400, 40)
	rs.scene.AddDrawable(disconnect.Attach(ui.Center, ui.Middle))
	rs.scene.AddDrawable(txt)
	disconnect.AddClick(func() { Client.network.SignalClose(errManualDisconnect) })

	uiFooter(rs.scene)
	return rs
}
Пример #9
0
func (u *uiLogo) tick(delta float64) {
	if logoTimer > 0 {
		logoTimer -= delta
	} else if logoTransTimer < 0 {
		logoTransTimer = 120
		logoTimer = r.Float64() * 60 * 30
		readStevenLogo()
		logoTexture = logoTargetTexture
		nextLogoTexture()
		nextLogoText()
		u.text.Update(logoText)
		width, _ := u.text.Size()
		u.textBaseScale = 300 / width
		if u.textBaseScale > 1 {
			u.textBaseScale = 1
		}
		u.text.SetX((-u.text.Width / 2) * u.textBaseScale)
		u.origX = u.text.X()
	} else {
		logoTransTimer -= delta
	}

	tex, tex2 := render.GetTexture(logoTexture), render.GetTexture(logoTargetTexture)
	for i := range logoLayers[0] {
		logoLayers[0][i].SetTexture(tex)
		logoLayers[1][i].SetTexture(tex2)

		logoLayers[0][i].SetA(int(255 * (logoTransTimer / 120)))
		logoLayers[1][i].SetA(int(255 * (1 - (logoTransTimer / 120))))
	}

	logoTextTimer += delta
	if logoTextTimer > 60 {
		logoTextTimer -= 60
	}
	off := (logoTextTimer / 30)
	if off > 1.0 {
		off = 2.0 - off
	}
	off = (math.Cos(off*math.Pi) + 1) / 2
	u.text.SetScaleX((0.7 + (off / 3)) * u.textBaseScale)
	u.text.SetScaleY((0.7 + (off / 3)) * u.textBaseScale)
	u.text.SetX(u.origX * u.text.ScaleX() * u.textBaseScale)
}
Пример #10
0
func newServerList() screen {
	sl := &serverList{
		scene: scene.New(true),
	}
	sl.logo.init(sl.scene)

	uiFooter(sl.scene)

	sl.redraw()

	refresh, txt := newButtonText("Refresh", 300, -50-15, 100, 30)
	sl.scene.AddDrawable(refresh.Attach(ui.Center, ui.Middle))
	sl.scene.AddDrawable(txt)
	refresh.AddClick(sl.redraw)

	add, txt := newButtonText("Add", 200, -50-15, 100, 30)
	sl.scene.AddDrawable(add.Attach(ui.Center, ui.Middle))
	sl.scene.AddDrawable(txt)
	add.AddClick(func() {
		setScreen(newEditServer(-1))
	})

	options := ui.NewButton(5, 25, 40, 40)
	sl.scene.AddDrawable(options.Attach(ui.Bottom, ui.Right))
	cog := ui.NewImage(render.GetTexture("steven:gui/cog"), 0, 0, 40, 40, 0, 0, 1, 1, 255, 255, 255)
	cog.AttachTo(options)
	sl.scene.AddDrawable(cog.Attach(ui.Center, ui.Middle))
	options.AddClick(func() {
		setScreen(newOptionMenu(newServerList))
	})

	if disconnectReason.Value != nil {
		disMsg := ui.NewText("Disconnected", 0, 32, 255, 0, 0).Attach(ui.Top, ui.Center)
		dis := ui.NewFormattedWidth(disconnectReason, 0, 48, 600)
		disB := ui.NewImage(render.GetTexture("solid"), 0, 30, math.Max(dis.Width, disMsg.Width)+4, dis.Height+4+16, 0, 0, 1, 1, 0, 0, 0)
		disB.SetA(100)
		sl.scene.AddDrawable(disB.Attach(ui.Top, ui.Center))
		sl.scene.AddDrawable(dis.Attach(ui.Top, ui.Center))
		sl.scene.AddDrawable(disMsg)
	}

	return sl
}
Пример #11
0
func (p *playerListUI) init() {
	p.info = map[protocol.UUID]*playerInfo{}
	p.scene = scene.New(false)
	for i := range p.background {
		p.background[i] = ui.NewImage(render.GetTexture("solid"), 0, 16, playerListWidth+48, 16, 0, 0, 1, 1, 0, 0, 0)
		p.background[i].SetA(120)
		p.background[i].SetDraw(false)
		p.scene.AddDrawable(p.background[i].Attach(ui.Top, ui.Center))
	}
}
Пример #12
0
func (c *ChatUI) init() {
	c.container = ui.NewContainer(0, 44, maxLineWidth, chatHistoryLines*18+2)
	c.container.Attach(ui.Bottom, ui.Left)
	c.input = ui.NewText("", 5, 1, 255, 255, 255).Attach(ui.Bottom, ui.Left)
	c.input.SetDraw(false)
	c.input.AttachTo(c.container)
	c.inputBackground = ui.NewImage(render.GetTexture("solid"), 0, 0, maxLineWidth, 20, 0, 0, 1, 1, 0, 0, 0).Attach(ui.Bottom, ui.Left)
	c.inputBackground.SetA(77)
	c.inputBackground.AttachTo(c.container)
	c.inputBackground.SetDraw(false)
	Client.scene.AddDrawable(c.inputBackground)
	Client.scene.AddDrawable(c.input)
}
Пример #13
0
func newProgressBar() *progressBar {
	p := &progressBar{
		id: len(progressBars),
	}
	p.bar = ui.NewImage(render.GetTexture("solid"), 0, 21*float64(p.id), 854, 21, 0, 0, 1, 1, 0, 125, 0)
	ui.AddDrawable(p.bar.Attach(ui.Top, ui.Left))
	p.text = ui.NewText("", 1, 21*float64(p.id)+1, 255, 255, 255)
	ui.AddDrawable(p.text.Attach(ui.Top, ui.Left))
	progressBars = append(progressBars, p)
	p.bar.SetLayer(-241)
	p.text.SetLayer(-240)
	return p
}
Пример #14
0
func (cs *consoleScreen) init() {
	cs.scene = scene.New(true)
	cs.container = ui.NewContainer(0, -220, 854, 220)
	cs.container.SetLayer(-200)
	cs.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 220, 0, 0, 1, 1, 0, 0, 0)
	cs.background.SetA(180)
	cs.background.AttachTo(cs.container)
	cs.scene.AddDrawable(cs.background.Attach(ui.Top, ui.Left))

	cs.inputText = ui.NewText("", 5, 200, 255, 255, 255)
	cs.inputText.AttachTo(cs.container)
	cs.scene.AddDrawable(cs.inputText.Attach(ui.Top, ui.Left))
	cs.pos = -220
	cs.visible = false
}
Пример #15
0
func (s *signComponent) create() {
	const yS = (6.0 / 16.0) / 4.0
	const xS = yS / 16.0

	var verts []*render.StaticVertex
	for i, line := range s.lines {
		if line.Value == nil {
			continue
		}
		format.ConvertLegacy(line)
		// Hijack ui.Formatted's component parsing to split
		// up components into ui.Text elements.
		// TODO(Think) Move this into some common place for
		// easier reuse in other places?
		wrap := &format.TextComponent{}
		wrap.Color = format.Black
		wrap.Extra = []format.AnyComponent{line}
		f := ui.NewFormatted(format.Wrap(wrap), 0, 0)
		offset := 0.0
		for _, txt := range f.Text {
			str := txt.Value()

			for _, r := range str {
				tex := render.CharacterTexture(r)
				if tex == nil {
					continue
				}
				s := render.SizeOfCharacter(r)
				if r == ' ' {
					offset += (s + 2) * xS
					continue
				}

				for _, v := range faceVertices[direction.North].verts {
					vert := &render.StaticVertex{
						X:        float32(v.X)*float32(s*xS) - float32(offset+s*xS) + float32(f.Width*xS*0.5),
						Y:        float32(v.Y)*yS - yS*float32(i-1),
						Z:        -.6 / 16.0,
						Texture:  tex,
						TextureX: float64(v.TOffsetX),
						TextureY: float64(v.TOffsetY),
						R:        byte(txt.R()),
						G:        byte(txt.G()),
						B:        byte(txt.B()),
						A:        255,
					}
					verts = append(verts, vert)
				}
				offset += (s + 2) * xS
			}
		}
	}
	wood := render.GetTexture("blocks/planks_oak")
	// The backboard
	verts = appendBoxExtra(verts, -0.5, -4/16.0, -0.5/16.0, 1.0, 8/16.0, 1/16.0, [6]render.TextureInfo{
		direction.Up:    wood.Sub(0, 0, 16, 2),
		direction.Down:  wood.Sub(0, 0, 16, 2),
		direction.East:  wood.Sub(0, 0, 2, 12),
		direction.West:  wood.Sub(0, 0, 2, 12),
		direction.North: wood.Sub(0, 4, 16, 12),
		direction.South: wood.Sub(0, 4, 16, 12),
	}, [6][2]float64{
		direction.Up:    {1.5, 1.0},
		direction.Down:  {1.5, 1.0},
		direction.East:  {1.0, 1.0},
		direction.West:  {1.0, 1.0},
		direction.North: {1.5, 1.0},
		direction.South: {1.5, 1.0},
	})
	if s.hasStand {
		// Stand
		log := render.GetTexture("blocks/log_oak")
		verts = appendBox(verts, -0.5/16.0, -0.25-9/16.0, -0.5/16.0, 1/16.0, 9/16.0, 1/16.0, [6]render.TextureInfo{
			direction.Up:    log.Sub(0, 0, 2, 2),
			direction.Down:  log.Sub(0, 0, 2, 2),
			direction.East:  log.Sub(0, 0, 2, 12),
			direction.West:  log.Sub(0, 0, 2, 12),
			direction.North: log.Sub(0, 0, 2, 12),
			direction.South: log.Sub(0, 0, 2, 12),
		})
	}
	s.model = render.NewStaticModel([][]*render.StaticVertex{
		verts,
	})
	s.model.Radius = 2
	x, y, z := s.position.X, s.position.Y, s.position.Z

	s.model.X, s.model.Y, s.model.Z = -float32(x)-0.5, -float32(y)-0.5, float32(z)+0.5
	s.model.Matrix[0] = mgl32.Translate3D(
		float32(x)+0.5,
		-float32(y)-0.5,
		float32(z)+0.5,
	).Mul4(mgl32.Rotate3DY(float32(s.rotation)).Mat4()).
		Mul4(mgl32.Translate3D(float32(s.ox), float32(-s.oy), float32(s.oz)))
}
Пример #16
0
func (sl *serverList) redraw() {
	for _, s := range sl.servers {
		s.Hide()
		render.FreeIcon(s.id)
	}
	sl.servers = sl.servers[:0]
	for i, s := range Config.Servers {
		sc := scene.New(true)
		container := ui.NewContainer(0, float64(i)*100, 700, 100).
			Attach(ui.Center, ui.Middle)
		r := make([]byte, 20)
		rand.Read(r)
		si := &serverListItem{
			Type:      sc,
			container: container,
			offset:    float64(i),
			id:        "servericon:" + string(r),
		}
		si.updatePosition()
		sl.servers = append(sl.servers, si)

		bck := ui.NewImage(render.GetTexture("solid"), 0, 0, 700, 100, 0, 0, 1, 1, 0, 0, 0).Attach(ui.Top, ui.Left)
		bck.SetA(100)
		bck.AttachTo(container)
		sc.AddDrawable(bck)
		txt := ui.NewText(s.Name, 90+10, 5, 255, 255, 255).Attach(ui.Top, ui.Left)
		txt.AttachTo(container)
		sc.AddDrawable(txt)

		icon := ui.NewImage(render.GetTexture("misc/unknown_server"), 5, 5, 90, 90, 0, 0, 1, 1, 255, 255, 255).
			Attach(ui.Top, ui.Left)
		icon.AttachTo(container)
		sc.AddDrawable(icon)

		ping := ui.NewImage(render.GetTexture("gui/icons"), 5, 5, 20, 16, 0, 56/256.0, 10/256.0, 8/256.0, 255, 255, 255).
			Attach(ui.Top, ui.Right)
		ping.AttachTo(container)
		sc.AddDrawable(ping)

		players := ui.NewText("???", 30, 5, 255, 255, 255).
			Attach(ui.Top, ui.Right)
		players.AttachTo(container)
		sc.AddDrawable(players)

		msg := &format.TextComponent{Text: "Connecting..."}
		motd := ui.NewFormattedWidth(format.Wrap(msg), 90+10, 5+18, 700-(90+10+5)).Attach(ui.Top, ui.Left)
		motd.AttachTo(container)
		sc.AddDrawable(motd)

		msg = &format.TextComponent{Text: ""}
		version := ui.NewFormattedWidth(format.Wrap(msg), 90+10, 5, 700-(90+10+5)).Attach(ui.Bottom, ui.Left)
		version.AttachTo(container)
		sc.AddDrawable(version)
		s := s
		go sl.pingServer(s.Address, motd, version, icon, si.id, ping, players)
		container.ClickFunc = func() {
			PlaySound("random.click")
			sl.connect(s.Address)
		}
		container.HoverFunc = func(over bool) {
			if over {
				bck.SetA(200)
			} else {
				bck.SetA(100)
			}
		}

		sc.AddDrawable(container)

		index := i
		del, txt := newButtonText("X", 0, 0, 25, 25)
		del.AttachTo(container)
		sc.AddDrawable(del.Attach(ui.Bottom, ui.Right))
		sc.AddDrawable(txt)
		del.AddClick(func() {
			Config.Servers = append(Config.Servers[:index], Config.Servers[index+1:]...)
			saveServers()
			sl.redraw()
		})
		edit, txt := newButtonText("E", 25, 0, 25, 25)
		edit.AttachTo(container)
		sc.AddDrawable(edit.Attach(ui.Bottom, ui.Right))
		sc.AddDrawable(txt)
		edit.AddClick(func() {
			setScreen(newEditServer(index))
		})
	}
}
Пример #17
0
func (p *playerListUI) render(delta float64) {
	if !p.scene.IsVisible() {
		return
	}
	for _, b := range p.background {
		b.SetDraw(false)
	}
	for _, e := range p.entries {
		e.set(false)
	}
	offset := 0
	count := 0
	bTab := 0
	lastEntry := 0
	for _, pl := range p.players() {
		if count >= 20 {
			entries := p.entries[lastEntry:offset]
			lastEntry = offset
			for _, e := range entries {
				if e.icon.ShouldDraw() {
					e.icon.SetX(-playerListWidth/2 - 12)
					e.iconHat.SetX(-playerListWidth/2 - 12)
					e.ping.SetX(playerListWidth/2 + 12)
				}
			}
			p.background[bTab].SetHeight(float64(count * 18))
			count = 0
			bTab++
			if bTab >= len(p.background) {
				break
			}
		}
		background := p.background[bTab]
		background.SetDraw(true)
		if offset >= len(p.entries) {
			text := ui.NewText("", 24, 0, 255, 255, 255).
				Attach(ui.Top, ui.Left)
			p.scene.AddDrawable(text)
			icon := ui.NewImage(pl.skin, 0, 0, 16, 16, 8/64.0, 8/64.0, 8/64.0, 8/64.0, 255, 255, 255).
				Attach(ui.Top, ui.Center)
			p.scene.AddDrawable(icon)
			iconHat := ui.NewImage(pl.skin, 0, 0, 16, 16, 40/64.0, 8/64.0, 8/64.0, 8/64.0, 255, 255, 255).
				Attach(ui.Top, ui.Center)
			p.scene.AddDrawable(iconHat)
			ping := ui.NewImage(render.GetTexture("gui/icons"), 0, 0, 20, 16, 0, 16/256.0, 10/256.0, 8/256.0, 255, 255, 255).
				Attach(ui.Top, ui.Center)
			p.scene.AddDrawable(ping)

			text.AttachTo(background)
			icon.AttachTo(background)
			iconHat.AttachTo(background)
			ping.AttachTo(background)

			p.entries = append(p.entries, &playerListUIEntry{
				text:    text,
				icon:    icon,
				iconHat: iconHat,
				ping:    ping,
			})
		}
		e := p.entries[offset]
		e.set(true)
		offset++
		e.text.SetY(1 + 18*float64(count))
		e.text.Update(pl.name)
		e.icon.SetY(1 + 18*float64(count))
		e.icon.SetTexture(pl.skin)
		e.iconHat.SetY(1 + 18*float64(count))
		e.iconHat.SetTexture(pl.skin)

		e.ping.SetY(1 + 18*float64(count))
		y := 0.0
		switch {
		case pl.ping <= 75:
			y = 16 / 256.0
		case pl.ping <= 150:
			y = 24 / 256.0
		case pl.ping <= 225:
			y = 32 / 256.0
		case pl.ping <= 350:
			y = 40 / 256.0
		case pl.ping < 999:
			y = 48 / 256.0
		default:
			y = 56 / 256.0
		}
		e.ping.SetTextureY(y)
		count++
	}

	if bTab < len(p.background) {
		for _, e := range p.entries {
			if e.icon.ShouldDraw() {
				e.icon.SetX(-playerListWidth/2 - 12)
				e.iconHat.SetX(-playerListWidth/2 - 12)
				e.ping.SetX(playerListWidth/2 + 12)
			}
		}
		p.background[bTab].SetHeight(float64(count * 18))
	}

	switch bTab {
	case 0: // Single
		p.background[0].SetX(0)
	case 1: // Double
		p.background[0].SetX(-p.background[0].Width() / 2)
		p.background[1].SetX(p.background[1].Width() / 2)
	case 2: // Triple
		p.background[0].SetX(-(p.background[1].Width() / 2) - p.background[0].Width()/2)
		p.background[1].SetX(0)
		p.background[2].SetX((p.background[1].Width() / 2) + p.background[2].Width()/2)
	default: // Quad
		p.background[0].SetX(-p.background[0].Width()/2 - p.background[1].Width())
		p.background[3].SetX(p.background[3].Width()/2 + p.background[2].Width())

		p.background[1].SetX(-p.background[1].Width() / 2)
		p.background[2].SetX(p.background[2].Width() / 2)
	}
}
Пример #18
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
				}
			}
		}
	}
}
Пример #19
0
func newClient() {
	c := &ClientState{
		Bounds: vmath.AABB{
			Min: mgl32.Vec3{-0.3, 0, -0.3},
			Max: mgl32.Vec3{0.3, 1.8, 0.3},
		},
		scene: scene.New(true),
	}
	Client = c
	c.playerInventory = NewInventory(InvPlayer, 0, 45)
	c.hotbarScene = scene.New(true)
	c.network.init()
	c.currentBreakingBlock = Blocks.Air.Base
	c.blockBreakers = map[int]BlockEntity{}
	widgets := render.GetTexture("gui/widgets")
	icons := render.GetTexture("gui/icons")
	// Crosshair
	c.scene.AddDrawable(
		ui.NewImage(icons, 0, 0, 32, 32, 0, 0, 16.0/256.0, 16.0/256.0, 255, 255, 255).
			Attach(ui.Middle, ui.Center),
	)
	// Hotbar
	hotbar := ui.NewImage(widgets, 0, 0, 182*2, 22*2, 0, 0, 182.0/256.0, 22.0/256.0, 255, 255, 255).
		Attach(ui.Bottom, ui.Center)
	c.scene.AddDrawable(hotbar)
	c.hotbar = hotbar
	c.hotbarUI = ui.NewImage(widgets, -22*2+4, -2, 24*2, 24*2, 0, 22.0/256.0, 24.0/256.0, 24.0/256.0, 255, 255, 255).
		Attach(ui.Bottom, ui.Center)
	c.scene.AddDrawable(c.hotbarUI)

	// Hearts / Food
	for i := 0; i < 10; i++ {
		l := ui.NewImage(icons, 16*float64(i), -16-8-10, 18, 18, 16.0/256.0, 0, 9.0/256.0, 9.0/256.0, 255, 255, 255).
			Attach(ui.Top, ui.Left)
		l.AttachTo(hotbar)
		c.scene.AddDrawable(l)
		c.lifeUI = append(c.lifeUI, l)
		l = ui.NewImage(icons, 16*float64(i), -16-8-10, 18, 18, (16+9*4)/256.0, 0, 9.0/256.0, 9.0/256.0, 255, 255, 255).
			Attach(ui.Top, ui.Left)
		l.AttachTo(hotbar)
		c.scene.AddDrawable(l)
		c.lifeFillUI = append(c.lifeFillUI, l)

		f := ui.NewImage(icons, 16*float64(i), -16-8-10, 18, 18, 16.0/256.0, 27.0/256.0, 9.0/256.0, 9.0/256.0, 255, 255, 255).
			Attach(ui.Top, ui.Right)
		f.AttachTo(hotbar)
		c.scene.AddDrawable(f)
		c.foodUI = append(c.foodUI, f)
		f = ui.NewImage(icons, 16*float64(i), -16-8-10, 18, 18, (16+9*4)/256.0, 27.0/256.0, 9.0/256.0, 9.0/256.0, 255, 255, 255).
			Attach(ui.Top, ui.Right)
		f.AttachTo(hotbar)
		c.scene.AddDrawable(f)
		c.foodFillUI = append(c.foodFillUI, f)
	}

	// Exp bar
	c.scene.AddDrawable(
		ui.NewImage(icons, 0, 22*2+4, 182*2, 10, 0, 64.0/256.0, 182.0/256.0, 5.0/256.0, 255, 255, 255).
			Attach(ui.Bottom, ui.Center),
	)

	c.itemNameUI = ui.NewFormatted(format.Wrap(&format.TextComponent{}), 0, -16-8-10-16-20)
	c.itemNameUI.AttachTo(c.hotbar)
	c.scene.AddDrawable(c.itemNameUI.Attach(ui.Top, ui.Middle))

	c.chat.init()
	c.initDebug()
	c.playerList.init()
	c.entities.init()

	c.initEntity(false)
}
Пример #20
0
func newOptionMenu(ret func() screen) *optionMenu {
	om := &optionMenu{
		scene: scene.New(true),
		ret:   ret,
	}

	om.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 480, 0, 0, 1, 1, 0, 0, 0)
	om.background.SetA(160)
	om.scene.AddDrawable(om.background.Attach(ui.Top, ui.Left))

	done, txt := newButtonText("Done", 0, 50, 400, 40)
	om.scene.AddDrawable(done.Attach(ui.Bottom, ui.Middle))
	om.scene.AddDrawable(txt)
	done.AddClick(func() { setScreen(om.ret()) })

	rp, txt := newButtonText("Resource packs", -160, 150, 300, 40)
	om.scene.AddDrawable(rp.Attach(ui.Bottom, ui.Middle))
	om.scene.AddDrawable(txt)
	rp.AddClick(func() { setScreen(newResourceList(om.ret)) })

	fov := newSlider(160, -100, 300, 40)
	fov.back.Attach(ui.Center, ui.Middle)
	fov.add(om.scene)
	om.fov = fov
	ftxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
	ftxt.AttachTo(fov.back)
	om.scene.AddDrawable(ftxt)
	fov.UpdateFunc = func() {
		render.FOV.SetValue(60 + round(119*fov.Value))
		ftxt.Update(fmt.Sprintf("FOV: %d", render.FOV.Value()))
	}
	fov.Value = (float64(render.FOV.Value()) - 60) / 119.0
	fov.update()

	vol, vtxt := newButtonText("Volume", -160, -100, 300, 40)
	om.scene.AddDrawable(vol.Attach(ui.Center, ui.Middle))
	om.scene.AddDrawable(vtxt)
	vol.AddClick(func() {
		setScreen(newVolumeMenu(om.ret))
	})

	vsync, vtxt := newButtonText("", -160, -50, 300, 40)
	om.scene.AddDrawable(vsync.Attach(ui.Center, ui.Middle))
	om.scene.AddDrawable(vtxt)
	vsync.AddClick(func() {
		renderVSync.SetValue(!renderVSync.Value())
		if renderVSync.Value() {
			vtxt.Update("VSync: Enabled")
		} else {
			vtxt.Update("VSync: Disabled")
		}
	})
	if renderVSync.Value() {
		vtxt.Update("VSync: Enabled")
	} else {
		vtxt.Update("VSync: Disabled")
	}

	mouseS := newSlider(160, -50, 300, 40)
	mouseS.back.Attach(ui.Center, ui.Middle)
	mouseS.add(om.scene)
	om.mouseS = mouseS
	mtxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
	mtxt.AttachTo(mouseS.back)
	om.scene.AddDrawable(mtxt)
	mouseS.UpdateFunc = func() {
		mouseSensitivity.SetValue(500 + round(9500.0*mouseS.Value))
		mtxt.Update(fmt.Sprintf("Mouse Speed: %d", mouseSensitivity.Value()))
	}
	mouseS.Value = (float64(mouseSensitivity.Value()) - 500) / 9500.0
	mouseS.update()

	om.scene.AddDrawable(
		ui.NewText("* Requires a client restart to take effect", 0, 100, 255, 200, 200).Attach(ui.Bottom, ui.Middle),
	)

	uiFooter(om.scene)

	scales := []string{
		uiAuto, uiSmall, uiMedium, uiLarge,
	}
	curScale := func() int {
		for i, s := range scales {
			if s == uiScale.Value() {
				return i
			}
		}
		return 0
	}

	uiS, utxt := newButtonText("", -160, 0, 300, 40)
	om.scene.AddDrawable(uiS.Attach(ui.Center, ui.Middle))
	om.scene.AddDrawable(utxt)
	uiS.AddClick(func() {
		uiScale.SetValue(scales[(curScale()+1)%len(scales)])
		utxt.Update(fmt.Sprintf("UI Scale: %s", uiScale.Value()))
	})
	utxt.Update(fmt.Sprintf("UI Scale: %s", uiScale.Value()))

	return om
}
Пример #21
0
func newVolumeMenu(ret func() screen) *volumeMenu {
	vm := &volumeMenu{
		scene: scene.New(true),
		ret:   ret,
	}

	vm.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 480, 0, 0, 1, 1, 0, 0, 0)
	vm.background.SetA(160)
	vm.scene.AddDrawable(vm.background.Attach(ui.Top, ui.Left))

	done, txt := newButtonText("Done", 0, 50, 400, 40)
	vm.scene.AddDrawable(done.Attach(ui.Bottom, ui.Middle))
	vm.scene.AddDrawable(txt)
	done.AddClick(func() { setScreen(newOptionMenu(vm.ret)) })

	master := newSlider(0, -100, 620, 40)
	master.back.Attach(ui.Center, ui.Middle)
	master.add(vm.scene)
	mtxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
	mtxt.AttachTo(master.back)
	vm.scene.AddDrawable(mtxt)
	master.UpdateFunc = func() {
		muVolMaster.SetValue(round(master.Value * 100))
		if muVolMaster.Value() == 0 {
			mtxt.Update("Master: OFF")
			return
		}
		mtxt.Update(fmt.Sprintf("Master: %d%%", muVolMaster.Value()))
	}
	master.Value = float64(muVolMaster.Value()) / 100.0
	master.update()
	vm.sliders = append(vm.sliders, master)

	for i, cat := range soundCategories {
		cat := cat
		x := 160.0
		if i&1 == 0 {
			x = -x
		}
		y := 50 * float64(i/2)
		snd := newSlider(x, -50+y, 300, 40)
		snd.back.Attach(ui.Center, ui.Middle)
		snd.add(vm.scene)
		stxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
		stxt.AttachTo(snd.back)
		vm.scene.AddDrawable(stxt)

		v := volVars[cat]

		snd.UpdateFunc = func() {
			v.SetValue(round(snd.Value * 100))
			if val := v.Value(); val != 0 {
				stxt.Update(fmt.Sprintf("%s: %d%%", strings.Title(string(cat)), val))
				return
			}
			stxt.Update(fmt.Sprintf("%s: OFF", strings.Title(string(cat))))
		}
		snd.Value = float64(v.Value()) / 100.0
		snd.update()
		vm.sliders = append(vm.sliders, snd)
	}

	return vm
}
Пример #22
0
func (handler) PlayerListInfo(p *protocol.PlayerInfo) {
	playerList := Client.playerList.info
	for _, pl := range p.Players {
		if _, ok := playerList[pl.UUID]; (!ok && p.Action != 0) || (ok && p.Action == 0) {
			continue
		}
		switch p.Action {
		case 0: // Add
			i := &playerInfo{
				name:        pl.Name,
				uuid:        pl.UUID,
				displayName: pl.DisplayName,
				gameMode:    gameMode(pl.GameMode),
				ping:        int(pl.Ping),
			}
			for _, prop := range pl.Properties {
				if prop.Name == "textures" {
					if !prop.IsSigned {
						Client.network.SignalClose(errors.New("Missing signature from textures"))
						return
					}
					data, err := base64.StdEncoding.DecodeString(prop.Value)
					if err != nil {
						Client.network.SignalClose(err)
						continue
					}

					sig, err := base64.StdEncoding.DecodeString(prop.Signature)
					if err != nil {
						Client.network.SignalClose(err)
						continue
					}

					if err := verifySkinSignature([]byte(prop.Value), sig); err != nil {
						Client.network.SignalClose(err)
						return
					}

					var blob skinBlob
					err = json.Unmarshal(data, &blob)
					if err != nil {
						Client.network.SignalClose(err)
						continue
					}
					url := blob.Textures.Skin.Url
					if strings.HasPrefix(url, "http://textures.minecraft.net/texture/") {
						i.skinHash = url[len("http://textures.minecraft.net/texture/"):]
						render.RefSkin(i.skinHash)
						i.skin = render.Skin(i.skinHash)
					}
					url = blob.Textures.Cape.Url
					if strings.HasPrefix(url, "http://textures.minecraft.net/texture/") {
						i.capeHash = url[len("http://textures.minecraft.net/texture/"):]
						render.RefSkin(i.capeHash)
						i.cape = render.Skin(i.capeHash)
					}
				}
			}
			if i.skin == nil {
				i.skin = render.GetTexture("entity/steve")
			}
			i.skin = render.RelativeTexture(i.skin, 64, 64)
			playerList[pl.UUID] = i

			// Special case for self
			if !Client.entityAdded && i.uuid == Client.entity.UUID() {
				Client.entities.container.AddEntity(Client.entity)
				Client.entityAdded = true
			}
		case 1: // Update gamemode
			playerList[pl.UUID].gameMode = gameMode(pl.GameMode)
		case 2: // Update ping
			playerList[pl.UUID].ping = int(pl.Ping)
		case 3: // Update display name
			playerList[pl.UUID].displayName = pl.DisplayName
		case 4: // Remove
			i := playerList[pl.UUID]
			if i.skinHash != "" {
				render.FreeSkin(i.skinHash)
			}
			delete(playerList, pl.UUID)
		}
	}
}
Пример #23
0
func (rl *resourceList) redraw() {
	for _, s := range rl.packs {
		s.Hide()
		render.FreeIcon(s.id)
	}
	rl.packs = rl.packs[:0]

	os.MkdirAll("./resource-packs", 0777)
	files, _ := ioutil.ReadDir("./resource-packs")

	for i, f := range files {
		f := f
		if !strings.HasSuffix(f.Name(), ".zip") {
			continue
		}

		fullName := filepath.Join("./resource-packs", f.Name())
		desc, iimg, ok := getPackInfo(fullName)
		if !ok {
			continue
		}

		sc := scene.New(true)
		container := ui.NewContainer(0, float64(i)*100, 700, 100).
			Attach(ui.Center, ui.Middle)
		r := make([]byte, 20)
		rand.Read(r)
		si := &resourceListItem{
			Type:      sc,
			container: container,
			offset:    float64(i),
			id:        "servericon:" + string(r),
		}
		si.updatePosition()
		rl.packs = append(rl.packs, si)

		var rr, gg, bb int
		if resource.IsActive(fullName) {
			rr = 200
			gg = 200
		}

		bck := ui.NewImage(render.GetTexture("solid"), 0, 0, 700, 100, 0, 0, 1, 1, rr, gg, bb).Attach(ui.Top, ui.Left)
		bck.SetA(100)
		bck.AttachTo(container)
		sc.AddDrawable(bck)
		txt := ui.NewText(f.Name(), 90+10, 5, 255, 255, 255).Attach(ui.Top, ui.Left)
		txt.AttachTo(container)
		sc.AddDrawable(txt)

		var tex render.TextureInfo
		if iimg == nil {
			tex = render.GetTexture("misc/unknown_pack")
		} else {
			render.AddIcon(si.id, iimg)
			tex = render.Icon(si.id)
		}
		icon := ui.NewImage(tex, 5, 5, 90, 90, 0, 0, 1, 1, 255, 255, 255).
			Attach(ui.Top, ui.Left)
		icon.AttachTo(container)
		sc.AddDrawable(icon)

		msg := format.Wrap(&format.TextComponent{Text: desc})
		format.ConvertLegacy(msg)
		motd := ui.NewFormattedWidth(msg, 90+10, 5+18, 700-(90+10+5)).Attach(ui.Top, ui.Left)
		motd.AttachTo(container)
		sc.AddDrawable(motd)
		container.ClickFunc = func() {
			if resource.IsActive(fullName) {
				RemovePack(fullName)
			} else {
				AddPack(fullName)
			}
			setScreen(newResourceList(rl.ret))
		}
		container.HoverFunc = func(over bool) {
			if over {
				bck.SetA(200)
			} else {
				bck.SetA(100)
			}
		}

		sc.AddDrawable(container)
	}
}
Пример #24
0
func (s *skullComponent) create() {
	var skin render.TextureInfo
	if s.SkullType == skullPlayer && s.OwnerSkin != nil {
		skin = s.OwnerSkin
	} else {
		switch s.SkullType {
		case skullPlayer:
			skin = render.RelativeTexture(render.GetTexture("entity/steve"), 64, 64)
		case skullZombie:
			skin = render.RelativeTexture(render.GetTexture("entity/zombie/zombie"), 64, 64)
		case skullSkeleton:
			skin = render.RelativeTexture(render.GetTexture("entity/skeleton/skeleton"), 64, 32)
		case skullWitherSkeleton:
			skin = render.RelativeTexture(render.GetTexture("entity/skeleton/wither_skeleton"), 64, 32)
		case skullCreeper:
			skin = render.RelativeTexture(render.GetTexture("entity/creeper/creeper"), 64, 32)
		}
	}

	var hverts []*render.ModelVertex
	// Base layer
	hverts = appendBox(hverts, -4/16.0, 0, -4/16.0, 8/16.0, 8/16.0, 8/16.0, [6]render.TextureInfo{
		direction.North: skin.Sub(8, 8, 8, 8),
		direction.South: skin.Sub(24, 8, 8, 8),
		direction.East:  skin.Sub(0, 8, 8, 8),
		direction.West:  skin.Sub(16, 8, 8, 8),
		direction.Up:    skin.Sub(8, 0, 8, 8),
		direction.Down:  skin.Sub(16, 0, 8, 8),
	})
	// Hat layer
	hverts = appendBox(hverts, -4.2/16.0, -.2/16.0, -4.2/16.0, 8.4/16.0, 8.4/16.0, 8.4/16.0, [6]render.TextureInfo{
		direction.North: skin.Sub(8+32, 8, 8, 8),
		direction.South: skin.Sub(24+32, 8, 8, 8),
		direction.East:  skin.Sub(0+32, 8, 8, 8),
		direction.West:  skin.Sub(16+32, 8, 8, 8),
		direction.Up:    skin.Sub(8+32, 0, 8, 8),
		direction.Down:  skin.Sub(16+32, 0, 8, 8),
	})

	s.model = render.NewModel([][]*render.ModelVertex{
		hverts,
	})
	model := s.model
	model.Radius = 2

	x, y, z := s.position.X, s.position.Y, s.position.Z

	model.X, model.Y, model.Z = -float32(x)-0.5, -float32(y), float32(z)+0.5

	mat := mgl32.Translate3D(float32(x)+0.5, -float32(y), float32(z)+0.5)
	if s.Facing == direction.Up {
		mat = mat.Mul4(mgl32.Rotate3DY(-(math.Pi / 8) * float32(s.Rotation)).Mat4())
	} else {
		ang := float32(0)
		switch s.Facing {
		case direction.South:
			ang = math.Pi
		case direction.East:
			ang = math.Pi / 2
		case direction.West:
			ang = -math.Pi / 2
		}
		mat = mat.Mul4(mgl32.Rotate3DY(ang).Mat4())
		mat = mat.Mul4(mgl32.Translate3D(0, -4/16.0, 4/16.0))
	}
	model.Matrix[0] = mat
}
Пример #25
0
func (bm *model) lookupTexture(name string) render.TextureInfo {
	if len(name) > 0 && name[0] == '#' {
		return bm.lookupTexture(bm.textureVars[name[1:]])
	}
	return render.GetTexture(name)
}
Пример #26
0
func (u *uiLogo) init(scene *scene.Type) {
	if logoText == "" {
		nextLogoText()
	}
	if logoTexture == "" {
		nextLogoTexture()
		logoTexture = logoTargetTexture
	}
	readStevenLogo()
	u.scene = scene
	row := 0
	tex, tex2 := render.GetTexture(logoTexture), render.GetTexture(logoTargetTexture)
	titleBox := ui.NewContainer(0, 8, 0, 0).Attach(ui.Top, ui.Center)
	logoTimer = r.Float64() * 60 * 30
	logoTransTimer = 120
	for _, line := range strings.Split(stevenLogo, "\n") {
		if line == "" {
			continue
		}
		for i, r := range line {
			if r == ' ' {
				continue
			}
			x, y := i*4, row*8
			rr, gg, bb := 255, 255, 255
			if r != ':' {
				rr, gg, bb = 170, 170, 170
			}
			shadow := ui.NewImage(
				render.GetTexture("solid"),
				float64(x+2), float64(y+4), 4, 8,
				float64(x%16)/16.0, float64(y%16)/16.0, 4/16.0, 8/16.0,
				0, 0, 0,
			)
			shadow.SetA(100)
			shadow.AttachTo(titleBox)
			u.scene.AddDrawable(shadow)

			img := ui.NewImage(
				tex,
				float64(x), float64(y), 4, 8,
				float64(x%16)/16.0, float64(y%16)/16.0, 4/16.0, 8/16.0,
				rr, gg, bb,
			)
			img.AttachTo(titleBox)
			u.scene.AddDrawable(img)
			logoLayers[0] = append(logoLayers[0], img)

			img = ui.NewImage(
				tex2,
				float64(x), float64(y), 4, 8,
				float64(x%16)/16.0, float64(y%16)/16.0, 4/16.0, 8/16.0,
				rr, gg, bb,
			)
			img.AttachTo(titleBox)
			img.SetA(0)
			u.scene.AddDrawable(img)
			logoLayers[1] = append(logoLayers[1], img)
			if titleBox.Width() < float64(x+4) {
				titleBox.SetWidth(float64(x + 4))
			}
		}
		row++
	}
	titleBox.SetHeight(float64(row) * 8.0)

	txt := ui.NewText(logoText, 0, -8, 255, 255, 0).Attach(ui.Bottom, ui.Right)
	txt.AttachTo(titleBox)
	txt.SetRotation(-math.Pi / 8)
	u.scene.AddDrawable(txt)
	u.text = txt
	width, _ := txt.Size()
	u.textBaseScale = 300 / width
	if u.textBaseScale > 1 {
		u.textBaseScale = 1
	}
	txt.SetX((-txt.Width / 2) * u.textBaseScale)
	u.origX = txt.X()
}
Пример #27
0
func genStaticModelFromItem(mdl *model, block Block, mode string) (out []*render.StaticVertex, mat mgl32.Mat4) {
	mat = mgl32.Rotate3DZ(math.Pi).Mat4().
		Mul4(mgl32.Rotate3DY(math.Pi / 2).Mat4()).
		Mul4(mgl32.Rotate3DZ(-math.Pi / 2).Mat4())

	if gui, ok := mdl.display[mode]; ok {
		if gui.Scale != nil {
			mat = mat.Mul4(mgl32.Scale3D(
				float32(gui.Scale[0]),
				float32(gui.Scale[1]),
				float32(gui.Scale[2]),
			))
		}
		if gui.Translation != nil {
			mat = mat.Mul4(mgl32.Translate3D(
				float32(gui.Translation[0]/32),
				float32(gui.Translation[1]/32),
				float32(gui.Translation[2]/32),
			))
		}
		if gui.Rotation != nil {
			mat = mat.Mul4(mgl32.Rotate3DX(math.Pi + float32(gui.Rotation[0]/180)*math.Pi).Mat4())
			mat = mat.Mul4(mgl32.Rotate3DZ(math.Pi + float32(gui.Rotation[2]/180)*math.Pi).Mat4())
			mat = mat.Mul4(mgl32.Rotate3DY(float32(gui.Rotation[1]/180) * math.Pi).Mat4())
		}
	}
	mat = mat.Mul4(mgl32.Rotate3DY(math.Pi / 2).Mat4())
	mat = mat.Mul4(mgl32.Translate3D(-1/16.0, 0, 0))

	tex := render.GetTexture("solid")
	rect := tex.Rect()

	tName, plugin := mdl.textureVars["layer0"], "minecraft"
	if pos := strings.IndexRune(tName, ':'); pos != -1 {
		plugin = tName[:pos]
		tName = tName[pos:]
	}
	f, err := resource.Open(plugin, "textures/"+tName+".png")
	if err != nil {
		return
	}
	defer f.Close()
	img, err := png.Decode(f)
	if err != nil {
		panic(err)
	}

	w, h := img.Bounds().Dx(), img.Bounds().Dy()
	sx := 1 / float32(w)
	sy := 1 / float32(h)

	isSolid := func(x, y int) bool {
		col := img.At(x, y)
		_, _, _, aa := col.RGBA()
		if aa == 0 {
			return false
		}
		return true
	}

	for x := 0; x < w; x++ {
		for y := 0; y < h; y++ {
			col := img.At(x, y)
			rr, gg, bb, aa := col.RGBA()
			if aa == 0 {
				continue
			}

			for i, f := range faceVertices {
				facing := direction.Type(i)
				if facing != direction.North && facing != direction.South {
					xx, yy, _ := facing.Offset()
					if isSolid(x+xx, y+yy) {
						continue
					}
				}

				var cr, cg, cb byte
				cr = byte(rr >> 8)
				cg = byte(gg >> 8)
				cb = byte(bb >> 8)
				if facing == direction.East || facing == direction.West {
					cr = byte(float64(cr) * 0.8)
					cg = byte(float64(cg) * 0.8)
					cb = byte(float64(cb) * 0.8)
				}
				if facing == direction.North || facing == direction.South {
					cr = byte(float64(cr) * 0.6)
					cg = byte(float64(cg) * 0.6)
					cb = byte(float64(cb) * 0.6)
				}

				for _, vert := range f.verts {
					vX, vY, vZ := float32(vert.X), float32(vert.Y), float32(vert.Z)
					vert := &render.StaticVertex{
						Y:        vY*sy - 0.5 + sy*float32(y),
						X:        vX*sx - 0.5 + sx*float32(x),
						Z:        (vZ - 0.5) * (1.0 / 16.0),
						Texture:  tex,
						TextureX: float64(vert.TOffsetX) / float64(16*rect.Width),
						TextureY: float64(vert.TOffsetY) / float64(16*rect.Height),
						R:        cr,
						G:        cg,
						B:        cb,
						A:        byte(aa >> 8),
					}
					out = append(out, vert)
				}
			}
		}
	}
	return
}