Moved client back to go
parent
346822164d
commit
5baf53e284
@ -1,17 +1,22 @@
|
|||||||
# Ignore everything
|
# Binaries for programs and plugins
|
||||||
*
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
# But not these files...
|
# Test binary, built with `go test -c`
|
||||||
!/.gitignore
|
*.test
|
||||||
|
|
||||||
!*.go
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
!go.sum
|
*.out
|
||||||
!go.mod
|
|
||||||
|
|
||||||
!README.md
|
# Dependency directories (remove the comment below to include it)
|
||||||
!LICENSE
|
# vendor/
|
||||||
|
|
||||||
# !Makefile
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
go.work.sum
|
||||||
|
|
||||||
# ...even if they are in subdirectories
|
# env file
|
||||||
!*/
|
.env
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
bin_PROGRAMS = roleplay
|
|
||||||
roleplay_SOURCES = src/main.c
|
|
||||||
roleplay_LDADD = @RAYLIB_LIBS@
|
|
||||||
roleplay_CFLAGS = @RAYLIB_CFLAGS@
|
|
@ -1,28 +0,0 @@
|
|||||||
# -*- Autoconf -*-
|
|
||||||
# Process this file with autoconf to produce a configure script.
|
|
||||||
|
|
||||||
AC_PREREQ([2.00])
|
|
||||||
AC_INIT([roleplay], [v1.0])
|
|
||||||
AC_CONFIG_SRCDIR([src/main.c])
|
|
||||||
AC_CONFIG_AUX_DIR([config])
|
|
||||||
|
|
||||||
# Initialize automake
|
|
||||||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
|
|
||||||
|
|
||||||
# Checks for programs.
|
|
||||||
AC_PROG_CC
|
|
||||||
|
|
||||||
# Checks for libraries.
|
|
||||||
PKG_CHECK_MODULES([RAYLIB], [raylib])
|
|
||||||
AC_SUBST([RAYLIB_CFLAGS])
|
|
||||||
AC_SUBST([RAYLIB_LIBS])
|
|
||||||
|
|
||||||
# Checks for header files.
|
|
||||||
AC_CHECK_HEADER([stdint.h])
|
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
|
||||||
|
|
||||||
# Checks for library functions.
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
|
||||||
AC_OUTPUT
|
|
@ -0,0 +1,150 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClientAuth struct {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
LOGIN_STATE_CREDENTIALS LoginState = iota
|
||||||
|
LOGIN_STATE_ATTEMPTING
|
||||||
|
LOGIN_STATE_ERROR
|
||||||
|
)
|
||||||
|
|
||||||
|
type ButtonState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
BUTTON_STATE_IDLE ButtonState = iota
|
||||||
|
BUTTON_STATE_HOVER
|
||||||
|
BUTTON_STATE_PRESSED
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClientState struct {
|
||||||
|
auth *ClientAuth
|
||||||
|
login LoginState
|
||||||
|
login_button ButtonState
|
||||||
|
ui_scale uint
|
||||||
|
window_scale rl.Vector2
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
WIDTH uint = 1600
|
||||||
|
HEIGHT uint = 1000
|
||||||
|
)
|
||||||
|
|
||||||
|
func scale(original rl.Rectangle, ui_scale uint, window_scale rl.Vector2) rl.Rectangle {
|
||||||
|
return rl.Rectangle{
|
||||||
|
X: original.X/window_scale.X,
|
||||||
|
Y: original.Y/window_scale.Y,
|
||||||
|
Width: original.Width*float32(ui_scale)/window_scale.X,
|
||||||
|
Height: original.Height*float32(ui_scale)/window_scale.Y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func center(original rl.Rectangle, off_x, off_y int, window_scale rl.Vector2, width, height uint) rl.Rectangle {
|
||||||
|
return rl.Rectangle{
|
||||||
|
X: (float32(width) /window_scale.X - original.Width )/2 + float32(off_x)/window_scale.X,
|
||||||
|
Y: (float32(height)/window_scale.Y - original.Height)/2 + float32(off_y)/window_scale.Y,
|
||||||
|
Width: original.Width,
|
||||||
|
Height: original.Height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func button(rectangle rl.Rectangle, idle, hover, pressed rl.Color, text string, font_size int32, text_color rl.Color, last_state ButtonState) (action bool, next_state ButtonState) {
|
||||||
|
over := rl.CheckCollisionPointRec(rl.GetMousePosition(), rectangle)
|
||||||
|
action = false
|
||||||
|
next_state = last_state
|
||||||
|
|
||||||
|
if(rl.IsMouseButtonPressed(rl.MouseButtonLeft) && over) {
|
||||||
|
next_state = BUTTON_STATE_PRESSED
|
||||||
|
} else if(rl.IsMouseButtonReleased(rl.MouseButtonLeft) && last_state == BUTTON_STATE_PRESSED) {
|
||||||
|
next_state = BUTTON_STATE_IDLE
|
||||||
|
if(over) {
|
||||||
|
action = true
|
||||||
|
}
|
||||||
|
} else if(rl.IsMouseButtonUp(rl.MouseButtonLeft)) {
|
||||||
|
if(last_state == BUTTON_STATE_IDLE && over) {
|
||||||
|
next_state = BUTTON_STATE_HOVER
|
||||||
|
} else if (last_state == BUTTON_STATE_HOVER && !over) {
|
||||||
|
next_state = BUTTON_STATE_IDLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var color rl.Color
|
||||||
|
switch(next_state) {
|
||||||
|
case BUTTON_STATE_HOVER:
|
||||||
|
color = hover
|
||||||
|
case BUTTON_STATE_PRESSED:
|
||||||
|
color = pressed
|
||||||
|
default:
|
||||||
|
color = idle
|
||||||
|
}
|
||||||
|
rl.DrawRectangleRec(rectangle, color)
|
||||||
|
text_size := rl.MeasureTextEx(rl.GetFontDefault(), text, float32(font_size), 1.0)
|
||||||
|
rl.DrawText(text, int32(rectangle.X + rectangle.Width/2 - text_size.X/2), int32(rectangle.Y + rectangle.Height/2 - text_size.Y/2), font_size, text_color)
|
||||||
|
|
||||||
|
return action, next_state
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
state := ClientState{
|
||||||
|
auth: nil,
|
||||||
|
login: LOGIN_STATE_CREDENTIALS,
|
||||||
|
login_button: BUTTON_STATE_IDLE,
|
||||||
|
ui_scale: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.SetConfigFlags(rl.FlagWindowHighdpi)
|
||||||
|
rl.InitWindow(0, 0, "roleplay")
|
||||||
|
rl.SetExitKey(0)
|
||||||
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
|
state.window_scale = rl.GetWindowScaleDPI()
|
||||||
|
rl.SetWindowSize(int(float32(WIDTH)/state.window_scale.X), int(float32(HEIGHT)/state.window_scale.Y))
|
||||||
|
|
||||||
|
for(rl.WindowShouldClose() == false) {
|
||||||
|
if(state.auth == nil) {
|
||||||
|
// Draw login
|
||||||
|
rl.BeginDrawing()
|
||||||
|
rl.ClearBackground(rl.White)
|
||||||
|
|
||||||
|
logo_rect := scale(rl.Rectangle{Width: 1200, Height: 300}, state.ui_scale, state.window_scale)
|
||||||
|
logo_rect = center(logo_rect, 0, -300, state.window_scale, WIDTH, HEIGHT)
|
||||||
|
rl.DrawRectangleRec(logo_rect, rl.Gray)
|
||||||
|
|
||||||
|
form_rect := scale(rl.Rectangle{Width: 600, Height: 400}, state.ui_scale, state.window_scale)
|
||||||
|
form_rect = center(form_rect, 0, 150, state.window_scale, WIDTH, HEIGHT)
|
||||||
|
rl.DrawRectangleRec(form_rect, rl.Gray)
|
||||||
|
|
||||||
|
switch(state.login) {
|
||||||
|
case LOGIN_STATE_CREDENTIALS:
|
||||||
|
submit_rect := scale(rl.Rectangle{Width: 100, Height: 50}, state.ui_scale, state.window_scale)
|
||||||
|
submit_rect = center(submit_rect, 0, 300, state.window_scale, WIDTH, HEIGHT)
|
||||||
|
var submit_action bool
|
||||||
|
submit_action, state.login_button = button(submit_rect, rl.Black, rl.Brown, rl.Red, "Submit", 12, rl.White, state.login_button)
|
||||||
|
if submit_action {
|
||||||
|
state.login = LOGIN_STATE_ATTEMPTING
|
||||||
|
}
|
||||||
|
case LOGIN_STATE_ATTEMPTING:
|
||||||
|
text := "Logging in..."
|
||||||
|
text_size := rl.MeasureTextEx(rl.GetFontDefault(), text, 20, 1.0)
|
||||||
|
text_rect := center(rl.Rectangle{Width: text_size.X, Height: text_size.Y}, 0, 0, state.window_scale, WIDTH, HEIGHT)
|
||||||
|
rl.DrawText(text, int32(text_rect.X), int32(text_rect.Y), 20, rl.Black)
|
||||||
|
case LOGIN_STATE_ERROR:
|
||||||
|
text := "Error: {TODO}"
|
||||||
|
text_size := rl.MeasureTextEx(rl.GetFontDefault(), text, 20, 1.0)
|
||||||
|
text_rect := center(rl.Rectangle{Width: text_size.X, Height: text_size.Y}, 0, 0, state.window_scale, WIDTH, HEIGHT)
|
||||||
|
rl.DrawText(text, int32(text_rect.X), int32(text_rect.Y), 20, rl.Black)
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.EndDrawing()
|
||||||
|
} else {
|
||||||
|
// Draw game
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
InitWindow(800, 600, "roleplay");
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
while(!WindowShouldClose()) {
|
|
||||||
BeginDrawing();
|
|
||||||
ClearBackground(WHITE);
|
|
||||||
DrawText("Hello, World!", 100, 100, 20, BLACK);
|
|
||||||
EndDrawing();
|
|
||||||
}
|
|
||||||
|
|
||||||
CloseWindow();
|
|
||||||
}
|
|
@ -0,0 +1,11 @@
|
|||||||
|
module git.metznet.ca/MetzNet/roleplay
|
||||||
|
|
||||||
|
go 1.23.1
|
||||||
|
|
||||||
|
require github.com/gen2brain/raylib-go/raylib v0.0.0-20240930075631-c66f9e2942fe
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/ebitengine/purego v0.7.1 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
|
||||||
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
|
)
|
@ -0,0 +1,8 @@
|
|||||||
|
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
|
||||||
|
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||||
|
github.com/gen2brain/raylib-go/raylib v0.0.0-20240930075631-c66f9e2942fe h1:mInjrbJkUglTM7tBmXG+epnPCE744aj15J7vjJwM4gs=
|
||||||
|
github.com/gen2brain/raylib-go/raylib v0.0.0-20240930075631-c66f9e2942fe/go.mod h1:BaY76bZk7nw1/kVOSQObPY1v1iwVE1KHAGMfvI6oK1Q=
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
|
||||||
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
|
||||||
|
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||||
|
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
@ -1,3 +0,0 @@
|
|||||||
module git.metznet.ca/MetzNet/roleplay/server
|
|
||||||
|
|
||||||
go 1.23.1
|
|
Loading…
Reference in New Issue