KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UPopup_DailyResult.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
4
5#include "ADailyKiosk.h"
7#include "UPopupManager.h"
8#include "UImageButton.h"
9#include "UTextureButton.h"
10#include "UConfigLibrary.h"
11#include "ULingoGameHelper.h"
12#include "GameLogging.h"
13#include "UDailyKioskWidget.h"
14
15#include "Components/VerticalBox.h"
16#include "Components/Spacer.h"
17#include "Components/WidgetComponent.h"
18#include "EngineUtils.h"
19
21{
22 Super::NativeConstruct();
23
24 // 버튼 바인딩
25 if (Btn_Confirm)
26 {
27 Btn_Confirm->OnButtonClickedEvent.RemoveDynamic(this, &UPopup_DailyResult::OnClickConfirm);
28 Btn_Confirm->OnButtonClickedEvent.AddDynamic(this, &UPopup_DailyResult::OnClickConfirm);
29 }
30
31 if (Btn_Close)
32 {
33 Btn_Close->OnButtonClickedEvent.RemoveDynamic(this, &UPopup_DailyResult::OnClickConfirm);
34 Btn_Close->OnButtonClickedEvent.AddDynamic(this, &UPopup_DailyResult::OnClickConfirm);
35 }
36
37}
38
39// ========================================
40// Public Methods
41// ========================================
42
44{
45 // 데이터 저장
46 StudyResult = Result;
47
48 // 질문 리스트 초기화
50}
51
52// ========================================
53// Button Events
54// ========================================
55
57{
58 // ConfigLibrary를 이용하여 점수 저장 (플레이어 인덱스 기준)
59 const int32 UserId = ULingoGameHelper::GetUserId(this);
60 const int32 CurrentScore = StudyResult.CurrentScore;
61
62 // 기존 최고 점수 가져오기
63 const int32 BestScore = UConfigLibrary::GetUserInt(UserId, TEXT("DailyBestScore"), 0);
64
65 // 현재 점수가 최고 점수보다 높으면 저장
66 bool bScoreUpdated = false;
67 if (CurrentScore > BestScore)
68 {
69 UConfigLibrary::SetUserInt(UserId, TEXT("DailyBestScore"), CurrentScore, true);
70 PRINTLOG(TEXT("[DailyResult] New best score saved: %d (Previous: %d)"), CurrentScore, BestScore);
71 bScoreUpdated = true;
72 }
73 else
74 {
75 PRINTLOG(TEXT("[DailyResult] Current score: %d (Best: %d)"), CurrentScore, BestScore);
76 }
77
78 // 모든 DailyKiosk의 위젯 업데이트 (클라이언트 측에서만 실행)
79 // Popup은 클라이언트 UI이므로 이 코드는 각 클라이언트에서 독립적으로 실행됩니다.
80 // Screen Space Widget이므로 각 클라이언트가 자신의 화면에만 렌더링합니다.
81 if (bScoreUpdated)
82 {
83 int32 UpdateCount = 0;
84 for (TActorIterator<ADailyKiosk> It(GetWorld()); It; ++It)
85 {
86 ADailyKiosk* Kiosk = *It;
87 if (Kiosk && Kiosk->GetWidgetComp())
88 {
89 if (UDailyKioskWidget* Widget = Cast<UDailyKioskWidget>(Kiosk->GetWidgetComp()->GetWidget()))
90 {
91 Widget->UpdateBestScore();
92 UpdateCount++;
93 }
94 }
95 }
96
97 if (UpdateCount > 0)
98 {
99 PRINTLOG(TEXT("[DailyResult] Updated %d DailyKiosk widget(s) for User %d"), UpdateCount, UserId);
100 }
101 }
102
103 // 팝업 닫기
104 if (auto PopupMgr = UPopupManager::Get(GetWorld()))
105 {
106 PopupMgr->HideCurrentPopup();
107 }
108}
109
110// ========================================
111// Question List Initialization
112// ========================================
113
115{
116 if (!VerticalBox)
117 return;
118
119 // 기존 아이템 제거
120 VerticalBox->ClearChildren();
121
122 // QuestionList와 AnswerList를 페어로 사용하여 아이템 생성
123 for (int32 i = 0; i < StudyResult.QuestionList.Num(); ++i)
124 {
125 // AnswerList 범위 체크
126 if (!StudyResult.AnswerList.IsValidIndex(i))
127 continue;
128
129 // 아이템 위젯 생성 및 초기화
130 if (auto ItemWidget = CreateWidget<UPopup_DailyResultItem>(GetWorld(), AnswerItemClass))
131 {
132 // 간단하게 3개 파라미터만 전달 (FWordData에서 한글 단어 추출)
133 ItemWidget->InitData(
134 i+1,
135 StudyResult.QuestionList[i].Kor, // Question (한글)
136 StudyResult.AnswerList[i].final_feedback, // FeedBack
137 StudyResult.AnswerList[i].final_overall_score // Score
138 );
139
140 VerticalBox->AddChildToVerticalBox(ItemWidget);
141
142 // 마지막 아이템이 아니면 Spacer 추가 (아이템 간 간격)
143 if (i < StudyResult.QuestionList.Num() - 1)
144 {
145 USpacer* Spacer = NewObject<USpacer>(this);
146 if (Spacer)
147 {
148 Spacer->SetSize(FVector2D(1.0f, 15.0f));
149 VerticalBox->AddChildToVerticalBox(Spacer);
150 }
151 }
152 }
153 }
154}
YiSan 전반에서 사용하는 공용 인터페이스를 선언합니다.
#define PRINTLOG(fmt,...)
Definition GameLogging.h:30
GConfig 래퍼 설정 관리 시스템
Daily Study Kiosk
Definition ADailyKiosk.h:19
class UWidgetComponent * GetWidgetComp()
Definition ADailyKiosk.h:25
static int32 GetUserInt(int32 UserId, const FString &Key, int32 DefaultValue=0)
유저별 정수 설정 읽기
static void SetUserInt(int32 UserId, const FString &Key, int32 Value, bool bAutoSave=true)
유저별 정수 설정 저장
static int32 GetUserId(const UObject *WorldContextObject)
TObjectPtr< class UVerticalBox > VerticalBox
결과 리스트를 담는 VerticalBox (스크롤 가능)
virtual void NativeConstruct() override
TObjectPtr< class UTextureButton > Btn_Close
void OnClickConfirm()
확인 버튼 클릭
TObjectPtr< class UImageButton > Btn_Confirm
확인 버튼 (팝업 닫기)
void InitQuestionList()
질문 리스트 초기화 (스크롤 가능한 아이템 생성)
FDailyStudyResult StudyResult
Daily Study 결과 데이터
TSubclassOf< class UPopup_DailyResultItem > AnswerItemClass
아이템 위젯 클래스
void InitPopup(const FDailyStudyResult &Result)
Daily Study 결과로 팝업 초기화
TArray< FWordData > QuestionList
질문 단어 데이터 리스트 (한글/영어/발음)
int32 CurrentScore
현재 점수
TArray< FResponseSpeakingJudes > AnswerList
답변 리스트