Skip to content
Open
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
9 changes: 5 additions & 4 deletions file_sharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

#include <curl/curl.h>

#include "steam_ugc.h"

#ifdef USE_STEAMWORKS
#include "steam_client.h"
#include "steam_user.h"
#include "steam_friends.h"
# include "steam_ugc.h"
# include "steam_client.h"
# include "steam_user.h"
# include "steam_friends.h"
#endif
#include "steam_info.h"

FileSharing::FileSharing(const string& url, const string& modVer, int saveVersion, Options& o, string id)
: uploadUrl(url), modVersion(modVer), saveVersion(saveVersion), options(o),
Expand Down
6 changes: 5 additions & 1 deletion game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
#include "body.h"
#include "enemy_aggression_level.h"
#include "unlocks.h"
#include "steam_achievements.h"
#include "progress_meter.h"
#ifdef USE_STEAMWORKS
# include "steam_achievements.h"
#endif

template <class Archive>
void Game::serialize(Archive& ar, const unsigned int version) {
Expand Down Expand Up @@ -833,8 +835,10 @@ void Game::addAnalytics(const string& name, const string& value) {
}

void Game::achieve(AchievementId id) const {
#ifdef USE_STEAMWORKS
if (steamAchievements)
steamAchievements->achieve(id);
#endif
if (!unlocks->isAchieved(id)) {
unlocks->achieve(id);
if (!steamAchievements) {
Expand Down
11 changes: 9 additions & 2 deletions gui_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@
#include "ai_type.h"
#include "container_range.h"
#include "keybinding_map.h"
#include "steam_input.h"
#include "tutorial_state.h"
#include "campaign_menu_index.h"
#include "tileset.h"
#include "zones.h"

#ifdef USE_STEAMWORKS
# include "steam_input.h"
#endif

using SDL::SDL_Keysym;
using SDL::SDL_Keycode;

Expand Down Expand Up @@ -816,7 +819,11 @@ int GuiBuilder::getImmigrationBarWidth() const {
}

bool GuiBuilder::hasController() const {
return !gui.getSteamInput()->controllers.empty();
#ifdef USE_STEAMWORKS
if (auto steamInput = gui.getSteamInput())
return !steamInput->controllers.empty();
#endif
return false;
}

SGuiElem GuiBuilder::drawTutorialOverlay(const TutorialInfo& info) {
Expand Down
21 changes: 19 additions & 2 deletions gui_elem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
#include "scripted_ui_data.h"
#include "mouse_button_id.h"
#include "tileset.h"
#include "steam_input.h"
#include "sound_library.h"
#include "sdl.h"

#ifdef USE_STEAMWORKS
# include "steam_input.h"
#endif

using SDL::SDL_Keysym;
using SDL::SDL_Keycode;

Expand Down Expand Up @@ -223,13 +226,17 @@ class TextFieldElem : public GuiElem {
: callback(std::move(callback)), getText(std::move(text)), controllerFocus(std::move(controllerFocus)),
maxLength(maxLength), alwaysFocused(alwaysFocused), steamInput(steamInput),
keybindingMap(keybindingMap) {
#ifdef USE_STEAMWORKS
if (alwaysFocused && steamInput)
steamInput->showFloatingKeyboard(Rectangle(100, 30, 800, 60));
#endif
}

virtual ~TextFieldElem() {
#ifdef USE_STEAMWORKS
if (alwaysFocused && steamInput)
steamInput->dismissFloatingKeyboard();
#endif
}

virtual bool onClick(MouseButtonId b, Vec2 pos) override {
Expand Down Expand Up @@ -283,17 +290,21 @@ class TextFieldElem : public GuiElem {
case SDL::SDLK_RETURN:
callback(current);
focused = false;
#ifdef USE_STEAMWORKS
if (!alwaysFocused && steamInput)
steamInput->dismissFloatingKeyboard();
return true;
#endif
default:
break;
}
return true;
} else if (!alwaysFocused && keybindingMap->matches(Keybinding("MENU_SELECT"), sym) && controllerFocus()) {
focused = true;
#ifdef USE_STEAMWORKS
if (steamInput)
steamInput->showFloatingKeyboard(getBounds());
#endif
return true;
}
return false;
Expand Down Expand Up @@ -568,8 +579,10 @@ class DrawScripted : public GuiElem {

SGuiElem GuiFactory::scripted(function<void()> endCallback, ScriptedUIId id, const ScriptedUIData& data,
ScriptedUIState& state) {
#if USE_STEAMWORKS
if (!state.highlightedElem && !getSteamInput()->controllers.empty())
state.highlightedElem = 0;
#endif
return SGuiElem(new DrawScripted(ScriptedContext{&renderer, this, endCallback, state, 0, 0}, id, data));
}

Expand Down Expand Up @@ -3294,12 +3307,14 @@ SGuiElem GuiFactory::sprite(TexId id, Alignment a, optional<Color> c) {

SGuiElem GuiFactory::steamInputGlyph(ControllerKey key, int size) {
return preferredSize(Vec2(size, size), drawCustom(
[this, key, size] (Renderer& r, Rectangle bounds) {
[this, key, size] (Renderer& r, Rectangle bounds) {
#ifdef USE_STEAMWORKS
if (auto path = getSteamInput()->getGlyph(key)) {
auto& tex = steamInputTexture(*path);
Vec2 texSize = tex.getSize();
r.drawSprite(bounds.topLeft(), Vec2(0, 0), texSize, tex, Vec2(size, size));
}
#endif
}));
}

Expand Down Expand Up @@ -3327,6 +3342,7 @@ SGuiElem GuiFactory::darken() {
}

void GuiFactory::propagateScrollEvent(const vector<SGuiElem>& guiElems) {
#ifdef USE_STEAMWORKS
if (auto steamInput = getSteamInput()) {
auto pos = steamInput->getJoyPos(ControllerJoy::MAP_SCROLLING);
auto time = Clock::getRealMillis();
Expand All @@ -3339,6 +3355,7 @@ void GuiFactory::propagateScrollEvent(const vector<SGuiElem>& guiElems) {
lastJoyScrollUpdate = time;
}
}
#endif
}

void GuiFactory::propagateEvent(const Event& event, const vector<SGuiElem>& guiElems) {
Expand Down
7 changes: 6 additions & 1 deletion gui_elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
#include "attr_type.h"
#include "view_id.h"
#include "keybinding.h"
#include "steam_input.h"

#ifdef USE_STEAMWORKS
# include "steam_input.h"
#else
# include "input.h"
#endif

class ViewObject;
class Clock;
Expand Down
42 changes: 42 additions & 0 deletions input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

enum ControllerKey {
C_ZLEVEL_UP = (1 << 20),
C_ZLEVEL_DOWN,
C_OPEN_MENU,
C_EXIT_CONTROL_MODE,
C_TOGGLE_CONTROL_MODE,
C_CHAT,
C_FIRE_PROJECTILE,
C_WAIT,
C_SKIP_TURN,
C_STAND_GROUND,
C_IGNORE_ENEMIES,
C_COMMANDS,
C_INVENTORY,
C_ABILITIES,
C_WORLD_MAP,
C_MINI_MAP,
C_ZOOM,
C_BUILDINGS_MENU,
C_MINIONS_MENU,
C_TECH_MENU,
C_HELP_MENU,
C_VILLAINS_MENU,
C_PAUSE,
C_SPEED_UP,
C_SPEED_DOWN,
C_BUILDINGS_UP,
C_BUILDINGS_DOWN,
C_BUILDINGS_LEFT,
C_BUILDINGS_RIGHT,
C_BUILDINGS_CONFIRM,
C_BUILDINGS_CANCEL,
C_SHIFT
};

enum class ControllerJoy {
WALKING,
MAP_SCROLLING,
MENU_SCROLLING
};
10 changes: 8 additions & 2 deletions keybinding_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include "gui_elem.h"
#include "pretty_archive.h"
#include "pretty_printing.h"
#include "steam_input.h"

#ifdef USE_STEAMWORKS
# include "steam_input.h"
#endif

KeybindingMap::KeybindingMap(const FilePath& defaults, const FilePath& user)
: defaultsPath(defaults), userPath(user) {
Expand Down Expand Up @@ -172,11 +175,14 @@ optional<string> KeybindingMap::getText(Keybinding key) {

SGuiElem KeybindingMap::getGlyph(SGuiElem label, GuiFactory* f, optional<ControllerKey> key, optional<string> alternative) {
SGuiElem add;
#ifdef USE_STEAMWORKS
auto steamInput = f->getSteamInput();
if (steamInput && !steamInput->controllers.empty()) {
if (key)
add = f->steamInputGlyph(*key);
} else if (alternative)
} else
#endif
if (alternative)
add = f->label("[" + *alternative + "]");
if (add)
label = f->getListBuilder()
Expand Down
9 changes: 7 additions & 2 deletions keybinding_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
#include "keybinding.h"
#include "file_path.h"
#include "color.h"
#include "steam_input.h"

#ifdef USE_STEAMWORKS
# include "steam_input.h"
#else
# include "input.h"
#endif

class FilePath;
class GuiFactory;
Expand Down Expand Up @@ -37,4 +42,4 @@ namespace SDL {

class PrettyInputArchive;

void serialize(PrettyInputArchive&, SDL::SDL_Keysym&);
void serialize(PrettyInputArchive&, SDL::SDL_Keysym&);
57 changes: 43 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
#include "fx_view_manager.h"
#include "layout_renderer.h"
#include "unlocks.h"
#include "steam_input.h"
#include "steam_achievements.h"

#include "stack_printer.h"

#ifdef USE_STEAMWORKS
#include "steam_base.h"
#include "steam_client.h"
#include "steam_user.h"
# include "steam_input.h"
# include "steam_achievements.h"
# include "steam_base.h"
# include "steam_client.h"
# include "steam_user.h"
#endif

#ifndef DATA_DIR
Expand Down Expand Up @@ -237,6 +237,35 @@ static void showLogoSplash(Renderer& renderer, FilePath logoPath, atomic<bool>&
}
}

class SteamPtrHolder {
private:
#ifdef USE_STEAMWORKS
unique_ptr<MySteamInput> steamInput;
unique_ptr<SteamAchievements> steamAchievements;
#endif
public:
MySteamInput * getInput() {
#ifdef USE_STEAMWORKS
return steamInput.get()
#else
return nullptr;
#endif
}
SteamAchievements * getAchievements() {
#ifdef USE_STEAMWORKS
return steamAchievements.get()
#else
return nullptr;
#endif
}
void create() {
#ifdef USE_STEAMWORKS
steamInput = make_unique<MySteamInput>();
steamAchievements = make_unique<SteamAchievements>();
#endif
}
};

static int keeperMain(po::parser& commandLineFlags) {
ENABLE_PROFILER;
if (commandLineFlags["help"].was_set()) {
Expand Down Expand Up @@ -306,21 +335,19 @@ static int keeperMain(po::parser& commandLineFlags) {
userKeysPath.erase();
highscoresPath.erase();
}
unique_ptr<MySteamInput> steamInput;
unique_ptr<SteamAchievements> steamAchievements;
SteamPtrHolder steamPtr;
#ifdef RELEASE
AppConfig appConfig(dataPath.file("appconfig.txt"));
#else
AppConfig appConfig(dataPath.file("appconfig-dev.txt"));
#endif
#ifdef USE_STEAMWORKS
steamInput = make_unique<MySteamInput>();
optional<steam::Client> steamClient;
if (appConfig.get<int>("steamworks") > 0) {
if (steam::initAPI()) {
steamPtr.create();
steamClient.emplace();
steamInput->init();
steamAchievements = make_unique<SteamAchievements>();
steamPtr.getInput()->init();
INFO << "\n" << steamClient->info();
}
#ifdef RELEASE
Expand All @@ -330,13 +357,15 @@ static int keeperMain(po::parser& commandLineFlags) {
}
#endif
KeybindingMap keybindingMap(freeDataPath.file("default_keybindings.txt"), userKeysPath);
Options options(settingsPath, &keybindingMap, steamInput.get());
Options options(settingsPath, &keybindingMap, steamPtr.getInput());
if (options.getBoolValue(OptionId::DPI_AWARE))
dpiAwareness();
Random.init(int(time(nullptr)));
auto installId = getInstallId(userPath.file("installId.txt"), Random);
if (steamInput->isRunningOnDeck())
#ifdef USE_STEAMWORKS
if (steamPtr.getInput()->isRunningOnDeck())
installId += "_deck";
#endif
AudioDevice audioDevice;
optional<string> audioError = audioDevice.initialize();
auto modsDir = userPath.subdirectory(gameConfigSubdir);
Expand Down Expand Up @@ -404,7 +433,7 @@ static int keeperMain(po::parser& commandLineFlags) {
}
Renderer renderer(
&clock,
steamInput.get(),
steamPtr.getInput(),
"KeeperRL",
contribDataPath,
freeDataPath.file("images/mouse_cursor.png"),
Expand Down Expand Up @@ -474,7 +503,7 @@ static int keeperMain(po::parser& commandLineFlags) {
options.addTrigger(OptionId::MUSIC, [&jukebox](int volume) { jukebox.setCurrentVolume(volume); });
Unlocks unlocks(&options, userPath.file("unlocks.txt"));
MainLoop loop(view.get(), &highscores, &fileSharing, paidDataPath, freeDataPath, userPath, modsDir, &options, &jukebox,
&sokobanInput, &tileSet, &unlocks, steamAchievements.get(), saveVersion, modVersion);
&sokobanInput, &tileSet, &unlocks, steamPtr.getAchievements(), saveVersion, modVersion);
try {
if (audioError)
USER_INFO << "Failed to initialize audio. The game will be started without sound. " << *audioError;
Expand Down
Loading