Ejemplo n.º 1
0
Archivo: chat.go Proyecto: num5/steven
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)
	}
}
Ejemplo n.º 2
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
}
Ejemplo n.º 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)
	}
}
Ejemplo n.º 4
0
func (cs *consoleScreen) tick(delta float64) {
	if cs.visible {
		if cs.pos == -220 {
			cs.lastWidth = -1 // Force a redraw
		}
		if cs.pos < 0 {
			cs.pos += delta * 4
		} else {
			cs.pos = 0
		}
	} else {
		if cs.pos > -220 {
			cs.pos -= delta * 4
		} else {
			cs.pos = -220
		}
		if cs.pos == -220 {
			cs.scene.Hide()
			return
		}
	}
	cs.container.SetY(cs.pos)
	// Not the most efficent way but handles the alpha issue for
	// now
	cs.scene.Hide()
	cs.scene.Show()

	// Resize to fill the screen width
	width, _ := window.GetFramebufferSize()
	sw := 854 / float64(width)
	var w float64
	if ui.DrawMode == ui.Unscaled {
		sw = ui.Scale
		w = 854 / sw
	} else {
		w = float64(width)
	}
	cs.container.SetWidth(w)
	cs.background.SetWidth(w)

	if cs.lastLine != console.History(1)[0] || cs.lastWidth != w {
		for _, l := range cs.lines {
			l.Remove()
		}
		cs.lines = cs.lines[:0]
		hist := console.History(-1)
		offset := 200.0
		for i := 0; i < len(hist) && offset > 0; i++ {
			line := hist[i]
			if line.Value == nil {
				break
			}
			fmt := ui.NewFormattedWidth(line, 5, 0, w-10)
			offset -= fmt.Height
			fmt.SetY(offset)
			fmt.AttachTo(cs.container)
			cs.lines = append(cs.lines, fmt)
			cs.scene.AddDrawable(fmt.Attach(ui.Top, ui.Left))
		}
	}

	cs.lastWidth = w
	cs.lastLine = console.History(1)[0]

	cs.cursorTick += delta
	// Add on our cursor
	if int(cs.cursorTick/30)%2 == 0 {
		cs.inputText.Update(string(cs.input) + "|")
	} else {
		cs.inputText.Update(string(cs.input))
	}
}
Ejemplo n.º 5
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))
		})
	}
}