keystate activators
parent
28c41baa93
commit
9482b41fb9
|
@ -3,7 +3,6 @@
|
|||
|
||||
static debug_draw_queue draw_queue = {0};
|
||||
|
||||
#define _DEBUG 1
|
||||
#ifndef _DEBUG
|
||||
static bool draw_is_enabled = false;
|
||||
#else
|
||||
|
|
|
@ -6,9 +6,20 @@ static bool build_is_in_draw_mode = false;
|
|||
static uint8_t build_num_placements = 0;
|
||||
static item_placement build_placements[BUILD_MAX_PLACEMENTS] = {0};
|
||||
|
||||
void buildmode_draw() {
|
||||
if (inv_is_open) return;
|
||||
#ifndef zpl_square
|
||||
#define zpl_square(x) ((x) * (x))
|
||||
#endif
|
||||
|
||||
void buildmode_clear_buffers(void) {
|
||||
item_placement empty_placement = { .x = 0.0f, .y = 0.0f, .kind = -1 };
|
||||
for (size_t i = 0; i < BUILD_MAX_PLACEMENTS; i++) {
|
||||
zpl_memcopy(&build_placements[i], &empty_placement, zpl_size_of(item_placement));
|
||||
}
|
||||
}
|
||||
|
||||
void buildmode_draw(void) {
|
||||
camera cam = camera_get();
|
||||
camera old_cam = cam;
|
||||
Vector2 mpos = GetMousePosition();
|
||||
entity_view *e = game_world_view_active_get_entity(cam.ent_id);
|
||||
if (!e) return;
|
||||
|
@ -22,15 +33,22 @@ void buildmode_draw() {
|
|||
cam.x += WORLD_BLOCK_SIZE/2.0f;
|
||||
cam.y += WORLD_BLOCK_SIZE/2.0f;
|
||||
|
||||
if (e->has_items && !e->inside_vehicle && e->items[e->selected_item].quantity > 0) {
|
||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && !build_is_in_draw_mode) {
|
||||
// NOTE(zaklaus): Check distance
|
||||
double dx = old_cam.x - cam.x;
|
||||
double dy = old_cam.y - cam.y;
|
||||
double dsq = (dx*dx + dy*dy);
|
||||
bool is_outside_range = (dsq > zpl_square(WORLD_BLOCK_SIZE*8));
|
||||
|
||||
if (build_submit_placements) {
|
||||
build_submit_placements = false;
|
||||
buildmode_clear_buffers();
|
||||
}
|
||||
|
||||
if (e->has_items && !e->inside_vehicle && e->items[e->selected_item].quantity > 0 && !is_outside_range) {
|
||||
if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && !build_is_in_draw_mode) {
|
||||
build_is_in_draw_mode = true;
|
||||
build_num_placements = 0;
|
||||
|
||||
item_placement empty_placement = { .x = 0.0f, .y = 0.0f, .kind = -1 };
|
||||
for (size_t i = 0; i < BUILD_MAX_PLACEMENTS; i++) {
|
||||
zpl_memcopy(&build_placements[i], &empty_placement, zpl_size_of(item_placement));
|
||||
}
|
||||
buildmode_clear_buffers();
|
||||
}
|
||||
|
||||
uint32_t qty = e->items[e->selected_item].quantity;
|
||||
|
@ -49,23 +67,28 @@ void buildmode_draw() {
|
|||
}
|
||||
}
|
||||
|
||||
build_num_placements = zpl_min(build_num_placements, qty);
|
||||
|
||||
for (size_t i = 0; i < build_num_placements; i++) {
|
||||
item_placement *it = &build_placements[i];
|
||||
renderer_draw_single(it->x, it->y, ASSET_DEBUG_TILE, ColorAlpha(BLUE, 0.4f));
|
||||
}
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) {
|
||||
build_is_in_draw_mode = false;
|
||||
}
|
||||
|
||||
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {
|
||||
build_submit_placements = true;
|
||||
build_is_in_draw_mode = false;
|
||||
}
|
||||
}
|
||||
|
||||
renderer_draw_single(cam.x, cam.y, ASSET_DEBUG_TILE, ColorAlpha(BLUE, 0.4f));
|
||||
if (!is_outside_range)
|
||||
renderer_draw_single(cam.x, cam.y, ASSET_DEBUG_TILE, ColorAlpha(BLUE, 0.4f));
|
||||
|
||||
build_num_placements = zpl_min(build_num_placements, qty);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < build_num_placements; i++) {
|
||||
item_placement *it = &build_placements[i];
|
||||
renderer_draw_single(it->x, it->y, ASSET_DEBUG_TILE, ColorAlpha(BLUE, 0.4f));
|
||||
}
|
||||
|
||||
if (build_is_in_draw_mode) {
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
build_is_in_draw_mode = false;
|
||||
}
|
||||
|
||||
if (IsMouseButtonReleased(MOUSE_RIGHT_BUTTON)) {
|
||||
build_submit_placements = true;
|
||||
build_is_in_draw_mode = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -24,7 +24,7 @@ void inventory_draw() {
|
|||
inv_is_open = !inv_is_open;
|
||||
}
|
||||
|
||||
if (!inv_is_open) {
|
||||
if (!inv_is_open || build_is_in_draw_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,18 +51,21 @@ int32_t pkt_send_keystate_handler(pkt_header *header) {
|
|||
i->y = zpl_clamp(table.y, -1.0f, 1.0f);
|
||||
i->mx = table.mx;
|
||||
i->my = table.my;
|
||||
i->use = table.use;
|
||||
i->use |= table.use;
|
||||
i->sprint = table.sprint;
|
||||
i->ctrl = table.ctrl;
|
||||
i->selected_item = zpl_clamp(table.selected_item, 0, ITEMS_INVENTORY_SIZE-1);
|
||||
i->drop = table.drop;
|
||||
i->swap = table.swap;
|
||||
i->drop |= table.drop;
|
||||
i->swap |= table.swap;
|
||||
i->swap_from = zpl_clamp(table.swap_from, 0, ITEMS_INVENTORY_SIZE-1);
|
||||
i->swap_to = zpl_clamp(table.swap_to, 0, ITEMS_INVENTORY_SIZE-1);
|
||||
i->num_placements = zpl_clamp(table.placement_num, 0, BUILD_MAX_PLACEMENTS);
|
||||
for (uint8_t j = 0; j < i->num_placements; j++) {
|
||||
i->placements_x[j] = table.placements[j].x;
|
||||
i->placements_y[j] = table.placements[j].y;
|
||||
|
||||
if (table.placement_num > 0) {
|
||||
i->num_placements = zpl_clamp(table.placement_num, 0, BUILD_MAX_PLACEMENTS);
|
||||
for (uint8_t j = 0; j < i->num_placements; j++) {
|
||||
i->placements_x[j] = table.placements[j].x;
|
||||
i->placements_y[j] = table.placements[j].y;
|
||||
}
|
||||
}
|
||||
debug_replay_record_keystate(table);
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@ static bool request_shutdown;
|
|||
#include "renderer_bridge.c"
|
||||
|
||||
// NOTE(zaklaus): add-ins
|
||||
#include "gui/inventory.c"
|
||||
#include "gui/build_mode.c"
|
||||
#include "gui/inventory.c"
|
||||
|
||||
void platform_init() {
|
||||
InitWindow(screenWidth, screenHeight, "eco2d");
|
||||
SetWindowState(FLAG_WINDOW_UNDECORATED|FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT);
|
||||
|
||||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
screenWidth = (uint16_t)GetScreenWidth();
|
||||
screenHeight = (uint16_t)GetScreenHeight();
|
||||
// ToggleFullscreen();
|
||||
// SetTargetFPS(60.0);
|
||||
|
||||
|
@ -110,7 +110,7 @@ void platform_input() {
|
|||
mouse_pos.y -= 0.5f;
|
||||
mouse_pos = Vector2Normalize(mouse_pos);
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) {
|
||||
if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) {
|
||||
x = mouse_pos.x;
|
||||
y = -mouse_pos.y;
|
||||
}
|
||||
|
@ -132,8 +132,6 @@ void platform_input() {
|
|||
};
|
||||
|
||||
if (build_submit_placements) {
|
||||
build_submit_placements = false;
|
||||
|
||||
in_data.placement_num = build_num_placements;
|
||||
zpl_memcopy(in_data.placements, build_placements, build_num_placements*zpl_size_of(item_placement));
|
||||
}
|
||||
|
@ -182,8 +180,8 @@ void platform_render() {
|
|||
renderer_debug_draw();
|
||||
{
|
||||
// NOTE(zaklaus): add-ins
|
||||
inventory_draw();
|
||||
buildmode_draw();
|
||||
inventory_draw();
|
||||
}
|
||||
display_conn_status();
|
||||
debug_draw();
|
||||
|
|
|
@ -123,6 +123,17 @@ void RegenerateHP(ecs_iter_t *it) {
|
|||
}
|
||||
}
|
||||
|
||||
void ResetActivators(ecs_iter_t *it) {
|
||||
Input *in = ecs_column(it, Input, 1);
|
||||
|
||||
for (int i = 0; i < it->count; i++) {
|
||||
in[i].use = false;
|
||||
in[i].swap = false;
|
||||
in[i].drop = false;
|
||||
in[i].num_placements = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyWorldDragOnVelocity(ecs_iter_t *it) {
|
||||
Position *p = ecs_column(it, Position, 1);
|
||||
Velocity *v = ecs_column(it, Velocity, 2);
|
||||
|
@ -168,6 +179,8 @@ void SystemsImport(ecs_world_t *ecs) {
|
|||
//ECS_SYSTEM(ecs, MergeItems, EcsPostUpdate, components.Position, components.ItemDrop);
|
||||
ECS_SYSTEM(ecs, UseItem, EcsPostUpdate, components.Input, components.Position, components.Inventory, !components.IsInVehicle);
|
||||
|
||||
ECS_SYSTEM(ecs, ResetActivators, EcsPostUpdate, components.Input);
|
||||
|
||||
ECS_SYSTEM(ecs, UpdateTrackerPos, EcsPostUpdate, components.Position, components.Velocity);
|
||||
|
||||
ECS_SYSTEM(ecs, ClearVehicle, EcsUnSet, components.Vehicle);
|
||||
|
|
|
@ -196,6 +196,7 @@ void UseItem(ecs_iter_t *it) {
|
|||
Position pos = {.x = in[i].placements_x[j], .y = in[i].placements_y[j]};
|
||||
item_use(it->world, item, pos);
|
||||
}
|
||||
in[i].num_placements = 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue