This commit is contained in:
Abdulmujeeb Raji 2023-07-28 18:20:41 +01:00
commit 6d5b74f7d0
23 changed files with 199 additions and 130 deletions

View file

@ -1,7 +1,7 @@
# Backend Usage
In order for this to work, you need to have [sqlite3](https://sqlite.org)
installed on your system. Once you do, make a databse called `users.db`
In order to run the backend, you need to have [sqlite3](https://sqlite.org)
installed on your system. Once you do, make a database file named `users.db`
and initialize it with the `sql/init.sql` script:
```sh
@ -12,4 +12,5 @@ You also need to create a `.env` file with the following variables:
- `JWT_SECRET`: Required. A cryptographically secure string used to encode
tokens.
- `PORT`: Optional. Overrides the default port of `7741`
- `PORT`: Optional. Overrides the default port of `7741`

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -5,9 +5,33 @@ import (
)
var (
//go:embed iosevka-bold.ttf
// Iosevka
//go:embed Iosevka/iosevka-bold.ttf
IosevkaBold_ttf []byte
//go:embed iosevka-regular.ttf
//go:embed Iosevka/iosevka-regular.ttf
IosevkaRegular_ttf []byte
/// FiraCode
//go:embed FiraMono/FiraMono-Bold.ttf
FiraBold_ttf []byte
//go:embed FiraMono/FiraMono-Medium.ttf
FiraMedium_ttf []byte
//go:embed FiraMono/FiraMono-Regular.ttf
FiraRegular_ttf []byte
/// Victor Mono
//go:embed VictorMono/VictorMono-ExtraLight.ttf
VictorExtraLight_ttf []byte
//go:embed VictorMono/VictorMono-Thin.ttf
VictorThin_ttf []byte
//go:embed VictorMono/VictorMono-Light.ttf
VictorLight_ttf []byte
//go:embed VictorMono/VictorMono-Regular.ttf
VictorRegular_ttf []byte
//go:embed VictorMono/VictorMono-Medium.ttf
VictorMedium_ttf []byte
//go:embed VictorMono/VictorMono-SemiBold.ttf
VictorSemiBold_ttf []byte
//go:embed VictorMono/VictorMono-Bold.ttf
VictorBold_ttf []byte
)

View file

@ -0,0 +1,3 @@
module github.com/devraza/ambition/frontend/assets/fonts
go 1.20

View file

@ -1,20 +1,29 @@
module github.com/devraza/ambition
module github.com/devraza/ambition/frontend
go 1.20
require (
github.com/ebitenui/ebitenui v0.5.4
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/devraza/ambition/frontend/player v0.0.0-00010101000000-000000000000
github.com/devraza/ambition/frontend/ui v0.0.0-00010101000000-000000000000
github.com/hajimehoshi/ebiten/v2 v2.5.5
golang.org/x/image v0.7.0
)
require (
github.com/devraza/ambition/frontend/assets/fonts v0.0.0-00010101000000-000000000000 // indirect
github.com/ebitengine/purego v0.3.2 // indirect
github.com/ebitenui/ebitenui v0.5.4 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/jezek/xgb v1.1.0 // indirect
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
golang.org/x/image v0.9.0 // indirect
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
)
replace (
github.com/devraza/ambition/frontend/assets/fonts => ./assets/fonts
github.com/devraza/ambition/frontend/player => ./player
github.com/devraza/ambition/frontend/ui => ./ui
)

View file

@ -24,8 +24,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 h1:539vykMVJsmdiucRtMmdeLLZaTVhWhaAHFcPabj2lws=
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY=
@ -59,8 +59,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

View file

@ -1,13 +1,13 @@
package main
import (
// Random
// Misc.
"log"
"math/rand"
// Logs
"log"
"strconv"
// Ambition
p "github.com/devraza/ambition/frontend/player"
u "github.com/devraza/ambition/frontend/ui"
// Ebitengine
"github.com/hajimehoshi/ebiten/v2"
@ -15,12 +15,12 @@ import (
)
// Initialise the test player
var testPlayer = initPlayer()
var testPlayer = p.GetPlayer()
// Create the `Game` struct
type Game struct {
ui UI
activePlayer Player
ui u.UI
activePlayer p.Player
}
// Define the window width/height
@ -31,15 +31,15 @@ const (
// Update implements Game
func (g *Game) Update() error {
g.ui.base.Update()
g.activePlayer.update()
g.ui.Base.Update()
g.activePlayer.Update()
return nil
}
// Draw implements Game
func (g *Game) Draw(screen *ebiten.Image) {
// Draw the UI onto the screen
g.ui.base.Draw(screen)
g.ui.Base.Draw(screen)
}
// Layout implements Game
@ -62,14 +62,12 @@ func main() {
// Engine setup
ebiten.SetWindowSize(window_width, window_height)
ebiten.SetWindowTitle(window_title)
testPlayer := initPlayer()
// Initialise the game
game := Game{
// Initialise the UI
activePlayer: testPlayer,
ui: uiInit(window_width, window_height),
ui: u.UiInit(window_width, window_height),
}
// Log and exit on error

3
frontend/player/go.mod Normal file
View file

@ -0,0 +1,3 @@
module github.com/devraza/ambition/frontend/player
go 1.20

View file

@ -1,16 +1,17 @@
package main
package player
import ()
// The player struct
type Player struct {
health int
health_max int
defence int
level int
exp float32
ambition float32
ambition_max float32
Health int
MaxHealth int
Defence int
Level int
Exp float32
NextExp float32
Ambition float32
MaxAmbition float32
}
// Create the maps for the level/(max) ambition gates
@ -18,15 +19,16 @@ var level_gates = make(map[int]float32)
var level_ambition = make(map[int]float32)
// TODO(midnadimple): Move player initialization to server upon login
func initPlayer() Player {
func GetPlayer() Player {
return Player{
health: 100,
health_max: 100,
defence: 0,
level: 1,
exp: 0.0,
ambition: 0.0, // NOTE(midnadimple): In the future this will be affected by player activity
ambition_max: level_ambition[1], // NOTE(midnadimple): In the future this will be affected by player activity
Health: 100,
MaxHealth: 100,
Defence: 0,
Level: 1,
Exp: 0.0,
NextExp: 0.0,
Ambition: 0.0, // NOTE(midnadimple): In the future this will be affected by player activity
MaxAmbition: level_ambition[1], // NOTE(midnadimple): In the future this will be affected by player activity
}
}
@ -37,7 +39,7 @@ func gain(basexp float32, modifier float32) float32 {
}
// Update the player
func (p *Player) update() {
func (p *Player) Update() {
// TODO(midnadimple): update health upon damage
// Auto-generate the level gates
@ -70,10 +72,13 @@ func (p *Player) update() {
}
}
// Set the XP needed for the player to reach the next level
p.NextExp = level_gates[p.Level]
// Set the XP to 0 and increase both the level and max ambition on level up
if p.exp >= level_gates[p.level] {
p.exp = 0.0
p.level += 1
p.ambition_max = level_ambition[p.level]
if p.Exp >= level_gates[p.Level] {
p.Exp = 0.0
p.Level += 1
p.MaxAmbition = level_ambition[p.Level]
}
}

24
frontend/ui/go.mod Normal file
View file

@ -0,0 +1,24 @@
module github.com/devraza/ambition/frontend/ui
go 1.20
require (
github.com/devraza/ambition/frontend/assets/fonts v0.0.0-00010101000000-000000000000
github.com/ebitenui/ebitenui v0.5.4
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
golang.org/x/image v0.9.0
)
require (
github.com/ebitengine/purego v0.3.2 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/hajimehoshi/ebiten/v2 v2.5.4 // indirect
github.com/jezek/xgb v1.1.0 // indirect
golang.org/x/exp/shiny v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
)
replace github.com/devraza/ambition/frontend/assets/fonts => ../assets/fonts
replace github.com/devraza/ambition/frontend/player => ../player

61
frontend/ui/go.sum Normal file
View file

@ -0,0 +1,61 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/ebitengine/purego v0.3.2 h1:+pV+tskAkn/bxEcUzGtDfw2VAe3bRQ26kdzFjPPrCww=
github.com/ebitengine/purego v0.3.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/ebitenui/ebitenui v0.5.4 h1:iXFIa+W/MZG88gGDwOvCU9TSzecnZsXWkrve+jjorEI=
github.com/ebitenui/ebitenui v0.5.4/go.mod h1:2iyyjninLWNQLZ+pdV/eJ9vRnSs+I+HrzEBLEIH4Y9A=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/hajimehoshi/bitmapfont/v2 v2.2.3 h1:jmq/TMNj352V062Tr5e3hAoipkoxCbY1JWTzor0zNps=
github.com/hajimehoshi/ebiten/v2 v2.5.4 h1:NvUU6LvVc6oc+u+rD9KfHMjruRdpNwbpalVUINNXufU=
github.com/hajimehoshi/ebiten/v2 v2.5.4/go.mod h1:mnHSOVysTr/nUZrN1lBTRqhK4NG+T9NR3JsJP2rCppk=
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp/shiny v0.0.0-20230522175609-2e198f4a06a1 h1:NxHSRPlbeyFGDc6rU7YsvxV/4bXS9XhuvUt5pP63XUs=
golang.org/x/exp/shiny v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 h1:539vykMVJsmdiucRtMmdeLLZaTVhWhaAHFcPabj2lws=
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View file

@ -1,4 +1,4 @@
package main
package ui
import (
// Image-related packages
@ -8,24 +8,30 @@ import (
// Misc.
// "fmt"
// Ambition
p "github.com/devraza/ambition/frontend/player"
// EbitenUI
"github.com/ebitenui/ebitenui"
"github.com/ebitenui/ebitenui/image"
"github.com/ebitenui/ebitenui/widget"
// Fonts
"github.com/devraza/ambition/assets/fonts"
"github.com/devraza/ambition/frontend/assets/fonts"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
)
// The UI struct
type UI struct {
base ebitenui.UI
Base ebitenui.UI
colors map[string]color.RGBA
width, height int
}
// Get the player from the `player` package
var player = p.GetPlayer()
// The `hazakura` colorscheme (default)
var hazakura = map[string]color.RGBA{
// The monotone colors
@ -49,7 +55,7 @@ var hazakura = map[string]color.RGBA{
}
// Function for UI initialization
func uiInit(width, height int) UI {
func UiInit(width, height int) UI {
var ui UI
// Define the UI colors
@ -69,8 +75,8 @@ func uiInit(width, height int) UI {
)
// Make the different faces
headingFace, _ := makeFace(18, fonts.IosevkaBold_ttf)
defaultFace, _ := makeFace(14, fonts.IosevkaRegular_ttf)
headingFace, _ := makeFace(18, fonts.FiraBold_ttf)
defaultFace, _ := makeFace(14, fonts.FiraRegular_ttf)
// Create the 'Profile' tab
tabProfile := widget.NewTabBookTab("Profile",
@ -159,49 +165,19 @@ func uiInit(width, height int) UI {
VerticalPosition: widget.AnchorLayoutPositionCenter,
})),
))
// Define the titlebar for the window
chatTitleContainer := widget.NewContainer(
// Set the background color of the titlebar
widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(ui.colors["overlay"])),
widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
)
chatTitleContainer.AddChild(widget.NewText(
widget.TextOpts.Text("Chat", headingFace, ui.colors["white"]),
widget.TextOpts.WidgetOpts(widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
HorizontalPosition: widget.AnchorLayoutPositionCenter,
VerticalPosition: widget.AnchorLayoutPositionCenter,
})),
))
// Define the chat window
chat := widget.NewWindow(
// Set the contents of the window
widget.WindowOpts.Contents(chatContainer),
// Set the titlebar for the window
widget.WindowOpts.TitleBar(chatTitleContainer, 25),
//Set the window above everything else and block input elsewhere
widget.WindowOpts.Modal(),
// Set how to close the window. CLICK_OUT will close the window when clicking anywhere
widget.WindowOpts.CloseMode(widget.CLICK_OUT),
// Make the window draggable
widget.WindowOpts.Draggable(),
// Make the window resizeable
widget.WindowOpts.Resizeable(),
// Set the minimum size of the window
widget.WindowOpts.MinSize(int(float32(width)/3.6), int(float32(height)/3.5)),
// Set the maximum size of the window
widget.WindowOpts.MaxSize(width/2, height/2),
)
// Place the window and add the window to the UI
showWindow(chat, ui, float32(width)-float32(width)/3.6, float32(height)-float32(height)/3.5)
ui.base.AddWindow(chat)
chatDimensionX, chatDimensionY := int(float32(width)/3.5), int(float32(height)/3)
chat := img.Rect(0, 0, chatDimensionX, chatDimensionY)
chat = chat.Add(img.Point{0, height - chatDimensionY})
// Set the position and size of the chat window
chatContainer.SetLocation(chat)
leftBar.AddChild(chatContainer)
// Set the position and size of the left bar
leftBar.SetLocation(img.Rect(0, 0, int(float32(width)/3.5), height))
// Add the left bar to the root container
root.AddChild(leftBar)
ui.base.Container = root
ui.Base.Container = root
return ui
}
@ -251,46 +227,11 @@ func makeStatsBars(parent *widget.TabBookTab, ui UI, face font.Face) {
},
),
// Set the min, max, and current values for each progressbar
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health),
widget.ProgressBarOpts.Values(0, player.Health, player.MaxHealth),
)
parent.AddChild(health)
parent.AddChild(health_progressbar)
// Defence
defence := widget.NewText(
widget.TextOpts.Text("Defence", face, ui.colors["white"]),
widget.TextOpts.WidgetOpts(widget.WidgetOpts.LayoutData(widget.GridLayoutData{
HorizontalPosition: widget.GridLayoutPositionStart,
})),
)
defence_progressbar := widget.NewProgressBar(
widget.ProgressBarOpts.WidgetOpts(
// Set the required anchor layout data to determine where in the container to place the progressbar
widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
HorizontalPosition: widget.AnchorLayoutPositionCenter,
VerticalPosition: widget.AnchorLayoutPositionCenter,
}),
// Set the minimum size for the progressbar.
widget.WidgetOpts.MinSize(200, 20),
),
widget.ProgressBarOpts.Images(
// Set the track colors
&widget.ProgressBarImage{
Idle: image.NewNineSliceColor(ui.colors["black"]),
Hover: image.NewNineSliceColor(ui.colors["black"]),
},
// Set the progress colors
&widget.ProgressBarImage{
Idle: image.NewNineSliceColor(ui.colors["yellow"]),
Hover: image.NewNineSliceColor(ui.colors["yellow"]),
},
),
// Set the min, max, and current values for each progressbar
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health),
)
parent.AddChild(defence)
parent.AddChild(defence_progressbar)
// XP/Level
level := widget.NewText(
widget.TextOpts.Text("Level", face, ui.colors["white"]),
@ -321,7 +262,7 @@ func makeStatsBars(parent *widget.TabBookTab, ui UI, face font.Face) {
},
),
// Set the min, max, and current values for each progressbar
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health_max),
widget.ProgressBarOpts.Values(0, int(player.Exp), int(player.NextExp)),
)
parent.AddChild(level)
parent.AddChild(level_progressbar)
@ -356,7 +297,7 @@ func makeStatsBars(parent *widget.TabBookTab, ui UI, face font.Face) {
},
),
// Set the min, max, and current values for each progressbar
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health),
widget.ProgressBarOpts.Values(0, int(player.Ambition), int(player.MaxAmbition)),
)
parent.AddChild(ambition)
parent.AddChild(ambition_progressbar)