Exemple #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)
}
Exemple #2
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)
		}
	}
}
Exemple #3
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
}