Skip to content

Commit

Permalink
Merge pull request #72 from jramstedt/more-features
Browse files Browse the repository at this point in the history
More features
  • Loading branch information
dertseha authored Oct 26, 2024
2 parents 2c0556e + f126dae commit 60d7185
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 30 deletions.
217 changes: 217 additions & 0 deletions editor/levels/ObjectsView.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,223 @@ func (view *ObjectsView) renderPropertyControl(lvl *level.Level, readOnly bool,
})
})

simplifier.SetSpecialHandler("MultiAnimation", func() {
/*
animationTypes := []string{"Random"}
selectedType := -1
if unifier.IsUnique() {
value := int(unifier.Unified().(int32))
selectedType = value >> 12
}
values.RenderUnifiedCombo(readOnly, key+"###"+fullKey+"-Type", unifier,
func(u values.Unifier) int {
key := unifier.Unified().(int32)
return int(key >> 12)
},
func(index int) string { return animationTypes[index] },
len(animationTypes),
func(newIndex int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0xF000)
result |= uint32(newIndex<<12) & uint32(0xF000)
return result
})
})
*/

// if selectedType == 0 {
values.RenderUnifiedSliderInt(readOnly, key+" infrequency###"+fullKey+"-infrequency", unifier,
func(u values.Unifier) int {
key := unifier.Unified().(int32)
return int(key & 0x0FFF)
},
func(value int) string { return "%d" },
0, 0x0FFF,
func(newValue int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x0FFF)
result |= uint32(newValue) & uint32(0x0FFF)
return result
})
})
//}
})

simplifier.SetSpecialHandler("PictureSource", func() {
indexConverter := func(u values.Unifier) int { return int(u.Unified().(int32)) & 0x007F }
indexUpdater := func(newValue int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x007F)
result |= uint32(newValue) & uint32(0x007F)
return result
})
}

sourceType := []string{"Data", "ObjectID"}
selectedType := -1
if unifier.IsUnique() {
value := int(unifier.Unified().(int32))
selectedType = (value & 0x1000) >> 12
}

imgui.Separator()
imgui.Text(key + ":")

values.RenderUnifiedCombo(readOnly, "Source###"+fullKey+"-Source", unifier,
func(u values.Unifier) int {
key := unifier.Unified().(int32)
return int((key & 0x1000) >> 12)
},
func(index int) string { return sourceType[index] },
len(sourceType),
func(newIndex int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x1000)
result |= uint32(newIndex<<12) & uint32(0x1000)
return result
})
})

if selectedType == 0 {
dataType := []string{"Screen", "Custom", "Text", "Scrolling Text"}
textureData := -1
index := -1
selectedDataType := -1

if unifier.IsUnique() {
value := int(unifier.Unified().(int32))
textureData = value & 0x0FFF
index = textureData & 0x007F
selectedDataType = (value & 0x0180) >> 7
}

values.RenderUnifiedCombo(readOnly, "Type###"+fullKey+"-Type", unifier,
func(u values.Unifier) int {
key := unifier.Unified().(int32)
return int((key & 0x0180) >> 7)
},
func(index int) string { return dataType[index] },
len(dataType),
func(newIndex int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x0180)
result |= uint32(newIndex<<7) & uint32(0x0180)
return result
})
})

if selectedDataType == 0 { // Screen
resInfo, _ := ids.Info(ids.ScreenTextures)

values.RenderUnifiedSliderInt(readOnly, "Index###"+fullKey+"-Index", unifier,
indexConverter,
func(value int) string { return "%d" },
0, resInfo.MaxCount-1,
indexUpdater)

render.TextureSelector(key+"-Screen###"+fullKey+"-Screen", -1, view.guiScale, resInfo.MaxCount, index,
view.textureCache,
func(index int) resource.Key {
return resource.KeyOf(ids.ScreenTextures.Plus(index), resource.LangAny, 0)
},
func(index int) string { return fmt.Sprintf("%3d", index) },
func(index int) {
if !readOnly {
indexUpdater(index)
}
})
} else if selectedDataType == 1 { // Custom
values.RenderUnifiedSliderInt(readOnly, "Index###"+fullKey+"-Index", unifier,
indexConverter,
func(value int) string {
if value >= 0x78 && value <= (0x78+8) {
return "%d - Camera"
} else if value == 0x77 {
return "%d - Static"
} else if value == 0x76 {
return "%d - SHODAN Proximity"
} else if value >= 0x70 && value <= (0x70+6) {
return "%d - Automap"
} else {
return "%d"
}
},
0, 0x007F,
indexUpdater)

resInfo, _ := ids.Info(ids.ObjectMaterialBitmaps)
if index < resInfo.MaxCount {
render.TextureImage("Preview", view.textureCache, resource.KeyOf(ids.ObjectMaterialBitmaps.Plus(index), resource.LangAny, 0), imgui.Vec2{X: 64 * view.guiScale, Y: 64 * view.guiScale})
}
} else if selectedDataType == 2 { // Text
values.RenderUnifiedSliderInt(readOnly, "Index###"+fullKey+"-Index", unifier,
indexConverter,
func(value int) string {
if value == 0x007F {
return "%d - (Random number)"
} else {
return "%d"
}
},
0, 0x007F,
indexUpdater)
} else if selectedDataType == 3 { // Scrolling Text
values.RenderUnifiedSliderInt(readOnly, "Index###"+fullKey+"-Index", unifier,
indexConverter,
func(value int) string { return "%d" },
0, 0x007F,
indexUpdater)
}

if selectedDataType == 2 || selectedDataType == 3 {
fontNames := []string{"Large Tech", "Small Tech"}
values.RenderUnifiedCombo(readOnly, "Font###"+fullKey+"-Font", unifier,
func(u values.Unifier) int {
key := unifier.Unified().(int32)
return int((key & 0x0800) >> 11)
},
func(value int) string { return fontNames[value] },
len(fontNames),
func(newValue int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x0800)
result |= uint32(newValue<<11) & uint32(0x0800)
return result
})
})
}

values.RenderUnifiedSliderInt(readOnly, "Scale###"+fullKey+"-Scale", unifier,
func(u values.Unifier) int {
key := unifier.Unified().(int32)
return int((key & 0x0600) >> 9)
},
func(value int) string { return "%d" },
0, 3,
func(newValue int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x0600)
result |= uint32(newValue<<9) & uint32(0x0600)
return result
})
})
} else {
// Indirection to another object
values.RenderUnifiedSliderInt(readOnly, "ObjectID###"+fullKey+"-Object", unifier,
func(u values.Unifier) int { return int(u.Unified().(int32)) & 0x0FFF },
func(value int) string { return "%d" },
0, lvl.ObjectCapacity(),
func(newValue int) {
updater(func(oldValue uint32) uint32 {
result := oldValue & ^uint32(0x0FFF)
result |= uint32(newValue) & uint32(0x0FFF)
return result
})
})
}
})

describer(simplifier)
}

Expand Down
29 changes: 20 additions & 9 deletions editor/levels/TilesView.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (view *TilesView) renderContent(lvl *level.Level, tiles []*level.TileMapEnt
ceilingHeightUnifier := values.NewUnifier()
slopeHeightUnifier := values.NewUnifier()
slopeControlUnifier := values.NewUnifier()
musicIndexUnifier := values.NewUnifier()
musicZoneUnifier := values.NewUnifier()

floorPaletteIndexUnifier := values.NewUnifier()
ceilingPaletteIndexUnifier := values.NewUnifier()
Expand All @@ -113,6 +113,7 @@ func (view *TilesView) renderContent(lvl *level.Level, tiles []*level.TileMapEnt
ceilingLightUnifier := values.NewUnifier()
ceilingLightDeltaUnifier := values.NewUnifier()
deconstructedUnifier := values.NewUnifier()
perildUnifier := values.NewUnifier()
floorHazardUnifier := values.NewUnifier()
ceilingHazardUnifier := values.NewUnifier()

Expand All @@ -122,7 +123,8 @@ func (view *TilesView) renderContent(lvl *level.Level, tiles []*level.TileMapEnt
ceilingHeightUnifier.Add(tile.Ceiling.AbsoluteHeight())
slopeHeightUnifier.Add(tile.SlopeHeight)
slopeControlUnifier.Add(tile.Flags.SlopeControl())
musicIndexUnifier.Add(tile.Flags.MusicIndex())
musicZoneUnifier.Add(tile.Flags.MusicZone())
perildUnifier.Add(tile.Flags.Peril())
if isCyberspace {
floorPaletteIndexUnifier.Add(tile.TextureInfo.FloorPaletteIndex())
ceilingPaletteIndexUnifier.Add(tile.TextureInfo.CeilingPaletteIndex())
Expand Down Expand Up @@ -180,11 +182,14 @@ func (view *TilesView) renderContent(lvl *level.Level, tiles []*level.TileMapEnt
func(value int) string { return slopeControls[value].String() },
len(slopeControls),
func(newValue int) { view.changeTiles(setSlopeControlTo(slopeControls[newValue])) })
values.RenderUnifiedSliderInt(readOnly, "Music Index", musicIndexUnifier,
func(u values.Unifier) int { return u.Unified().(int) },
func(value int) string { return "%d" },
0, 15,
func(newValue int) { view.changeTiles(setMusicIndexTo(newValue)) })
musicZones := level.TileMusicZones()
values.RenderUnifiedCombo(readOnly, "Music Zone", musicZoneUnifier,
func(u values.Unifier) int { return int(u.Unified().(level.TileMusicZone)) },
func(value int) string { return musicZones[value].String() },
len(musicZones),
func(newValue int) { view.changeTiles(setMusicZoneTo(musicZones[newValue])) })
values.RenderUnifiedCheckboxCombo(readOnly, "Music Peril", perildUnifier,
func(newValue bool) { view.changeTiles(setPerilTo(newValue)) })

imgui.Separator()

Expand Down Expand Up @@ -400,9 +405,15 @@ func setSlopeControlTo(value level.TileSlopeControl) tileMapEntryModifier {
}
}

func setMusicIndexTo(value int) tileMapEntryModifier {
func setPerilTo(value bool) tileMapEntryModifier {
return func(tile *level.TileMapEntry) {
tile.Flags = tile.Flags.WithMusicIndex(value)
tile.Flags = tile.Flags.WithPeril(value)
}
}

func setMusicZoneTo(value level.TileMusicZone) tileMapEntryModifier {
return func(tile *level.TileMapEntry) {
tile.Flags = tile.Flags.WithMusicZone(value)
}
}

Expand Down
81 changes: 72 additions & 9 deletions ss1/content/archive/level/TileFlag.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package level

import "fmt"

// TileFlag describes simple properties of a map tile.
type TileFlag uint32

Expand All @@ -19,17 +21,28 @@ func (flag TileFlag) ForCyberspace() CyberspaceFlag {
return CyberspaceFlag(flag)
}

// MusicIndex returns the music identifier. Range: [0..15].
func (flag TileFlag) MusicIndex() int {
return int((flag & 0x0000F000) >> 12)
// MusicZone returns the music zone.
func (flag TileFlag) MusicZone() TileMusicZone {
return TileMusicZone((flag & 0x0000E000) >> 13)
}

// WithMusicIndex returns a new flag value with the given music index set. Values beyond allowed range are ignored.
func (flag TileFlag) WithMusicIndex(value int) TileFlag {
if (value < 0) || (value > 15) {
return flag
// WithMusicZone returns a new flag value with the given music index set.
func (flag TileFlag) WithMusicZone(value TileMusicZone) TileFlag {
return TileFlag(uint32(flag&^0x0000E000) | (uint32(value) << 13))
}

// Peril returns whether the tile is marked as peril (may play peril music).
func (flag TileFlag) Peril() bool {
return (flag & 0x00001000) != 0
}

// WithPeril returns a flag with the given peril set.
func (flag TileFlag) WithPeril(value bool) TileFlag {
var valueFlag uint32
if value {
valueFlag = 0x00001000
}
return TileFlag(uint32(flag&^0x0000F000) | (uint32(value) << 12))
return TileFlag(uint32(flag&^0x00001000) | valueFlag)
}

// SlopeControl returns the slope control as per flags.
Expand Down Expand Up @@ -126,7 +139,7 @@ func (flag RealWorldFlag) TileVisited() bool {
return (flag & 0x80000000) != 0
}

// WithTileVisited returns a flag with the given deconstruction set.
// WithTileVisited returns a flag with the given visited set.
func (flag RealWorldFlag) WithTileVisited(value bool) RealWorldFlag {
var valueFlag uint32
if value {
Expand Down Expand Up @@ -162,3 +175,53 @@ func (flag CyberspaceFlag) WithFlightPull(value CyberspaceFlightPull) Cyberspace
newFlag |= uint32(value&0x10) << 20
return CyberspaceFlag(newFlag)
}

type TileMusicZone byte

const (
TileMusicZoneNoMusic TileMusicZone = 0
TileMusicZoneHospital TileMusicZone = 1
TileMusicZoneExecutive TileMusicZone = 2
TileMusicZoneIndustrial TileMusicZone = 3
TileMusicZoneMetal TileMusicZone = 4
TileMusicZonePark TileMusicZone = 5
TileMusicZoneBridge TileMusicZone = 6
TileMusicZoneElevator TileMusicZone = 7
)

// TileSlopeControls returns all control values.
func TileMusicZones() []TileMusicZone {
return []TileMusicZone{
TileMusicZoneNoMusic,
TileMusicZoneHospital,
TileMusicZoneExecutive,
TileMusicZoneIndustrial,
TileMusicZoneMetal,
TileMusicZonePark,
TileMusicZoneBridge,
TileMusicZoneElevator,
}
}

func (ctrl TileMusicZone) String() string {
switch ctrl {
case TileMusicZoneNoMusic:
return "No Music"
case TileMusicZoneHospital:
return "Hospital"
case TileMusicZoneExecutive:
return "Executive"
case TileMusicZoneIndustrial:
return "Industrial"
case TileMusicZoneMetal:
return "Metal"
case TileMusicZonePark:
return "Park"
case TileMusicZoneBridge:
return "Bridge"
case TileMusicZoneElevator:
return "Elevator"
default:
return fmt.Sprintf("Unknown%02X", int(ctrl))
}
}
Loading

0 comments on commit 60d7185

Please sign in to comment.