๊ธฐ์กด UI ๊ตฌ์กฐ์์ Selection๊ณผ Command๋ ๊ฐ๊ฐ ์์ ํ๋์ด ์์์ง๋ง
์ค์ RTS ํ๋ฆ ๊ธฐ์ค์์๋ ๋ค์ ๋ฌธ์ ๊ฐ ๋จ์ ์์๋ค.
| ๊ตฌ๋ถ | ๋ฌธ์ |
|---|---|
| Selection | Multi Selection ํํ ๊ฐ๋ฅํ์ง๋ง ์คํ๊ณผ ์ฐ๊ฒฐ๋์ง ์์ |
| Command | UI ํ์๊น์ง๋ง ๊ฐ๋ฅ, ์ค์ ์คํ ๊ตฌ์กฐ ์์ |
| UI ํ๋ฆ | ์ํ ํํ๊ณผ ํ๋ ์คํ์ด ๋ถ๋ฆฌ๋์ด ์์ |
| ๊ตฌ์กฐ ์ฐ๊ฒฐ | UI โ Gameplay๋ก ์ด์ด์ง๋ ๊ฒฝ๋ก ๋ถ์ฌ |
Selection
โ ViewModel
โ SelectionPanel ํ์
CommandPanel
โ ViewModel ํ์๋ง ์ํ
ํต์ฌ ๋ฌธ์ ๋ ๋จ์ ๊ธฐ๋ฅ์ด ์๋๋ผ
โ์ํ โ ์คํ โ ์ํ ๊ฐฑ์ โ ํ๋ฆ์ด ๋๊ฒจ ์๋ค๋ ์ ์ด์๋ค.
์ด์ ๋จ๊ณ์์ Selection์ ๋ค์ ๊ตฌ์กฐ๋ก ํ์ฅ๋์๋ค.
UENUM()
enum class ESelectionViewMode : uint8
{
None,
Single,
Multi
};
USTRUCT()
struct FSelectionViewModel
{
GENERATED_BODY()
ESelectionViewMode ViewMode;
// Single
FName SelectionId;
// Multi
int32 TotalSelectedCount;
TArray<FSelectionSummaryItemViewModel> SummaryItems;
};
ํ์ง๋ง ์ด ์ํ์์๋:
Command ํด๋ฆญ โ ์คํ ๊ฒฝ๋ก ์์
๊ธฐ์กด ๋ฐฉ์:
// โ ์๋ชป๋ ๊ตฌ์กฐ (์์)
void UCommandWidget::OnClick()
{
// ์ง์ ์คํ or ์๋ฌด ์ฒ๋ฆฌ ์์
}
๋ฌธ์ :
Selection ์ํ
โ Command ์์ฑ
โ ์
๋ ฅ ๋ฐ์
โ ์คํ
โ ์ํ ๋ณ๊ฒฝ
โ UI ๊ฐฑ์
// CommandSlotWidget.cpp
void URTSCommandSlotWidget::OnClicked()
{
if (OwningPC)
{
OwningPC->ExecuteCommandById(CommandId);
}
}
// PlayerController.cpp
bool ARTSUIPrototypePlayerController::ExecuteCommandById(FName CommandId)
{
if (!CommandDispatcher || CommandId.IsNone())
{
return false;
}
return CommandDispatcher->DispatchCommandById(CommandId);
}
// CommandDispatcher.cpp
bool URTSCommandDispatcher::DispatchCommandById(FName CommandId)
{
// 1. UI Context ์ฒ๋ฆฌ
if (OwnerPC->HandleLocalOnlyCommand(CommandId))
{
return true;
}
// 2. ์๋ฒ ์คํ ์์ฒญ ์์ฑ
FRTSCommandRequest Request = BuildCommandRequest(CommandId);
return OwnerPC->IssueCommandRequest(Request);
}
FRTSCommandRequest URTSCommandDispatcher::BuildCommandRequest(FName CommandId)
{
FRTSCommandRequest Request;
Request.CommandId = CommandId;
Request.SelectedEntityIds = SelectionProvider->GetSelectedIds();
Request.TargetLocation = OwnerPC->GetCachedMouseHitLocation();
return Request;
}
UFUNCTION(Server, Reliable)
void ARTSUIPrototypePlayerController::ServerIssueCommand(
const FRTSCommandRequest& Request)
{
OrderService->ExecuteCommandOnServer(Request);
}
// OrderService.cpp
bool URTSOrderService::ExecuteCommandOnServer(
const FRTSCommandRequest& Request)
{
if (Request.CommandId == "Move")
{
ExecuteMove(Request);
}
else if (Request.CommandId == "Attack")
{
ExecuteAttack(Request);
}
return true;
}
TArray<FName> URTSUIHUDCoordinator::BuildCommonCommandIds()
{
TArray<TArray<FName>> AllCommands;
for (const FName& EntityId : SelectedEntities)
{
AllCommands.Add(CommandTable->GetCommands(EntityId));
}
return Intersect(AllCommands);
}
Marine: Move, Attack, Stop
SCV: Move, Attack, Stop, Build
โ ๊ฒฐ๊ณผ
Move, Attack, Stop
void USelectionProvider::PushContext(FName NewContext)
{
ContextStack.Push(CurrentContext);
CurrentContext = NewContext;
}
void USelectionProvider::PopContext()
{
if (ContextStack.Num() > 0)
{
CurrentContext = ContextStack.Pop();
}
}
bool APlayerController::HandleLocalOnlyCommand(FName CommandId)
{
if (CommandId == "BuildMenu")
{
SelectionProvider->PushContext("BuildMenu");
return true;
}
if (CommandId == "Back")
{
SelectionProvider->PopContext();
return true;
}
return false;
}
// Provider ๋ด๋ถ
void USelectionProvider::NotifySelectionChanged()
{
OnSelectionChanged.Broadcast();
}
void URTSUIHUDCoordinator::Initialize(...)
{
SelectionProvider->OnSelectionChanged.AddUObject(
this,
&URTSUIHUDCoordinator::RefreshAll
);
}
void URTSUIHUDCoordinator::RefreshAll()
{
RefreshSelectionPanel();
RefreshCommandPanel();
}
UI (Widget)
โ PlayerController
โ CommandDispatcher
โ Server RPC
โ OrderService
โ Provider
โ Coordinator
โ UI
// 1. ํด๋ฆญ
Widget โ ExecuteCommandById
// 2. ๋ถ๊ธฐ
Dispatcher โ Local or Server
// 3. ์คํ
Server โ OrderService
// 4. ์ํ ๋ณ๊ฒฝ
Provider
// 5. UI ๊ฐฑ์
Coordinator โ Widget
| ํญ๋ชฉ | ๋ณ๊ฒฝ |
|---|---|
| Selection | Single โ Multi ํ์ฅ |
| Command | ํ์ โ ์คํ ๊ฐ๋ฅ |
| ์ ๋ ฅ | ๋จ์ผ ์ง์ ์ |
| ์ํ ๊ด๋ฆฌ | Provider ์ง์ค |
| ์คํ ๊ตฌ์กฐ | Dispatcher ๋ถ๋ฆฌ |
Selection ํ์ฅ
โ Command ์์ฑ
โ ExecuteCommandById
โ Dispatcher
โ Server
โ ์ํ ๋ณ๊ฒฝ
โ UI ๊ฐฑ์
- Multi Selection ๊ตฌ์กฐ๋ฅผ ์ค์ Command ์คํ๊น์ง ์ฐ๊ฒฐํ๋ค
- ์ ๋ ฅ โ ์คํ โ ์ํ ๊ฐฑ์ โ UI ๋ฐ์ ํ๋ฆ์ด ์์ฑ๋๋ค
- UI๋ ๋๊น์ง ๋ฐ์ดํฐ ์๋น๋ง ํ๊ณ , ์คํ๊ณผ ์ํ๋ ์ธ๋ถ ๊ณ์ธต์์ ์ฒ๋ฆฌํ๋๋ก ์ ์งํ๋ค