KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UResultStatWidget.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
3#include "UResultStatWidget.h"
4
6#include "Components/WidgetSwitcher.h"
7#include "Components/TextBlock.h"
8#include "Components/Image.h"
9#include "Components/Border.h"
10#include "UGameDataManager.h"
11
12#define COLORSTYLEDATA_PATH TEXT("/Game/CustomContents/MasterData/DT_ColorStyleData.DT_ColorStyleData")
13
15{
16 Super::NativePreConstruct();
17
18 // StyleTable이 비어있으면 자동으로 로드
19 if (StyleTable.Num() == 0)
20 {
22 }
23
25 ApplyStyle();
26}
27
29{
30 // 색상 타입 설정
31 SetColorType(InData.ColorType);
32
33 // 위젯 타입 설정
35
36 // 타이틀 텍스트 설정
37 SetTitleText(InData.TitleText);
38
39 // 타입별 데이터 설정
40 switch (InData.WidgetType)
41 {
44 break;
45
48 break;
49
52 break;
53
56 break;
57 }
58}
59
60/* -----------------------------
61 패널 데이터 설정
62 -----------------------------*/
68
70{
71 ColorType = InType;
72 ApplyStyle();
73}
74
75void UResultStatWidget::SetTitleText(const FText InText)
76{
77 Text_Title->SetText(InText);
78}
79
80
82{
83 if (!Image_Grade)
84 return;
85
86 // GameDataManager에서 TextureType에 해당하는 텍스처 가져오기
87 UGameDataManager* DataManager = UGameDataManager::Get(this);
88 if (!DataManager)
89 return;
90
91 UTexture2D* Texture = DataManager->GetTexture(TextureType);
92 if (!Texture)
93 return;
94
95 // Image의 Brush 데이터 변경
96 FSlateBrush Brush = Image_Grade->GetBrush();
97 Brush.SetResourceObject(Texture);
98 Image_Grade->SetBrush(Brush);
99}
100
101void UResultStatWidget::SetScoreValue(const float InValue, const FLinearColor InScoreTextColor)
102{
103 ScoreValue = InValue;
104 ScoreTextColor = InScoreTextColor;
105
106 if (Txt_Score)
107 {
108 Txt_Score->SetText(FText::AsNumber(InValue));
109 Txt_Score->SetColorAndOpacity(ScoreTextColor);
110 }
111}
112
113void UResultStatWidget::SetRateValue(const float InPercent)
114{
115 RateValue = InPercent;
116
117 if (Txt_Rate)
118 {
119 FString Str = FString::Printf(TEXT("%.1f%%"), InPercent * 100.f);
120 Txt_Rate->SetText(FText::FromString(Str));
121 }
122
123 ImageProgress_Rate->SetPercent(InPercent);
124}
125
126void UResultStatWidget::SetSymbolValue(const EResourceTextureType TextureType, const FString& InValue)
127{
128 SymbolValue = InValue;
129
130 if (!Image_Grade)
131 return;
132
133 // GameDataManager에서 TextureType에 해당하는 텍스처 가져오기
134 UGameDataManager* DataManager = UGameDataManager::Get(this);
135 if (!DataManager)
136 return;
137
138 UTexture2D* Texture = DataManager->GetTexture(TextureType);
139 if (!Texture)
140 return;
141
142 // Image의 Brush 데이터 변경
143 FSlateBrush Brush = Image_Symbol->GetBrush();
144 Brush.SetResourceObject(Texture);
145 Image_Symbol->SetBrush(Brush);
146
147 if (Txt_ImageRate)
148 Txt_ImageRate->SetText(FText::FromString(InValue));
149}
150
151/* -----------------------------
152 스타일 적용
153 -----------------------------*/
155{
156 if (auto DM = UGameDataManager::Get(this))
157 {
158 // 런타임: GameDataManager에서 가져오기
159 StyleTable = DM->GetAllColorStyleData();
160 return;
161 }
162
163#if WITH_EDITOR
164 // 에디터 모드: DataTable 직접 로드
165 if (auto ColorStyleTable = LoadObject<UDataTable>(nullptr, COLORSTYLEDATA_PATH ))
166 {
167 for (const FName& RowName : ColorStyleTable->GetRowNames())
168 {
169 if (FColorStyleData* Row = ColorStyleTable->FindRow<FColorStyleData>(RowName, TEXT("")))
170 {
171 FString EnumString = RowName.ToString();
172 EColorStyleType TempColorType = static_cast<EColorStyleType>(
173 StaticEnum<EColorStyleType>()->GetValueByNameString(EnumString)
174 );
175 StyleTable.Add(TempColorType, *Row);
176 }
177 }
178 }
179#endif
180}
181
183{
184 if (!StyleTable.Contains(ColorType))
185 return;
186
187 const auto& Style = StyleTable[ColorType];
188
189 if (Image_BG)
190 Image_BG->SetColorAndOpacity(Style.BGColor);
191
192 if (Border_Title)
193 Border_Title->SetBrushColor(Style.BorderColor);
194
195 if (Text_Title)
196 Text_Title->SetColorAndOpacity(Style.TitleColor);
197}
198
199/* -----------------------------
200 WidgetSwitcher 제어
201 -----------------------------*/
203{
204 if (!WidgetSwitcher)
205 return;
206
207 int32 Index = 0;
208
209 switch (WidgetType)
210 {
212 Index = 0;
213 break;
214
216 Index = 1;
217 break;
218
220 Index = 2;
221 break;
222
224 Index = 3;
225 break;
226 }
227
228 WidgetSwitcher->SetActiveWidgetIndex(Index);
229}
EColorStyleType
EResourceTextureType
EResultItemWidgetType
#define COLORSTYLEDATA_PATH
UGameDataManager 클래스를 선언합니다.
데이터 테이블(.csv)에서 게임 데이터를 로드하고 캐시하여 런타임에 빠르게 접근할 수 있도록 제공하는 데이터 관리 서브시스템입니다.
UTexture2D * GetTexture(EResourceTextureType Type) const
TObjectPtr< class UTextBlock > Txt_Rate
void UpdateWidgetPanel() const
TObjectPtr< class UImage > Image_BG
void SetWidgetType(const EResultItemWidgetType InType)
위젯 타입 설정
EResultItemWidgetType WidgetType
TObjectPtr< class UCircularProgressBar > ImageProgress_Rate
virtual void NativePreConstruct() override
void SetSymbolValue(const EResourceTextureType TextureType, const FString &InValue)
TMap< EColorStyleType, FColorStyleData > StyleTable
void SetRateValue(const float InPercent)
TObjectPtr< class UTextBlock > Txt_ImageRate
TObjectPtr< class UImage > Image_Grade
TObjectPtr< class UWidgetSwitcher > WidgetSwitcher
void SetColorType(const EColorStyleType InType)
스타일 설정
void InitData(const FResultStatData &InData)
통합 데이터로 위젯 설정
TObjectPtr< class UBorder > Border_Title
void SetGradeValue(const EResourceTextureType TextureType)
패널 데이터 설정
void SetTitleText(const FText InText)
void SetScoreValue(const float InValue, const FLinearColor InScoreTextColor)
TObjectPtr< class UTextBlock > Text_Title
FLinearColor ScoreTextColor
EColorStyleType ColorType
TObjectPtr< class UTextBlock > Txt_Score
TObjectPtr< class UImage > Image_Symbol
Result Stat 위젯 통합 데이터 구조 위젯 타입, 색상 스타일, 각 타입별 데이터를 통합 관리
EResourceTextureType SymbolTextureType
Symbol 타입 전용: 심볼 문자열
FLinearColor ScoreTextColor
float RatePercent
Rate 타입 전용: 퍼센트 값 (0.0 ~ 1.0)
EColorStyleType ColorType
색상 스타일
FText TitleText
타이틀 텍스트
EResultItemWidgetType WidgetType
위젯 타입
EResourceTextureType GradeTextureType
Grade 타입 전용: 텍스처 타입
float ScoreValue
Score 타입 전용: 점수 값