mirror of https://github.com/AxioDL/metaforce.git
Merge pull request #222 from lioncash/view
CGameOptions: Make use of std::string_view where applicable
This commit is contained in:
commit
4eaed95c11
|
@ -31,12 +31,12 @@ CGameHintInfo::SHintLocation::SHintLocation(CInputStream& in, s32)
|
|||
, x8_areaId(in.readUint32Big())
|
||||
, xc_stringId(in.readUint32Big()) {}
|
||||
|
||||
int CGameHintInfo::FindHintIndex(const char* str) {
|
||||
int CGameHintInfo::FindHintIndex(std::string_view str) {
|
||||
const std::vector<CGameHint>& gameHints = g_MemoryCardSys->GetHints();
|
||||
const auto& it = std::find_if(gameHints.begin(), gameHints.end(),
|
||||
[&str](const CGameHint& gh) -> bool { return gh.GetName() == str; });
|
||||
const auto it =
|
||||
std::find_if(gameHints.cbegin(), gameHints.cend(), [&str](const CGameHint& gh) { return gh.GetName() == str; });
|
||||
|
||||
return (it != gameHints.end() ? it - gameHints.begin() : -1);
|
||||
return it != gameHints.cend() ? it - gameHints.cbegin() : -1;
|
||||
}
|
||||
|
||||
CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer, CObjectReference*) {
|
||||
|
|
|
@ -42,7 +42,7 @@ private:
|
|||
public:
|
||||
CGameHintInfo(CInputStream&, s32);
|
||||
const std::vector<CGameHint>& GetHints() const { return x0_hints; }
|
||||
static int FindHintIndex(const char* str);
|
||||
static int FindHintIndex(std::string_view str);
|
||||
};
|
||||
|
||||
CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream&, const CVParamTransfer, CObjectReference*);
|
||||
|
|
|
@ -578,43 +578,51 @@ const CHintOptions::SHintState* CHintOptions::GetCurrentDisplayedHint() const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void CHintOptions::DelayHint(const char* name) {
|
||||
int idx = CGameHintInfo::FindHintIndex(name);
|
||||
if (idx == -1)
|
||||
void CHintOptions::DelayHint(std::string_view name) {
|
||||
const int idx = CGameHintInfo::FindHintIndex(name);
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x10_nextHintIdx == idx)
|
||||
for (SHintState& state : x0_hintStates)
|
||||
if (x10_nextHintIdx == idx) {
|
||||
for (SHintState& state : x0_hintStates) {
|
||||
state.x4_time += 60.f;
|
||||
}
|
||||
}
|
||||
|
||||
x0_hintStates[idx].x0_state = EHintState::Delayed;
|
||||
}
|
||||
|
||||
void CHintOptions::ActivateImmediateHintTimer(const char* name) {
|
||||
int idx = CGameHintInfo::FindHintIndex(name);
|
||||
if (idx == -1)
|
||||
void CHintOptions::ActivateImmediateHintTimer(std::string_view name) {
|
||||
const int idx = CGameHintInfo::FindHintIndex(name);
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
SHintState& hintState = x0_hintStates[idx];
|
||||
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[idx];
|
||||
if (hintState.x0_state != EHintState::Zero)
|
||||
if (hintState.x0_state != EHintState::Zero) {
|
||||
return;
|
||||
}
|
||||
|
||||
hintState.x0_state = EHintState::Waiting;
|
||||
hintState.x4_time = hint.GetImmediateTime();
|
||||
}
|
||||
|
||||
void CHintOptions::ActivateContinueDelayHintTimer(const char* name) {
|
||||
void CHintOptions::ActivateContinueDelayHintTimer(std::string_view name) {
|
||||
int idx = x10_nextHintIdx;
|
||||
if (idx != 0)
|
||||
if (idx != 0) {
|
||||
idx = CGameHintInfo::FindHintIndex(name);
|
||||
if (idx == -1)
|
||||
}
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
SHintState& hintState = x0_hintStates[idx];
|
||||
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[idx];
|
||||
if (hintState.x0_state != EHintState::Displaying)
|
||||
if (hintState.x0_state != EHintState::Displaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
hintState.x4_time = hint.GetTextTime();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "Runtime/CSaveWorld.hpp"
|
||||
|
@ -205,9 +206,9 @@ public:
|
|||
void SetNextHintTime();
|
||||
void InitializeMemoryState();
|
||||
const SHintState* GetCurrentDisplayedHint() const;
|
||||
void DelayHint(const char* name);
|
||||
void ActivateImmediateHintTimer(const char* name);
|
||||
void ActivateContinueDelayHintTimer(const char* name);
|
||||
void DelayHint(std::string_view name);
|
||||
void ActivateImmediateHintTimer(std::string_view name);
|
||||
void ActivateContinueDelayHintTimer(std::string_view name);
|
||||
void DismissDisplayedHint();
|
||||
u32 GetNextHintIdx() const;
|
||||
const std::vector<SHintState>& GetHintStates() const { return x0_hintStates; }
|
||||
|
|
|
@ -396,12 +396,13 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
|
|||
}
|
||||
case ESpecialFunction::RedundantHintSystem: {
|
||||
CHintOptions& hintOptions = g_GameState->HintOptions();
|
||||
if (msg == EScriptObjectMessage::Action)
|
||||
hintOptions.ActivateContinueDelayHintTimer(xec_locatorName.c_str());
|
||||
else if (msg == EScriptObjectMessage::Increment)
|
||||
hintOptions.ActivateImmediateHintTimer(xec_locatorName.c_str());
|
||||
else if (msg == EScriptObjectMessage::Decrement)
|
||||
hintOptions.DelayHint(xec_locatorName.c_str());
|
||||
if (msg == EScriptObjectMessage::Action) {
|
||||
hintOptions.ActivateContinueDelayHintTimer(xec_locatorName);
|
||||
} else if (msg == EScriptObjectMessage::Increment) {
|
||||
hintOptions.ActivateImmediateHintTimer(xec_locatorName);
|
||||
} else if (msg == EScriptObjectMessage::Decrement) {
|
||||
hintOptions.DelayHint(xec_locatorName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESpecialFunction::Billboard: {
|
||||
|
|
Loading…
Reference in New Issue