slight refactor, gofmt
This commit is contained in:
@ -20,11 +20,11 @@ func (c *GameCamera) MoveCamera(targetX int, targetY int, mapWidth int, mapHeigh
|
||||
y = 0
|
||||
}
|
||||
|
||||
if x > mapWidth - c.Width {
|
||||
if x > mapWidth-c.Width {
|
||||
x = mapWidth - c.Width
|
||||
}
|
||||
|
||||
if y > mapHeight - c.Height {
|
||||
if y > mapHeight-c.Height {
|
||||
y = mapHeight - c.Height
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,11 @@
|
||||
package mainwindow
|
||||
|
||||
import blt "lab.zaar.be/thefish/bearlibterminal"
|
||||
|
||||
type LayerInterface interface {
|
||||
Render()
|
||||
Put(x, y int, symbol rune, color string)
|
||||
}
|
||||
import (
|
||||
blt "lab.zaar.be/thefish/bearlibterminal"
|
||||
)
|
||||
|
||||
type Layer struct {
|
||||
idx int
|
||||
idx int
|
||||
defaultColor uint32
|
||||
}
|
||||
|
||||
@ -35,31 +32,28 @@ func (layer *Layer) after() *Layer {
|
||||
return layer
|
||||
}
|
||||
|
||||
func (layer Layer) Put(x,y int, symbol string) {
|
||||
rnes := []rune(symbol)
|
||||
func (layer Layer) Put(x, y int, symbol interface{}) {
|
||||
if symbol == nil {
|
||||
return
|
||||
}
|
||||
rnes := []rune(symbol.(string))
|
||||
if (len(rnes)) > 0 {
|
||||
blt.Put(x, y, int(rnes[0]))
|
||||
}
|
||||
}
|
||||
|
||||
func (layer Layer) Print(x,y int, txt string) (w,h int) {
|
||||
return blt.Print(x,y, txt)
|
||||
func (layer Layer) Print(x, y int, txt string) (w, h int) {
|
||||
return blt.Print(x, y, txt)
|
||||
}
|
||||
|
||||
|
||||
func (layer Layer) DrawWindow (title string, x, y, w, h int) {
|
||||
if len(title) > (w -2) {
|
||||
title = title[:(w-2)]
|
||||
}
|
||||
layer.NewRect(x,y,w,h).DrawBorder()
|
||||
centerX := x + (w / 2)
|
||||
layer.Print(centerX - (len(title) / 2) - 1, y, "╡" + title + "╞")
|
||||
};
|
||||
|
||||
func (layer *Layer) Decorate (f func (args ...interface{})) func (args ...interface{}) {
|
||||
return func (args ...interface{}) {
|
||||
func (layer *Layer) Decorate(f func(args ...interface{})) func(args ...interface{}) {
|
||||
return func(args ...interface{}) {
|
||||
layer.before()
|
||||
f(args)
|
||||
layer.after()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (layer *Layer) Render() {
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,14 @@ package mainwindow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
blt "lab.zaar.be/thefish/bearlibterminal"
|
||||
)
|
||||
|
||||
type MainWindow struct {
|
||||
ctx util.ClientCtx
|
||||
layers []LayerInterface
|
||||
ctx util.ClientCtx
|
||||
layers []types.Renderable
|
||||
}
|
||||
|
||||
func Init(ctx util.ClientCtx) *MainWindow {
|
||||
@ -47,6 +48,6 @@ func (mw *MainWindow) Render() {
|
||||
}
|
||||
}
|
||||
|
||||
func (mw *MainWindow) AddLayer(li LayerInterface) {
|
||||
func (mw *MainWindow) AddLayer(li types.Renderable) {
|
||||
mw.layers = append(mw.layers, li)
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package mainwindow
|
||||
|
||||
type Rect struct {
|
||||
x,y,w,h int
|
||||
layer *Layer
|
||||
}
|
||||
|
||||
type rectFill struct {
|
||||
top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight, body string
|
||||
}
|
||||
|
||||
func (layer *Layer) NewRect(x,y,w,h int) *Rect {
|
||||
return &Rect{x,y,w,h, layer}
|
||||
}
|
||||
|
||||
var noborder = rectFill{
|
||||
top: "▄",
|
||||
bottom: "▀",
|
||||
left: "▐",
|
||||
right: "▌",
|
||||
topLeft: "▗",
|
||||
topRight: "▖",
|
||||
bottomLeft: "▝",
|
||||
bottomRight: "▘",
|
||||
body: "█",
|
||||
}
|
||||
|
||||
var splash = rectFill{
|
||||
top: "█",
|
||||
bottom: "█",
|
||||
left: "█",
|
||||
right: "█",
|
||||
topLeft: "█",
|
||||
topRight: "█",
|
||||
bottomLeft: "█",
|
||||
bottomRight: "█",
|
||||
body: "█",
|
||||
}
|
||||
|
||||
var doubleBorder = rectFill {
|
||||
top: "═",
|
||||
bottom: "═",
|
||||
left: "║",
|
||||
right: "║",
|
||||
topLeft: "╔",
|
||||
topRight: "╗",
|
||||
bottomLeft: "╚",
|
||||
bottomRight: "╝",
|
||||
}
|
||||
|
||||
func (r *Rect) Fill() {
|
||||
r.render(noborder)
|
||||
}
|
||||
|
||||
func (r *Rect) Splash() {
|
||||
r.render(splash)
|
||||
}
|
||||
|
||||
func (r *Rect) DrawBorder() {
|
||||
r.render(doubleBorder)
|
||||
}
|
||||
|
||||
func (r *Rect) render (fillage rectFill) {
|
||||
|
||||
if fillage.body != "" {
|
||||
for i := r.x + 1; i < r.x+r.w; i++ {
|
||||
for j := r.y + 1; j < r.y+r.h; j++ {
|
||||
r.layer.Put(i, j, fillage.body);
|
||||
//lii.Put(i, j, "X");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i := r.x + 1; i < r.x+r.w; i++ {
|
||||
r.layer.Put(i, r.y, fillage.top);
|
||||
//lii.Put(i, y-1, "Q");
|
||||
r.layer.Put(i, r.y+r.h, fillage.bottom);
|
||||
//lii.Put(i, y+h, "H");
|
||||
}
|
||||
|
||||
for j := r.y + 1; j < r.y+r.h; j++ {
|
||||
r.layer.Put(r.x, j, fillage.left);
|
||||
//lii.Put(x-1, j, "U");
|
||||
r.layer.Put(r.x+r.w, j, fillage.right);
|
||||
//lii.Put(x+w, j, "M");
|
||||
}
|
||||
|
||||
r.layer.Put(r.x, r.y, fillage.topLeft);
|
||||
//lii.Put(x-1, y-1, "T");
|
||||
r.layer.Put(r.x, r.y+r.h, fillage.bottomLeft);
|
||||
//lii.Put(x-1, y+h, "q");
|
||||
r.layer.Put(r.x+r.w, r.y, fillage.topRight);
|
||||
//lii.Put(x+w, y-1, "L");
|
||||
r.layer.Put(r.x+r.w, r.y+r.h, fillage.bottomRight);
|
||||
|
||||
};
|
||||
|
68
ui/mainwindow/uiwindow.go
Normal file
68
ui/mainwindow/uiwindow.go
Normal file
@ -0,0 +1,68 @@
|
||||
package mainwindow
|
||||
|
||||
import "lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
|
||||
var noborder = types.RectFill{
|
||||
Top: "▄",
|
||||
Bottom: "▀",
|
||||
Left: "▐",
|
||||
Right: "▌",
|
||||
TopLeft: "▗",
|
||||
TopRight: "▖",
|
||||
BottomLeft: "▝",
|
||||
BottomRight: "▘",
|
||||
Body: "█",
|
||||
}
|
||||
|
||||
var splash = types.RectFill{
|
||||
Top: "█",
|
||||
Bottom: "█",
|
||||
Left: "█",
|
||||
Right: "█",
|
||||
TopLeft: "█",
|
||||
TopRight: "█",
|
||||
BottomLeft: "█",
|
||||
BottomRight: "█",
|
||||
Body: "█",
|
||||
}
|
||||
|
||||
var doubleBorder = types.RectFill{
|
||||
Top: "═",
|
||||
Bottom: "═",
|
||||
Left: "║",
|
||||
Right: "║",
|
||||
TopLeft: "╔",
|
||||
TopRight: "╗",
|
||||
BottomLeft: "╚",
|
||||
BottomRight: "╝",
|
||||
}
|
||||
|
||||
type UiWindow struct {
|
||||
*types.Rect
|
||||
layer *Layer
|
||||
fillage types.RectFill
|
||||
}
|
||||
|
||||
func (layer *Layer) NewWindow(x, y, w, h int) *UiWindow {
|
||||
return &UiWindow{
|
||||
Rect: types.NewRect(x, y, w, h),
|
||||
layer: layer,
|
||||
}
|
||||
}
|
||||
|
||||
func (uiw *UiWindow) NoBorder() {
|
||||
uiw.RenderToLayer(noborder, uiw.layer)
|
||||
}
|
||||
|
||||
func (uiw *UiWindow) Splash() {
|
||||
uiw.RenderToLayer(splash, uiw.layer)
|
||||
}
|
||||
|
||||
func (uiw *UiWindow) DoubleBordered(title string) {
|
||||
uiw.RenderToLayer(doubleBorder, uiw.layer)
|
||||
if len(title) > (uiw.W - 2) {
|
||||
title = title[:(uiw.W - 2)]
|
||||
}
|
||||
centerX := uiw.X + (uiw.W / 2)
|
||||
uiw.layer.Print(centerX-(len(title)/2)-1, uiw.Y, "╡"+title+"╞")
|
||||
}
|
Reference in New Issue
Block a user