Example #1
0
func (sl *serverList) remove() {
	window.SetScrollCallback(onScroll)
	sl.scene.Hide()
	for _, s := range sl.servers {
		s.Hide()
		render.FreeIcon(s.id)
	}
}
Example #2
0
func (rl *resourceList) remove() {
	window.SetScrollCallback(onScroll)
	window.SetKeyCallback(onKey)
	rl.scene.Hide()
	for _, s := range rl.packs {
		s.Hide()
		render.FreeIcon(s.id)
	}
}
Example #3
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)
	}
}
Example #4
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))
		})
	}
}