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

Corrected formatting by running format-files.sh script. #1018

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
68 changes: 40 additions & 28 deletions src/MainMenu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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 @@ -70,10 +71,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 @@ -86,7 +90,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 @@ -107,10 +111,12 @@ bool mainMenu()
{
beginFrame();

while (SDL_PollEvent(&event) != 0) { // while there is a pending event
while (SDL_PollEvent(&event) != 0)
{ // while there is a pending event
ImGui_ImplSDL2_ProcessEvent(&event);

if (event.type == SDL_QUIT) {
if (event.type == SDL_QUIT)
{
startGame = false;
mainMenuLoop = false;
}
Expand All @@ -119,23 +125,24 @@ bool mainMenu()
if (showLoadDialog)
{
loadMenu.draw();
switch (loadMenu.result()) {
case LoadMenu::e_close:
showLoadDialog = false;
break;

case LoadMenu::e_load_file:
#ifdef USE_AUDIO
playAudioMajorSelection();
#endif // USE_AUDIO
SignalMediator::instance().signalLoadGame.emit(loadMenu.filename());
mainMenuLoop = false;
break;
default:
break;
switch (loadMenu.result())
{
case LoadMenu::e_close:
showLoadDialog = false;
break;

case LoadMenu::e_load_file:
#ifdef USE_AUDIO
playAudioMajorSelection();
#endif // USE_AUDIO
SignalMediator::instance().signalLoadGame.emit(loadMenu.filename());
mainMenuLoop = false;
break;
default:
break;
}
}
else
else
{
ui::PushFont(buttonFont);
ui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
Expand All @@ -147,37 +154,42 @@ 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", buttonSize)) {
#ifdef USE_AUDIO
if (ui::ButtonCt("New Game", buttonSize))
{
#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", buttonSize)) {
if (ui::ButtonCt("Load Game", buttonSize))
{
showLoadDialog = true;
}

buttonPos.y += buttonSize.y + buttonInterval;
ui::SetCursorPos(buttonPos);
if (ui::ButtonCt("Quit Game", buttonSize)) {
if (ui::ButtonCt("Quit Game", buttonSize))
{
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
2 changes: 1 addition & 1 deletion src/engine/Layout.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct LayoutData
int groupHeight = 0; ///< <internal> height of all elements in group
int groupWidth = 0; ///< <internal> Width of all elements in group
uint32_t fontSize = 20; ///< <internal> default font size of all elements in group
struct ImFont *font = nullptr; ///< <internal> font pointer for elements
struct ImFont *font = nullptr; ///< <internal> font pointer for elements
};

#endif
38 changes: 16 additions & 22 deletions src/engine/UIManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,23 @@ ImFont *UIManager::loadFont(const std::string &fontPath, uint32_t size)
return newFont;
}

void UIManager::initializeImGuiFonts() {
void UIManager::initializeImGuiFonts()
{
std::string fontPath = fs::getBasePath() + Settings::instance().fontFileName.get(); // fix for macos, need to use abs path

const auto names = {"MainMenuButtons", "PauseMenuButtons", "LoadDialogButtons", "BuildMenuButtons"};
for (const auto &name : names)
{
if (const auto it = m_layouts.find(name); it != m_layouts.end())
{
auto &layout = it->second;
layout.font = loadFont(fontPath, layout.fontSize);
auto &layout = it->second;
layout.font = loadFont(fontPath, layout.fontSize);
}
}
}

void UIManager::loadSettings(json& uiLayout) {
void UIManager::loadSettings(json &uiLayout)
{
std::string jsonFileContent = fs::readFileAsString(Settings::instance().uiLayoutJSONFile.get());
uiLayout = json::parse(jsonFileContent, nullptr, false);

Expand All @@ -89,7 +91,7 @@ void UIManager::loadSettings(json& uiLayout) {
throw ConfigurationError(TRACE_INFO "Error parsing JSON File " + Settings::instance().uiLayoutJSONFile.get());
}

void UIManager::parseLayouts(const json& uiLayout)
void UIManager::parseLayouts(const json &uiLayout)
{
// parse Layout
for (const auto &it : uiLayout["LayoutGroups"].items())
Expand Down Expand Up @@ -137,9 +139,7 @@ void UIManager::parseLayouts(const json& uiLayout)
}
}

void UIManager::setFPSCounterText(const std::string &fps) {
m_fpsCounter = fps;
}
void UIManager::setFPSCounterText(const std::string &fps) { m_fpsCounter = fps; }

void UIManager::closeOpenMenus()
{
Expand Down Expand Up @@ -179,10 +179,7 @@ void UIManager::addPersistentMenu(GameMenu::Ptr menu)
}
}

bool UIManager::isMouseHovered() const
{
return ImGui::IsAnyItemHovered();
}
bool UIManager::isMouseHovered() const { return ImGui::IsAnyItemHovered(); }

void UIManager::drawUI()
{
Expand All @@ -199,7 +196,8 @@ void UIManager::drawUI()
m->draw();
}

if (!m_tooltip.empty()) {
if (!m_tooltip.empty())
{
ImVec2 pos = ui::GetMousePos();
ui::SetCursorScreenPos(pos);
ui::Text(m_tooltip.c_str());
Expand All @@ -211,20 +209,16 @@ void UIManager::drawUI()
ui::SetNextWindowSize(ImVec2(140, 20));

bool open = true;
ui::Begin("##fpswindow", &open, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ui::Begin("##fpswindow", &open,
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse);
ui::Text(m_fpsCounter.c_str());
ui::SameLine();
ui::Checkbox("debug", &m_showDebugMenu);
ui::End();
}
}

void UIManager::setTooltip(const std::string &tooltipText)
{
m_tooltip = tooltipText;
}
void UIManager::setTooltip(const std::string &tooltipText) { m_tooltip = tooltipText; }

void UIManager::clearTooltip()
{
m_tooltip.clear();
}
void UIManager::clearTooltip() { m_tooltip.clear(); }
25 changes: 13 additions & 12 deletions src/engine/UIManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ struct GameMenu
{
using Ptr = std::shared_ptr<GameMenu>;
virtual ~GameMenu() = default;
virtual void draw() const { /* default implementation do nothing */ }
virtual void draw() const
{ /* default implementation do nothing */
}
virtual bool isMouseHovered() const { return false; }
virtual void closeSubmenus() { /* default implementation do nothing */ }
virtual void closeSubmenus()
{ /* default implementation do nothing */
}
};

struct BuildMenu;
Expand Down Expand Up @@ -47,7 +51,7 @@ public:
struct ImFont *loadFont(const std::string &name, uint32_t size);
void initializeImGuiFonts();

void loadSettings(json& uiLayout);
void loadSettings(json &uiLayout);
void parseLayouts(const json &uiLayout);

/**
Expand Down Expand Up @@ -75,7 +79,7 @@ public:
std::unordered_map<std::string, LayoutData> &getLayouts() { return m_layouts; }

void setTooltip(const std::string &tooltipText);

/**
* @brief Hides and resets the active tooltip.
* @see Tooltip#reset
Expand All @@ -89,8 +93,7 @@ public:

void openMenu(GameMenu::Ptr menuOption);

template<class Menu>
void openMenu() { openMenu(std::make_shared<Menu>()); }
template <class Menu> void openMenu() { openMenu(std::make_shared<Menu>()); }

void closeMenu();
inline bool isAnyMenuOpen() const { return !m_menuStack.empty(); }
Expand All @@ -99,8 +102,8 @@ public:

bool isMouseHovered() const;

template<class Menu>
inline GameMenu::Ptr findMenu() const {
template <class Menu> inline GameMenu::Ptr findMenu() const
{
for (const auto &m : m_menuStack)
{
if (dynamic_cast<Menu *>(m.get()))
Expand All @@ -119,15 +122,13 @@ public:

return nullptr;
}

template<class Menu>
void addPersistentMenu() { addPersistentMenu(std::make_shared<Menu>()); }

template <class Menu> void addPersistentMenu() { addPersistentMenu(std::make_shared<Menu>()); }

BUILDMENU_LAYOUT buildMenuLayout() const { return m_buildMenuLayout; }
void setBuildMenuLayout(BUILDMENU_LAYOUT l) { m_buildMenuLayout = l; }

private:

UIManager() = default;
~UIManager() = default;

Expand Down
7 changes: 3 additions & 4 deletions src/engine/WindowManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ WindowManager::WindowManager()
if (!m_window)
throw UIError(TRACE_INFO "Failed to create window: " + string{SDL_GetError()});

rendererFlags = SDL_RENDERER_ACCELERATED
| (Settings::instance().vSync ? SDL_RENDERER_PRESENTVSYNC : 0);
rendererFlags = SDL_RENDERER_ACCELERATED | (Settings::instance().vSync ? SDL_RENDERER_PRESENTVSYNC : 0);

#if defined(TESTING_ENABLED) && defined(__linux)
// Set the index to 2 for running tests
Expand Down Expand Up @@ -179,7 +178,7 @@ void WindowManager::initializeImguiRenderer()
ImGui_ImplSDLRenderer_Init(m_renderer);
}

void WindowManager::destroyImGuiRenderer()
void WindowManager::destroyImGuiRenderer()
{
ImGui_ImplSDLRenderer_Shutdown();
ImGui_ImplSDL2_Shutdown();
Expand Down Expand Up @@ -226,7 +225,7 @@ void WindowManager::newImGuiFrame()
{
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
ImGui::NewFrame();
}

void WindowManager::renderScreen()
Expand Down
3 changes: 2 additions & 1 deletion src/engine/basics/Camera.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void Camera::moveCamera(int xOffset, int yOffset)
m_CameraOffset.y -= yOffset;
MapFunctions::instance().refreshVisibleMap();
// update center coordinates
m_CenterIsoCoordinates = convertScreenToIsoCoordinates({Settings::instance().screenWidth / 2, Settings::instance().screenHeight / 2});
m_CenterIsoCoordinates =
convertScreenToIsoCoordinates({Settings::instance().screenWidth / 2, Settings::instance().screenHeight / 2});
}

const SDL_Point &Camera::cameraOffset() const noexcept { return m_CameraOffset; }
Expand Down
3 changes: 2 additions & 1 deletion src/engine/basics/GameStates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct GameStatesData
{
bool drawUI = true; ///< Draw UI. This is a temporary variable until the new UI has been implemented.
bool rectangularRoads = false; ///< place rectangular road tiles instead of diagonal tiles
LayerEditMode layerEditMode = LayerEditMode::TERRAIN; ///< Specifies the Layer Editmode. Editing Terrain or Blueprint (water pipes, subway,..)
LayerEditMode layerEditMode =
LayerEditMode::TERRAIN; ///< Specifies the Layer Editmode. Editing Terrain or Blueprint (water pipes, subway,..)
PlacementMode placementMode = PlacementMode::LINE; ///< Specifies the placement mode when holding down the mouse
DemolishMode demolishMode = DemolishMode::DEFAULT;
};
Expand Down
Loading