128 lines
3.4 KiB
C++
128 lines
3.4 KiB
C++
|
|
#include "SquirrelStage.h"
|
|||
|
|
|
|||
|
|
#include "SquirrelClassEx.h"
|
|||
|
|
extern SquirrelClassEx* TObject;
|
|||
|
|
extern Cursor* Mouse_Object;
|
|||
|
|
|
|||
|
|
extern std::map<std::uint64_t, int>UI_HOVER_ZORDER;
|
|||
|
|
extern std::map<std::uint64_t, UiFrameWork*>UI_HOVER_OBJECT;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
void SquirrelStage::OnEvent(Event* evt) {
|
|||
|
|
if (evt->IsType<KeyEvent>())
|
|||
|
|
{
|
|||
|
|
if (evt->IsType<KeyDownEvent>())
|
|||
|
|
{
|
|||
|
|
KeyCode key = dynamic_cast<KeyDownEvent*>(evt)->code;
|
|||
|
|
SquirrelClassEx::RunUpdateScript("KeyDownEventCallBack", (int)key);
|
|||
|
|
}
|
|||
|
|
else if (evt->IsType<KeyUpEvent>())
|
|||
|
|
{
|
|||
|
|
KeyCode key = dynamic_cast<KeyUpEvent*>(evt)->code;
|
|||
|
|
SquirrelClassEx::RunUpdateScript("KeyUpEventCallBack", (int)key);
|
|||
|
|
}
|
|||
|
|
else if (evt->IsType<KeyCharEvent>())
|
|||
|
|
{
|
|||
|
|
char ch = dynamic_cast<KeyCharEvent*>(evt)->value;
|
|||
|
|
SquirrelClassEx::RunUpdateScript("KeyCharEventCallBack", (int)ch);
|
|||
|
|
}
|
|||
|
|
else if (evt->IsType<IMEInputEvent>())
|
|||
|
|
{
|
|||
|
|
const auto& str = dynamic_cast<IMEInputEvent*>(evt)->value;
|
|||
|
|
const auto utf8_str = strings::WideToUTF8(strings::NarrowToWide(str));
|
|||
|
|
SquirrelClassEx::RunUpdateScript("KeyIMEInputEventCallBack", utf8_str.c_str());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelStage::InitKeyInPut()
|
|||
|
|
{
|
|||
|
|
AddListener<KeyDownEvent>(Closure(this, &SquirrelStage::OnEvent));
|
|||
|
|
AddListener<KeyUpEvent>(Closure(this, &SquirrelStage::OnEvent));
|
|||
|
|
AddListener<KeyCharEvent>(Closure(this, &SquirrelStage::OnEvent));
|
|||
|
|
AddListener<IMEInputEvent>(Closure(this, &SquirrelStage::OnEvent));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelStage::PushBaseUi()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UIͼ<49><CDBC>
|
|||
|
|
LayerActorPtr MouseUiLayer = new LayerActor();
|
|||
|
|
MouseUiLayer->SetName("Scene_Mouse_UI_Layer");
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>㼶<EFBFBD><E3BCB6><EFBFBD><EFBFBD>
|
|||
|
|
MouseUiLayer->SetZOrder(100000);
|
|||
|
|
SquirrelClassEx::PushLayerActorPtrToMap(MouseUiLayer);
|
|||
|
|
this->AddChild(MouseUiLayer);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ͼ<EFBFBD><CDBC>
|
|||
|
|
LayerActorPtr DefaultLayer = new LayerActor();
|
|||
|
|
DefaultLayer->SetName(this->GetName() + "_Default_Layer");
|
|||
|
|
SquirrelClassEx::PushLayerActorPtrToMap(DefaultLayer);
|
|||
|
|
this->AddChild(DefaultLayer);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelStage::OnEnter()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
|||
|
|
Mouse_Object->RemoveFromParent();
|
|||
|
|
|
|||
|
|
ActorPtr MouseUiLayer = this->GetChild("Scene_Mouse_UI_Layer");
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD>
|
|||
|
|
MouseUiLayer->AddChild(Mouse_Object);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if(this->GetName().find("GameMap") == std::string::npos)TObject->RunSceneScript(this->GetName() + "_Enter", this);
|
|||
|
|
//ȫ<>ֽ<EFBFBD><D6BD><EFBFBD>
|
|||
|
|
TObject->RunSceneScript("Game_Enter", this);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SquirrelStage::OnExit()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>UI<55><49>Map
|
|||
|
|
UI_HOVER_ZORDER.clear();
|
|||
|
|
UI_HOVER_OBJECT.clear();
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
|||
|
|
Mouse_Object->RemoveFromParent();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>
|
|||
|
|
if (this->GetName().find("GameMap") == std::string::npos)TObject->RunSceneScript(this->GetName() + "_Exit", this);
|
|||
|
|
//ȫ<><C8AB><EFBFBD>˳<EFBFBD>
|
|||
|
|
TObject->RunSceneScript("Game_Exit", this);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void SquirrelStage::OnUpdate(Duration dt)
|
|||
|
|
{
|
|||
|
|
static float TimeFlag = 0.0;
|
|||
|
|
|
|||
|
|
TimeFlag += dt.GetSeconds();
|
|||
|
|
|
|||
|
|
TObject->RunSceneScript("Game_Proc", this, dt.GetSeconds());
|
|||
|
|
|
|||
|
|
if (TimeFlag >= 0.00694) {
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Proc
|
|||
|
|
if (this->GetName().find("GameMap") == std::string::npos)TObject->RunSceneScript(this->GetName() + "_Proc", this, TimeFlag);
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (Director::GetInstance().GetCurrentStage()->GetHashName() == this->GetHashName() && this->GetName().find("LoadingGame") == std::string::npos) {
|
|||
|
|
//ȫ<><C8AB>Proc
|
|||
|
|
TObject->RunSceneScript("Game_Proc_144", this, TimeFlag);
|
|||
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
|||
|
|
if (FILE* file = fopen("Yosin_Game_Reloading.Sign", "r")) {
|
|||
|
|
SquirrelClassEx::ReloadingScript();
|
|||
|
|
//OnExit();
|
|||
|
|
//OnEnter();
|
|||
|
|
fclose(file);
|
|||
|
|
remove("Yosin_Game_Reloading.Sign");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TimeFlag = 0.0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|