Skip to content

Commit

Permalink
remove the custom button thing, use UIManager everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Dec 30, 2017
1 parent da79923 commit 765eb5d
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 328 deletions.
173 changes: 0 additions & 173 deletions src/Button.re

This file was deleted.

75 changes: 42 additions & 33 deletions src/FreePlayPicker.re
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
open SharedTypes;

let buttons = (Button.Normal, [
("Easy", Easy),
("Medium", Medium),
("Hard", Hard),
("Ludicrous", Ludicrous)
]);
let initialState = ();

let backButton = (ctx, env) =>
Button.singleBottom(env, "Back", ctx.textFont, (Reprocessing.Env.width(env) / 2, Reprocessing.Env.height(env) - 10));
let button = (ctx, name, diff, enabled) => UIManager.Button(
name,
diff,
{...WelcomeScreen2.buttonStyle(~enabled, ctx.textFont), margin: 18}
);

let initialState = ();
let root = (ctx, env) => {
let highest = UserData.highestBeatenStage(ctx.userData);
UIManager.{
el: VBox(
[
Text("Difficulty", {font: ctx.titleFont, tint: None}, Center),
Spacer(25),
button(ctx, "Easy", Easy, true),
button(ctx, "Medium", Medium, highest >= 0),
button(ctx, "Hard", Hard, highest >= 1),
button(ctx, "Ludicrous", Ludicrous, highest >= 2),
],
10,
Center
),
align: Center,
valign: Top,
pos: (Reprocessing.Env.width(env) / 2, 20)
};
};

let back = (ctx, env) => UIManager.{
el: Button("Back", (), WelcomeScreen2.buttonStyle(ctx.textFont)),
align: Center,
valign: Bottom,
pos: (Reprocessing.Env.width(env) / 2, Reprocessing.Env.height(env) - 10)
};

let screen =
ScreenManager.stateless(
~run=
(ctx, env) => {
open Reprocessing;
Draw.background(Constants.black, env);
DrawUtils.centerText(
~font=ctx.titleFont,
~pos=(Env.width(env) / 2, 20),
~body="Difficulty",
env
);
Button.draw(
~enabled=((i, _) => i <= 1+ UserData.highestBeatenStage(ctx.userData)),
(Env.width(env) / 2, 100),
buttons,
~ctx,
~env
);
Button.drawSingle(env, backButton(ctx, env));

UIManager.draw(env, root(ctx, env));
UIManager.draw(env, back(ctx, env));
Stateless(ctx)
},

~mouseDown=
(ctx, env) => {
open Reprocessing;
let res = Button.hit(
~enabled=((i, _) => i <= 1+ UserData.highestBeatenStage(ctx.userData)),
(Env.width(env) / 2, 100), buttons, ~ctx, ~env, Env.mouse(env));
switch res {
| None => if (Button.hitSingle(env, backButton(ctx, env))) {
Transition(ctx, `Quit)
} else { Stateless(ctx) }
| Some(dest) => Transition(ctx, `FreeStyle(dest))
switch (UIManager.act(env, root(ctx, env))) {
| Some(level) => Transition(ctx, `FreeStyle(level))
| None =>
switch (UIManager.act(env, back(ctx, env))) {
| Some(()) => Transition(ctx, `Quit)
| None => Same(ctx, ())
}
}
},
~keyPressed=
Expand Down
17 changes: 10 additions & 7 deletions src/HighScores.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ let drawScores = (ctx, env, name, scores, y) => {
}) + 20
};

let backButton = (ctx, env) => {
Button.singleBottom(env, "Back", ctx.textFont, (Env.width(env) / 2, Env.height(env) - 10))
let back = (ctx, env) => UIManager.{
el: Button("Back", (), WelcomeScreen2.buttonStyle(ctx.textFont)),
align: Center,
valign: Bottom,
pos: (Reprocessing.Env.width(env) / 2, Reprocessing.Env.height(env) - 10)
};


let run = (ctx, (dy, vy, down), env) => {
Draw.background(Constants.black, env);
let w = Env.width(env) / 2;
Expand Down Expand Up @@ -69,7 +73,7 @@ let run = (ctx, (dy, vy, down), env) => {
env
);
DrawUtils.centerText(~font=ctx.boldTextFont, ~body="High scores", ~pos=(w, h), env);
Button.drawSingle(env, backButton(ctx, env));
UIManager.draw(env, back(ctx, env));

/* let vy = abs_float(vy) < 0.01 ? 0. : vy *. 0.90; */
(dy, vy, down)
Expand All @@ -81,10 +85,9 @@ let screen = {
Same(ctx, run(ctx, state, env))
},
mouseDown: (ctx, (dy, vy, down), env) => {
if (Button.hitSingle(env, backButton(ctx, env))) {
Transition(ctx, `Quit)
} else {
Same(ctx, (dy, 0., Some(Env.mouse(env) |> snd |> float_of_int)))
switch (UIManager.act(env, back(ctx, env))) {
| Some(()) => Transition(ctx, `Quit)
| None => Same(ctx, (dy, 0., Some(Env.mouse(env) |> snd |> float_of_int)))
}
},
mouseUp: (ctx, (dy, vy, down), env) => {
Expand Down
Loading

0 comments on commit 765eb5d

Please sign in to comment.