Skip to content

Commit

Permalink
Merge branch 'master' into player_defeated
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Sep 3, 2023
2 parents 3c7bb78 + b90eac0 commit 815124a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 16 deletions.
3 changes: 3 additions & 0 deletions doc/lua/events.md
Expand Up @@ -56,6 +56,9 @@ end
Only meaningfull if `addonsAll=false` and `addonsSome=true`:
Return a list with addonIds that the host can change.

**isMapPreviewEnabled()**
Is map preview enabled. Default is true

## Game

**onStart(isFirstStart)**
Expand Down
40 changes: 25 additions & 15 deletions libs/s25main/desktops/dskGameLobby.cpp
Expand Up @@ -233,24 +233,34 @@ dskGameLobby::dskGameLobby(ServerType serverType, std::shared_ptr<GameLobby> gam
// Karte laden, um Kartenvorschau anzuzeigen
if(!gameLobby_->isSavegame())
{
// Map laden
libsiedler2::Archiv mapArchiv;
// Karteninformationen laden
if(int ec = libsiedler2::loader::LoadMAP(GAMECLIENT.GetMapPath(), mapArchiv))
bool isMapPreviewEnabled = !lua || lua->IsMapPreviewEnabled();
if(!isMapPreviewEnabled)
{
WINDOWMANAGER.ShowAfterSwitch(
std::make_unique<iwMsgbox>(_("Error"), _("Could not load map:\n") + libsiedler2::getErrorString(ec), this,
MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 0));
AddTextDeepening(70, DrawPoint(560, 40), Extent(220, 220), TextureColor::Grey, _("No preview"), LargeFont,
COLOR_YELLOW);
AddText(71, DrawPoint(670, 40 + 220 + 10), _("Map: ") + GAMECLIENT.GetMapTitle(), COLOR_YELLOW,
FontStyle::CENTER, NormalFont);
} else
{
auto* map = static_cast<libsiedler2::ArchivItem_Map*>(mapArchiv.get(0));
ctrlPreviewMinimap* preview = AddPreviewMinimap(70, DrawPoint(560, 40), Extent(220, 220), map);

// Titel der Karte, Y-Position relativ je nach Höhe der Minimap festlegen, daher nochmals danach
// verschieben, da diese Position sonst skaliert wird!
ctrlText* text = AddText(71, DrawPoint(670, 0), _("Map: ") + GAMECLIENT.GetMapTitle(), COLOR_YELLOW,
FontStyle::CENTER, NormalFont);
text->SetPos(DrawPoint(text->GetPos().x, preview->GetPos().y + preview->GetMapArea().bottom + 10));
// Map laden
libsiedler2::Archiv mapArchiv;
// Karteninformationen laden
if(int ec = libsiedler2::loader::LoadMAP(GAMECLIENT.GetMapPath(), mapArchiv))
{
WINDOWMANAGER.ShowAfterSwitch(
std::make_unique<iwMsgbox>(_("Error"), _("Could not load map:\n") + libsiedler2::getErrorString(ec),
this, MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 0));
} else
{
auto* map = static_cast<libsiedler2::ArchivItem_Map*>(mapArchiv.get(0));
ctrlPreviewMinimap* preview = AddPreviewMinimap(70, DrawPoint(560, 40), Extent(220, 220), map);

// Titel der Karte, Y-Position relativ je nach Höhe der Minimap festlegen, daher nochmals danach
// verschieben, da diese Position sonst skaliert wird!
ctrlText* text = AddText(71, DrawPoint(670, 0), _("Map: ") + GAMECLIENT.GetMapTitle(), COLOR_YELLOW,
FontStyle::CENTER, NormalFont);
text->SetPos(DrawPoint(text->GetPos().x, preview->GetPos().y + preview->GetMapArea().bottom + 10));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/lua/LuaInterfaceGameBase.cpp
Expand Up @@ -16,7 +16,7 @@ unsigned LuaInterfaceGameBase::GetVersion()

unsigned LuaInterfaceGameBase::GetFeatureLevel()
{
return 3;
return 4;
}

LuaInterfaceGameBase::LuaInterfaceGameBase(const ILocalGameState& localGameState) : localGameState(localGameState)
Expand Down
10 changes: 10 additions & 0 deletions libs/s25main/lua/LuaInterfaceSettings.cpp
Expand Up @@ -237,3 +237,13 @@ std::vector<AddonId> LuaInterfaceSettings::GetAllowedAddons()
}
return std::vector<AddonId>();
}

bool LuaInterfaceSettings::IsMapPreviewEnabled()
{
kaguya::LuaRef func = lua["isMapPreviewEnabled"];
if(func.type() == LUA_TFUNCTION)
{
return func.call<bool>();
}
return true;
}
1 change: 1 addition & 0 deletions libs/s25main/lua/LuaInterfaceSettings.h
Expand Up @@ -35,6 +35,7 @@ class LuaInterfaceSettings : public LuaInterfaceGameBase
bool IsChangeAllowed(const std::string& name, bool defaultVal = false);
/// Get addons that are allowed to be changed
std::vector<AddonId> GetAllowedAddons();
bool IsMapPreviewEnabled();

private:
IGameLobbyController& lobbyServerController_;
Expand Down
7 changes: 7 additions & 0 deletions tests/s25Main/lua/testLuaSettings.cpp
Expand Up @@ -149,6 +149,13 @@ BOOST_AUTO_TEST_CASE(Events)
BOOST_TEST_REQUIRE(allowedAddons[0] == AddonId::LIMIT_CATAPULTS);
BOOST_TEST_REQUIRE(allowedAddons[1] == AddonId::CHARBURNER);
BOOST_TEST_REQUIRE(allowedAddons[2] == AddonId::TRADE);

BOOST_TEST(lua.IsMapPreviewEnabled()); // Not defined in lua -> Default to enabled
executeLua("function isMapPreviewEnabled()\n return false\nend");
BOOST_TEST(!lua.IsMapPreviewEnabled());
executeLua("function isMapPreviewEnabled()\n return true\nend");
BOOST_TEST(lua.IsMapPreviewEnabled());

// Return invalid type -> ignored, but log output
clearLog();
executeLua("function getAllowedAddons()\n return {'ADDON_FAIL_ME'}\nend");
Expand Down
4 changes: 4 additions & 0 deletions tests/testData/maps/LuaFunctions.lua
Expand Up @@ -20,6 +20,10 @@ function getAllowedChanges()
return {general=true, addonsAll=false, addonsSome=true, swapping=false, playerState = not isSinglePlayer, ownNation = true, ownColor=true, ownTeam=false, aiNation = false, aiColor=false, aiTeam=false}
end

function isMapPreviewEnabled()
return false
end

function onSettingsInit(isSinglePlayerArg, isSavegameArg)
isSinglePlayer = isSinglePlayerArg
isSavegame = isSavegameArg
Expand Down

0 comments on commit 815124a

Please sign in to comment.