2024-12-20 18:58:53 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
|
|
)
|
|
|
|
|
|
|
|
var transition = NewTransitionManager()
|
|
|
|
var currentStep = 0
|
|
|
|
var targetStep = 0
|
|
|
|
var useDefault = false
|
|
|
|
|
|
|
|
var step1DefaultRect rl.Rectangle
|
|
|
|
var step1CustomRect rl.Rectangle
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
monitor := rl.GetCurrentMonitor()
|
|
|
|
screenW := rl.GetMonitorWidth(monitor)
|
|
|
|
screenH := rl.GetMonitorHeight(monitor)
|
|
|
|
|
|
|
|
rl.InitWindow(int32(screenW), int32(screenH), "Spitfire Browser Installer")
|
|
|
|
rl.SetWindowState(rl.FlagFullscreenMode)
|
|
|
|
defer rl.CloseWindow()
|
|
|
|
|
|
|
|
rl.SetTargetFPS(60)
|
|
|
|
|
|
|
|
InitBackground(rl.GetScreenWidth(), rl.GetScreenHeight())
|
|
|
|
|
|
|
|
targetStep = 0
|
|
|
|
|
|
|
|
for !rl.WindowShouldClose() {
|
|
|
|
screenW = rl.GetScreenWidth()
|
|
|
|
screenH = rl.GetScreenHeight()
|
|
|
|
mousePos := rl.GetMousePosition()
|
|
|
|
|
|
|
|
buttonW := 100
|
|
|
|
buttonH := 30
|
|
|
|
prevX := int32(50)
|
|
|
|
prevY := int32(screenH - 50)
|
|
|
|
nextX := int32(screenW - 150)
|
|
|
|
nextY := prevY
|
|
|
|
|
|
|
|
oldAlpha, oldScale, oldOffsetX, newAlpha, newScale, newOffsetX := transition.Update()
|
|
|
|
|
|
|
|
if !transition.IsActive() && currentStep != targetStep {
|
|
|
|
currentStep = targetStep
|
|
|
|
}
|
|
|
|
|
|
|
|
if !transition.IsActive() && rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
|
|
|
handleInput(mousePos, screenW, screenH, buttonW, buttonH, prevX, prevY, nextX, nextY)
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateBackground(screenW, screenH)
|
|
|
|
|
|
|
|
rl.BeginDrawing()
|
|
|
|
DrawBackground(screenW, screenH)
|
|
|
|
|
|
|
|
drawHeader(screenW)
|
|
|
|
|
|
|
|
oldStep := currentStep
|
|
|
|
newStep := currentStep
|
|
|
|
if transition.IsActive() {
|
|
|
|
oldStep = transition.oldStep
|
|
|
|
newStep = transition.newStep
|
|
|
|
}
|
|
|
|
|
|
|
|
phase := transition.GetPhase()
|
|
|
|
if transition.IsActive() {
|
|
|
|
if phase == TransitionOutFadeScale {
|
|
|
|
drawStep(oldStep, screenW, screenH, mousePos, oldAlpha, oldScale, oldOffsetX)
|
|
|
|
} else {
|
|
|
|
drawStep(oldStep, screenW, screenH, mousePos, oldAlpha, oldScale, oldOffsetX)
|
|
|
|
drawStep(newStep, screenW, screenH, mousePos, newAlpha, newScale, newOffsetX)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawStep(currentStep, screenW, screenH, mousePos, 1.0, 1.0, 0.0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !transition.IsActive() {
|
|
|
|
if currentStep > 0 && currentStep < 3 {
|
|
|
|
drawButton("Previous", prevX, prevY, int32(buttonW), int32(buttonH), mousePos)
|
|
|
|
}
|
|
|
|
if currentStep == 1 {
|
|
|
|
drawButton("Next", nextX, nextY, int32(buttonW), int32(buttonH), mousePos)
|
|
|
|
} else if currentStep == 2 {
|
|
|
|
drawButton("Finish", nextX, nextY, int32(buttonW), int32(buttonH), mousePos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rl.EndDrawing()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func startTransition(from, to int) {
|
|
|
|
targetStep = to
|
|
|
|
transition.Start(from, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleInput(mousePos rl.Vector2, screenW, screenH, buttonW, buttonH int, prevX, prevY, nextX, nextY int32) {
|
|
|
|
if currentStep == 0 {
|
|
|
|
if overRect(mousePos, step1DefaultRect) {
|
|
|
|
fmt.Println("Installation complete with default settings.")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if overRect(mousePos, step1CustomRect) {
|
|
|
|
useDefault = false
|
|
|
|
startTransition(currentStep, 1)
|
|
|
|
}
|
|
|
|
} else if currentStep == 1 {
|
|
|
|
if overButton(mousePos, nextX, nextY, int32(buttonW), int32(buttonH)) {
|
|
|
|
startTransition(currentStep, 2)
|
|
|
|
}
|
|
|
|
if overButton(mousePos, int32(prevX), int32(prevY), int32(buttonW), int32(buttonH)) {
|
|
|
|
startTransition(currentStep, 0)
|
|
|
|
}
|
|
|
|
selectColor(mousePos)
|
|
|
|
selectContrastIcon(mousePos)
|
|
|
|
selectTheme(mousePos)
|
|
|
|
} else if currentStep == 2 {
|
|
|
|
if overButton(mousePos, nextX, nextY, int32(buttonW), int32(buttonH)) {
|
|
|
|
fmt.Printf("Installation complete:\nDefault: %v\nColor: %s\nTheme: %s\nLayout: %s\n",
|
|
|
|
useDefault, selectedColor, selectedTheme, selectedLayout)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if overButton(mousePos, int32(prevX), int32(prevY), int32(buttonW), int32(buttonH)) {
|
|
|
|
startTransition(currentStep, 1)
|
|
|
|
}
|
|
|
|
selectLayoutOption(mousePos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func drawHeader(screenW int) {
|
|
|
|
title := "Spitfire Browser Installer"
|
|
|
|
titleFontSize := int32(30)
|
|
|
|
titleWidth := rl.MeasureText(title, titleFontSize)
|
|
|
|
rl.DrawText(title, (int32(screenW)-titleWidth)/2, 20, titleFontSize, rl.RayWhite)
|
|
|
|
rl.DrawLine(50, 60, int32(screenW)-50, 60, rl.Fade(rl.White, 0.5))
|
|
|
|
}
|