diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/EventDispatcher.cpp | 6 | ||||
-rw-r--r-- | common/EventMapper.cpp | 38 | ||||
-rw-r--r-- | common/events.h | 17 | ||||
-rw-r--r-- | common/gui_options.cpp | 17 | ||||
-rw-r--r-- | common/gui_options.h | 5 | ||||
-rw-r--r-- | common/language.cpp | 18 | ||||
-rw-r--r-- | common/language.h | 6 | ||||
-rw-r--r-- | common/rendermode.cpp | 41 | ||||
-rw-r--r-- | common/rendermode.h | 6 | ||||
-rw-r--r-- | common/translation.cpp | 5 |
10 files changed, 136 insertions, 23 deletions
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp index 4c7286bbb5..012a2dfce5 100644 --- a/common/EventDispatcher.cpp +++ b/common/EventDispatcher.cpp @@ -60,6 +60,12 @@ void EventDispatcher::dispatch() { } } } + + List<Event> delayedEvents = _mapper->getDelayedEvents(); + for (List<Event>::iterator k = delayedEvents.begin(); k != delayedEvents.end(); ++k) { + const Event delayedEvent = *k; + dispatchEvent(delayedEvent); + } } void EventDispatcher::registerMapper(EventMapper *mapper) { diff --git a/common/EventMapper.cpp b/common/EventMapper.cpp index 2808a7b5fd..47db61e472 100644 --- a/common/EventMapper.cpp +++ b/common/EventMapper.cpp @@ -22,6 +22,9 @@ #include "common/events.h" +#include "common/system.h" +#include "common/textconsole.h" + namespace Common { List<Event> DefaultEventMapper::mapEvent(const Event &ev, EventSource *source) { @@ -46,9 +49,44 @@ List<Event> DefaultEventMapper::mapEvent(const Event &ev, EventSource *source) { // if it didn't get mapped, just pass it through if (mappedEvent.type == EVENT_INVALID) mappedEvent = ev; + +#ifdef ENABLE_VKEYBD + // TODO: this check is not needed post-split + if (mappedEvent.type == EVENT_CUSTOM_BACKEND_HARDWARE) { + warning("EVENT_CUSTOM_BACKEND_HARDWARE was not mapped"); + return List<Event>(); + } +#endif + events.push_back(mappedEvent); return events; } +void DefaultEventMapper::addDelayedEvent(uint32 millis, Event ev) { + if (_delayedEvents.empty()) { + _delayedEffectiveTime = g_system->getMillis() + millis; + millis = 0; + } + DelayedEventsEntry entry = DelayedEventsEntry(millis, ev); + _delayedEvents.push(entry); +} + +List<Event> DefaultEventMapper::getDelayedEvents() { + List<Event> events; + + if (_delayedEvents.empty()) + return events; + + uint32 now = g_system->getMillis(); + + while (!_delayedEvents.empty() && now >= _delayedEffectiveTime) { + DelayedEventsEntry entry = _delayedEvents.pop(); + if (!_delayedEvents.empty()) + _delayedEffectiveTime += _delayedEvents.front().timerOffset; + events.push_back(entry.event); + } + return events; +} + } // namespace Common diff --git a/common/events.h b/common/events.h index 4efdd67b91..7366c51d36 100644 --- a/common/events.h +++ b/common/events.h @@ -79,6 +79,8 @@ enum EventType { // IMPORTANT NOTE: This is part of the WIP Keymapper. If you plan to use // this, please talk to tsoliman and/or LordHoto. EVENT_CUSTOM_BACKEND_ACTION = 18, + EVENT_CUSTOM_BACKEND_HARDWARE = 21, + EVENT_GUI_REMAP_COMPLETE_ACTION = 22, EVENT_KEYMAPPER_REMAP = 19 #endif #ifdef ENABLE_VKEYBD @@ -230,12 +232,27 @@ public: * Map an incoming event to one or more action events */ virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0; + + virtual List<Event> getDelayedEvents() = 0; }; class DefaultEventMapper : public EventMapper { public: + DefaultEventMapper() : _delayedEvents(), _delayedEffectiveTime(0) {} // EventMapper interface virtual List<Event> mapEvent(const Event &ev, EventSource *source); + virtual List<Event> getDelayedEvents(); +protected: + virtual void addDelayedEvent(uint32 millis, Event ev); + + struct DelayedEventsEntry { + const uint32 timerOffset; + const Event event; + DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { } + }; + + Queue<DelayedEventsEntry> _delayedEvents; + uint32 _delayedEffectiveTime; }; /** diff --git a/common/gui_options.cpp b/common/gui_options.cpp index 5b7d939dc4..32a7cc9c41 100644 --- a/common/gui_options.cpp +++ b/common/gui_options.cpp @@ -79,23 +79,6 @@ bool checkGameGUIOption(const String &option, const String &str) { return false; } -bool checkGameGUIOptionLanguage(Language lang, const String &str) { - if (!str.contains("lang_")) // If no languages are specified - return true; - - if (str.contains(getGameGUIOptionsDescriptionLanguage(lang))) - return true; - - return false; -} - -const String getGameGUIOptionsDescriptionLanguage(Language lang) { - if (lang == UNK_LANG) - return ""; - - return String("lang_") + getLanguageDescription(lang); -} - String parseGameGUIOptions(const String &str) { String res; diff --git a/common/gui_options.h b/common/gui_options.h index 5649f1103d..33ecccad63 100644 --- a/common/gui_options.h +++ b/common/gui_options.h @@ -23,8 +23,6 @@ #ifndef COMMON_GUI_OPTIONS_H #define COMMON_GUI_OPTIONS_H -#include "common/language.h" - #define GUIO_NONE "\000" #define GUIO_NOSUBTITLES "\001" #define GUIO_NOMUSIC "\002" @@ -68,12 +66,11 @@ namespace Common { +class String; bool checkGameGUIOption(const String &option, const String &str); -bool checkGameGUIOptionLanguage(Common::Language lang, const String &str); String parseGameGUIOptions(const String &str); const String getGameGUIOptionsDescription(const String &options); -const String getGameGUIOptionsDescriptionLanguage(Common::Language lang); /** * Updates the GUI options of the current config manager diff --git a/common/language.cpp b/common/language.cpp index 1de01b0207..898adf8d0e 100644 --- a/common/language.cpp +++ b/common/language.cpp @@ -20,6 +20,7 @@ */ #include "common/language.h" +#include "common/gui_options.h" #include "common/str.h" namespace Common { @@ -104,4 +105,21 @@ const char *getLanguageDescription(Language id) { return 0; } +bool checkGameGUIOptionLanguage(Language lang, const String &str) { + if (!str.contains("lang_")) // If no languages are specified + return true; + + if (str.contains(getGameGUIOptionsDescriptionLanguage(lang))) + return true; + + return false; +} + +const String getGameGUIOptionsDescriptionLanguage(Language lang) { + if (lang == UNK_LANG) + return ""; + + return String("lang_") + getLanguageDescription(lang); +} + } // End of namespace Common diff --git a/common/language.h b/common/language.h index b83f0d34fd..db552fc9c4 100644 --- a/common/language.h +++ b/common/language.h @@ -75,6 +75,12 @@ extern const char *getLanguageCode(Language id); extern const char *getLanguageLocale(Language id); extern const char *getLanguageDescription(Language id); +// TODO: Document this GUIO related function +const String getGameGUIOptionsDescriptionLanguage(Common::Language lang); + +// TODO: Document this GUIO related function +bool checkGameGUIOptionLanguage(Common::Language lang, const String &str); + } // End of namespace Common #endif diff --git a/common/rendermode.cpp b/common/rendermode.cpp index 62b67faee5..e8f3146630 100644 --- a/common/rendermode.cpp +++ b/common/rendermode.cpp @@ -22,6 +22,7 @@ #include "common/rendermode.h" +#include "common/gui_options.h" #include "common/str.h" #include "common/translation.h" @@ -43,6 +44,26 @@ const RenderModeDescription g_renderModes[] = { {0, 0, kRenderDefault} }; +struct RenderGUIOMapping { + RenderMode id; + const char *guio; +}; + +// TODO: Merge s_renderGUIOMapping into g_renderModes? the kRenderDefault +// could be used to indicate "any" mode when passed to renderMode2GUIO (if +// we wanted to merge allRenderModesGUIOs back into) +static const RenderGUIOMapping s_renderGUIOMapping[] = { + { kRenderHercG, GUIO_RENDERHERCGREEN }, + { kRenderHercA, GUIO_RENDERHERCAMBER }, + { kRenderCGA, GUIO_RENDERCGA }, + { kRenderEGA, GUIO_RENDEREGA }, + { kRenderVGA, GUIO_RENDERVGA }, + { kRenderAmiga, GUIO_RENDERAMIGA }, + { kRenderFMTowns, GUIO_RENDERFMTOWNS }, + { kRenderPC9821, GUIO_RENDERPC9821 }, + { kRenderPC9801, GUIO_RENDERPC9801 } +}; + DECLARE_TRANSLATION_ADDITIONAL_CONTEXT("Hercules Green", "lowres") DECLARE_TRANSLATION_ADDITIONAL_CONTEXT("Hercules Amber", "lowres") @@ -77,5 +98,25 @@ const char *getRenderModeDescription(RenderMode id) { return 0; } +String renderMode2GUIO(RenderMode id) { + String res; + + for (int i = 0; i < ARRAYSIZE(s_renderGUIOMapping); i++) { + if (id == s_renderGUIOMapping[i].id) + res += s_renderGUIOMapping[i].guio; + } + + return res; +} + +String allRenderModesGUIOs() { + String res; + + for (int i = 0; i < ARRAYSIZE(s_renderGUIOMapping); i++) { + res += s_renderGUIOMapping[i].guio; + } + + return res; +} } // End of namespace Common diff --git a/common/rendermode.h b/common/rendermode.h index c2fece77ee..945c4e7d9d 100644 --- a/common/rendermode.h +++ b/common/rendermode.h @@ -61,6 +61,12 @@ extern RenderMode parseRenderMode(const String &str); extern const char *getRenderModeCode(RenderMode id); extern const char *getRenderModeDescription(RenderMode id); +// TODO: Rename the following to something better; also, document it +extern String renderMode2GUIO(RenderMode id); + +// TODO: Rename the following to something better; also, document it +extern String allRenderModesGUIOs(); + } // End of namespace Common diff --git a/common/translation.cpp b/common/translation.cpp index 219fce8794..2bc31c617b 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -232,8 +232,9 @@ bool TranslationManager::openTranslationsFile(File &inFile) { ArchiveMemberList fileList; SearchMan.listMatchingMembers(fileList, "translations.dat"); for (ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { - SeekableReadStream *stream = it->get()->createReadStream(); - if (stream && inFile.open(stream, it->get()->getName())) { + ArchiveMember const &m = **it; + SeekableReadStream *const stream = m.createReadStream(); + if (stream && inFile.open(stream, m.getName())) { if (checkHeader(inFile)) return true; inFile.close(); |