Skip to content

Commit

Permalink
# - creator mode ding tools
Browse files Browse the repository at this point in the history
  • Loading branch information
en-software committed Dec 26, 2023
1 parent 2d22e92 commit 370dde7
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 39 deletions.
8 changes: 4 additions & 4 deletions controller-stuff.cpp
Expand Up @@ -42,25 +42,25 @@ namespace blooDot::ControllerStuff
{
auto playerIndex = SDL_JoystickGetDevicePlayerIndex(instanceId);

if (playerIndex == 1)
if (playerIndex == 1 && controller1 == nullptr)
{
controller1Connected = instanceId;
controller1 = SDL_GameControllerOpen(i);
controller1Name.assign(SDL_GameControllerNameForIndex(i));
}
else if (playerIndex == 2)
else if (playerIndex == 2 && controller2 == nullptr)
{
controller2Connected = instanceId;
controller2 = SDL_GameControllerOpen(i);
controller2Name.assign(SDL_GameControllerNameForIndex(i));
}
else if (playerIndex == 3)
else if (playerIndex == 3 && controller3 == nullptr)
{
controller3Connected = instanceId;
controller3 = SDL_GameControllerOpen(i);
controller3Name.assign(SDL_GameControllerNameForIndex(i));
}
else if (playerIndex == 4)
else if (playerIndex == 4 && controller4 == nullptr)
{
controller4Connected = instanceId;
controller4 = SDL_GameControllerOpen(i);
Expand Down
8 changes: 4 additions & 4 deletions dialogcontrols.cpp
Expand Up @@ -58,8 +58,8 @@ cairo_t* DrawControllerButtonTip(cairo_t* context, double x, double y, ControlHi
x + CONTROLLER_BUTTON_TIP_INSET,
y + CONTROLLER_BUTTON_TIP_INSET,
CONTROLLER_BUTTON_TIP_RADIUS,
-(M_PI + M_PI_2) + 0.1,
0 - 0.1
-(M_PI + M_PI_2) + 0.3,
-0.3
);

cairo_fill(context);
Expand All @@ -70,8 +70,8 @@ cairo_t* DrawControllerButtonTip(cairo_t* context, double x, double y, ControlHi
x + CONTROLLER_BUTTON_TIP_INSET,
y + CONTROLLER_BUTTON_TIP_INSET,
CONTROLLER_BUTTON_TIP_RADIUS - BUTTON_INSET,
-(M_PI + M_PI_2) + 0.1,
0 - 0.1
-(M_PI + M_PI_2) + 0.3,
-0.3
);

cairo_stroke(context);
Expand Down
7 changes: 7 additions & 0 deletions makercontrols.cpp
Expand Up @@ -5,6 +5,13 @@

namespace blooDot::MakerControls
{
cairo_t* DrawDingSelectionTool(cairo_t* context, int x, int y)
{
x = x * y;

return context;
}

cairo_t* DrawSelectedLayerTool(cairo_t* context, int x, double baseY, double yStride, double xExtent, double xSlantExtent, int yExtent, double padding, int etage)
{
auto const& intendedX = x + 2 * padding;
Expand Down
1 change: 1 addition & 0 deletions makercontrols.h
Expand Up @@ -5,5 +5,6 @@

namespace blooDot::MakerControls
{
cairo_t* DrawDingSelectionTool(cairo_t* context, int x, int y);
cairo_t* DrawSelectedLayerTool(cairo_t* context, int x, double baseY, double yStride, double xExtent, double xSlantExtent, int yExtent, double padding, int etage);
}
15 changes: 2 additions & 13 deletions orchestrator.cpp
Expand Up @@ -3,6 +3,7 @@
#include "physics-render-binding.h"
#include "shader-engine.h"
#include "ingame-prerendered.h"
#include "controller-stuff.h"

#ifndef NDEBUG
#include "physicsdebugdraw.h"
Expand Down Expand Up @@ -57,6 +58,7 @@ namespace blooDot::Orchestrator
toggleDebugView = isCreatorMode;

#endif
blooDot::ControllerStuff::StatusQuo();
blooDot::InGamePreRendered::PreRender(renderer);
if (!InitializeDings())
{
Expand Down Expand Up @@ -145,14 +147,6 @@ namespace blooDot::Orchestrator
int numKeys;
SDL_GetKeyboardState(&numKeys);
SDL_GameControllerEventState(SDL_ENABLE);
for (int i = 0; i < SDL_NumJoysticks(); ++i)
{
if (SDL_IsGameController(i))
{
controller = SDL_GameControllerOpen(i);
break;
}
}

// shaders
shaderPrograms[SHADER_PROGRAM_INDEX_RETRO] = CompileProgram
Expand Down Expand Up @@ -568,11 +562,6 @@ namespace blooDot::Orchestrator
}

THAT_ESCALATED_QUICKLY:
if (controller != nullptr)
{
SDL_GameControllerClose(controller);
}

_TeardownGPU();
DestroyTexture(&texTarget);
TeardownDingSheets();
Expand Down
14 changes: 7 additions & 7 deletions planning/creatormode.ligma
Expand Up @@ -42,13 +42,13 @@
to the lightbox, which is bigger than the stripes' height.

[ ] Biomes are:
- garden
- profane
- sacral
- winter
- desert
- wetlands
- scabland
- garden (where it is always late summer/autumn)
- profane (towns)
- sacral (with the cathedral and the cemetary)
- arctic (where there is snow and ice)
- desert (with the oracle)
- wetlands (featuring the marshes of doubtful drowning hazard)
- scabland (with volcanics)

[ ] Ding stripes are:
- flooring/ground
Expand Down
121 changes: 110 additions & 11 deletions playerhud.cpp
Expand Up @@ -11,8 +11,8 @@ extern int blooDot::Player::NumPlayers;

namespace blooDot::Hud
{
constexpr SDL_Rect Source = { 0,0,49,49 };
constexpr int const Padding = 9;
constexpr const auto LESSER_GU = GRIDUNIT / 3 * 2;
constexpr SDL_Rect Source = { 0,0,GRIDUNIT,GRIDUNIT };

SDL_Texture* LetterboxBackdropL = nullptr;
SDL_Texture* LetterboxBackdropR = nullptr;
Expand All @@ -29,6 +29,9 @@ namespace blooDot::Hud
SDL_Rect minimapDest = { 0 };

// makermode stuff
SDL_Texture* DingSelector = nullptr;
SDL_Rect dingSelectorDims = { 0 };
SDL_Rect dingSelectorDest = { 0 };
SDL_Texture* DesignLayers = nullptr;
SDL_Rect designLayersDims = { 0 };
SDL_Rect designLayersDest = { 0 };
Expand Down Expand Up @@ -227,8 +230,15 @@ namespace blooDot::Hud
if (selectedDesignLayer != layer)
{
selectedDesignLayer = layer;
_RedrawDesignLayersTool();
_RedrawDingSelectorTool();
if (!_RedrawDesignLayersTool())
{
return false;
}

if (!_RedrawDingSelectorTool())
{
return false;
}

return true;
}
Expand Down Expand Up @@ -447,6 +457,7 @@ namespace blooDot::Hud
{
/* draw the extra stuff that is only there when
* we are operating in creator (maker) mode */
SDL_RenderCopy(GameViewRenderer, DingSelector, &dingSelectorDims, &dingSelectorDest);
SDL_RenderCopy(GameViewRenderer, DesignLayers, &designLayersDims, &designLayersDest);
}
else
Expand Down Expand Up @@ -493,11 +504,36 @@ namespace blooDot::Hud
DestroyTexture(&designLayerFloorLabel);
DestroyTexture(&designLayerFloorLabelSelected);
DestroyTexture(&DesignLayers);
DestroyTexture(&DingSelector);
}
}

bool _InitializeDingSelectorTool()
{
dingSelectorDims.w = 2 + 7 * LESSER_GU + 6 * Padding + 2;
dingSelectorDims.h = dingSelectorDims.w;
dingSelectorDest.x = letterboxWidth / 2 - dingSelectorDims.w / 2;
dingSelectorDest.y = 49;
dingSelectorDest.w = dingSelectorDims.w;
dingSelectorDest.h = dingSelectorDims.h;

const auto& selectorTexture = SDL_CreateTexture(
GameViewRenderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET,
dingSelectorDims.w,
dingSelectorDims.h
);

if (!selectorTexture)
{
const auto createError = SDL_GetError();
ReportError("Failed to create the ding selector tool texture", createError);

return false;
}

DingSelector = selectorTexture;

return _RedrawDingSelectorTool();
}
Expand Down Expand Up @@ -623,6 +659,76 @@ namespace blooDot::Hud

bool _RedrawDingSelectorTool()
{
if (SDL_SetRenderTarget(GameViewRenderer, DingSelector) < 0)
{
const auto targetError = SDL_GetError();
ReportError("Failed to set the ding selector tool texture as the render target", targetError);

return false;
}

SDL_SetTextureBlendMode(DingSelector, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(GameViewRenderer, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
SDL_RenderClear(GameViewRenderer);

auto canvasTexture = BeginRenderDrawing(GameViewRenderer, dingSelectorDims.w, dingSelectorDims.h);
auto const& canvas = GetDrawingSink();

cairo_set_line_width(canvas, 2.6);
cairo_set_source_rgb(canvas, .3, .2, .6);
cairo_set_line_join(canvas, CAIRO_LINE_JOIN_BEVEL);

SDL_Rect biome1 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 0 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect biome2 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 1 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect biome3 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 2 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect biome4 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 3 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect biome5 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 4 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect biome6 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 5 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect biome7 = { dingSelectorDims.x + 2, dingSelectorDims.y + 2 + 6 * (LESSER_GU + Padding), LESSER_GU, LESSER_GU };
SDL_Rect dingbx = { dingSelectorDims.x + 2 + LESSER_GU + Padding, dingSelectorDims.y + 2, 6 * LESSER_GU + 5 * Padding, 5 * LESSER_GU + 4 * Padding };
SDL_Rect moving = { dingSelectorDims.x + dingSelectorDims.w - 2 - 1 * (2 * LESSER_GU + Padding), dingSelectorDims.y + dingSelectorDims.h - 2 - 2 * LESSER_GU - Padding, 2 * LESSER_GU + Padding, 2 * LESSER_GU + Padding};
SDL_Rect roting = { dingSelectorDims.x + dingSelectorDims.w - 2 - 2 * (2 * LESSER_GU + Padding) - Padding, dingSelectorDims.y + dingSelectorDims.h - 2 - 2 * LESSER_GU - Padding, 2 * LESSER_GU + Padding, 2 * LESSER_GU + Padding};
SDL_Rect splode = { dingSelectorDims.x + dingSelectorDims.w - 2 - 3 * (2 * LESSER_GU + Padding) - 2 * Padding, dingSelectorDims.y + dingSelectorDims.h - 2 - 2 * LESSER_GU - Padding, 2 * LESSER_GU + Padding, 2 * LESSER_GU + Padding };

cairo_rectangle(canvas, biome1.x, biome1.y, biome1.w, biome1.h);
cairo_rectangle(canvas, biome2.x, biome2.y, biome2.w, biome2.h);
cairo_rectangle(canvas, biome3.x, biome3.y, biome3.w, biome3.h);
cairo_rectangle(canvas, biome4.x, biome4.y, biome4.w, biome4.h);
cairo_rectangle(canvas, biome5.x, biome5.y, biome5.w, biome5.h);
cairo_rectangle(canvas, biome6.x, biome6.y, biome6.w, biome6.h);
cairo_rectangle(canvas, biome7.x, biome7.y, biome7.w, biome7.h);
cairo_rectangle(canvas, dingbx.x, dingbx.y, dingbx.w, dingbx.h);
cairo_rectangle(canvas, moving.x, moving.y, moving.w, moving.h);
cairo_rectangle(canvas, roting.x, roting.y, roting.w, roting.h);
cairo_rectangle(canvas, splode.x, splode.y, splode.w, splode.h);
cairo_stroke(canvas);

// X XXXXXXXXXXXXXXXXXXXXXXX
// X X
// X X X
// X X
// X X X
// X X
// X X X
// X X
// X X X
// X X
// X XXXXXXXXXXXXXXXXXXXXXXX
//
// X X X X
//
// left column = biome preset
// bottom row = move/rotate/remove tool

EndRenderDrawing(GameViewRenderer, canvasTexture, nullptr);
if (SDL_SetRenderTarget(GameViewRenderer, NULL) < 0)
{
const auto resetError = SDL_GetError();
ReportError("Failed to reset the render target after rendering to ding selector tool texture", resetError);

return false;
}

return true;
}

Expand All @@ -646,13 +752,6 @@ namespace blooDot::Hud

auto canvasTexture = BeginRenderDrawing(GameViewRenderer, designLayersDims.w, designLayersDims.h);
auto const& canvas = GetDrawingSink();

//cairo_set_line_width(canvas, 5.);
//cairo_set_source_rgba(canvas, .4, .4, .1, .5);
//cairo_set_line_join(canvas, CAIRO_LINE_JOIN_ROUND);
//cairo_rectangle(canvas, designLayersDims.x + 3, designLayersDims.y + 3, designLayersDims.w - 6, designLayersDims.h - 6);
//cairo_stroke(canvas);

auto const& yStride = designLayersDims.w / 4.;
auto const& xExtent = designLayersDims.w / 3.;
auto const& xSlantExtent = designLayersDims.w / 4.;
Expand Down
2 changes: 2 additions & 0 deletions playerhud.h
Expand Up @@ -12,6 +12,8 @@

namespace blooDot::Hud
{
constexpr int const Padding = 9;

bool Initialize();
DingProps GetDesignLayer();
bool SetDesignLayer(DingProps layer);
Expand Down

0 comments on commit 370dde7

Please sign in to comment.