diff --git a/indigo/sandbox/assets/platform.png b/indigo/sandbox/assets/platform.png new file mode 100644 index 000000000..83e4dd80d Binary files /dev/null and b/indigo/sandbox/assets/platform.png differ diff --git a/indigo/sandbox/assets/window.png b/indigo/sandbox/assets/window.png new file mode 100644 index 000000000..f0baf315d Binary files /dev/null and b/indigo/sandbox/assets/window.png differ diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxAssets.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxAssets.scala index b8979ef1b..570dd0254 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxAssets.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxAssets.scala @@ -17,7 +17,11 @@ object SandboxAssets { val light: AssetName = AssetName("light") val dots: AssetName = AssetName("dots") val cameraIcon: AssetName = AssetName("camera_icon") - val nineSlice: AssetName = AssetName("nineslice") + + // NineSlice assets + val nineSlice: AssetName = AssetName("nineslice") + val platform: AssetName = AssetName("platform") + val window: AssetName = AssetName("window") val fontMaterial: Material.ImageEffects = Material.ImageEffects(smallFontName) val lightMaterial: Material.ImageEffects = Material.ImageEffects(light) @@ -98,7 +102,9 @@ object SandboxAssets { AssetType.Image(cratesDiffuseName, AssetPath("assets/" + cratesDiffuseName + ".png")), AssetType.Image(cratesNormalName, AssetPath("assets/" + cratesNormalName + ".png")), AssetType.Image(cameraIcon, AssetPath("assets/camera_icon.png")), - AssetType.Image(nineSlice, AssetPath("assets/nineslice.png")) + AssetType.Image(nineSlice, AssetPath("assets/nineslice.png")), + AssetType.Image(platform, AssetPath("assets/platform.png")), + AssetType.Image(window, AssetPath("assets/window.png")) ) } diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala index d4fd2cf5b..b1aed9845 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala @@ -16,6 +16,7 @@ import com.example.sandbox.scenes.LightsScene import com.example.sandbox.scenes.LineReflectionScene import com.example.sandbox.scenes.ManyEventHandlers import com.example.sandbox.scenes.MutantsScene +import com.example.sandbox.scenes.NineSliceScene import com.example.sandbox.scenes.OriginalScene import com.example.sandbox.scenes.PathFindingScene import com.example.sandbox.scenes.PointersScene @@ -52,7 +53,7 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb val viewportHeight: Int = gameHeight * magnificationLevel // 256 def initialScene(bootData: SandboxBootData): Option[SceneName] = - Some(TextureTileScene.name) + Some(NineSliceScene.name) def scenes(bootData: SandboxBootData): NonEmptyList[Scene[SandboxStartupData, SandboxGameModel, SandboxViewModel]] = NonEmptyList( @@ -80,7 +81,8 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb LineReflectionScene, CameraWithCloneTilesScene, PathFindingScene, - CaptureScreenScene + CaptureScreenScene, + NineSliceScene ) val eventFilters: EventFilters = EventFilters.Permissive diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/NineSliceScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/NineSliceScene.scala new file mode 100644 index 000000000..5e708a7c1 --- /dev/null +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/NineSliceScene.scala @@ -0,0 +1,91 @@ +package com.example.sandbox.scenes + +import com.example.sandbox.SandboxAssets +import com.example.sandbox.SandboxGameModel +import com.example.sandbox.SandboxStartupData +import com.example.sandbox.SandboxViewModel +import indigo._ +import indigo.scenes._ +import indigoextras.effectmaterials.Refraction + +object NineSliceScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxViewModel] { + + type SceneModel = SandboxGameModel + type SceneViewModel = SandboxViewModel + + def eventFilters: EventFilters = + EventFilters.Restricted + + def modelLens: Lens[SandboxGameModel, SandboxGameModel] = + Lens.keepOriginal + + def viewModelLens: Lens[SandboxViewModel, SandboxViewModel] = + Lens.keepOriginal + + def name: SceneName = + SceneName("nine slice scene") + + def subSystems: Set[SubSystem[SandboxGameModel]] = + Set() + + def updateModel( + context: SceneContext[SandboxStartupData], + model: SandboxGameModel + ): GlobalEvent => Outcome[SandboxGameModel] = + _ => Outcome(model) + + def updateViewModel( + context: SceneContext[SandboxStartupData], + model: SandboxGameModel, + viewModel: SandboxViewModel + ): GlobalEvent => Outcome[SandboxViewModel] = + _ => Outcome(viewModel) + + def fit(originalSize: Vector2, screenSize: Vector2): Vector2 = + Vector2(Math.max(screenSize.x / originalSize.x, screenSize.y / originalSize.y)) + + def boxSize(t: Seconds): Int = Signal.SmoothPulse.map(d => (d * 64) + 32).map(_.toInt).at(t) + + def present( + context: SceneContext[SandboxStartupData], + model: SandboxGameModel, + viewModel: SandboxViewModel + ): Outcome[SceneUpdateFragment] = { + val viewCenter: Point = context.startUpData.viewportCenter + + val boxSizeValue: Int = boxSize(context.frame.time.running) + + Outcome( + SceneUpdateFragment.empty + .addLayers( + Layer( + Graphic( + boxSizeValue, + boxSizeValue, + Material.Bitmap(SandboxAssets.nineSlice).nineSlice(Rectangle(16, 16, 32, 32)) + ).moveTo(5, 5), + // Shape + // .Box(Rectangle(boxSizeValue, boxSizeValue), Fill.None, Stroke(1, RGBA.Green)) + // .moveTo(5, 5), + Graphic( + boxSizeValue, + boxSizeValue, + Material.Bitmap(SandboxAssets.platform).nineSlice(Rectangle(8, 20, 112, 40)) + ).moveTo(100, 5), + // Shape + // .Box(Rectangle(boxSizeValue, boxSizeValue), Fill.None, Stroke(1, RGBA.Green)) + // .moveTo(75, 5), + Graphic( + boxSizeValue, + boxSizeValue, + Material.Bitmap(SandboxAssets.window).nineSlice(Rectangle(3, 15, 121, 41)) + ).moveTo(5, 100) + // Shape + // .Box(Rectangle(boxSizeValue, boxSizeValue), Fill.None, Stroke(1, RGBA.Green)) + // .moveTo(5, 75), + ) + ) + ) + } + +} diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextureTileScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextureTileScene.scala index bbd4b0e8d..08d3bc00b 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextureTileScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextureTileScene.scala @@ -66,15 +66,7 @@ object TextureTileScene extends Scene[SandboxStartupData, SandboxGameModel, Sand .modifyMaterial(_.withAlpha(0.2)), Graphic(64, 64, Material.Bitmap(SandboxAssets.dots).normal).moveTo(10, 90), Graphic(200, 75, Material.Bitmap(SandboxAssets.dots).tile).moveTo(10, 10), - Graphic(50, 75, Material.Bitmap(SandboxAssets.dots).stretch).moveTo(100, 75), - Graphic( - boxSizeValue, - boxSizeValue, - Material.Bitmap(SandboxAssets.nineSlice).nineSlice(Rectangle(16, 16, 32, 32)) - ).moveTo(10, 50), - Shape - .Box(Rectangle(boxSizeValue, boxSizeValue), Fill.None, Stroke(1, RGBA.Green)) - .moveTo(10, 50) + Graphic(50, 75, Material.Bitmap(SandboxAssets.dots).stretch).moveTo(100, 75) ) ) )