Updated readme. Menu updates.

This commit is contained in:
Tim Sarbin 2019-10-26 12:55:36 -04:00
parent e9181535be
commit 4231199459
7 changed files with 82 additions and 18 deletions

View File

@ -131,7 +131,7 @@ func CreateSprite(data []byte, palette Palette) *Sprite {
func (v *Sprite) GetSize() (uint32, uint32) { func (v *Sprite) GetSize() (uint32, uint32) {
frame := v.Frames[uint32(v.Frame)+(uint32(v.Direction)*v.FramesPerDirection)] frame := v.Frames[uint32(v.Frame)+(uint32(v.Direction)*v.FramesPerDirection)]
for frame.Loaded == false { for frame.Loaded == false {
time.Sleep(time.Millisecond) time.Sleep(time.Millisecond * 5)
} }
return frame.Width, frame.Height return frame.Width, frame.Height
} }
@ -212,7 +212,7 @@ func (v *Sprite) DrawSegments(target *ebiten.Image, xSegments, ySegments, offset
opts.ColorM = ColorToColorM(v.ColorMod) opts.ColorM = ColorToColorM(v.ColorMod)
} }
for frame.Loaded == false { for frame.Loaded == false {
time.Sleep(time.Millisecond) time.Sleep(time.Millisecond * 5)
} }
target.DrawImage(frame.Image, opts) target.DrawImage(frame.Image, opts)
xOffset += int32(frame.Width) xOffset += int32(frame.Width)

View File

@ -3,6 +3,8 @@
[Join us on Discord!](https://discord.gg/pRy8tdc)\ [Join us on Discord!](https://discord.gg/pRy8tdc)\
[Development Live stream](https://www.twitch.tv/essial/) [Development Live stream](https://www.twitch.tv/essial/)
![Main Menu](docs/MainMenuSS.png)
## About this project ## About this project
OpenDiablo2 is an ARPG game engine in the same vein of the 2000's games, and supports playing Diablo 2. The engine is written in golang and is cross platform. However, please note that this project does not ship with the assets or content required to play Diablo 2. You must have a legally purchased copy of [Diablo 2](https://us.shop.battle.net/en-us/product/diablo-ii) and its expansion [Lord of Destruction](https://us.shop.battle.net/en-us/product/diablo-ii-lord-of-destruction) installed on your computer in order to run that game on this engine. If you have an original copy of the disks, those files should work fine as well. OpenDiablo2 is an ARPG game engine in the same vein of the 2000's games, and supports playing Diablo 2. The engine is written in golang and is cross platform. However, please note that this project does not ship with the assets or content required to play Diablo 2. You must have a legally purchased copy of [Diablo 2](https://us.shop.battle.net/en-us/product/diablo-ii) and its expansion [Lord of Destruction](https://us.shop.battle.net/en-us/product/diablo-ii-lord-of-destruction) installed on your computer in order to run that game on this engine. If you have an original copy of the disks, those files should work fine as well.

View File

@ -94,16 +94,18 @@ const (
// --- Fonts --- // --- Fonts ---
Font6 = "/data/local/font/latin/font6" Font6 = "/data/local/font/latin/font6"
Font8 = "/data/local/font/latin/font8" Font8 = "/data/local/font/latin/font8"
Font16 = "/data/local/font/latin/font16" Font16 = "/data/local/font/latin/font16"
Font24 = "/data/local/font/latin/font24" Font24 = "/data/local/font/latin/font24"
Font30 = "/data/local/font/latin/font30" Font30 = "/data/local/font/latin/font30"
FontFormal12 = "/data/local/font/latin/fontformal12" FontFormal12 = "/data/local/font/latin/fontformal12"
FontFormal11 = "/data/local/font/latin/fontformal11" FontFormal11 = "/data/local/font/latin/fontformal11"
FontFormal10 = "/data/local/font/latin/fontformal10" FontFormal10 = "/data/local/font/latin/fontformal10"
FontExocet10 = "/data/local/font/latin/fontexocet10" FontExocet10 = "/data/local/font/latin/fontexocet10"
FontExocet8 = "/data/local/font/latin/fontexocet8" FontExocet8 = "/data/local/font/latin/fontexocet8"
FontSucker = "/data/local/font/latin/ReallyTheLastSucker"
FontRediculous = "/data/local/font/latin/fontridiculous"
// --- UI --- // --- UI ---

View File

@ -1,8 +1,12 @@
package Scenes package Scenes
import ( import (
"fmt"
"image/color" "image/color"
"log"
"os" "os"
"os/exec"
"runtime"
"github.com/essial/OpenDiablo2/Common" "github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes" "github.com/essial/OpenDiablo2/Palettes"
@ -25,10 +29,14 @@ type MainMenu struct {
diabloLogoRight *Common.Sprite diabloLogoRight *Common.Sprite
diabloLogoLeftBack *Common.Sprite diabloLogoLeftBack *Common.Sprite
diabloLogoRightBack *Common.Sprite diabloLogoRightBack *Common.Sprite
singlePlayerButton *UI.Button
githubButton *UI.Button
exitDiabloButton *UI.Button exitDiabloButton *UI.Button
creditsButton *UI.Button creditsButton *UI.Button
cinematicsButton *UI.Button
copyrightLabel *UI.Label copyrightLabel *UI.Label
copyrightLabel2 *UI.Label copyrightLabel2 *UI.Label
openDiabloLabel *UI.Label
ShowTrademarkScreen bool ShowTrademarkScreen bool
leftButtonHeld bool leftButtonHeld bool
} }
@ -63,6 +71,13 @@ func (v *MainMenu) Load() []func() {
v.copyrightLabel2.Color = color.RGBA{188, 168, 140, 255} v.copyrightLabel2.Color = color.RGBA{188, 168, 140, 255}
v.copyrightLabel2.MoveTo(400, 525) v.copyrightLabel2.MoveTo(400, 525)
}, },
func() {
v.openDiabloLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal10, Palettes.Static)
v.openDiabloLabel.Alignment = UI.LabelAlignCenter
v.openDiabloLabel.SetText("OpenDiablo2 is neither developed by, nor endorsed by Blizzard or its parent company Activision")
v.openDiabloLabel.Color = color.RGBA{255, 255, 140, 255}
v.openDiabloLabel.MoveTo(400, 580)
},
func() { func() {
v.background = v.fileProvider.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky) v.background = v.fileProvider.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky)
v.background.MoveTo(0, 0) v.background.MoveTo(0, 0)
@ -105,9 +120,51 @@ func (v *MainMenu) Load() []func() {
v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() }) v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() })
v.uiManager.AddWidget(v.creditsButton) v.uiManager.AddWidget(v.creditsButton)
}, },
func() {
v.cinematicsButton = UI.CreateButton(UI.ButtonTypeShort, v.fileProvider, "CINEMATICS")
v.cinematicsButton.MoveTo(401, 505)
v.cinematicsButton.SetVisible(!v.ShowTrademarkScreen)
v.uiManager.AddWidget(v.cinematicsButton)
},
func() {
v.singlePlayerButton = UI.CreateButton(UI.ButtonTypeWide, v.fileProvider, "SINGLE PLAYER")
v.singlePlayerButton.MoveTo(264, 290)
v.singlePlayerButton.SetVisible(!v.ShowTrademarkScreen)
v.uiManager.AddWidget(v.singlePlayerButton)
},
func() {
v.githubButton = UI.CreateButton(UI.ButtonTypeWide, v.fileProvider, "PROJECT WEBSITE")
v.githubButton.MoveTo(264, 330)
v.githubButton.SetVisible(!v.ShowTrademarkScreen)
v.githubButton.OnActivated(func() { v.onGithubButtonClicked() })
v.uiManager.AddWidget(v.githubButton)
},
} }
} }
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}
}
func (v *MainMenu) onGithubButtonClicked() {
openbrowser("https://www.github.com/essial/OpenDiablo2")
}
func (v *MainMenu) onExitButtonClicked() { func (v *MainMenu) onExitButtonClicked() {
os.Exit(0) os.Exit(0)
} }
@ -137,7 +194,7 @@ func (v *MainMenu) Render(screen *ebiten.Image) {
v.copyrightLabel.Draw(screen) v.copyrightLabel.Draw(screen)
v.copyrightLabel2.Draw(screen) v.copyrightLabel2.Draw(screen)
} else { } else {
v.openDiabloLabel.Draw(screen)
} }
} }
@ -149,6 +206,9 @@ func (v *MainMenu) Update(tickTime float64) {
v.ShowTrademarkScreen = false v.ShowTrademarkScreen = false
v.exitDiabloButton.SetVisible(true) v.exitDiabloButton.SetVisible(true)
v.creditsButton.SetVisible(true) v.creditsButton.SetVisible(true)
v.cinematicsButton.SetVisible(true)
v.singlePlayerButton.SetVisible(true)
v.githubButton.SetVisible(true)
} }
return return
} }

View File

@ -55,7 +55,7 @@ type ButtonLayout struct {
// ButtonLayouts define the type of buttons you can have // ButtonLayouts define the type of buttons you can have
var ButtonLayouts = map[ButtonType]ButtonLayout{ var ButtonLayouts = map[ButtonType]ButtonLayout{
ButtonTypeWide: {2, 1, ResourcePaths.WideButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true}, ButtonTypeWide: {2, 1, ResourcePaths.WideButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true},
ButtonTypeShort: {1, 1, ResourcePaths.ShortButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet8, nil, true}, ButtonTypeShort: {1, 1, ResourcePaths.ShortButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontRediculous, nil, true},
ButtonTypeMedium: {1, 1, ResourcePaths.MediumButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true}, ButtonTypeMedium: {1, 1, ResourcePaths.MediumButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true},
/* /*
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } }, {eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
@ -123,9 +123,9 @@ func CreateButton(buttonType ButtonType, fileProvider Common.FileProvider, text
result.normalImage, _ = ebiten.NewImage(int(result.width), int(result.height), ebiten.FilterNearest) result.normalImage, _ = ebiten.NewImage(int(result.width), int(result.height), ebiten.FilterNearest)
result.pressedImage, _ = ebiten.NewImage(int(result.width), int(result.height), ebiten.FilterNearest) result.pressedImage, _ = ebiten.NewImage(int(result.width), int(result.height), ebiten.FilterNearest)
textWidth, textHeight := font.GetTextMetrics(text) textWidth, _ := font.GetTextMetrics(text)
textX := (result.width / 2) - (textWidth / 2) textX := (result.width / 2) - (textWidth / 2)
textY := (result.height / 2) - (textHeight / 2) + 1 textY := (result.height / 2)
buttonSprite.MoveTo(0, 0) buttonSprite.MoveTo(0, 0)
buttonSprite.Blend = true buttonSprite.Blend = true
buttonSprite.DrawSegments(result.normalImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame) buttonSprite.DrawSegments(result.normalImage, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame)

View File

@ -62,8 +62,8 @@ func (v *Font) GetTextMetrics(text string) (width, height uint32) {
ch := text[i] ch := text[i]
metric := v.metrics[uint8(ch)] metric := v.metrics[uint8(ch)]
width += uint32(metric.Width) width += uint32(metric.Width)
_, h := v.fontSprite.GetFrameSize(int(ch)) //_, h := v.fontSprite.GetFrameSize(int(ch))
height = Common.Max(height, h) height = Common.Max(height, uint32(metric.Height))
} }
return return
} }

BIN
docs/MainMenuSS.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 KiB