1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-12 23:43:24 -05:00

Minor changes to get map rendering started.

This commit is contained in:
Tim Sarbin 2019-11-01 14:12:23 -04:00
parent c4a27ad5ab
commit 7d228d116e
20 changed files with 397 additions and 222 deletions

View File

@ -1,9 +1,9 @@
package Common
import "github.com/essial/OpenDiablo2/Palettes"
import "github.com/essial/OpenDiablo2/PaletteDefs"
// FileProvider is an instance that can provide different types of files
type FileProvider interface {
LoadFile(fileName string) []byte
LoadSprite(fileName string, palette Palettes.Palette) *Sprite
LoadSprite(fileName string, palette PaletteDefs.PaletteType) *Sprite
}

View File

@ -24,6 +24,13 @@ func MaxInt32(a, b int32) int32 {
return b
}
func AbsInt32(a int32) int32 {
if a < 0 {
return -a
}
return a
}
// MinInt32 returns the higher of two values
func MinInt32(a, b int32) int32 {
if a < b {

7
Common/MpqFileRecord.go Normal file
View File

@ -0,0 +1,7 @@
package Common
type MpqFileRecord struct {
MpqFile string
IsPatch bool
UnpatchedMpqFile string
}

View File

@ -1,21 +1,28 @@
package Common
import "github.com/essial/OpenDiablo2/Palettes"
import (
"log"
"strings"
"github.com/essial/OpenDiablo2/PaletteDefs"
)
// PaletteRGB represents a color in a palette
type PaletteRGB struct {
R, G, B uint8
}
// Palette represents a palette
type Palette struct {
Name Palettes.Palette
// PaletteType represents a palette
type PaletteRec struct {
Name PaletteDefs.PaletteType
Colors [256]PaletteRGB
}
var Palettes map[PaletteDefs.PaletteType]PaletteRec
// CreatePalette creates a palette
func CreatePalette(name Palettes.Palette, data []byte) Palette {
result := Palette{Name: name}
func CreatePalette(name PaletteDefs.PaletteType, data []byte) PaletteRec {
result := PaletteRec{Name: name}
for i := 0; i <= 255; i++ {
result.Colors[i] = PaletteRGB{
@ -24,6 +31,19 @@ func CreatePalette(name Palettes.Palette, data []byte) Palette {
R: data[(i*3)+2],
}
}
return result
}
func LoadPalettes(mpqFiles map[string]*MpqFileRecord, fileProvider FileProvider) {
Palettes = make(map[PaletteDefs.PaletteType]PaletteRec)
for file := range mpqFiles {
if strings.Index(file, "/data/global/palette/") != 0 || strings.Index(file, ".dat") != len(file)-4 {
continue
}
nameParts := strings.Split(file, `/`)
paletteName := PaletteDefs.PaletteType(nameParts[len(nameParts)-2])
palette := CreatePalette(paletteName, fileProvider.LoadFile(file))
Palettes[paletteName] = palette
}
log.Printf("Loaded %d palettes", len(Palettes))
}

View File

@ -40,7 +40,7 @@ type SpriteFrame struct {
}
// CreateSprite creates an instance of a sprite
func CreateSprite(data []byte, palette Palette) *Sprite {
func CreateSprite(data []byte, palette PaletteRec) *Sprite {
result := &Sprite{
X: 50,
Y: 50,

View File

@ -10,11 +10,12 @@ import (
"strings"
"sync"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/Sound"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/MPQ"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/ResourcePaths"
"github.com/essial/OpenDiablo2/Scenes"
"github.com/essial/OpenDiablo2/UI"
@ -37,25 +38,18 @@ type EngineConfig struct {
BgmVolume float64
}
type MpqFileRecord struct {
MpqFile string
IsPatch bool
UnpatchedMpqFile string
}
// Engine is the core OpenDiablo2 engine
type Engine struct {
Settings *EngineConfig // Engine configuration settings from json file
Files map[string]*MpqFileRecord // Map that defines which files are in which MPQs
Palettes map[Palettes.Palette]Common.Palette // Color palettes
LoadingSprite *Common.Sprite // The sprite shown when loading stuff
loadingProgress float64 // LoadingProcess is a range between 0.0 and 1.0. If set, loading screen displays.
stepLoadingSize float64 // The size for each loading step
CurrentScene Scenes.Scene // The current scene being rendered
UIManager *UI.Manager // The UI manager
SoundManager *Sound.Manager // The sound manager
nextScene Scenes.Scene // The next scene to be loaded at the end of the game loop
fullscreenKey bool // When true, the fullscreen toggle is still being pressed
Settings *EngineConfig // Engine configuration settings from json file
Files map[string]*Common.MpqFileRecord // Map that defines which files are in which MPQs
LoadingSprite *Common.Sprite // The sprite shown when loading stuff
loadingProgress float64 // LoadingProcess is a range between 0.0 and 1.0. If set, loading screen displays.
stepLoadingSize float64 // The size for each loading step
CurrentScene Scenes.Scene // The current scene being rendered
UIManager *UI.Manager // The UI manager
SoundManager *Sound.Manager // The sound manager
nextScene Scenes.Scene // The next scene to be loaded at the end of the game loop
fullscreenKey bool // When true, the fullscreen toggle is still being pressed
}
// CreateEngine creates and instance of the OpenDiablo2 engine
@ -67,7 +61,7 @@ func CreateEngine() *Engine {
result.loadConfigurationFile()
ResourcePaths.LanguageCode = result.Settings.Language
result.mapMpqFiles()
result.loadPalettes()
Common.LoadPalettes(result.Files, result)
Common.LoadTextDictionary(result)
Common.LoadLevelTypes(result)
Common.LoadLevelPresets(result)
@ -75,7 +69,7 @@ func CreateEngine() *Engine {
result.SoundManager = Sound.CreateManager(result)
result.SoundManager.SetVolumes(result.Settings.BgmVolume, result.Settings.SfxVolume)
result.UIManager = UI.CreateManager(result, *result.SoundManager)
result.LoadingSprite = result.LoadSprite(ResourcePaths.LoadingScreen, Palettes.Loading)
result.LoadingSprite = result.LoadSprite(ResourcePaths.LoadingScreen, PaletteDefs.Loading)
loadingSpriteSizeX, loadingSpriteSizeY := result.LoadingSprite.GetSize()
result.LoadingSprite.MoveTo(int(400-(loadingSpriteSizeX/2)), int(300+(loadingSpriteSizeY/2)))
result.SetNextScene(Scenes.CreateMainMenu(result, result, result.UIManager, result.SoundManager))
@ -113,7 +107,7 @@ func (v *Engine) loadConfigurationFile() {
func (v *Engine) mapMpqFiles() {
log.Println("mapping mpq file structure")
v.Files = make(map[string]*MpqFileRecord)
v.Files = make(map[string]*Common.MpqFileRecord)
for _, mpqFileName := range v.Settings.MpqLoadOrder {
mpqPath := path.Join(v.Settings.MpqPath, mpqFileName)
mpq, err := MPQ.Load(mpqPath)
@ -134,7 +128,8 @@ func (v *Engine) mapMpqFiles() {
}
continue
}
v.Files[`/`+strings.ReplaceAll(strings.ToLower(filePath), `\`, `/`)] = &MpqFileRecord{mpqPath, false, ""}
v.Files[`/`+strings.ReplaceAll(strings.ToLower(filePath), `\`, `/`)] = &Common.MpqFileRecord{
mpqPath, false, ""}
}
}
}
@ -162,7 +157,7 @@ func (v *Engine) LoadFile(fileName string) []byte {
continue
}
// We found the super-secret file!
v.Files[strings.ToLower(fileName)] = &MpqFileRecord{mpqFilePath, false, ""}
v.Files[strings.ToLower(fileName)] = &Common.MpqFileRecord{mpqFilePath, false, ""}
break
}
} else if mpqFile.IsPatch {
@ -193,24 +188,10 @@ func (v *Engine) IsLoading() bool {
return v.loadingProgress < 1.0
}
func (v *Engine) loadPalettes() {
v.Palettes = make(map[Palettes.Palette]Common.Palette)
log.Println("loading palettes")
for file := range v.Files {
if strings.Index(file, "/data/global/palette/") != 0 || strings.Index(file, ".dat") != len(file)-4 {
continue
}
nameParts := strings.Split(file, `/`)
paletteName := Palettes.Palette(nameParts[len(nameParts)-2])
palette := Common.CreatePalette(paletteName, v.LoadFile(file))
v.Palettes[paletteName] = palette
}
}
// LoadSprite loads a sprite from the game's data files
func (v *Engine) LoadSprite(fileName string, palette Palettes.Palette) *Common.Sprite {
func (v *Engine) LoadSprite(fileName string, palette PaletteDefs.PaletteType) *Common.Sprite {
data := v.LoadFile(fileName)
sprite := Common.CreateSprite(data, v.Palettes[palette])
sprite := Common.CreateSprite(data, Common.Palettes[palette])
return sprite
}

View File

@ -23,7 +23,7 @@ type Tile struct {
Direction int32
RoofHeight int16
SoundIndex byte
Animated byte
Animated bool
Height int32
Width int32
Orientation int32
@ -58,14 +58,14 @@ func LoadDT1(path string, fileProvider Common.FileProvider) *DT1 {
}
br.SkipBytes(260)
numberOfTiles := br.GetInt32()
br.SkipBytes(4)
br.SetPosition(uint64(br.GetInt32()))
result.Tiles = make([]Tile, numberOfTiles)
for tileIdx := range result.Tiles {
newTile := Tile{}
newTile.Direction = br.GetInt32()
newTile.RoofHeight = br.GetInt16()
newTile.SoundIndex = br.GetByte()
newTile.Animated = br.GetByte()
newTile.Animated = br.GetByte() == 1
newTile.Height = br.GetInt32()
newTile.Width = br.GetInt32()
br.SkipBytes(4)
@ -92,7 +92,12 @@ func LoadDT1(path string, fileProvider Common.FileProvider) *DT1 {
br.SkipBytes(2)
result.Tiles[tileIdx].Blocks[blockIdx].GridX = br.GetByte()
result.Tiles[tileIdx].Blocks[blockIdx].GridY = br.GetByte()
result.Tiles[tileIdx].Blocks[blockIdx].Format = BlockDataFormat(br.GetInt16())
formatValue := br.GetInt16()
if formatValue == 1 {
result.Tiles[tileIdx].Blocks[blockIdx].Format = BlockFormatIsometric
} else {
result.Tiles[tileIdx].Blocks[blockIdx].Format = BlockFormatRLE
}
result.Tiles[tileIdx].Blocks[blockIdx].Length = br.GetInt32()
br.SkipBytes(2)
result.Tiles[tileIdx].Blocks[blockIdx].FileOffset = br.GetInt32()

View File

@ -2,6 +2,7 @@ package Map
import (
"image"
"math/rand"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Sound"
@ -10,14 +11,16 @@ import (
type EngineRegion struct {
Rect image.Rectangle
Region Region
Region *Region
}
type Engine struct {
soundManager *Sound.Manager
gameState *Common.GameState
fileProvider Common.FileProvider
regions []*EngineRegion
regions []EngineRegion
OffsetX float64
OffsetY float64
}
func CreateMapEngine(gameState *Common.GameState, soundManager *Sound.Manager, fileProvider Common.FileProvider) *Engine {
@ -25,22 +28,31 @@ func CreateMapEngine(gameState *Common.GameState, soundManager *Sound.Manager, f
gameState: gameState,
soundManager: soundManager,
fileProvider: fileProvider,
regions: make([]*EngineRegion, 0),
regions: make([]EngineRegion, 0),
}
return result
}
func (v *Engine) GenerateMap(regionType RegionIdType, levelPreset int) {
//randomSource := rand.NewSource(v.gameState.Seed)
//region := LoadRegion(randomSource, regionType, levelPreset, v.fileProvider)
v.soundManager.PlayBGM("/data/global/music/Act1/tristram.wav")
v.ReloadMapCache()
}
func (v *Engine) ReloadMapCache() {
randomSource := rand.NewSource(v.gameState.Seed)
region := LoadRegion(randomSource, regionType, levelPreset, v.fileProvider)
v.regions = append(v.regions, EngineRegion{
Rect: image.Rectangle{image.Point{0, 0}, image.Point{int(region.TileWidth), int(region.TileHeight)}},
Region: region,
})
v.soundManager.PlayBGM("/data/global/music/Act1/tristram.wav") // TODO: Temp stuff here
}
func (v *Engine) Render(target *ebiten.Image) {
//v.region.RenderTile(300, 300, 0, 0, Map.RegionLayerTypeFloors, 0, screen)
// TODO: Temporary hack for testing
for y := 0; y < int(v.regions[0].Region.TileHeight); y++ {
offX := -(y * 80)
offY := y * 40
for x := 0; x < int(v.regions[0].Region.TileWidth); x++ {
v.regions[0].Region.RenderTile(400+offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeFloors, 0, target)
offX += 80
offY += 40
}
}
}

View File

@ -4,12 +4,21 @@ import (
"log"
"math"
"math/rand"
"strconv"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/hajimehoshi/ebiten"
"github.com/essial/OpenDiablo2/Common"
)
type TileCacheRecord struct {
Image *ebiten.Image
XOffset int
YOffset int
}
type Region struct {
levelType Common.LevelTypeRecord
levelPreset Common.LevelPresetRecord
@ -17,6 +26,8 @@ type Region struct {
TileHeight int32
Tiles []Tile
DS1 *DS1
Palette Common.PaletteRec
TileCache map[uint32]*TileCacheRecord
}
type RegionLayerType int
@ -71,8 +82,16 @@ func LoadRegion(seed rand.Source, levelType RegionIdType, levelPreset int, fileP
levelType: Common.LevelTypes[levelType],
levelPreset: Common.LevelPresets[levelPreset],
Tiles: make([]Tile, 0),
TileCache: make(map[uint32]*TileCacheRecord),
}
result.Palette = Common.Palettes[PaletteDefs.PaletteType("act"+strconv.Itoa(int(result.levelType.Act)))]
bm := result.levelPreset.Dt1Mask
for _, levelTypeDt1 := range result.levelType.Files {
if bm&1 == 0 {
bm >>= 1
continue
}
bm >>= 1
if len(levelTypeDt1) == 0 || levelTypeDt1 == "" || levelTypeDt1 == "0" {
continue
}
@ -105,21 +124,126 @@ func (v *Region) RenderTile(offsetX, offsetY, tileX, tileY int, layerType Region
}
}
func (v *Region) getTile(mainIndex, subIndex int32) Tile {
func (v *Region) getTile(mainIndex, subIndex, orientation int32) Tile {
// TODO: Need to support randomly grabbing tile based on x/y as there can be multiple matches for same main/sub index
for _, tile := range v.Tiles {
if tile.MainIndex != mainIndex || tile.SubIndex != subIndex {
if tile.MainIndex != mainIndex || tile.SubIndex != subIndex || tile.Orientation != orientation {
continue
}
return tile
}
log.Fatalf("Unknown tile ID [%d %d]", mainIndex, subIndex)
log.Fatalf("Unknown tile ID [%d %d %d]", mainIndex, subIndex, orientation)
return Tile{}
}
func (v *Region) renderFloor(tile FloorShadowRecord, offsetX, offsetY int, target *ebiten.Image) {
tileData := v.getTile(int32(tile.MainIndex), int32(tile.SubIndex))
log.Printf("Pro1: %d", tileData.Direction)
tileCacheIndex := (uint32(tile.MainIndex) << 16) + (uint32(tile.SubIndex) << 8)
tileCache := v.TileCache[tileCacheIndex]
if tileCache == nil {
v.TileCache[tileCacheIndex] = v.generateFloorCache(tile)
tileCache = v.TileCache[tileCacheIndex]
}
opts := &ebiten.DrawImageOptions{}
opts.GeoM.Translate(float64(offsetX+tileCache.XOffset), float64(offsetY+tileCache.YOffset))
target.DrawImage(tileCache.Image, opts)
}
func (v *Region) generateFloorCache(tile FloorShadowRecord) *TileCacheRecord {
var pixels []byte
tileData := v.getTile(int32(tile.MainIndex), int32(tile.SubIndex), 0)
tileYMinimum := int32(0)
for _, block := range tileData.Blocks {
tileYMinimum = Common.MinInt32(tileYMinimum, int32(block.Y))
}
tileYOffset := Common.AbsInt32(tileYMinimum)
tileHeight := Common.AbsInt32(tileData.Height)
image, _ := ebiten.NewImage(int(tileData.Width), int(tileHeight), ebiten.FilterNearest)
special := false
pixels = make([]byte, 4*tileData.Width*tileHeight)
for _, block := range tileData.Blocks {
// TODO: Move this to a less stupid place
if block.Format == BlockFormatIsometric {
// 3D isometric decoding
xjump := []int32{14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14}
nbpix := []int32{4, 8, 12, 16, 20, 24, 28, 32, 28, 24, 20, 16, 12, 8, 4}
blockX := int32(block.X)
blockY := int32(block.Y)
length := int32(256)
x := int32(0)
y := int32(0)
idx := 0
for length > 0 {
x = xjump[y]
n := nbpix[y]
length -= n
for n > 0 {
colorIndex := block.EncodedData[idx]
if colorIndex != 0 {
pixelColor := v.Palette.Colors[colorIndex]
pixels[(4 * (((blockY + y) * tileData.Width) + (blockX + x)))] = pixelColor.R
pixels[(4*(((blockY+y)*tileData.Width)+(blockX+x)))+1] = pixelColor.G
pixels[(4*(((blockY+y)*tileData.Width)+(blockX+x)))+2] = pixelColor.B
pixels[(4*(((blockY+y)*tileData.Width)+(blockX+x)))+3] = 255
} else {
pixels[(4*(((blockY+y)*tileData.Width)+(blockX+x)))+3] = 0
}
x++
n--
idx++
}
y++
}
} else {
// RLE Encoding
special = true
blockX := int32(block.X)
blockY := int32(block.Y)
x := int32(0)
y := int32(0)
idx := 0
length := block.Length
for length > 0 {
length -= 2
if (block.EncodedData[idx] + block.EncodedData[idx+1]) == 0 {
x = 0
y++
idx += 2
continue
}
length -= int32(block.EncodedData[idx+1])
x += int32(block.EncodedData[idx])
b2 := block.EncodedData[idx+1]
idx += 2
for b2 > 0 {
colorIndex := block.EncodedData[idx]
if colorIndex != 0 {
pixelColor := v.Palette.Colors[colorIndex]
pixels[(4 * (((blockY + y + tileYOffset) * tileData.Width) + (blockX + x)))] = pixelColor.R
pixels[(4*(((blockY+y+tileYOffset)*tileData.Width)+(blockX+x)))+1] = pixelColor.G
pixels[(4*(((blockY+y+tileYOffset)*tileData.Width)+(blockX+x)))+2] = pixelColor.B
pixels[(4*(((blockY+y+tileYOffset)*tileData.Width)+(blockX+x)))+3] = 255
} else {
pixels[(4*(((blockY+y+tileYOffset)*tileData.Width)+(blockX+x)))+3] = 0
}
idx++
x++
b2--
}
}
}
}
image.ReplacePixels(pixels)
yOffset := 0
if special {
yOffset = int(128 + tileData.Height)
}
return &TileCacheRecord{
image,
int(tileData.Width),
yOffset,
}
}
func (v *Region) renderWall(tile WallRecord, offsetX, offsetY int, target *ebiten.Image) {

View File

@ -0,0 +1,43 @@
package PaletteDefs
// PaletteType represents a named palette
type PaletteType string
const (
// Act1 palette
Act1 PaletteType = "act1"
// Act2 palette
Act2 PaletteType = "act2"
// Act3 palette
Act3 PaletteType = "act3"
// Act4 palette
Act4 PaletteType = "act4"
// Act5 palette
Act5 PaletteType = "act5"
// EndGame palette
EndGame PaletteType = "endgame"
// EndGame2 palette
EndGame2 PaletteType = "endgame2"
// Fechar palette
Fechar PaletteType = "fechar"
// Loading palette
Loading PaletteType = "loading"
// Menu0 palette
Menu0 PaletteType = "menu0"
// Menu1 palette
Menu1 PaletteType = "menu1"
// Menu2 palette
Menu2 PaletteType = "menu2"
// Menu3 palette
Menu3 PaletteType = "menu3"
// Menu4 palette
Menu4 PaletteType = "menu4"
// Sky palette
Sky PaletteType = "sky"
// Static palette
Static PaletteType = "static"
// Trademark palette
Trademark PaletteType = "trademark"
// Units palette
Units PaletteType = "units"
)

View File

@ -1,43 +0,0 @@
package Palettes
// Palette represents a named palette
type Palette string
const (
// Act1 palette
Act1 Palette = "act1"
// Act2 palette
Act2 Palette = "act2"
// Act3 palette
Act3 Palette = "act3"
// Act4 palette
Act4 Palette = "act4"
// Act5 palette
Act5 Palette = "act5"
// EndGame palette
EndGame Palette = "endgame"
// EndGame2 palette
EndGame2 Palette = "endgame2"
// Fechar palette
Fechar Palette = "fechar"
// Loading palette
Loading Palette = "loading"
// Menu0 palette
Menu0 Palette = "menu0"
// Menu1 palette
Menu1 Palette = "menu1"
// Menu2 palette
Menu2 Palette = "menu2"
// Menu3 palette
Menu3 Palette = "menu3"
// Menu4 palette
Menu4 Palette = "menu4"
// Sky palette
Sky Palette = "sky"
// Static palette
Static Palette = "static"
// Trademark palette
Trademark Palette = "trademark"
// Units palette
Units Palette = "units"
)

View File

@ -2,7 +2,7 @@ package Scenes
import (
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/ResourcePaths"
"github.com/essial/OpenDiablo2/Sound"
"github.com/essial/OpenDiablo2/UI"
@ -41,7 +41,7 @@ func (v *CharacterSelect) Load() []func() {
v.soundManager.PlayBGM(ResourcePaths.BGMTitle)
return []func(){
func() {
v.background = v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectionBackground, Palettes.Sky)
v.background = v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectionBackground, PaletteDefs.Sky)
v.background.MoveTo(0, 0)
},
func() {

View File

@ -5,7 +5,7 @@ import (
"strings"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/ResourcePaths"
"github.com/essial/OpenDiablo2/Sound"
"github.com/essial/OpenDiablo2/UI"
@ -52,7 +52,7 @@ func CreateCredits(fileProvider Common.FileProvider, sceneProvider SceneProvider
func (v *Credits) Load() []func() {
return []func(){
func() {
v.creditsBackground = v.fileProvider.LoadSprite(ResourcePaths.CreditsBackground, Palettes.Sky)
v.creditsBackground = v.fileProvider.LoadSprite(ResourcePaths.CreditsBackground, PaletteDefs.Sky)
v.creditsBackground.MoveTo(0, 0)
},
func() {
@ -87,7 +87,7 @@ func (v *Credits) Render(screen *ebiten.Image) {
}
}
const secondsPerCycle = (float64(40) / float64(1000))
const secondsPerCycle = float64(0.02)
// Update runs the update logic on the credits scene
func (v *Credits) Update(tickTime float64) {
@ -190,7 +190,7 @@ func (v *Credits) getNewFontLabel(isHeading bool) *UI.Label {
newLabelItem := &labelItem{
Available: false,
IsHeading: isHeading,
Label: UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal10, Palettes.Sky),
Label: UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal10, PaletteDefs.Sky),
}
if isHeading {

View File

@ -9,7 +9,7 @@ import (
"runtime"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/Sound"
"github.com/essial/OpenDiablo2/UI"
@ -61,52 +61,52 @@ func (v *MainMenu) Load() []func() {
v.soundManager.PlayBGM(ResourcePaths.BGMTitle)
return []func(){
func() {
v.copyrightLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal12, Palettes.Static)
v.copyrightLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal12, PaletteDefs.Static)
v.copyrightLabel.Alignment = UI.LabelAlignCenter
v.copyrightLabel.SetText("Diablo 2 is © Copyright 2000-2016 Blizzard Entertainment")
v.copyrightLabel.Color = color.RGBA{188, 168, 140, 255}
v.copyrightLabel.MoveTo(400, 500)
},
func() {
v.copyrightLabel2 = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal12, Palettes.Static)
v.copyrightLabel2 = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal12, PaletteDefs.Static)
v.copyrightLabel2.Alignment = UI.LabelAlignCenter
v.copyrightLabel2.SetText(Common.TranslateString("#1614"))
v.copyrightLabel2.Color = color.RGBA{188, 168, 140, 255}
v.copyrightLabel2.MoveTo(400, 525)
},
func() {
v.openDiabloLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal10, Palettes.Static)
v.openDiabloLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.FontFormal10, PaletteDefs.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() {
v.background = v.fileProvider.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky)
v.background = v.fileProvider.LoadSprite(ResourcePaths.GameSelectScreen, PaletteDefs.Sky)
v.background.MoveTo(0, 0)
},
func() {
v.trademarkBackground = v.fileProvider.LoadSprite(ResourcePaths.TrademarkScreen, Palettes.Sky)
v.trademarkBackground = v.fileProvider.LoadSprite(ResourcePaths.TrademarkScreen, PaletteDefs.Sky)
v.trademarkBackground.MoveTo(0, 0)
},
func() {
v.diabloLogoLeft = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units)
v.diabloLogoLeft = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, PaletteDefs.Units)
v.diabloLogoLeft.Blend = true
v.diabloLogoLeft.Animate = true
v.diabloLogoLeft.MoveTo(400, 120)
},
func() {
v.diabloLogoRight = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.Units)
v.diabloLogoRight = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoFireRight, PaletteDefs.Units)
v.diabloLogoRight.Blend = true
v.diabloLogoRight.Animate = true
v.diabloLogoRight.MoveTo(400, 120)
},
func() {
v.diabloLogoLeftBack = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units)
v.diabloLogoLeftBack = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, PaletteDefs.Units)
v.diabloLogoLeftBack.MoveTo(400, 120)
},
func() {
v.diabloLogoRightBack = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.Units)
v.diabloLogoRightBack = v.fileProvider.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, PaletteDefs.Units)
v.diabloLogoRightBack.MoveTo(400, 120)
},
func() {

View File

@ -18,7 +18,11 @@ type MapEngineTest struct {
mapEngine *Map.Engine
}
func CreateMapEngineTest(fileProvider Common.FileProvider, sceneProvider SceneProvider, uiManager *UI.Manager, soundManager *Sound.Manager) *MapEngineTest {
func CreateMapEngineTest(
fileProvider Common.FileProvider,
sceneProvider SceneProvider,
uiManager *UI.Manager,
soundManager *Sound.Manager) *MapEngineTest {
result := &MapEngineTest{
fileProvider: fileProvider,
uiManager: uiManager,
@ -50,5 +54,16 @@ func (v *MapEngineTest) Render(screen *ebiten.Image) {
}
func (v *MapEngineTest) Update(tickTime float64) {
if v.uiManager.KeyPressed(ebiten.KeyDown) {
v.mapEngine.OffsetY -= tickTime * 800
}
if v.uiManager.KeyPressed(ebiten.KeyUp) {
v.mapEngine.OffsetY += tickTime * 800
}
if v.uiManager.KeyPressed(ebiten.KeyLeft) {
v.mapEngine.OffsetX += tickTime * 800
}
if v.uiManager.KeyPressed(ebiten.KeyRight) {
v.mapEngine.OffsetX -= tickTime * 800
}
}

View File

@ -4,7 +4,7 @@ import (
"image"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/ResourcePaths"
"github.com/essial/OpenDiablo2/Sound"
"github.com/essial/OpenDiablo2/UI"
@ -73,38 +73,38 @@ func (v *SelectHeroClass) Load() []func() {
v.soundManager.PlayBGM(ResourcePaths.BGMTitle)
return []func(){
func() {
v.bgImage = v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBackground, Palettes.Fechar)
v.bgImage = v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBackground, PaletteDefs.Fechar)
v.bgImage.MoveTo(0, 0)
},
func() {
v.headingLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.Font30, Palettes.Units)
v.headingLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.Font30, PaletteDefs.Units)
fontWidth, _ := v.headingLabel.GetSize()
v.headingLabel.MoveTo(400-int(fontWidth/2), 17)
v.headingLabel.SetText("Select Hero Class")
v.headingLabel.Alignment = UI.LabelAlignCenter
},
func() {
v.heroClassLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.Font30, Palettes.Units)
v.heroClassLabel = UI.CreateLabel(v.fileProvider, ResourcePaths.Font30, PaletteDefs.Units)
v.heroClassLabel.Alignment = UI.LabelAlignCenter
v.heroClassLabel.MoveTo(400, 65)
},
func() {
v.heroDesc1Label = UI.CreateLabel(v.fileProvider, ResourcePaths.Font16, Palettes.Units)
v.heroDesc1Label = UI.CreateLabel(v.fileProvider, ResourcePaths.Font16, PaletteDefs.Units)
v.heroDesc1Label.Alignment = UI.LabelAlignCenter
v.heroDesc1Label.MoveTo(400, 100)
},
func() {
v.heroDesc2Label = UI.CreateLabel(v.fileProvider, ResourcePaths.Font16, Palettes.Units)
v.heroDesc2Label = UI.CreateLabel(v.fileProvider, ResourcePaths.Font16, PaletteDefs.Units)
v.heroDesc2Label.Alignment = UI.LabelAlignCenter
v.heroDesc2Label.MoveTo(400, 115)
},
func() {
v.heroDesc3Label = UI.CreateLabel(v.fileProvider, ResourcePaths.Font16, Palettes.Units)
v.heroDesc3Label = UI.CreateLabel(v.fileProvider, ResourcePaths.Font16, PaletteDefs.Units)
v.heroDesc3Label.Alignment = UI.LabelAlignCenter
v.heroDesc3Label.MoveTo(400, 130)
},
func() {
v.campfire = v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectCampfire, Palettes.Fechar)
v.campfire = v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectCampfire, PaletteDefs.Fechar)
v.campfire.MoveTo(380, 335)
v.campfire.Animate = true
v.campfire.Blend = true
@ -118,13 +118,13 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroBarbarian] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianForwardWalkOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianForwardWalk, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianForwardWalkOverlay, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianSelected, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectBarbarianBackWalk, PaletteDefs.Fechar),
nil,
image.Rectangle{Min: image.Point{364, 201}, Max: image.Point{90, 170}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXBarbarianSelect),
@ -152,14 +152,14 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroSorceress] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressForwardWalkOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressSelectedOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressBackWalkOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressForwardWalk, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressForwardWalkOverlay, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressSelected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressSelectedOverlay, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressBackWalk, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecSorceressBackWalkOverlay, PaletteDefs.Fechar),
image.Rectangle{Min: image.Point{580, 240}, Max: image.Point{65, 160}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXSorceressSelect),
v.soundManager.LoadSoundEffect(ResourcePaths.SFXSorceressDeselect),
@ -195,14 +195,14 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroNecromancer] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectNecromancerUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectNecromancerUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerForwardWalkOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerSelectedOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalkOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectNecromancerUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectNecromancerUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerForwardWalk, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerForwardWalkOverlay, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerSelected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerSelectedOverlay, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalk, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecNecromancerBackWalkOverlay, PaletteDefs.Fechar),
image.Rectangle{Min: image.Point{265, 220}, Max: image.Point{55, 175}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXNecromancerSelect),
v.soundManager.LoadSoundEffect(ResourcePaths.SFXNecromancerDeselect),
@ -238,13 +238,13 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroPaladin] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectPaladinUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectPaladinUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinForwardWalkOverlay, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectPaladinUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectPaladinUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinForwardWalk, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinForwardWalkOverlay, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinSelected, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecPaladinBackWalk, PaletteDefs.Fechar),
nil,
image.Rectangle{Min: image.Point{490, 210}, Max: image.Point{65, 180}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXPaladinSelect),
@ -272,13 +272,13 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroAmazon] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAmazonUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAmazonUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecAmazonForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAmazonUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAmazonUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecAmazonForwardWalk, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecAmazonSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecAmazonSelected, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecAmazonBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelecAmazonBackWalk, PaletteDefs.Fechar),
nil,
image.Rectangle{Min: image.Point{70, 220}, Max: image.Point{55, 200}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXAmazonSelect),
@ -302,13 +302,13 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroAssassin] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinForwardWalk, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinSelected, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectAssassinBackWalk, PaletteDefs.Fechar),
nil,
image.Rectangle{Min: image.Point{175, 235}, Max: image.Point{50, 180}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXAssassinSelect),
@ -332,13 +332,13 @@ func (v *SelectHeroClass) Load() []func() {
func() {
v.heroRenderInfo[Common.HeroDruid] = &HeroRenderInfo{
HeroStanceIdle,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidUnselected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidUnselectedH, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidForwardWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidUnselected, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidUnselectedH, PaletteDefs.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidForwardWalk, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidSelected, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidSelected, PaletteDefs.Fechar),
nil,
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidBackWalk, Palettes.Fechar),
v.fileProvider.LoadSprite(ResourcePaths.CharacterSelectDruidBackWalk, PaletteDefs.Fechar),
nil,
image.Rectangle{Min: image.Point{680, 220}, Max: image.Point{70, 195}},
v.soundManager.LoadSoundEffect(ResourcePaths.SFXDruidSelect),

View File

@ -5,7 +5,7 @@ import (
"image/color"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/ResourcePaths"
"github.com/hajimehoshi/ebiten"
)
@ -40,44 +40,44 @@ const (
// ButtonLayout defines the type of buttons
type ButtonLayout struct {
XSegments int //1
YSegments int // 1
ResourceName string // Font Name
PaletteName Palettes.Palette // Palette
Toggleable bool // false
BaseFrame int // 0
DisabledFrame int // -1
FontPath string // ResourcePaths.FontExocet10
ClickableRect *image.Rectangle // nil
AllowFrameChange bool // true
TextOffset int // 0
XSegments int //1
YSegments int // 1
ResourceName string // Font Name
PaletteName PaletteDefs.PaletteType // PaletteType
Toggleable bool // false
BaseFrame int // 0
DisabledFrame int // -1
FontPath string // ResourcePaths.FontExocet10
ClickableRect *image.Rectangle // nil
AllowFrameChange bool // true
TextOffset int // 0
}
// ButtonLayouts define the type of buttons you can have
var ButtonLayouts = map[ButtonType]ButtonLayout{
ButtonTypeWide: {2, 1, ResourcePaths.WideButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true, 1},
ButtonTypeShort: {1, 1, ResourcePaths.ShortButtonBlank, Palettes.Units, false, 0, -1, ResourcePaths.FontRediculous, nil, true, -1},
ButtonTypeMedium: {1, 1, ResourcePaths.MediumButtonBlank, Palettes.Units, false, 0, 0, ResourcePaths.FontExocet10, nil, true, 0},
ButtonTypeTall: {1, 1, ResourcePaths.TallButtonBlank, Palettes.Units, false, 0, 0, ResourcePaths.FontExocet10, nil, true, 5},
ButtonTypeWide: {2, 1, ResourcePaths.WideButtonBlank, PaletteDefs.Units, false, 0, -1, ResourcePaths.FontExocet10, nil, true, 1},
ButtonTypeShort: {1, 1, ResourcePaths.ShortButtonBlank, PaletteDefs.Units, false, 0, -1, ResourcePaths.FontRediculous, nil, true, -1},
ButtonTypeMedium: {1, 1, ResourcePaths.MediumButtonBlank, PaletteDefs.Units, false, 0, 0, ResourcePaths.FontExocet10, nil, true, 0},
ButtonTypeTall: {1, 1, ResourcePaths.TallButtonBlank, PaletteDefs.Units, false, 0, 0, ResourcePaths.FontExocet10, nil, true, 5},
/*
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Narrow, new ButtonLayout { ResourceName = ResourcePaths.NarrowButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Cancel, new ButtonLayout { ResourceName = ResourcePaths.CancelButton, PaletteName = Palettes.Units } },
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = PaletteDefs.Units } },
{eButtonType.Narrow, new ButtonLayout { ResourceName = ResourcePaths.NarrowButtonBlank, PaletteName = PaletteDefs.Units } },
{eButtonType.Cancel, new ButtonLayout { ResourceName = ResourcePaths.CancelButton, PaletteName = PaletteDefs.Units } },
// Minipanel
{eButtonType.MinipanelCharacter, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 0 } },
{eButtonType.MinipanelInventory, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 2 } },
{eButtonType.MinipanelSkill, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 4 } },
{eButtonType.MinipanelAutomap, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 8 } },
{eButtonType.MinipanelMessage, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 10 } },
{eButtonType.MinipanelQuest, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 12 } },
{eButtonType.MinipanelMenu, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = Palettes.Units, BaseFrame = 14 } },
{eButtonType.MinipanelCharacter, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 0 } },
{eButtonType.MinipanelInventory, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 2 } },
{eButtonType.MinipanelSkill, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 4 } },
{eButtonType.MinipanelAutomap, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 8 } },
{eButtonType.MinipanelMessage, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 10 } },
{eButtonType.MinipanelQuest, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 12 } },
{eButtonType.MinipanelMenu, new ButtonLayout { ResourceName = ResourcePaths.MinipanelButton, PaletteName = PaletteDefs.Units, BaseFrame = 14 } },
{eButtonType.SecondaryInvHand, new ButtonLayout { ResourceName = ResourcePaths.InventoryWeaponsTab, PaletteName = Palettes.Units, ClickableRect = new Rectangle(0, 0, 0, 20), AllowFrameChange = false } },
{eButtonType.Run, new ButtonLayout { ResourceName = ResourcePaths.RunButton, PaletteName = Palettes.Units, Toggleable = true } },
{eButtonType.Menu, new ButtonLayout { ResourceName = ResourcePaths.MenuButton, PaletteName = Palettes.Units, Toggleable = true } },
{eButtonType.GoldCoin, new ButtonLayout { ResourceName = ResourcePaths.GoldCoinButton, PaletteName = Palettes.Units } },
{eButtonType.Close, new ButtonLayout { ResourceName = ResourcePaths.SquareButton, PaletteName = Palettes.Units, BaseFrame = 10 } },
{eButtonType.Skill, new ButtonLayout { ResourceName = ResourcePaths.AddSkillButton, PaletteName = Palettes.Units, DisabledFrame = 2
{eButtonType.SecondaryInvHand, new ButtonLayout { ResourceName = ResourcePaths.InventoryWeaponsTab, PaletteName = PaletteDefs.Units, ClickableRect = new Rectangle(0, 0, 0, 20), AllowFrameChange = false } },
{eButtonType.Run, new ButtonLayout { ResourceName = ResourcePaths.RunButton, PaletteName = PaletteDefs.Units, Toggleable = true } },
{eButtonType.Menu, new ButtonLayout { ResourceName = ResourcePaths.MenuButton, PaletteName = PaletteDefs.Units, Toggleable = true } },
{eButtonType.GoldCoin, new ButtonLayout { ResourceName = ResourcePaths.GoldCoinButton, PaletteName = PaletteDefs.Units } },
{eButtonType.Close, new ButtonLayout { ResourceName = ResourcePaths.SquareButton, PaletteName = PaletteDefs.Units, BaseFrame = 10 } },
{eButtonType.Skill, new ButtonLayout { ResourceName = ResourcePaths.AddSkillButton, PaletteName = PaletteDefs.Units, DisabledFrame = 2
*/
}
@ -111,7 +111,7 @@ func CreateButton(buttonType ButtonType, fileProvider Common.FileProvider, text
}
buttonLayout := ButtonLayouts[buttonType]
result.buttonLayout = buttonLayout
font := GetFont(buttonLayout.FontPath, Palettes.Units, fileProvider)
font := GetFont(buttonLayout.FontPath, PaletteDefs.Units, fileProvider)
buttonSprite := fileProvider.LoadSprite(buttonLayout.ResourceName, buttonLayout.PaletteName)
totalButtonTypes := buttonSprite.GetTotalFrames() / (buttonLayout.XSegments * buttonLayout.YSegments)
for i := 0; i < buttonLayout.XSegments; i++ {

View File

@ -5,7 +5,7 @@ import (
"strings"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/hajimehoshi/ebiten"
)
@ -24,7 +24,7 @@ type Font struct {
}
// GetFont creates or loads an existing font
func GetFont(font string, palette Palettes.Palette, fileProvider Common.FileProvider) *Font {
func GetFont(font string, palette PaletteDefs.PaletteType, fileProvider Common.FileProvider) *Font {
cacheItem, exists := fontCache[font+"_"+string(palette)]
if exists {
return cacheItem
@ -35,7 +35,7 @@ func GetFont(font string, palette Palettes.Palette, fileProvider Common.FileProv
}
// CreateFont creates an instance of a MPQ Font
func CreateFont(font string, palette Palettes.Palette, fileProvider Common.FileProvider) *Font {
func CreateFont(font string, palette PaletteDefs.PaletteType, fileProvider Common.FileProvider) *Font {
result := &Font{
metrics: make(map[uint8]FontSize),
}

View File

@ -4,7 +4,7 @@ import (
"image/color"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/hajimehoshi/ebiten"
)
@ -34,7 +34,7 @@ type Label struct {
}
// CreateLabel creates a new instance of a UI label
func CreateLabel(provider Common.FileProvider, font string, palette Palettes.Palette) *Label {
func CreateLabel(provider Common.FileProvider, font string, palette PaletteDefs.PaletteType) *Label {
result := &Label{
Alignment: LabelAlignLeft,
Color: color.White,

View File

@ -2,7 +2,7 @@ package UI
import (
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Palettes"
"github.com/essial/OpenDiablo2/PaletteDefs"
"github.com/essial/OpenDiablo2/ResourcePaths"
"github.com/essial/OpenDiablo2/Sound"
"github.com/hajimehoshi/ebiten"
@ -35,7 +35,7 @@ func CreateManager(fileProvider Common.FileProvider, soundManager Sound.Manager)
result := &Manager{
pressedIndex: -1,
widgets: make([]Widget, 0),
cursorSprite: fileProvider.LoadSprite(ResourcePaths.CursorDefault, Palettes.Units),
cursorSprite: fileProvider.LoadSprite(ResourcePaths.CursorDefault, PaletteDefs.Units),
clickSfx: soundManager.LoadSoundEffect(ResourcePaths.SFXButtonClick),
waitForLeftMouseUp: false,
}
@ -142,3 +142,7 @@ func (v *Manager) Update() {
func (v *Manager) CursorButtonPressed(button CursorButton) bool {
return v.cursorButtons&button > 0
}
func (v *Manager) KeyPressed(key ebiten.Key) bool {
return ebiten.IsKeyPressed(key)
}