mirror of
https://github.com/Kapendev/parin.git
synced 2025-04-26 13:09:56 +03:00
Some bugs and more pointers for global data.
This commit is contained in:
parent
14ce68833c
commit
eb98e15f49
5 changed files with 58 additions and 28 deletions
|
@ -18,7 +18,7 @@ bool update(float dt) {
|
|||
}
|
||||
// Create the drag handle and print if it is dragged.
|
||||
if (uiDragHandle(handleArea, handleOptions)) {
|
||||
println(handleArea.position);
|
||||
printfln("({}, {})", handleArea.position.x, handleArea.position.y);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,14 +21,14 @@ bool update(float dt) {
|
|||
auto group = Rect();
|
||||
// Group 1.
|
||||
group = area.subTop(groupHeight);
|
||||
uiText(group.subLeft(textWidth), "Cool Button", UiOptions(Alignment.left));
|
||||
if (uiButton(group.subLeft(buttonWidth), "")) println("Cool");
|
||||
uiText(group.subLeft(textWidth), "SUPER Button", UiOptions(Alignment.left));
|
||||
if (uiButton(group.subLeft(buttonWidth), "")) println("SUPER");
|
||||
// Margin.
|
||||
area.subTop(groupMargin);
|
||||
// Group 2.
|
||||
group = area.subTop(groupHeight);
|
||||
uiText(group.subLeft(textWidth), "Super Button", UiOptions(Alignment.left));
|
||||
if (uiButton(group.subLeft(buttonWidth), "")) println("Super");
|
||||
uiText(group.subLeft(textWidth), "HOT Button", UiOptions(Alignment.left));
|
||||
if (uiButton(group.subLeft(buttonWidth), "")) println("HOT");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -881,6 +881,7 @@ struct EngineViewport {
|
|||
|
||||
/// The engine state.
|
||||
struct EngineState {
|
||||
// LABEL
|
||||
EngineFlags flags;
|
||||
EngineFullscreenState fullscreenState;
|
||||
Sz tickCount;
|
||||
|
@ -1271,9 +1272,11 @@ void openUrl(IStr url = "https://github.com/Kapendev/parin") {
|
|||
void openWindow(int width, int height, const(IStr)[] args, IStr title = "Parin") {
|
||||
if (rl.IsWindowReady) return;
|
||||
engineState = cast(EngineState*) stdc.malloc(EngineState.sizeof);
|
||||
stdc.memset(engineState, 0, EngineState.sizeof);
|
||||
// This part is a hack for the `runGame` mixin.
|
||||
engineState.envArgsBuffer.clear();
|
||||
foreach (arg; args) engineState.envArgsBuffer.append(arg);
|
||||
// Set raylib stuff.
|
||||
// Raylib stuff.
|
||||
rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE | rl.FLAG_VSYNC_HINT);
|
||||
rl.SetTraceLogLevel(rl.LOG_ERROR);
|
||||
rl.InitWindow(width, height, title.toCStr().getOr());
|
||||
|
@ -1282,7 +1285,7 @@ void openWindow(int width, int height, const(IStr)[] args, IStr title = "Parin")
|
|||
rl.SetTargetFPS(60);
|
||||
rl.rlSetBlendFactorsSeparate(0x0302, 0x0303, 1, 0x0303, 0x8006, 0x8006);
|
||||
setWindowMinSize(240, 135);
|
||||
// Set engine stuff.
|
||||
// Engine stuff.
|
||||
engineState.flags.canUseAssetsPath = true;
|
||||
engineState.fullscreenState.previousWindowWidth = width;
|
||||
engineState.fullscreenState.previousWindowHeight = height;
|
||||
|
|
|
@ -21,15 +21,18 @@ import joka.types;
|
|||
|
||||
@safe @nogc nothrow:
|
||||
|
||||
alias BaseBoxId = int;
|
||||
alias BaseBoxIdGroup = FixedList!(BaseBoxId, 510);
|
||||
|
||||
alias ActorBoxId = BaseBoxId;
|
||||
alias ActorBoxFlags = ubyte;
|
||||
alias WallBoxId = BaseBoxId;
|
||||
alias WallBoxFlags = ubyte;
|
||||
alias OneWaySide = RideSide;
|
||||
alias BaseBoxId = uint;
|
||||
alias BaseBoxFlags = ubyte;
|
||||
alias WallBoxId = BaseBoxId;
|
||||
alias WallBoxFlags = BaseBoxFlags;
|
||||
alias ActorBoxId = BaseBoxId;
|
||||
alias ActorBoxFlags = BaseBoxFlags;
|
||||
alias TaggedBaseBoxId = BaseBoxId;
|
||||
alias TaggedBaseBoxIdGroup = FixedList!(TaggedBaseBoxId, 510);
|
||||
alias OneWaySide = RideSide;
|
||||
|
||||
enum wallBoxTag = 0;
|
||||
enum actorBoxTag = 1;
|
||||
enum boxPassableFlag = 0x1;
|
||||
enum boxRidingFlag = 0x2;
|
||||
|
||||
|
@ -141,7 +144,7 @@ struct BoxWorld {
|
|||
List!ActorBoxProperties actorsProperties;
|
||||
List!ActorBoxId squishedIdsBuffer;
|
||||
List!BaseBoxId collisionIdsBuffer;
|
||||
Grid!BaseBoxIdGroup grid;
|
||||
Grid!TaggedBaseBoxIdGroup grid;
|
||||
int gridTileWidth;
|
||||
int gridTileHeight;
|
||||
|
||||
|
@ -150,17 +153,25 @@ struct BoxWorld {
|
|||
void enableSpatialGrid(Sz rowCount, Sz colCount, int tileWidth, int tileHeight) {
|
||||
gridTileWidth = tileWidth;
|
||||
gridTileHeight = tileHeight;
|
||||
grid.resizeBlank(rowCount, colCount);
|
||||
foreach (ref group; grid) {
|
||||
group.length = 0;
|
||||
}
|
||||
foreach (i, ref properties; wallsProperties) {
|
||||
properties.gridX = walls[i].position.x / gridTileWidth - (walls[i].position.x < 0);
|
||||
properties.gridY = walls[i].position.y / gridTileHeight - (walls[i].position.y < 0);
|
||||
// TODO: There are two problems to think about. Negative values and boxes touching more than one group.
|
||||
auto id = cast(TaggedBaseBoxId) (i + 1);
|
||||
id &= ~(1 << 31);
|
||||
grid[properties.gridY, properties.gridX].append(id);
|
||||
}
|
||||
foreach (i, ref properties; actorsProperties) {
|
||||
properties.gridX = actors[i].position.x / gridTileWidth - (actors[i].position.x < 0);
|
||||
properties.gridY = actors[i].position.y / gridTileHeight - (actors[i].position.y < 0);
|
||||
}
|
||||
grid.resizeBlank(rowCount, colCount);
|
||||
foreach (ref group; grid) {
|
||||
group.length = 0;
|
||||
// TODO: There are two problems to think about. Negative values and boxes touching more than one group.
|
||||
auto id = cast(TaggedBaseBoxId) (i + 1);
|
||||
id |= (1 << 31);
|
||||
grid[properties.gridY, properties.gridX].append(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +182,7 @@ struct BoxWorld {
|
|||
}
|
||||
|
||||
ref IRect getWall(WallBoxId id) {
|
||||
if (id <= 0) {
|
||||
if (id == 0) {
|
||||
assert(0, "ID `0` is always invalid and represents a box that was never created.");
|
||||
} else if (id > walls.length) {
|
||||
assert(0, "ID `{}` does not exist.".format(id));
|
||||
|
@ -180,7 +191,7 @@ struct BoxWorld {
|
|||
}
|
||||
|
||||
ref IRect getActor(ActorBoxId id) {
|
||||
if (id <= 0) {
|
||||
if (id == 0) {
|
||||
assert(0, "ID `0` is always invalid and represents a box that was never created.");
|
||||
} else if (id > actors.length) {
|
||||
assert(0, "ID `{}` does not exist.".format(id));
|
||||
|
@ -189,7 +200,7 @@ struct BoxWorld {
|
|||
}
|
||||
|
||||
ref WallBoxProperties getWallProperties(WallBoxId id) {
|
||||
if (id <= 0) {
|
||||
if (id == 0) {
|
||||
assert(0, "ID `0` is always invalid and represents a box that was never created.");
|
||||
} else if (id > wallsProperties.length) {
|
||||
assert(0, "ID `{}` does not exist.".format(id));
|
||||
|
@ -198,7 +209,7 @@ struct BoxWorld {
|
|||
}
|
||||
|
||||
ref ActorBoxProperties getActorProperties(ActorBoxId id) {
|
||||
if (id <= 0) {
|
||||
if (id == 0) {
|
||||
assert(0, "ID `0` is always invalid and represents a box that was never created.");
|
||||
} else if (id > actorsProperties.length) {
|
||||
assert(0, "ID `{}` does not exist.".format(id));
|
||||
|
|
|
@ -10,13 +10,14 @@
|
|||
module parin.ui;
|
||||
|
||||
import rl = parin.rl;
|
||||
import stdc = joka.stdc;
|
||||
import joka.ascii;
|
||||
import parin.engine;
|
||||
|
||||
@safe @nogc nothrow:
|
||||
|
||||
UiState uiState;
|
||||
UiState uiPreviousState;
|
||||
UiState* uiState;
|
||||
UiState* uiPreviousState;
|
||||
|
||||
enum defaultUiDisabledColor = 0x202020.toRgb();
|
||||
enum defaultUiIdleColor = 0x414141.toRgb();
|
||||
|
@ -107,7 +108,22 @@ int findSpaceInTextField(IStr text) {
|
|||
return result;
|
||||
}
|
||||
|
||||
@trusted
|
||||
void prepareUi() {
|
||||
if (uiState == null) {
|
||||
// NOTE: This will leak, but who cares.
|
||||
uiState = cast(UiState*) stdc.malloc(UiState.sizeof);
|
||||
uiPreviousState = cast(UiState*) stdc.malloc(UiState.sizeof);
|
||||
stdc.memset(uiState, 0, UiState.sizeof);
|
||||
stdc.memset(uiPreviousState, 0, UiState.sizeof);
|
||||
// TODO: Should be changed to something better looking.
|
||||
uiState.mouseClickAction = Mouse.left;
|
||||
uiState.keyboardClickAction = Keyboard.enter;
|
||||
uiState.gamepadClickAction = Gamepad.a;
|
||||
uiPreviousState.mouseClickAction = Mouse.left;
|
||||
uiPreviousState.keyboardClickAction = Keyboard.enter;
|
||||
uiPreviousState.gamepadClickAction = Gamepad.a;
|
||||
}
|
||||
setUiViewportState(Vec2(), resolution, Vec2(1.0f));
|
||||
uiState.itemId = 0;
|
||||
uiState.hotItemId = 0;
|
||||
|
@ -251,7 +267,7 @@ void wrapUiFocus(short step, Sz length) {
|
|||
}
|
||||
|
||||
void updateUiState(Rect area, bool isHot, bool isActive, bool isClicked) {
|
||||
uiPreviousState = uiState;
|
||||
*uiPreviousState = *uiState;
|
||||
uiState.itemId += 1;
|
||||
if (isHot) {
|
||||
uiState.hotItemId = uiState.itemId;
|
||||
|
@ -396,7 +412,7 @@ bool updateUiDragHandle(ref Rect area, UiOptions options = UiOptions()) {
|
|||
auto m = (mouse - uiState.viewportPosition) / uiState.viewportScale; // NOTE: Maybe this should be a function?
|
||||
area.position.y = clamp(m.y + uiDragOffset.y, dragLimitY.x, dragLimitY.y - area.size.y);
|
||||
area.position.x = clamp(m.x + uiDragOffset.x, dragLimitX.x, dragLimitX.y - area.size.x);
|
||||
uiState = uiPreviousState;
|
||||
*uiState = *uiPreviousState;
|
||||
updateUiButton(area, "", options);
|
||||
return true;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue