|
|
|
|
@ -109,6 +109,7 @@ init()
|
|
|
|
|
g_game_state->grid.draw_mode = NONE; |
|
|
|
|
// TODO: maybe add this as an option to scene json?
|
|
|
|
|
g_game_state->grid.normal = v3f(0.f, 0.f, 1.f); |
|
|
|
|
g_game_state->select_mode = ENTITY_SELECT; |
|
|
|
|
|
|
|
|
|
// init global render state
|
|
|
|
|
g_render_state = UTIL_ALLOC(1, render_state); |
|
|
|
|
@ -162,7 +163,7 @@ mapMouseToViewport(int32 x, int32 y)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
startDrawHelper(int32 x, int32 y) |
|
|
|
|
startHexDrawHelper(int32 x, int32 y) |
|
|
|
|
{ |
|
|
|
|
hgResetHexes(g_game_state->grid); |
|
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
|
@ -175,7 +176,7 @@ startDrawHelper(int32 x, int32 y)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
|
handleHexMouseDown(SDL_MouseButtonEvent& e) |
|
|
|
|
{ |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
render_state* rs = g_render_state; |
|
|
|
|
@ -184,13 +185,13 @@ handleMouseDown(SDL_MouseButtonEvent &e)
|
|
|
|
|
|
|
|
|
|
switch (gs->grid.draw_mode) { |
|
|
|
|
case FILL: |
|
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
|
startHexDrawHelper(coords.x, coords.y); |
|
|
|
|
break; |
|
|
|
|
case LINE: |
|
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
|
startHexDrawHelper(coords.x, coords.y); |
|
|
|
|
break; |
|
|
|
|
case CONE_FILL: |
|
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
|
startHexDrawHelper(coords.x, coords.y); |
|
|
|
|
break; |
|
|
|
|
case PATHFINDING: |
|
|
|
|
break; |
|
|
|
|
@ -223,7 +224,7 @@ handleMouseDown(SDL_MouseButtonEvent &e)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handleMouseMove(SDL_MouseMotionEvent &e) |
|
|
|
|
handleHexMouseMove(SDL_MouseMotionEvent& e) |
|
|
|
|
{ |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
render_state* rs = g_render_state; |
|
|
|
|
@ -243,7 +244,7 @@ handleMouseMove(SDL_MouseMotionEvent &e)
|
|
|
|
|
break; |
|
|
|
|
case PATHFINDING: |
|
|
|
|
break; |
|
|
|
|
case ADD_HEXES: { |
|
|
|
|
case ADD_HEXES: |
|
|
|
|
if (gs->grid.is_selecting) { |
|
|
|
|
v3f ray = cameraCreateRay(rs->cam, coords, dims); |
|
|
|
|
v3f xsect; |
|
|
|
|
@ -251,8 +252,7 @@ handleMouseMove(SDL_MouseMotionEvent &e)
|
|
|
|
|
hgAddHex(gs->grid, xsect, rs->filled_hex_render_group, rs->hex_line_render_group); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case REMOVE_HEXES: { |
|
|
|
|
case REMOVE_HEXES: |
|
|
|
|
if (gs->grid.is_selecting) { |
|
|
|
|
v3f ray = cameraCreateRay(rs->cam, coords, dims); |
|
|
|
|
v3f xsect; |
|
|
|
|
@ -260,13 +260,63 @@ handleMouseMove(SDL_MouseMotionEvent &e)
|
|
|
|
|
hgRemoveHex(gs->grid, xsect, rs->filled_hex_render_group, rs->hex_line_render_group); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case NONE: |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handleEntityMouseDown(SDL_MouseButtonEvent& e) |
|
|
|
|
{ |
|
|
|
|
LOG(DEBUG) << "hey\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handleMouseDown(SDL_MouseButtonEvent& e, bool gooey_wants) |
|
|
|
|
{ |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
|
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (e.button == SDL_BUTTON_LEFT) { |
|
|
|
|
if (gs->select_mode == HEX_SELECT) { |
|
|
|
|
gs->grid.is_selecting = true; |
|
|
|
|
handleHexMouseDown(e); |
|
|
|
|
} else if (gs->select_mode == ENTITY_SELECT) { |
|
|
|
|
handleEntityMouseDown(e); |
|
|
|
|
} |
|
|
|
|
} else if (e.button == SDL_BUTTON_RIGHT) { |
|
|
|
|
gs->is_camera_rotate = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handleMouseUp(SDL_MouseButtonEvent& e, bool gooey_wants) |
|
|
|
|
{ |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
|
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (e.button == SDL_BUTTON_LEFT && gs->select_mode == HEX_SELECT) |
|
|
|
|
gs->grid.is_selecting = false; |
|
|
|
|
else if (e.button == SDL_BUTTON_RIGHT) |
|
|
|
|
gs->is_camera_rotate = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
handleMouseMove(SDL_MouseMotionEvent& e, bool gooey_wants) |
|
|
|
|
{ |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
|
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (gs->select_mode == HEX_SELECT && gs->grid.is_selecting) |
|
|
|
|
handleHexMouseMove(e); |
|
|
|
|
else if(gs->is_camera_rotate) |
|
|
|
|
cameraRotate(g_render_state->cam, e.xrel, e.yrel); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
processSDLEvents() |
|
|
|
|
{ |
|
|
|
|
@ -274,9 +324,6 @@ processSDLEvents()
|
|
|
|
|
bool run = true; |
|
|
|
|
|
|
|
|
|
while (SDL_PollEvent(&e)) { |
|
|
|
|
// let gooey have event
|
|
|
|
|
// TODO: need to check for both io.WantCaptureKeyboard and io.WantCaptureMouse
|
|
|
|
|
// to fix bug with 'ESC' not passing through while in imgui
|
|
|
|
|
bool gooey_wants = gooProcessEvent(e); |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
|
|
|
|
|
@ -310,28 +357,13 @@ processSDLEvents()
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case SDL_MOUSEBUTTONDOWN: |
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) { |
|
|
|
|
gs->grid.is_selecting = true; |
|
|
|
|
handleMouseDown(e.button); |
|
|
|
|
} else if (e.button.button == SDL_BUTTON_RIGHT) { |
|
|
|
|
gs->is_camera_rotate = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
handleMouseDown(e.button, gooey_wants); |
|
|
|
|
break; |
|
|
|
|
case SDL_MOUSEBUTTONUP: |
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) |
|
|
|
|
gs->grid.is_selecting = false; |
|
|
|
|
else if (e.button.button == SDL_BUTTON_RIGHT) |
|
|
|
|
gs->is_camera_rotate = false; |
|
|
|
|
} |
|
|
|
|
handleMouseUp(e.button, gooey_wants); |
|
|
|
|
break; |
|
|
|
|
case SDL_MOUSEMOTION: |
|
|
|
|
if (!gooey_wants && gs->grid.is_selecting) |
|
|
|
|
handleMouseMove(e.motion); |
|
|
|
|
else if(!gooey_wants && gs->is_camera_rotate) |
|
|
|
|
cameraRotate(g_render_state->cam, e.motion.xrel, e.motion.yrel); |
|
|
|
|
handleMouseMove(e.motion, gooey_wants); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
|