From d53b233380fed4937a4a3cee152cd71a442c794d Mon Sep 17 00:00:00 2001 From: "Lilith N." Date: Wed, 24 Jul 2024 21:53:32 +0200 Subject: [PATCH] Improve `NO_STEAMWORKS` support --- file_sharing.cpp | 9 ++-- game.cpp | 6 ++- gui_builder.cpp | 11 ++++- gui_elem.cpp | 21 ++++++++- gui_elem.h | 7 ++- input.h | 42 +++++++++++++++++ keybinding_map.cpp | 10 +++- keybinding_map.h | 9 +++- main.cpp | 57 +++++++++++++++++------ main_loop.cpp | 4 +- map_gui.cpp | 2 + options.cpp | 14 ++++-- renderer.cpp | 11 ++++- scripted_ui.cpp | 7 ++- sdl_keycodes.cpp | 5 +- steam_base.h | 22 ++------- steam_info.h | 113 +++++++++++++++++++++++++++++++++++++++++++++ steam_input.h | 44 ++---------------- steam_ugc.h | 86 +--------------------------------- video.cpp | 7 ++- window_view.cpp | 11 ++++- window_view.h | 5 +- 22 files changed, 322 insertions(+), 181 deletions(-) create mode 100644 input.h create mode 100644 steam_info.h diff --git a/file_sharing.cpp b/file_sharing.cpp index 4b5d12c4b..042314511 100644 --- a/file_sharing.cpp +++ b/file_sharing.cpp @@ -10,13 +10,14 @@ #include -#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), diff --git a/game.cpp b/game.cpp index f3e2babc4..0431cdaf1 100644 --- a/game.cpp +++ b/game.cpp @@ -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 void Game::serialize(Archive& ar, const unsigned int version) { @@ -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) { diff --git a/gui_builder.cpp b/gui_builder.cpp index f897370dc..bd0809113 100644 --- a/gui_builder.cpp +++ b/gui_builder.cpp @@ -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; @@ -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) { diff --git a/gui_elem.cpp b/gui_elem.cpp index ffbd3593f..51b55a902 100644 --- a/gui_elem.cpp +++ b/gui_elem.cpp @@ -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; @@ -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 { @@ -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; @@ -568,8 +579,10 @@ class DrawScripted : public GuiElem { SGuiElem GuiFactory::scripted(function 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)); } @@ -3294,12 +3307,14 @@ SGuiElem GuiFactory::sprite(TexId id, Alignment a, optional 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 })); } @@ -3327,6 +3342,7 @@ SGuiElem GuiFactory::darken() { } void GuiFactory::propagateScrollEvent(const vector& guiElems) { +#ifdef USE_STEAMWORKS if (auto steamInput = getSteamInput()) { auto pos = steamInput->getJoyPos(ControllerJoy::MAP_SCROLLING); auto time = Clock::getRealMillis(); @@ -3339,6 +3355,7 @@ void GuiFactory::propagateScrollEvent(const vector& guiElems) { lastJoyScrollUpdate = time; } } +#endif } void GuiFactory::propagateEvent(const Event& event, const vector& guiElems) { diff --git a/gui_elem.h b/gui_elem.h index 852f05a56..06b4eac40 100644 --- a/gui_elem.h +++ b/gui_elem.h @@ -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; diff --git a/input.h b/input.h new file mode 100644 index 000000000..44050b99a --- /dev/null +++ b/input.h @@ -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 +}; diff --git a/keybinding_map.cpp b/keybinding_map.cpp index f45981781..f8797d362 100644 --- a/keybinding_map.cpp +++ b/keybinding_map.cpp @@ -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) { @@ -172,11 +175,14 @@ optional KeybindingMap::getText(Keybinding key) { SGuiElem KeybindingMap::getGlyph(SGuiElem label, GuiFactory* f, optional key, optional 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() diff --git a/keybinding_map.h b/keybinding_map.h index a784976a6..5496ac2b7 100644 --- a/keybinding_map.h +++ b/keybinding_map.h @@ -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; @@ -37,4 +42,4 @@ namespace SDL { class PrettyInputArchive; -void serialize(PrettyInputArchive&, SDL::SDL_Keysym&); \ No newline at end of file +void serialize(PrettyInputArchive&, SDL::SDL_Keysym&); diff --git a/main.cpp b/main.cpp index c6f2278af..cd2ff53b9 100644 --- a/main.cpp +++ b/main.cpp @@ -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 @@ -237,6 +237,35 @@ static void showLogoSplash(Renderer& renderer, FilePath logoPath, atomic& } } +class SteamPtrHolder { + private: +#ifdef USE_STEAMWORKS + unique_ptr steamInput; + unique_ptr 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(); + steamAchievements = make_unique(); +#endif + } +}; + static int keeperMain(po::parser& commandLineFlags) { ENABLE_PROFILER; if (commandLineFlags["help"].was_set()) { @@ -306,21 +335,19 @@ static int keeperMain(po::parser& commandLineFlags) { userKeysPath.erase(); highscoresPath.erase(); } - unique_ptr steamInput; - unique_ptr 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(); optional steamClient; if (appConfig.get("steamworks") > 0) { if (steam::initAPI()) { + steamPtr.create(); steamClient.emplace(); - steamInput->init(); - steamAchievements = make_unique(); + steamPtr.getInput()->init(); INFO << "\n" << steamClient->info(); } #ifdef RELEASE @@ -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 audioError = audioDevice.initialize(); auto modsDir = userPath.subdirectory(gameConfigSubdir); @@ -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"), @@ -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; diff --git a/main_loop.cpp b/main_loop.cpp index 6391d7803..5e8c6303b 100644 --- a/main_loop.cpp +++ b/main_loop.cpp @@ -60,8 +60,8 @@ #include "collective.h" #ifdef USE_STEAMWORKS -#include "steam_ugc.h" -#include "steam_client.h" +# include "steam_ugc.h" +# include "steam_client.h" #endif MainLoop::MainLoop(View* v, Highscores* h, FileSharing* fSharing, const DirectoryPath& paidDataPath, diff --git a/map_gui.cpp b/map_gui.cpp index 4f2481584..3d2b7201a 100644 --- a/map_gui.cpp +++ b/map_gui.cpp @@ -1510,9 +1510,11 @@ void MapGui::updateObjects(CreatureView* view, Renderer& renderer, MapLayout* ma const optional& tutorial) { selectionSize = view->getSelectionSize(); playerPosition = view->getPlayerPosition(); +#ifdef USE_STEAMWORKS renderer.getSteamInput()->setGameActionLayer(!!playerPosition ? MySteamInput::GameActionLayer::TURNED_BASED : MySteamInput::GameActionLayer::REAL_TIME); +#endif if (tutorial) { tutorialHighlightLow = tutorial->highlightedSquaresLow; tutorialHighlightHigh = tutorial->highlightedSquaresHigh; diff --git a/options.cpp b/options.cpp index 2321a9a99..2b705bb49 100644 --- a/options.cpp +++ b/options.cpp @@ -20,7 +20,10 @@ #include "scripted_ui_data.h" #include "keybinding_map.h" #include "content_factory.h" -#include "steam_input.h" + +#ifdef USE_STEAMWORKS +# include "steam_input.h" +#endif const EnumMap defaults { {OptionId::HINTS, 1}, @@ -189,7 +192,9 @@ Options::Value Options::getValue(OptionId id) { case OptionId::CONTROLLER_HINT_MAIN_MENU: case OptionId::CONTROLLER_HINT_TURN_BASED: case OptionId::CONTROLLER_HINT_REAL_TIME: +#ifdef USE_STEAMWORKS if (!steamInput || steamInput->controllers.empty()) +#endif return 0; break; default: @@ -535,10 +540,13 @@ void Options::handle(View* view, const ContentFactory* factory, OptionSet set, i [&] { keybindingsTab = false; wasSet = true; return true; } }; main.elems["set_keys"] = ScriptedUIDataElems::Callback{ [&] { +#ifdef USE_STEAMWORKS if (steamInput && !steamInput->controllers.empty()) { steamInput->showBindingScreen(); return false; - } else { + } else +#endif + { keybindingsTab = true; wasSet = true; return true; @@ -618,4 +626,4 @@ void Options::writeValues() { KeybindingMap* Options::getKeybindingMap() { return keybindingMap; -} \ No newline at end of file +} diff --git a/renderer.cpp b/renderer.cpp index d4d5a71d0..f72c2a981 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -27,7 +27,10 @@ #include "gzstream.h" #include "opengl.h" #include "tileset.h" -#include "steam_input.h" + +#ifdef USE_STEAMWORKS +# include "steam_input.h" +#endif void Renderer::renderDeferredSprites() { static vector vertices; @@ -669,8 +672,10 @@ void Renderer::setAnimationsDirectory(const DirectoryPath& path) { } void Renderer::drawAndClearBuffer() { +#ifdef USE_STEAMWORKS if (steamInput) steamInput->runFrame(); +#endif renderDeferredSprites(); CHECK_OPENGL_ERROR(); if (fpsLimit) { @@ -738,6 +743,7 @@ void Renderer::considerMouseMoveEvent(Event& ev) { bool Renderer::pollEvent(Event& ev) { CHECK(currentThreadId() == *renderThreadId); +#ifdef USE_STEAMWORKS if (steamInput) if (auto e = steamInput->getEvent()) { ev.type = SDL::SDL_KEYDOWN; @@ -750,6 +756,7 @@ bool Renderer::pollEvent(Event& ev) { }; return true; } +#endif if (monkey) { if (Random.roll(2)) return pollEventOrFromQueue(ev); @@ -761,6 +768,7 @@ bool Renderer::pollEvent(Event& ev) { Vec2 Renderer::getDiscreteJoyPos(ControllerJoy joy) { Vec2 ret; +#ifdef USE_STEAMWORKS if (steamInput) { auto pos = steamInput->getJoyPos(joy); if (pos.first <= -0.5) @@ -772,6 +780,7 @@ Vec2 Renderer::getDiscreteJoyPos(ControllerJoy joy) { else if (pos.second >= 0.5) ret.y = -1; } +#endif return ret; } diff --git a/scripted_ui.cpp b/scripted_ui.cpp index 5cb9ebe6a..8bb6fbb56 100644 --- a/scripted_ui.cpp +++ b/scripted_ui.cpp @@ -9,11 +9,14 @@ #include "clock.h" #include "container_range.h" #include "tileset.h" -#include "steam_input.h" #include "keybinding.h" #include "keybinding_map.h" #include "sound_library.h" +#ifdef USE_STEAMWORKS +# include "steam_input.h" +#endif + namespace EnumsDetail { enum class TextureFlip; enum class PlacementPos; @@ -205,12 +208,14 @@ REGISTER_SCRIPTED_UI(KeybindingHandler); struct RenderKeybinding : ScriptedUIInterface { variant getKeybindingGlyph(GuiFactory* f, Keybinding binding) const { +#ifdef USE_STEAMWORKS auto steamInput = f->getSteamInput(); if (steamInput && !steamInput->controllers.empty()) { if (auto key = KeybindingMap::getControllerMapping(binding)) if (auto path = steamInput->getGlyph(*key)) return &f->steamInputTexture(*path); } +#endif if (!controllerOnly) if (auto k = f->getKeybindingMap()->getText(binding)) return "[" + *k + "]"; diff --git a/sdl_keycodes.cpp b/sdl_keycodes.cpp index 9db5dde60..931202a9b 100644 --- a/sdl_keycodes.cpp +++ b/sdl_keycodes.cpp @@ -1,6 +1,9 @@ #include "util.h" #include "sdl.h" -#include "steam_input.h" + +#ifdef USE_STEAMWORKS +# include "steam_input.h" +#endif #define LIST_KEYS \ X(SDLK_UNKNOWN)\ diff --git a/steam_base.h b/steam_base.h index 6335ed2a7..2ceca5cfa 100644 --- a/steam_base.h +++ b/steam_base.h @@ -2,6 +2,11 @@ #include "util.h" +#ifndef USE_STEAMWORKS +#error steam_base.h included despite USE_STEAMWORKS not being defined! +#endif + + // Notes: // // - Whole interface is NOT thread safe, it should be used on a single thread only @@ -20,9 +25,6 @@ RICH_ENUM(QueryStatus, invalid, pending, completed, failed); namespace steam { - using int64 = long long; - using uint64 = unsigned long long; - #define STEAM_IFACE_DECL(name, Type) \ Type* ptr; \ name(Type*); \ @@ -46,20 +48,6 @@ class UGC; class Utils; class User; -struct UserId { - explicit UserId(uint64 v) :value(v) {} - operator uint64() const { return value; } - - uint64 value; -}; - -struct ItemId { - explicit ItemId(uint64 v) :value(v) {} - operator uint64() const { return value; } - - uint64 value; -}; - bool initAPI(); // Also updates UGC queries diff --git a/steam_info.h b/steam_info.h new file mode 100644 index 000000000..3d2555c44 --- /dev/null +++ b/steam_info.h @@ -0,0 +1,113 @@ +#pragma once + +// Note: while part of the steam:: api, this header can be included without USE_STEAMWORKS +// as it exclusively contains type definitions without any methods, thus not relying on +// steamworks + +#include "util.h" + +RICH_ENUM(SteamFindOrder, votes, date, subscriptions, playtime); +RICH_ENUM(SteamItemVisibility, public_, friends, private_); + +namespace steam { + + using int64 = long long; + using uint64 = unsigned long long; + + using FindOrder = SteamFindOrder; + using ItemVisibility = SteamItemVisibility; + + struct UserId { + explicit UserId(uint64 v) :value(v) {} + operator uint64() const { return value; } + + uint64 value; + }; + + struct ItemId { + explicit ItemId(uint64 v) :value(v) {} + operator uint64() const { return value; } + + uint64 value; + }; + + struct DownloadInfo { + unsigned long long bytesDownloaded; + unsigned long long bytesTotal; + }; + + struct InstallInfo { + unsigned long long sizeOnDisk; + string folder; + unsigned timeStamp; + }; + + struct ItemDetailsInfo { + unsigned playtimeStatsDays = 0; + bool additionalPreviews = false; + bool children = false; + bool keyValueTags = false; + bool longDescription = false; + bool metadata = false; + }; + + struct FindItemInfo { + FindOrder order = FindOrder::playtime; + string searchText; + vector tags; + bool anyTag = false; + + optional maxItemCount; + }; + + struct UpdateItemInfo { + optional id; + optional title; + optional description; + optional folder; + optional previewFile; + optional visibility; + vector tags; + optional>> keyValues; + optional metadata; + }; + + struct UpdateItemResult { + bool valid() const { + return itemId && !error; + } + + optional itemId; + optional error; + bool requireLegalAgreement; + }; + + struct ItemStats { + unsigned long long subscriptions, favorites, followers; + unsigned long long uniqueSubscriptions, uniqueFavorites, uniqueFollowers; + unsigned long long uniqueWebsiteViews, reportScore; + unsigned long long secondsPlayed, playtimeSessions, comments; + unsigned long long secondsPlayedDuringTimePeriod, playtimeSessionsDuringTimePeriod; + }; + + struct ItemInfo { + ItemInfo(ItemId iid, UserId oid) :id(iid), ownerId(oid) {} + + ItemId id; + UserId ownerId; + std::time_t creationTime, updateTime; + int votesUp, votesDown; + float score; + ItemVisibility visibility; + bool isValid; + + string title; + string description; + vector tags; + heap_optional stats; + + vector> keyValues; + string metadata; + }; + +} diff --git a/steam_input.h b/steam_input.h index e8d6ad52d..5b8e94773 100644 --- a/steam_input.h +++ b/steam_input.h @@ -1,49 +1,13 @@ #pragma once #include "util.h" +#include "input.h" #include "sdl.h" #include "file_path.h" -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 -}; +#ifndef USE_STEAMWORKS +#error steam_input.h included despite USE_STEAMWORKS not being defined! +#endif class MySteamInput { public: diff --git a/steam_ugc.h b/steam_ugc.h index bb33dd8bd..276b1140b 100644 --- a/steam_ugc.h +++ b/steam_ugc.h @@ -1,97 +1,13 @@ #pragma once #include "steam_base.h" - -RICH_ENUM(SteamFindOrder, votes, date, subscriptions, playtime); -RICH_ENUM(SteamItemVisibility, public_, friends, private_); +#include "steam_info.h" class ProgressMeter; struct ISteamUGC; namespace steam { -using FindOrder = SteamFindOrder; -using ItemVisibility = SteamItemVisibility; - -struct DownloadInfo { - unsigned long long bytesDownloaded; - unsigned long long bytesTotal; -}; - -struct InstallInfo { - unsigned long long sizeOnDisk; - string folder; - unsigned timeStamp; -}; - -struct ItemDetailsInfo { - unsigned playtimeStatsDays = 0; - bool additionalPreviews = false; - bool children = false; - bool keyValueTags = false; - bool longDescription = false; - bool metadata = false; -}; - -struct FindItemInfo { - FindOrder order = FindOrder::playtime; - string searchText; - vector tags; - bool anyTag = false; - - optional maxItemCount; -}; - -struct UpdateItemInfo { - optional id; - optional title; - optional description; - optional folder; - optional previewFile; - optional visibility; - vector tags; - optional>> keyValues; - optional metadata; -}; - -struct UpdateItemResult { - bool valid() const { - return itemId && !error; - } - - optional itemId; - optional error; - bool requireLegalAgreement; -}; - -struct ItemStats { - unsigned long long subscriptions, favorites, followers; - unsigned long long uniqueSubscriptions, uniqueFavorites, uniqueFollowers; - unsigned long long uniqueWebsiteViews, reportScore; - unsigned long long secondsPlayed, playtimeSessions, comments; - unsigned long long secondsPlayedDuringTimePeriod, playtimeSessionsDuringTimePeriod; -}; - -struct ItemInfo { - ItemInfo(ItemId iid, UserId oid) :id(iid), ownerId(oid) {} - - ItemId id; - UserId ownerId; - std::time_t creationTime, updateTime; - int votesUp, votesDown; - float score; - ItemVisibility visibility; - bool isValid; - - string title; - string description; - vector tags; - heap_optional stats; - - vector> keyValues; - string metadata; -}; - class UGC { STEAM_IFACE_DECL(UGC, ISteamUGC) diff --git a/video.cpp b/video.cpp index 6e1445912..7142dc9ba 100644 --- a/video.cpp +++ b/video.cpp @@ -12,7 +12,12 @@ #include "theoraplay.h" #include "renderer.h" -#include "steam_input.h" + +#ifdef USE_STEAMWORKS +# include "steam_input.h" +#else +# include "input.h" +#endif using namespace SDL; diff --git a/window_view.cpp b/window_view.cpp index 967a462c4..237d243df 100644 --- a/window_view.cpp +++ b/window_view.cpp @@ -42,7 +42,10 @@ #include "target_type.h" #include "keybinding_map.h" #include "mouse_button_id.h" -#include "steam_input.h" + +#ifdef USE_STEAMWORKS +# include "steam_input.h" +#endif using SDL::SDL_Keysym; using SDL::SDL_Keycode; @@ -616,8 +619,12 @@ optional WindowView::chooseDirection(Vec2 playerPos, const string& message addReturnDialog>(returnQueue, [=] ()-> optional { rebuildGui(); refreshScreen(); +#ifdef USE_STEAMWORKS renderer.getSteamInput()->setGameActionLayer(MySteamInput::GameActionLayer::TURNED_BASED); bool useController = !gui.getSteamInput()->controllers.empty(); +#else + bool useController = false; +#endif do { Event event; if (renderer.getDiscreteJoyPos(ControllerJoy::WALKING) != Vec2(0, 0)) @@ -702,8 +709,10 @@ View::TargetResult WindowView::chooseTarget(Vec2 playerPos, TargetType targetTyp refreshScreen(); guiBuilder.disableClickActions = true; optional controllerPos; +#ifdef USE_STEAMWORKS if (!gui.getSteamInput()->controllers.empty()) controllerPos = playerPos; +#endif do { auto pos = controllerPos ? controllerPos : mapGui->projectOnMap(renderer.getMousePos()); Event event; diff --git a/window_view.h b/window_view.h index 22ec714c3..345c43624 100644 --- a/window_view.h +++ b/window_view.h @@ -23,7 +23,10 @@ #include "gui_builder.h" #include "clock.h" #include "sound.h" -#include "steam_input.h" + +#ifdef USE_STEAMWORKSE +# include "steam_input.h" +#endif class SoundLibrary; class ViewIndex;