Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Set tile id in map node #967

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/MainMenu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ bool mainMenu()
int logoTexW, logoTexH;
SDL_QueryTexture(logoTex, nullptr, nullptr, &logoTexW, &logoTexH);

auto beginFrame = [] {
auto beginFrame = []
{
SDL_RenderClear(WindowManager::instance().getRenderer());

WindowManager::instance().newImGuiFrame();
Expand All @@ -66,10 +67,13 @@ bool mainMenu()
ui::SetNextWindowSize(ui::GetIO().DisplaySize);

bool open = true;
ui::Begin("MainWnd", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ui::Begin("MainWnd", &open,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse);
};

auto renderFrame = [] {
auto renderFrame = []
{
ui::End();

WindowManager::instance().renderScreen();
Expand All @@ -82,7 +86,7 @@ bool mainMenu()
{
beginFrame();

// break the loop if an event occurs
// break the loop if an event occurs
const bool has_event = SDL_PollEvent(&event) != 0;
if (has_event && event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYDOWN)
opacity = 254;
Expand All @@ -93,7 +97,6 @@ bool mainMenu()
ui::Image(logoTex, ImVec2(logoTexW, logoTexH), ImVec2(0, 0), ImVec2(1, 1), ImVec4{op, op, op, op});
ui::PopStyleVar(1);


renderFrame();
}

Expand All @@ -102,10 +105,12 @@ bool mainMenu()
{
beginFrame();

while (SDL_PollEvent(&event) != 0) {
while (SDL_PollEvent(&event) != 0)
{
ImGui_ImplSDL2_ProcessEvent(&event);

if (event.type == SDL_QUIT) {
if (event.type == SDL_QUIT)
{
startGame = false;
mainMenuLoop = false;
}
Expand All @@ -123,41 +128,46 @@ bool mainMenu()
constexpr int buttonInterval = 20;
ImVec2 buttonPos(screenWidth / 2 - buttonSize.x / 2, screenHeight / 2 - buttonSize.y);
ui::SetCursorPos(buttonPos);
if (ui::ButtonCt("New Game", { 200, 40 })) {
#ifdef USE_AUDIO
if (ui::ButtonCt("New Game", {200, 40}))
{
#ifdef USE_AUDIO
playAudioMajorSelection();
#endif // USE_AUDIO
#endif // USE_AUDIO
mainMenuLoop = false;
SignalMediator::instance().signalNewGame.emit(true);
}

buttonPos.y += buttonSize.y + buttonInterval;
ui::SetCursorPos(buttonPos);
if (ui::ButtonCt("Load Game", { 200, 40 })) {
#ifdef USE_AUDIO
if (ui::ButtonCt("Load Game", {200, 40}))
{
#ifdef USE_AUDIO
playAudioMajorSelection();
#endif // USE_AUDIO
#endif // USE_AUDIO
SignalMediator::instance().signalLoadGame.emit("save.cts");
mainMenuLoop = false;
}

buttonPos.y += buttonSize.y + buttonInterval;
ui::SetCursorPos(buttonPos);
if (ui::ButtonCt("Quit Game", { 200, 40 })) {
if (ui::ButtonCt("Quit Game", {200, 40}))
{
startGame = false;
mainMenuLoop = false;
}

constexpr int xOffset = 5, btnSize = 32;
ImVec2 leftBottom(xOffset, screenHeight - btnSize - xOffset * 2);
ui::SetCursorPos(leftBottom);
if (ui::ImageButton(discordTex, ImVec2(btnSize, btnSize))) {
if (ui::ImageButton(discordTex, ImVec2(btnSize, btnSize)))
{
OSystem::openDir("https://discord.gg/MG3tgYV6ce");
}

leftBottom.x += xOffset * 2 + btnSize; // xOffset * 2 because, need interval between buttons
ui::SetCursorPos(leftBottom);
if (ui::ImageButton(githubTex, ImVec2(btnSize, btnSize))) {
if (ui::ImageButton(githubTex, ImVec2(btnSize, btnSize)))
{
OSystem::openDir("https://github.com/CytopiaTeam/Cytopia/issues/new");
}

Expand Down
39 changes: 15 additions & 24 deletions src/engine/EventManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ void EventManager::pickTileUnderCursor(Point mouseIsoCoords)
// update placement mode
switch (topMostActiveLayer)
{
case Layer::BUILDINGS:
GameStates::instance().placementMode = PlacementMode::SINGLE;
break;
case Layer::ROAD:
case Layer::POWERLINES:
case Layer::UNDERGROUND:
GameStates::instance().placementMode = PlacementMode::LINE;
break;
case Layer::GROUND_DECORATION:
case Layer::WATER:
case Layer::ZONE:
GameStates::instance().placementMode = PlacementMode::RECTANGLE;
break;
default:
break;
case Layer::BUILDINGS:
GameStates::instance().placementMode = PlacementMode::SINGLE;
break;
case Layer::ROAD:
case Layer::POWERLINES:
case Layer::UNDERGROUND:
GameStates::instance().placementMode = PlacementMode::LINE;
break;
case Layer::GROUND_DECORATION:
case Layer::WATER:
case Layer::ZONE:
GameStates::instance().placementMode = PlacementMode::RECTANGLE;
break;
default:
break;
}
mapNodeData = node.getMapNodeData();
tileToPlace = mapNodeData[topMostActiveLayer].tileID;
Expand Down Expand Up @@ -304,15 +304,6 @@ void EventManager::checkEvents(SDL_Event &event)
mouseScreenCoords = {event.button.x, event.button.y};
mouseIsoCoords = convertScreenToIsoCoordinates(mouseScreenCoords);

// if it's a multi-node tile, get the origin corner point
Point origCornerPoint =
MapFunctions::instance().getNodeOrigCornerPoint(mouseIsoCoords, TileManager::instance().getTileLayer(tileToPlace));

if (origCornerPoint == Point::INVALID())
{
origCornerPoint = mouseIsoCoords;
}

// canceling transparent buildings
for (const auto &it : m_transparentBuildings)
{
Expand Down
Loading