107 lines
3.4 KiB
C++
107 lines
3.4 KiB
C++
#include "TjdUiAppGameAdapter.h"
|
|
#include "TjdUiAppGameView.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "style.h"
|
|
#include "ui_checkbox.h"
|
|
#include "NativeAbility.h"
|
|
#include "sys_config.h"
|
|
|
|
namespace TJD {
|
|
|
|
#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
|
|
static int16_t HorizontalCenter(int16_t width) { return (OHOS::HORIZONTAL_RESOLUTION - width) / 2; }
|
|
|
|
GameCaseItemView::GameCaseItemView(GameCaseInfo &info)
|
|
{
|
|
Resize(450, 110);
|
|
SetStyle(OHOS::STYLE_MARGIN_TOP, 4);
|
|
SetStyle(OHOS::STYLE_MARGIN_BOTTOM, 4);
|
|
SetStyle(OHOS::STYLE_BORDER_RADIUS, 55);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
|
|
|
SetTouchable(true);
|
|
|
|
Add(&icon_);
|
|
Add(&name_);
|
|
|
|
UpdateView(info);
|
|
}
|
|
|
|
GameCaseItemView::~GameCaseItemView()
|
|
{
|
|
RemoveAll();
|
|
}
|
|
|
|
bool GameCaseItemView::OnClickEvent(const OHOS::ClickEvent &event)
|
|
{
|
|
int16_t index_ = GetViewIndex();
|
|
printf("OnClickEvent index = %d\n", index_);
|
|
// if(index_ == 0 || index_ == 8){
|
|
// return false;
|
|
// }
|
|
TjdUiAppGameView::GetInstance()->ChooseGameItem(static_cast<GameItemIndex>(index_));
|
|
return OHOS::UIView::OnClickEvent(event);
|
|
}
|
|
|
|
void GameCaseItemView::UpdateView(GameCaseInfo &info)
|
|
{
|
|
SetViewIndex(info.index);
|
|
icon_.SetPosition(16, 12, 84, 84);
|
|
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
|
|
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
name_.SetText(info.name);
|
|
icon_.SetSrc(info.imgInfo);
|
|
// name_.SetX(HorizontalCenter(name_.GetWidth()));
|
|
name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
name_.SetPosition(HorizontalCenter(name_.GetWidth()), 30);
|
|
printf("UpdateView index = %d, name = %s\n", info.index, info.name);
|
|
|
|
}
|
|
TjdUiAppGameAdapter::~TjdUiAppGameAdapter()
|
|
{
|
|
printf("TjdUiAppGameAdapter::~TjdUiAppGameAdapter()\n");
|
|
// if(itemView_!= nullptr){
|
|
// delete itemView_;
|
|
// itemView_ = nullptr;
|
|
// }
|
|
}
|
|
|
|
OHOS::UIView *TjdUiAppGameAdapter::GetView(OHOS::UIView *inView, int16_t index)
|
|
{
|
|
OHOS::List<GameCaseInfo> &gameList_ = TjdUiAppGameView::GetInstance()->GetGameItemList();
|
|
if (gameList_.IsEmpty() || index > gameList_.Size() - 1 || index < 0) {
|
|
return nullptr;
|
|
}
|
|
|
|
OHOS::ListNode<GameCaseInfo> *node = gameList_.Begin();
|
|
for (uint16_t i = 0; i < index; i++) {
|
|
node = node->next_;
|
|
}
|
|
|
|
if (inView == nullptr) {
|
|
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
|
|
itemView_ = new GameCaseItemView(node->data_);
|
|
} else {
|
|
static_print_debug("%s , line is %d", __FUNCTION__, __LINE__);
|
|
itemView_ = static_cast<GameCaseItemView *>(inView);
|
|
itemView_->UpdateView(node->data_);
|
|
}
|
|
|
|
return itemView_;
|
|
}
|
|
|
|
uint16_t TjdUiAppGameAdapter::GetCount() { return TjdUiAppGameView::GetInstance()->GetGameItemList().Size(); }
|
|
|
|
} // namespace TJD
|