Updating a few more things to state events, will probably stop here for now and revist the trailing things later.
This commit is contained in:
@ -4,9 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "event/Event.hpp"
|
||||
#include "state/State.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AssetManager;
|
||||
@ -18,6 +16,7 @@ namespace Dawn {
|
||||
uint8_t state = 0x00;
|
||||
bool loaded = false;
|
||||
Event<> eventLoaded;
|
||||
StateEvent<> event2Loaded;
|
||||
|
||||
/**
|
||||
* Create an abstract Asset object.
|
||||
|
@ -28,10 +28,12 @@ void AssetManager::queueLoad(Asset *asset) {
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(std::vector<Asset*> assets) {
|
||||
std::cout << "Asset list was queued to unload, but is not yet implemented" << std::endl;
|
||||
vectorAppend(&this->assetsToUnload, &assets);
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(Asset *asset) {
|
||||
std::cout << "Asset was queued to unload, but is not yet implemented" << std::endl;
|
||||
this->assetsToUnload.push_back(asset);
|
||||
}
|
||||
|
||||
@ -64,12 +66,12 @@ void AssetManager::queueSwap(
|
||||
|
||||
void AssetManager::syncTick() {
|
||||
auto it = this->assetsToLoad.begin();
|
||||
// auto it = this->assetsNotLoaded.begin();
|
||||
while(it != this->assetsToLoad.end()) {
|
||||
auto asset = *it;
|
||||
if(asset->loaded) {
|
||||
it = this->assetsToLoad.erase(it);
|
||||
asset->eventLoaded.invoke();
|
||||
asset->event2Loaded.invoke();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -79,12 +81,13 @@ void AssetManager::syncTick() {
|
||||
if(asset->loaded) {
|
||||
it = this->assetsToLoad.erase(it);
|
||||
asset->eventLoaded.invoke();
|
||||
asset->event2Loaded.invoke();
|
||||
continue;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// auto it = this->assetsNotLoaded.begin();
|
||||
// auto it2 = this->assetsToUnload.begin();
|
||||
// while(it2 != this->assetsToUnload.end()) {
|
||||
// ++it2;
|
||||
|
@ -20,7 +20,6 @@ void AudioAsset::updateSync() {
|
||||
// THIS WILL DEFINITELY CHANGE
|
||||
this->state = 0x08;
|
||||
this->loaded = true;
|
||||
this->eventLoaded.invoke();
|
||||
}
|
||||
|
||||
void AudioAsset::updateAsync() {
|
||||
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "event/Event.hpp"
|
||||
#include "state/State.hpp"
|
||||
#include "Easing.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
|
||||
@ -16,6 +16,7 @@ namespace Dawn {
|
||||
float_t time = 0;
|
||||
float_t duration = 0;
|
||||
Event<> eventAnimationEnd;
|
||||
StateEvent<> event2AnimationEnd;
|
||||
|
||||
/**
|
||||
* Ticks the animation along. Delta is whatever you want to update the
|
||||
|
@ -195,6 +195,7 @@ namespace Dawn {
|
||||
// Animation end.
|
||||
this->finished = true;
|
||||
this->eventAnimationEnd.invoke();
|
||||
this->event2AnimationEnd.invoke();
|
||||
}
|
||||
|
||||
void clear() override {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "dawnlibs.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "state/StateEvent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
@ -32,6 +33,9 @@ namespace Dawn {
|
||||
public:
|
||||
DawnGame *game;
|
||||
|
||||
StateEvent<inputbind_t> eventBindPressed;
|
||||
StateEvent<inputbind_t> eventBindReleased;
|
||||
|
||||
IInputManager(DawnGame *game) {
|
||||
assertNotNull(game);
|
||||
this->game = game;
|
||||
@ -163,7 +167,7 @@ namespace Dawn {
|
||||
|
||||
// For each bind...
|
||||
while(it != this->binds.end()) {
|
||||
float_t value = 0.0f;
|
||||
float_t value = 0.0f, valCurrent;
|
||||
|
||||
// For each input axis...
|
||||
auto bindIt = it->second.begin();
|
||||
@ -176,10 +180,20 @@ namespace Dawn {
|
||||
|
||||
// Set into current values
|
||||
if(this->currentIsLeft) {
|
||||
valCurrent = this->valuesRight[it->first];
|
||||
this->valuesLeft[it->first] = value;
|
||||
} else {
|
||||
valCurrent = this->valuesLeft[it->first];
|
||||
this->valuesRight[it->first] = value;
|
||||
}
|
||||
|
||||
// Fire events when necessary.
|
||||
if(value == 0 && valCurrent == 1) {
|
||||
eventBindReleased.invoke(it->first);
|
||||
} else if(valCurrent == 0 && value == 1) {
|
||||
eventBindPressed.invoke(it->first);
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "event/Event.hpp"
|
||||
#include "state/State.hpp"
|
||||
#include "asset/AssetManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
@ -14,7 +14,7 @@ namespace Dawn {
|
||||
std::string language;
|
||||
};
|
||||
|
||||
class LocaleManager {
|
||||
class LocaleManager : public StateOwner {
|
||||
private:
|
||||
DawnGame *game;
|
||||
LanguageAsset *asset;
|
||||
@ -26,8 +26,8 @@ namespace Dawn {
|
||||
void onLanguageLoaded();
|
||||
|
||||
public:
|
||||
Event<> eventLocaleChanged;
|
||||
Event<> eventLanguageUpdated;
|
||||
StateEvent<> eventLocaleChanged;
|
||||
StateEvent<> eventLanguageUpdated;
|
||||
|
||||
/**
|
||||
* Initializes the Locale Manager Instance. Locale Manager is responsible
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "util/array.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "state/State.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum UIComponentAlign {
|
||||
@ -20,7 +21,7 @@ namespace Dawn {
|
||||
|
||||
class UIGrid;
|
||||
|
||||
class UIComponent {
|
||||
class UIComponent : public StateOwner {
|
||||
protected:
|
||||
// Calculated (and cached) values
|
||||
float_t width = 1;
|
||||
|
@ -9,9 +9,12 @@
|
||||
using namespace Dawn;
|
||||
|
||||
UILabel::UILabel(UICanvas *canvas) : UIComponent(canvas) {
|
||||
getGame()->localeManager.eventLanguageUpdated.addListener(
|
||||
this, &UILabel::onLanguageUpdated
|
||||
);
|
||||
evtLangUpdated = useEvent([&]{
|
||||
this->needsRebuffering = true;
|
||||
if(key.size() > 0 && this->getGame()->localeManager.getString(key).size() > 0) {
|
||||
this->hasText = true;
|
||||
}
|
||||
}, getGame()->localeManager.eventLanguageUpdated);
|
||||
}
|
||||
|
||||
void UILabel::updatePositions() {
|
||||
@ -105,16 +108,3 @@ void UILabel::setTransform(
|
||||
this->needsRebuffering = true;
|
||||
UIComponent::setTransform(xAlign, yAlign, alignment, z);
|
||||
}
|
||||
|
||||
void UILabel::onLanguageUpdated() {
|
||||
this->needsRebuffering = true;
|
||||
if(key.size() > 0 && this->getGame()->localeManager.getString(key).size()>0){
|
||||
this->hasText = true;
|
||||
}
|
||||
}
|
||||
|
||||
UILabel::~UILabel() {
|
||||
getGame()->localeManager.eventLanguageUpdated.removeListener(
|
||||
this, &UILabel::onLanguageUpdated
|
||||
);
|
||||
}
|
@ -17,12 +17,10 @@ namespace Dawn {
|
||||
std::string key = "";
|
||||
float_t fontSize = 10.0f;
|
||||
bool_t hasText = false;
|
||||
std::function<void()> evtLangUpdated;
|
||||
|
||||
void updatePositions() override;
|
||||
|
||||
/** Event for when the language strings are updated */
|
||||
void onLanguageUpdated();
|
||||
|
||||
std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||
glm::mat4 projection,
|
||||
glm::mat4 view,
|
||||
@ -79,7 +77,5 @@ namespace Dawn {
|
||||
* @return Font size of the label.
|
||||
*/
|
||||
float_t getFontSize();
|
||||
|
||||
~UILabel();
|
||||
};
|
||||
}
|
@ -6,5 +6,5 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
DawnHostWin32.cpp
|
||||
DawnHostTux32.cpp
|
||||
)
|
@ -3,7 +3,7 @@
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnHostWin32.hpp"
|
||||
#include "DawnHostTux32.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
@ -52,12 +52,12 @@ namespace Dawn {
|
||||
enum AudioSourceState state = AUDIO_SOURCE_STATE_STOPPED;
|
||||
AudioSourcePlayMode playMode;
|
||||
|
||||
Event<> eventPlaying;
|
||||
Event<> eventResumed;
|
||||
Event<> eventPaused;
|
||||
Event<> eventStopped;
|
||||
Event<> eventFinished;
|
||||
Event<> eventLooped;
|
||||
StateEvent<> eventPlaying;
|
||||
StateEvent<> eventResumed;
|
||||
StateEvent<> eventPaused;
|
||||
StateEvent<> eventStopped;
|
||||
StateEvent<> eventFinished;
|
||||
StateEvent<> eventLooped;
|
||||
|
||||
/**
|
||||
* Creates an Audio Source item component.
|
||||
|
@ -23,32 +23,32 @@ namespace Dawn {
|
||||
|
||||
class LanguageParser : public XmlParser<struct LanguageString> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes();
|
||||
std::map<std::string, std::string> getOptionalAttributes();
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct LanguageString *out,
|
||||
std::string *error
|
||||
);
|
||||
) override;
|
||||
};
|
||||
|
||||
class LanguageGroupParser : public XmlParser<struct LanguageGroup> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes();
|
||||
std::map<std::string, std::string> getOptionalAttributes();
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct LanguageGroup *out,
|
||||
std::string *error
|
||||
);
|
||||
) override;
|
||||
};
|
||||
|
||||
class LanguageRootParser : public XmlParser<struct LanguageRoot> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes();
|
||||
std::map<std::string, std::string> getOptionalAttributes();
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
@ -61,18 +61,6 @@ namespace Dawn {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
|
||||
int32_t parseGroup(
|
||||
Xml *node,
|
||||
std::string key,
|
||||
std::map<std::string, std::vector<struct LanguageString>> *strings
|
||||
);
|
||||
|
||||
int32_t parseString(
|
||||
Xml *node,
|
||||
std::string key,
|
||||
std::map<std::string, std::vector<struct LanguageString>> *strings
|
||||
);
|
||||
|
||||
public:
|
||||
int32_t start() override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user