mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-07-05 12:45:23 +00:00
* export d2asset singleton * add *d2asset.AssetManager to d2app - d2app now has a reference to an asset manager which it will use for loading - added asset loader methods to the asset manager - functions in d2asset are now wrappers for asset manager methods * add asset manager reference to audio provider - d2app asset manager reference is now passed to audio provider - asset manager is created in main.go for now to pass into audio provider - CreateSoundEffect is now a method, no longer exported, uses the asset manager reference * d2app passes asset manager refence to map engine test * in d2asset, all calls to LoadFile replaced with call to Singleton.Loadfile * blizzard intro and credits screen - d2app passes reference to the asset manager to these screens * asset manager for d2map - adding MapStampFactory, takes an asset manager reference - embedded MapStampFactory into the MapEngine - LoadStamp is now a method of the MapStampFactory * d2asset: removed LoadFileStream, LoadFile, and FileExists * d2gui changes - singleton now has an asset manager reference - calls to d2asset loader functions removed - createButton is now a method of LayoutManager - moved LayoutEntry to its own file * map entity factory - Map engine has an embedded map entity factory - Map stamp factory gets a reference to the map engine's entity factory - Stamps are given a reference to the map engine entity factory when created - Character select gets a map entity factory - Embedded the stamp factory into the MapEngine * asset manager for d2ui - d2ui is passed an asset manager reference when created - all calls to d2asset loader functions in d2ui now refer to the asset manager - d2gamescreen gets a ui manager when created - help overlay is now passed a ui manager when created * d2gamescreen + d2player: asset manager references added an asset manager reference to - inventory panel + inventory grid - mini panel - game controls - help overlay - character select - main menu - select hero class - hero stats panel * Removed d2asset.LoadAnimation all references to this function have been replaced with calls to the asset manager method * adding asset to help overlay, bugfix for 4d59c91 * Removed d2asset.LoadFont and d2asset.LoadAnimationWithEffect all references to these have been replaced with calls to the asset manager methods * MapRenderer now gets an asset manager reference * removed d2asset.LoadPalette all references have been replaced with calls to an asset manager instance * merged d2object with d2mapentity d2object was only being used to create objects in the map, so the provider function is now a method of the map entity factory. calls to d2asset have been removed. * removed d2asset.LoadComposite all calls are now made to the asset manager method * removed d2asset singleton all singleton references have been removed, a single instance of the asset manager is passed around the entire app * rename Initialize to NewAssetManager
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package d2gui
|
|
|
|
import (
|
|
"errors"
|
|
"image/color"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
|
)
|
|
|
|
func loadFont(fontStyle FontStyle) (d2interface.Font, error) {
|
|
config := getFontStyleConfig(fontStyle)
|
|
if config == nil {
|
|
return nil, errors.New("invalid font style")
|
|
}
|
|
|
|
return singleton.asset.LoadFont(config.fontBasePath+".tbl", config.fontBasePath+".dc6",
|
|
config.palettePath)
|
|
}
|
|
|
|
func renderSegmented(animation d2interface.Animation, segmentsX, segmentsY, frameOffset int,
|
|
target d2interface.Surface) error {
|
|
var currentY int
|
|
|
|
for y := 0; y < segmentsY; y++ {
|
|
var currentX, maxHeight int
|
|
|
|
for x := 0; x < segmentsX; x++ {
|
|
if err := animation.SetCurrentFrame(x + y*segmentsX + frameOffset*segmentsX*segmentsY); err != nil {
|
|
return err
|
|
}
|
|
|
|
target.PushTranslation(x+currentX, y+currentY)
|
|
err := animation.Render(target)
|
|
target.Pop()
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
width, height := animation.GetCurrentFrameSize()
|
|
maxHeight = d2math.MaxInt(maxHeight, height)
|
|
currentX += width
|
|
}
|
|
|
|
currentY += maxHeight
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func half(n int) int {
|
|
return n / 2
|
|
}
|
|
|
|
func rgbaColor(rgba uint32) color.RGBA {
|
|
result := color.RGBA{}
|
|
a, b, g, r := 0, 1, 2, 3
|
|
byteWidth := 8
|
|
byteMask := 0xff
|
|
|
|
for idx := 0; idx < 4; idx++ {
|
|
shift := idx * byteWidth
|
|
component := uint8(rgba>>shift) & uint8(byteMask)
|
|
|
|
switch idx {
|
|
case a:
|
|
result.A = component
|
|
case b:
|
|
result.B = component
|
|
case g:
|
|
result.G = component
|
|
case r:
|
|
result.R = component
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|