-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an engine specific loading icon
- Loading branch information
Dominic Dolan
committed
Oct 3, 2020
1 parent
02c384a
commit 1826065
Showing
31 changed files
with
252 additions
and
21 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
application-interface/src/main/kotlin/com/mechanica/engine/context/loader/FontLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package com.mechanica.engine.context.loader | ||
|
||
import com.mechanica.engine.text.Font | ||
import com.mechanica.engine.resources.Resource | ||
import com.mechanica.engine.text.Font | ||
import com.mechanica.engine.text.FontAtlasConfiguration | ||
|
||
interface FontLoader { | ||
val defaultFont: Font | ||
fun font(res: Resource, initializer: FontAtlasConfiguration.() -> Unit): Font | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
application-interface/src/main/kotlin/com/mechanica/engine/text/FontSet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.mechanica.engine.text | ||
|
||
import com.mechanica.engine.resources.Resource | ||
|
||
open class FontSet(protected val name: String, protected val configureAtlas: FontAtlasConfiguration.() -> Unit = { }) { | ||
protected var modifier = Modifiers.REGULAR | ||
protected var italic = "" | ||
|
||
protected val fileName: String | ||
get() = "res/fonts/${toString()}.ttf" | ||
|
||
fun regular(italic: Boolean): Font { | ||
if (italic) this.italic = italicString | ||
modifier = Modifiers.REGULAR | ||
return create() | ||
} | ||
|
||
fun bold(italic: Boolean): Font { | ||
if (italic) this.italic = italicString | ||
modifier = Modifiers.BOLD | ||
return create() | ||
} | ||
|
||
fun medium(italic: Boolean): Font { | ||
if (italic) this.italic = italicString | ||
modifier = Modifiers.MEDIUM | ||
return create() | ||
} | ||
|
||
fun black(italic: Boolean): Font { | ||
if (italic) this.italic = italicString | ||
modifier = Modifiers.BLACK | ||
return create() | ||
} | ||
|
||
fun light(italic: Boolean): Font { | ||
if (italic) this.italic = italicString | ||
modifier = Modifiers.LIGHT | ||
return create() | ||
} | ||
|
||
fun thin(italic: Boolean): Font { | ||
if (italic) this.italic = italicString | ||
modifier = Modifiers.THIN | ||
return create() | ||
} | ||
|
||
open fun create() = Font.create(Resource(fileName), configureAtlas) | ||
|
||
override fun toString(): String { | ||
return "$name-$modifier$italic" | ||
} | ||
|
||
enum class Modifiers(val string: String) { | ||
REGULAR("Regular"), | ||
BOLD("Bold"), | ||
BLACK("Black"), | ||
LIGHT("Light"), | ||
THIN("Thin"), | ||
MEDIUM("Medium"); | ||
|
||
override fun toString(): String { | ||
return string | ||
} | ||
} | ||
|
||
companion object { | ||
const val italicString = "Italic" | ||
} | ||
} | ||
|
||
class CachedFontSet(name: String, configureAtlas: FontAtlasConfiguration.() -> Unit = { }) : FontSet(name, configureAtlas) { | ||
override fun create(): Font { | ||
val fileName = this.fileName | ||
return fontMap[fileName] ?: super.create().also { fontMap[fileName] = it } | ||
} | ||
|
||
companion object { | ||
private val fontMap = HashMap<String, Font>() | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
application-interface/src/main/kotlin/com/mechanica/engine/text/Text.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
desktop-application/src/main/kotlin/com/mechanica/engine/context/loader/LwjglFontLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
package com.mechanica.engine.context.loader | ||
|
||
import com.mechanica.engine.text.LwjglStandardFont | ||
import com.mechanica.engine.text.Font | ||
import com.mechanica.engine.resources.Resource | ||
import com.mechanica.engine.text.FontAtlasConfiguration | ||
import com.mechanica.engine.text.LwjglStandardFont | ||
|
||
class LwjglFontLoader : FontLoader { | ||
override val defaultFont: Font by lazy { LwjglStandardFont(Resource("res/fonts/Roboto-Regular.ttf")) { | ||
width = 1024 | ||
height = 1024 | ||
characterSize = 200f | ||
} } | ||
|
||
override fun font(res: Resource, initializer: FontAtlasConfiguration.() -> Unit) = LwjglStandardFont(res, initializer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
mechanica/src/main/kotlin/com/mechanica/engine/scenes/scenes/logo/MechanicaLoadingIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.mechanica.engine.scenes.scenes.logo | ||
|
||
import com.mechanica.engine.animation.AnimationFormula | ||
import com.mechanica.engine.animation.AnimationFormulas | ||
import com.mechanica.engine.drawer.Drawer | ||
import com.mechanica.engine.game.view.View | ||
import com.mechanica.engine.models.Image | ||
import com.mechanica.engine.resources.Res | ||
import com.mechanica.engine.scenes.addAnimationSequence | ||
import com.mechanica.engine.scenes.scenes.sprites.StaticSprite | ||
import com.mechanica.engine.unit.angle.degrees | ||
|
||
open class MechanicaLoadingIcon(view: View, order: Int = 0) : StaticSprite(view, order) { | ||
private val mother = Image.loadImage(Res.image("logo/astrolabe-mother")) | ||
private val rete = Image.loadImage(Res.image("logo/astrolabe-rete")) | ||
private val rule = Image.loadImage(Res.image("logo/astrolabe-rule")) | ||
|
||
private var buffer = AnimationFormula(-1.5, 0.0) { 1.0 } | ||
private var ruleAngle = AnimationFormula(0.0, 2.5, AnimationFormulas.quadraticBump(0.0, 360.0)) | ||
private var reteAngle = AnimationFormula(0.0, 2.5, AnimationFormulas.quadraticAscending(360.0, 0.0)) | ||
|
||
val sequence = addAnimationSequence(buffer, reteAngle, ruleAngle) | ||
|
||
constructor( | ||
x: Double = 0.0, | ||
y: Double = 0.0, | ||
width: Double = 1.0, | ||
height: Double = 1.0, | ||
order: Int = 0) : this(View.create(x, y, width, height), order) | ||
|
||
init { | ||
sequence.play() | ||
sequence.looped = true | ||
} | ||
|
||
override fun render(draw: Drawer) { | ||
draw.inView.image(mother) | ||
draw.inView.rotated(reteAngle.value.degrees).image(rete) | ||
draw.inView.rotated(ruleAngle.value.degrees).image(rule) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../src/main/kotlin/com/mechanica/engine/scenes/scenes/logo/MechanicaStartupLoadingScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.mechanica.engine.scenes.scenes.logo | ||
|
||
import com.mechanica.engine.animation.AnimationSequence | ||
import com.mechanica.engine.color.Color | ||
import com.mechanica.engine.scenes.scenes.LoadScene | ||
|
||
abstract class MechanicaStartupLoadingScreen(textColor: Color = Color.black, order: Int = 0) : LoadScene(order) { | ||
private val startupScreen = addScene(MechanicaStartupScreen(textColor)) | ||
val sequence: AnimationSequence | ||
get() = startupScreen.sequence | ||
} |
43 changes: 43 additions & 0 deletions
43
mechanica/src/main/kotlin/com/mechanica/engine/scenes/scenes/logo/MechanicaStartupScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.mechanica.engine.scenes.scenes.logo | ||
|
||
import com.mechanica.engine.animation.AnimationFormula | ||
import com.mechanica.engine.animation.AnimationFormulas | ||
import com.mechanica.engine.color.Color | ||
import com.mechanica.engine.drawer.Drawer | ||
import com.mechanica.engine.game.view.View | ||
import com.mechanica.engine.models.Image | ||
import com.mechanica.engine.models.ImageModel | ||
import com.mechanica.engine.resources.Res | ||
import com.mechanica.engine.scenes.addAnimationSequence | ||
import com.mechanica.engine.scenes.scenes.UIScene | ||
import com.mechanica.engine.text.Font | ||
import com.mechanica.engine.text.Text | ||
import kotlin.math.min | ||
|
||
class MechanicaStartupScreen(private val textColor: Color = Color.black, order: Int = 0) : UIScene(order) { | ||
private val titleSize: Double = min(camera.width, camera.height) | ||
private val title = ImageModel(Image.loadImage(Res.image("logo/mechanica-title"))) | ||
|
||
private val poweredBy = Text("Powered by", Font.defaults.bold(true)) | ||
|
||
private val logo = addScene(object : MechanicaLoadingIcon(0.0, -0.075*titleSize, 0.37*titleSize, 0.37*titleSize, 1){ | ||
override fun drawInView(draw: Drawer, view: View): Drawer { | ||
return super.drawInView(draw, view).ui.color.alpha(logoFadeIn.value) | ||
} | ||
}) | ||
|
||
private val textFadeIn = AnimationFormula(2.0, 4.0, AnimationFormulas.linear(0.0, 1.0) ) | ||
private val logoFadeIn = AnimationFormula(-1.0, 1.0, AnimationFormulas.linear(0.0, 1.0) ) | ||
val sequence = addAnimationSequence(textFadeIn, logoFadeIn, logo.sequence) | ||
|
||
init { | ||
logo.sequence.looped = false | ||
sequence.play() | ||
} | ||
|
||
override fun render(draw: Drawer) { | ||
draw.darkGrey.alpha(textFadeIn.value).text(poweredBy, 0.04*titleSize, -0.47*titleSize, 0.225*titleSize) | ||
draw.color(textColor).alpha(textFadeIn.value) | ||
draw.centered.ui.transformed.scale(titleSize).model(title, 0f, 1f, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions
52
samples/src/main/kotlin/com/mechanica/engine/samples/scenes/LoadSceneDemo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mechanica.engine.samples.scenes | ||
|
||
import com.mechanica.engine.color.Color | ||
import com.mechanica.engine.config.configure | ||
import com.mechanica.engine.drawer.Drawer | ||
import com.mechanica.engine.game.Game | ||
import com.mechanica.engine.scenes.scenes.LoadScene | ||
import com.mechanica.engine.scenes.scenes.Scene | ||
import com.mechanica.engine.scenes.scenes.logo.MechanicaStartupScreen | ||
import com.mechanica.engine.scenes.setNewMainScene | ||
import com.mechanica.engine.text.Font | ||
import com.mechanica.engine.text.Text | ||
|
||
fun main() { | ||
Game.configure { | ||
setViewport(height = 10.0) | ||
setStartingScene { LoadSceneDemo() } | ||
setFullscreen(true) | ||
} | ||
|
||
Game.loop() | ||
} | ||
|
||
|
||
class LoadSceneDemo : LoadScene() { | ||
|
||
init { | ||
addScene(MechanicaStartupScreen(Color.white)) | ||
} | ||
|
||
override fun load() { | ||
// Assets can be loaded here | ||
Thread.sleep(6000) | ||
} | ||
|
||
override fun onFinish() { | ||
setNewMainScene { ExampleGameScene() } | ||
} | ||
|
||
override fun render(draw: Drawer) { | ||
draw.black.background() | ||
} | ||
} | ||
|
||
|
||
class ExampleGameScene : Scene() { | ||
val text = Text("Example Game Scene", Font.defaults.black(true)) | ||
override fun render(draw: Drawer) { | ||
draw.white.background() | ||
draw.centered.darkGrey.text(text) | ||
} | ||
} |