[update] Implemented a background transition for selecting songs.
This commit is contained in:
parent
1a289a6dda
commit
7e41c98cd3
@ -9,7 +9,7 @@
|
|||||||
"play-offset": 1000,
|
"play-offset": 1000,
|
||||||
"play-loop": 2000,
|
"play-loop": 2000,
|
||||||
"bg-inner-color": [0.8, 0.8, 0.8, 1],
|
"bg-inner-color": [0.8, 0.8, 0.8, 1],
|
||||||
"bg-outer-color": [0.8, 0.8, 0.8, 1]
|
"bg-outer-color": [0.1, 0.1, 0.1, 1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -120,14 +120,14 @@ private class FirstSetupState : AbstractSceneState {
|
|||||||
public:
|
public:
|
||||||
this(SelectScene owner) {
|
this(SelectScene owner) {
|
||||||
super(owner);
|
super(owner);
|
||||||
stage_appear_state_ = new StageAppearState(owner);
|
stage_appear_state_ = new SongAppearState(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AnimeFrames = 30;
|
enum AnimeFrames = 30;
|
||||||
enum BgInnerColor = vec4(0.8, 0.6, 0.6, 1);
|
enum BgInnerColor = vec4(0.4, 0.2, 0.2, 1);
|
||||||
enum BgOuterColor = vec4(-0.4, -0.4, -0.4, 1);
|
enum BgOuterColor = vec4(-0.4, -0.4, -0.4, 1);
|
||||||
|
|
||||||
enum CubeRotationSpeed = vec3(0, PI/10, 0);
|
enum CubeRotationSpeed = vec3(0, PI/5, 0);
|
||||||
enum CubeInterval = 0.06;
|
enum CubeInterval = 0.06;
|
||||||
|
|
||||||
void Initialize() {
|
void Initialize() {
|
||||||
@ -154,7 +154,7 @@ private class FirstSetupState : AbstractSceneState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StageAppearState stage_appear_state_;
|
SongAppearState stage_appear_state_;
|
||||||
|
|
||||||
Animation anime_;
|
Animation anime_;
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ private class FirstSetupState : AbstractSceneState {
|
|||||||
|
|
||||||
Easing!float cube_interval_ease_;
|
Easing!float cube_interval_ease_;
|
||||||
}
|
}
|
||||||
private class StageAppearState : AbstractSceneState {
|
private class SongAppearState : AbstractSceneState {
|
||||||
public:
|
public:
|
||||||
this(SelectScene owner) {
|
this(SelectScene owner) {
|
||||||
super(owner);
|
super(owner);
|
||||||
@ -177,7 +177,16 @@ private class StageAppearState : AbstractSceneState {
|
|||||||
|
|
||||||
anime_ = Animation(AnimeFrames);
|
anime_ = Animation(AnimeFrames);
|
||||||
|
|
||||||
cube_interval_ease_ = Easing!float(owner.lobby_.cube_interval, 0.005);
|
auto lobby = owner.lobby_;
|
||||||
|
|
||||||
|
cube_rota_speed_ease_ = Easing!vec3(
|
||||||
|
FirstSetupState.CubeRotationSpeed, CubeRotationSpeed);
|
||||||
|
cube_interval_ease_ = Easing!float(lobby.cube_interval, 0.005);
|
||||||
|
|
||||||
|
with (owner.songs_[song_index_].preview) {
|
||||||
|
bg_inner_ease_ = Easing!vec4(lobby.background.inner_color, bg_inner_color);
|
||||||
|
bg_outer_ease_ = Easing!vec4(lobby.background.outer_color, bg_outer_color);
|
||||||
|
}
|
||||||
|
|
||||||
sfSound_setBuffer(owner.sound_, owner.soundres_.spotlight);
|
sfSound_setBuffer(owner.sound_, owner.soundres_.spotlight);
|
||||||
sfSound_play(owner.sound_);
|
sfSound_play(owner.sound_);
|
||||||
@ -185,9 +194,11 @@ private class StageAppearState : AbstractSceneState {
|
|||||||
override UpdateResult Update(KeyInput input) {
|
override UpdateResult Update(KeyInput input) {
|
||||||
const ratio = anime_.Update();
|
const ratio = anime_.Update();
|
||||||
|
|
||||||
owner.lobby_.cube_matrix.rotation += CubeRotationSpeed +
|
owner.lobby_.cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio);
|
||||||
(FirstSetupState.CubeRotationSpeed - CubeRotationSpeed) * (1-ratio);
|
|
||||||
owner.lobby_.cube_interval = cube_interval_ease_.Calculate(ratio);
|
owner.lobby_.cube_interval = cube_interval_ease_.Calculate(ratio);
|
||||||
|
|
||||||
|
owner.lobby_.background.inner_color = bg_inner_ease_.Calculate(ratio);
|
||||||
|
owner.lobby_.background.outer_color = bg_outer_ease_.Calculate(ratio);
|
||||||
return CreateResult(this);
|
return CreateResult(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,5 +207,9 @@ private class StageAppearState : AbstractSceneState {
|
|||||||
|
|
||||||
Animation anime_;
|
Animation anime_;
|
||||||
|
|
||||||
|
Easing!vec3 cube_rota_speed_ease_;
|
||||||
Easing!float cube_interval_ease_;
|
Easing!float cube_interval_ease_;
|
||||||
|
|
||||||
|
Easing!vec4 bg_inner_ease_;
|
||||||
|
Easing!vec4 bg_outer_ease_;
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,7 @@ import std.array,
|
|||||||
std.exception,
|
std.exception,
|
||||||
std.json,
|
std.json,
|
||||||
std.path,
|
std.path,
|
||||||
std.string,
|
std.string;
|
||||||
std.typecons;
|
|
||||||
|
|
||||||
import derelict.sfml2.audio,
|
import derelict.sfml2.audio,
|
||||||
derelict.sfml2.system;
|
derelict.sfml2.system;
|
||||||
@ -26,9 +25,9 @@ class Song {
|
|||||||
size_t play_offset;
|
size_t play_offset;
|
||||||
|
|
||||||
///
|
///
|
||||||
Nullable!vec4 bg_inner_color;
|
vec4 bg_inner_color = vec4(0, 0, 0, 0);
|
||||||
///
|
///
|
||||||
Nullable!vec4 bg_outer_color;
|
vec4 bg_outer_color = vec4(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -51,7 +50,13 @@ class Song {
|
|||||||
music_ = sfMusic_createFromFile(music_path.toStringz).enforce;
|
music_ = sfMusic_createFromFile(music_path.toStringz).enforce;
|
||||||
script_path_ = buildPath(basepath, json["script"].str);
|
script_path_ = buildPath(basepath, json["script"].str);
|
||||||
|
|
||||||
// TODO: update preview config
|
with (preview_) {
|
||||||
|
const preview_json = json["preview"];
|
||||||
|
|
||||||
|
play_offset = preview_json["play-offset"].integer;
|
||||||
|
bg_inner_color = GetVectorFromJson!4(preview_json["bg-inner-color"]);
|
||||||
|
bg_outer_color = GetVectorFromJson!4(preview_json["bg-outer-color"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
~this() {
|
~this() {
|
||||||
sfMusic_destroy(music_);
|
sfMusic_destroy(music_);
|
||||||
@ -83,6 +88,15 @@ class Song {
|
|||||||
static float GetNumericAsFloatFromJson(in JSONValue json) {
|
static float GetNumericAsFloatFromJson(in JSONValue json) {
|
||||||
return json.type == JSONType.float_? json.floating: json.integer;
|
return json.type == JSONType.float_? json.floating: json.integer;
|
||||||
}
|
}
|
||||||
|
static Vector!(float, dim) GetVectorFromJson(size_t dim)(in JSONValue json) {
|
||||||
|
(json.array.length == dim).enforce;
|
||||||
|
|
||||||
|
Vector!(float, dim) v;
|
||||||
|
static foreach (i; 0..dim) {
|
||||||
|
v.vector[i] = GetNumericAsFloatFromJson(json.array[i]);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
string name_;
|
string name_;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user