mcu_hi3321_watch/tjd/ui/app/motion_sensing_game/TjdUiAppMSGameView.cpp
2025-05-26 20:15:20 +08:00

173 lines
5.7 KiB
C++

#include "TjdUiAppMSGameView.h"
#include "TjdUiImageIds.h"
#include "TjdUiMultiLanguageExt.h"
#include "animator/animator_manager.h"
#include "common/image_cache_manager.h"
#include "sys_config.h"
#define ENABLE_PRINT_INFO 1
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印一般常开
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#define static_print_debug(...)
#endif
namespace TJD {
#define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_ms_game.bin"
MSGameViewIndex TjdUiAppMSGameView::currentViewIndex_ = MSGameViewIndex::MS_GAME_UNKNOWN;
static TjdUiAppMSGameView *g_msGameView = nullptr;
TjdUiAppMSGameView::TjdUiAppMSGameView() { g_msGameView = this; }
TjdUiAppMSGameView::~TjdUiAppMSGameView() { g_msGameView = nullptr; }
TjdUiAppMSGameView *TjdUiAppMSGameView::GetInstance(void) { return g_msGameView; }
void TjdUiAppMSGameView::OnStart()
{
OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(IMAGE_BIN_PATH);
if (mainView_ == nullptr) {
mainView_ = new OHOS::UIScrollView();
}
mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
// mainView_->SetOnDragListener(TjdUiAppMSGamePresenter::GetInstance());
AddViewToRootContainer(mainView_);
}
void TjdUiAppMSGameView::OnStop()
{
for (int i = 0; i < MSGameViewIndex::MS_GAME_UNKNOWN; i++) {
if (viewManager_[i] != nullptr) {
viewManager_[i]->RemoveAll();
delete viewManager_[i];
viewManager_[i] = nullptr;
}
}
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
}
void TjdUiAppMSGameView::InitTargetView(MSGameViewIndex index)
{
if (viewManager_[index] != nullptr) {
return;
}
// clang-format off
switch (index) {
case MS_GAME_MAIN: viewManager_[index] = new MSGameMainView(); break;
case MS_GAME_DISCONNECT: viewManager_[index] = new MSGameDisConnectView(); break;
default: break;
}
// clang-format on
if (viewManager_[index] == nullptr) {
return;
}
viewManager_[index]->SetPosition(0, 0);
viewManager_[index]->SetVisible(false);
mainView_->Add(viewManager_[index]);
}
void TjdUiAppMSGameView::ShowView(MSGameViewIndex showIndex)
{
if (showIndex < 0 || showIndex >= MSGameViewIndex::MS_GAME_UNKNOWN) {
return;
}
InitTargetView(showIndex);
if (currentViewIndex_ >= 0 && currentViewIndex_ < MSGameViewIndex::MS_GAME_UNKNOWN &&
viewManager_[currentViewIndex_] != nullptr) {
viewManager_[currentViewIndex_]->HideView();
}
if (viewManager_[showIndex] != nullptr) {
viewManager_[showIndex]->ShowView();
}
currentViewIndex_ = showIndex;
}
MSGameMainView::MSGameMainView()
{
auto &image = OHOS::ImageCacheManager::GetInstance();
auto bgRes = image.LoadOneInMultiRes(IMG_MS_GAME_WATCH, IMAGE_BIN_PATH);
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) {
SetOnDragListener(TjdUiAppMSGamePresenter::GetInstance());
}
bg_.SetPosition(125, 92, 213, 156);
if (bgRes != nullptr) {
bg_.SetSrc(bgRes);
}
desc_.SetTextId(STR_ID_382);
desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
desc_.Resize(350, 125);
desc_.SetX((GetWidth() >> 1) - (desc_.GetWidth() >> 1));
desc_.SetY(bg_.GetY() + bg_.GetHeight() + 10);
desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP);
descButtom_.SetTextId(STR_ID_383);
descButtom_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
descButtom_.Resize(270, 48);
descButtom_.SetX((GetWidth() >> 1) - (descButtom_.GetWidth() >> 1));
descButtom_.SetY(desc_.GetY() + desc_.GetHeight() + 10);
descButtom_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5);
descButtom_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
descButtom_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP);
Add(&bg_);
Add(&desc_);
Add(&descButtom_);
}
MSGameDisConnectView::MSGameDisConnectView()
{
auto &image = OHOS::ImageCacheManager::GetInstance();
auto bgRes = image.LoadOneInMultiRes(IMG_MS_GAME_PROMPT_FAIL, IMAGE_BIN_PATH);
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) {
SetOnDragListener(TjdUiAppMSGamePresenter::GetInstance());
}
bg_.SetPosition(140, 144, 217, 131);
if (bgRes != nullptr) {
bg_.SetSrc(bgRes);
}
desc_.SetTextId(STR_ID_384);
desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
desc_.Resize(350, 125);
desc_.SetX((GetWidth() >> 1) - (desc_.GetWidth() >> 1));
desc_.SetY(bg_.GetY() + bg_.GetHeight() + 10);
desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP);
descButtom_.SetTextId(STR_ID_383);
descButtom_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
descButtom_.Resize(270, 48);
descButtom_.SetX((GetWidth() >> 1) - (descButtom_.GetWidth() >> 1));
descButtom_.SetY(desc_.GetY() + desc_.GetHeight() + 10);
descButtom_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5);
descButtom_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
descButtom_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP);
Add(&bg_);
Add(&desc_);
Add(&descButtom_);
}
} // namespace TJD