Beispiel #1
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
}
Beispiel #2
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
}
Beispiel #3
0
func newResourceList(ret func() screen) screen {
	rl := &resourceList{
		scene: scene.New(true),
		ret:   ret,
	}
	rl.logo.init(rl.scene)

	uiFooter(rl.scene)

	rl.redraw()

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

	done, txt := newButtonText("Done", 200, -50-15, 100, 30)
	rl.scene.AddDrawable(done.Attach(ui.Center, ui.Middle))
	rl.scene.AddDrawable(txt)
	done.AddClick(func() {
		setScreen(newOptionMenu(rl.ret))
	})

	return rl
}
Beispiel #4
0
func NewInventory(ty InventoryType, id, size int) *Inventory {
	return &Inventory{
		Type:  ty,
		ID:    id,
		Items: make([]*ItemStack, size),
		scene: scene.New(true),
	}
}
Beispiel #5
0
func (i *inventoryScreen) init() {
	i.prev = window.SetKeyCallback(i.onKey)
	i.activeSlot = -1
	i.cursorItem = nil
	if i.scene != nil {
		i.scene.Hide()
	}
	i.scene = scene.New(true)
}
Beispiel #6
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))
	}
}
Beispiel #7
0
func (i *inventoryScreen) setCursor(item *ItemStack) {
	i.scene.Hide()
	i.scene = scene.New(true)
	i.cursorItem = item
	i.cursorIcon = nil
	if item != nil {
		i.cursorIcon = createItemIcon(item, i.scene, i.lastMX-16, i.lastMY-16)
		i.cursorIcon.SetLayer(100)
	}
	Client.activeInventory.Update()
}
Beispiel #8
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
}
Beispiel #9
0
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
}
Beispiel #10
0
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
}
Beispiel #11
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
}
Beispiel #12
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
				}
			}
		}
	}
}
Beispiel #13
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)
}
Beispiel #14
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
}
Beispiel #15
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
}
Beispiel #16
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)
	}
}
Beispiel #17
0
func (inv *Inventory) Update() {
	was := inv.scene.IsVisible()
	inv.scene.Hide()
	inv.scene = scene.New(was)
	inv.Type.Draw(inv.scene, inv)
}
Beispiel #18
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))
		})
	}
}