This repository has been archived by the owner on Oct 22, 2023. It is now read-only.
forked from ZeppelinMC/Zeppelin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.go
71 lines (66 loc) · 2.44 KB
/
gui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"io"
"net/http"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
var playerCountText *widget.RichText
var playerContainer *widget.List
func LaunchGUI() fyne.Window {
app := app.New()
window := app.NewWindow("Dynamite Server")
title := widget.NewRichTextFromMarkdown("# Dynamite Server")
consoleTitle := widget.NewRichTextFromMarkdown("## Console")
server.Logger.GUIConsole = widget.NewTextGridFromString(strings.Join(server.Logger.ConsoleText, "\n"))
command := widget.NewEntry()
command.SetPlaceHolder("Input a command")
command.OnSubmitted = func(s string) {
server.Command("console", s)
command.SetText("")
}
console := container.NewBorder(consoleTitle, command, nil, nil, container.NewScroll(server.Logger.GUIConsole))
playersTitle := widget.NewRichTextFromMarkdown("## Players")
max := fmt.Sprint(server.Config.MaxPlayers)
if max == "-1" {
max = "Unlimited"
}
playerCountText = widget.NewRichTextFromMarkdown(fmt.Sprintf("### %d/%s players", len(server.Players.Players), max))
playerContainer = widget.NewList(
func() int {
return len(server.Players.Players)
},
func() fyne.CanvasObject {
return container.NewHBox()
},
func(i widget.ListItemID, o fyne.CanvasObject) {
cont := o.(*fyne.Container)
player := server.Players.Players[server.Players.PlayerIDs[i]]
if len(cont.Objects) == 0 {
res, _ := http.Get(fmt.Sprintf("https://crafatar.com/avatars/%s", player.UUID.String))
skinData, _ := io.ReadAll(res.Body)
skin := widget.NewIcon(fyne.NewStaticResource("skin", skinData))
skin.Resize(fyne.NewSize(640, 640))
cont.Objects = append(cont.Objects, skin, widget.NewRichTextFromMarkdown("### "+player.Name))
cont.Refresh()
}
})
/*for _, player := range server.Players.Players {
res, _ := http.Get(fmt.Sprintf("https://crafatar.com/avatars/%s", player.UUID))
skinData, _ := io.ReadAll(res.Body)
skin := widget.NewIcon(fyne.NewStaticResource("skin", skinData))
skin.Resize(fyne.NewSize(640, 640))
cont := container.NewHBox(skin, widget.NewRichTextFromMarkdown("### "+player.Name))
playerContainer.Add(cont)
}*/
players := container.NewBorder(container.NewVBox(playersTitle, playerCountText), nil, nil, nil, playerContainer)
sp := container.NewHSplit(console, players)
sp.SetOffset(0.6)
window.SetContent(container.NewBorder(title, nil, nil, nil, sp))
window.Resize(fyne.NewSize(700, 300))
return window
}