예제 #1
0
파일: ui.go 프로젝트: 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),
	)
}
예제 #2
0
파일: clientdebug.go 프로젝트: num5/steven
func (c *ClientState) displayTargetInfo() {
	t, b, face, _ := c.targetBlock()
	c.debug.target.Update(fmt.Sprintf("Target(%d,%d,%d)-%s", t.X, t.Y, t.Z, face))
	c.debug.targetName.Update(fmt.Sprintf("%s:%s", b.Plugin(), b.Name()))

	for i, s := range b.states() {
		var r, g, b int = 255, 255, 255
		text := fmt.Sprint(s.Value)
		switch val := s.Value.(type) {
		case bool:
			b = 0
			if val {
				g = 255
				r = 0
			} else {
				r = 255
				g = 0
			}
		case color:
			r, g, b = chatColorRGB(debugStateColors[val])
		}
		if i >= len(c.debug.targetInfo) {
			c.debug.targetInfo = append(c.debug.targetInfo, [2]*ui.Text{})
			c.debug.targetInfo[i] = [2]*ui.Text{
				ui.NewText("", 5, 59+18*(1+float64(i)), 255, 255, 255).Attach(ui.Top, ui.Right),
				ui.NewText("", 5, 59+18*(1+float64(i)), 255, 255, 255).Attach(ui.Top, ui.Right),
			}
			for _, t := range c.debug.targetInfo[i] {
				c.scene.AddDrawable(t)
			}
		}
		v := c.debug.targetInfo[i][0]
		v.SetDraw(true)
		v.SetR(r)
		v.SetG(g)
		v.SetB(b)
		v.Update(text)
		k := c.debug.targetInfo[i][1]
		k.SetDraw(true)
		k.SetX(7 + v.Width)
		k.Update(fmt.Sprintf("%s=", s.Key))
	}
	for i := len(b.states()); i < len(c.debug.targetInfo); i++ {
		info := &c.debug.targetInfo[i]
		info[0].SetDraw(false)
		info[1].SetDraw(false)
	}
}
예제 #3
0
파일: uirespawn.go 프로젝트: num5/steven
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
}
예제 #4
0
파일: uilogin.go 프로젝트: num5/steven
func newLoginScreen() *loginScreen {
	ls := &loginScreen{
		scene: scene.New(false),
	}
	if clientToken.Value() == "" {
		data := make([]byte, 16)
		crand.Read(data)
		clientToken.SetValue(hex.EncodeToString(data))
	}

	ls.logo.init(ls.scene)

	ls.LoginBtn, ls.LoginTxt = newButtonText("Login", 0, 100, 400, 40)
	ls.scene.AddDrawable(ls.LoginBtn.Attach(ui.Middle, ui.Center))
	ls.scene.AddDrawable(ls.LoginTxt)
	ls.LoginBtn.AddClick(ls.Login)

	ls.LoginError = ui.NewText("", 0, 150, 255, 50, 50).Attach(ui.Middle, ui.Center)
	ls.scene.AddDrawable(ls.LoginError)

	{
		ls.User = ui.NewTextBox(0, -20, 400, 40).Attach(ui.Middle, ui.Center)
		ls.scene.AddDrawable(ls.User)
		label := ui.NewText("Username/Email:", 0, -18, 255, 255, 255)
		label.AttachTo(ls.User)
		ls.scene.AddDrawable(label)
	}

	{
		ls.Pass = ui.NewTextBox(0, 40, 400, 40).Attach(ui.Middle, ui.Center)
		ls.Pass.SubmitFunc = ls.Login
		ls.Pass.SetPassword(true)
		ls.scene.AddDrawable(ls.Pass)
		label := ui.NewText("Password:", 0, -18, 255, 255, 255)
		label.AttachTo(ls.Pass)
		ls.scene.AddDrawable(label)
	}

	uiFooter(ls.scene)

	ls.scene.Show()
	if getProfile().IsComplete() {
		ls.refresh()
	}

	return ls
}
예제 #5
0
파일: inventory.go 프로젝트: num5/steven
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
}
예제 #6
0
파일: uieditserver.go 프로젝트: num5/steven
func newEditServer(index int) *editServer {
	se := &editServer{
		scene: scene.New(true),
		index: index,
	}

	se.logo.init(se.scene)

	uiFooter(se.scene)

	done, txt := newButtonText("Done", 110, 100, 200, 40)
	se.scene.AddDrawable(done.Attach(ui.Center, ui.Middle))
	se.scene.AddDrawable(txt)
	done.AddClick(func() {
		se.save()
	})

	cancel, txt := newButtonText("Cancel", -110, 100, 200, 40)
	se.scene.AddDrawable(cancel.Attach(ui.Center, ui.Middle))
	se.scene.AddDrawable(txt)
	cancel.AddClick(func() {
		setScreen(newServerList())
	})

	se.name = ui.NewTextBox(0, -20, 400, 40)
	se.scene.AddDrawable(se.name.Attach(ui.Middle, ui.Center))
	label := ui.NewText("Name:", 0, -18, 255, 255, 255).Attach(ui.Top, ui.Left)
	label.AttachTo(se.name)
	se.scene.AddDrawable(label)

	se.address = ui.NewTextBox(0, 40, 400, 40)
	se.scene.AddDrawable(se.address.Attach(ui.Middle, ui.Center))
	label = ui.NewText("Address:", 0, -18, 255, 255, 255).Attach(ui.Top, ui.Left)
	label.AttachTo(se.address)
	se.scene.AddDrawable(label)

	if index != -1 {
		server := Config.Servers[index]
		se.name.Update(server.Name)
		se.address.Update(server.Address)
	}

	return se
}
예제 #7
0
파일: chat.go 프로젝트: num5/steven
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)
}
예제 #8
0
파일: progress.go 프로젝트: num5/steven
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
}
예제 #9
0
파일: ui.go 프로젝트: num5/steven
func newButtonText(str string, x, y, w, h float64) (*ui.Button, *ui.Text) {
	btn := ui.NewButton(x, y, w, h)
	text := ui.NewText(str, 0, 0, 255, 255, 255).Attach(ui.Middle, ui.Center)
	text.AttachTo(btn)
	btn.AddHover(func(over bool) {
		if over && !btn.Disabled() {
			text.SetB(160)
		} else {
			text.SetB(255)
		}
	})
	return btn, text
}
예제 #10
0
파일: console.go 프로젝트: num5/steven
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
}
예제 #11
0
파일: uiserverlist.go 프로젝트: num5/steven
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
}
예제 #12
0
파일: clientdebug.go 프로젝트: num5/steven
func (c *ClientState) initDebug() {
	c.debug.position = ui.NewText("X:0 Y:0 Z:0", 5, 5, 255, 255, 255).
		Attach(ui.Top, ui.Left)
	c.scene.AddDrawable(c.debug.position)
	c.debug.facing = ui.NewText("Facing: invalid", 5, 23, 255, 255, 255).
		Attach(ui.Top, ui.Left)
	c.scene.AddDrawable(c.debug.facing)

	c.debug.fps = ui.NewText("FPS: 0", 5, 5, 255, 255, 255).
		Attach(ui.Top, ui.Right)
	c.scene.AddDrawable(c.debug.fps)
	c.debug.memory = ui.NewText("0/0", 5, 23, 255, 255, 255).
		Attach(ui.Top, ui.Right)
	c.scene.AddDrawable(c.debug.memory)

	c.debug.target = ui.NewText("", 5, 41, 255, 255, 255).
		Attach(ui.Top, ui.Right)
	c.scene.AddDrawable(c.debug.target)
	c.debug.targetName = ui.NewText("", 5, 59, 255, 255, 255).
		Attach(ui.Top, ui.Right)
	c.scene.AddDrawable(c.debug.targetName)
	c.debug.enabled = true
	c.toggleDebug()
}
예제 #13
0
파일: uilogo.go 프로젝트: num5/steven
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()
}
예제 #14
0
파일: uiserverlist.go 프로젝트: num5/steven
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))
		})
	}
}
예제 #15
0
파일: playerlist.go 프로젝트: num5/steven
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)
	}
}
예제 #16
0
파일: uivolume.go 프로젝트: num5/steven
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
}
예제 #17
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)
	}
}
예제 #18
0
파일: uioptions.go 프로젝트: num5/steven
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
}