Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spaghett
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hall of Fame
Spaghett
Commits
c8a0e551
Commit
c8a0e551
authored
2 years ago
by
BotyDns
Browse files
Options
Downloads
Patches
Plain Diff
Comment TradeViewModel
parent
fa49f611
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#30771
canceled
2 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CatanGame/ViewModel/TradeViewModel.cs
+40
-2
40 additions, 2 deletions
CatanGame/ViewModel/TradeViewModel.cs
with
40 additions
and
2 deletions
CatanGame/ViewModel/TradeViewModel.cs
+
40
−
2
View file @
c8a0e551
...
...
@@ -7,37 +7,71 @@ using CatanGame.Model;
namespace
CatanGame.ViewModel
{
/// <summary>
/// ViewModel representing a trade.
/// </summary>
public
class
TradeViewModel
:
ViewModelBase
{
#
region
Private
fields
private
GameModel
_model
;
private
ObservableDictionary
<
string
,
TradeDataViewModel
>
_tradeData
;
#
endregion
#
region
Public
properties
private
ObservableDictionary
<
string
,
TradeDataViewModel
>
_tradeData
;
/// <summary>
/// Gets or sets the Data related to trading.
/// </summary>
public
ObservableDictionary
<
string
,
TradeDataViewModel
>
TradeData
{
get
=>
_tradeData
;
set
=>
ChangeProperty
(
ref
_tradeData
,
value
);
}
/// <summary>
/// Gets whether a trade is possible.
/// </summary>
public
bool
CanTrade
{
get
=>
_model
.
CanTrade
(
OfferedResources
,
RequestedResources
);
}
/// <summary>
/// Gets whether the player can request anymore resources.
/// </summary>
public
bool
CanRequest
{
get
=>
_model
.
CanRequest
(
OfferedResources
,
RequestedResources
);
}
#
endregion
#
region
Commands
/// <summary>
/// Command for accepting a trade.
/// </summary>
public
DelegateCommand
AcceptTradeCommand
{
get
;
private
set
;
}
/// <summary>
/// Command for clearing the trade.
/// </summary>
public
DelegateCommand
ClearTradeCommand
{
get
;
private
set
;
}
/// <summary>
/// Command for canceling a trade.
/// </summary>
public
DelegateCommand
CancelCommand
{
get
;
private
set
;
}
#
endregion
#
region
Public
events
/// <summary>
/// Event: Gets invoked when a trade is accepted.
/// </summary>
public
event
EventHandler
<
TradeAcceptedEventArgs
>
TradeAccepted
;
/// <summary>
/// Event: Gets invoked when a trade is canceled.
/// </summary>
public
event
EventHandler
Cancel
;
#
endregion
#
region
Private
properties
/// <summary>
/// Gets the resources offered by the player.
/// </summary>
private
List
<(
ResourceType
,
int
)>
OfferedResources
{
get
=>
_tradeData
.
Dict
.
Select
(
data
=>
((
ResourceType
)
Enum
.
Parse
(
typeof
(
ResourceType
),
data
.
Key
),
data
.
Value
.
OfferedCnt
)).
ToList
();
}
}
/// <summary>
/// Gets the resources requested by the player.
/// </summary>
private
List
<(
ResourceType
,
int
)>
RequestedResources
{
get
=>
_tradeData
.
Dict
.
Select
(
data
=>
((
ResourceType
)
Enum
.
Parse
(
typeof
(
ResourceType
),
data
.
Key
),
data
.
Value
.
RequestedCnt
)).
ToList
();
...
...
@@ -63,6 +97,10 @@ namespace CatanGame.ViewModel
#
endregion
#
region
Public
methods
/// <summary>
/// Updates this viewmodel with the data from the given player.
/// </summary>
/// <param name="player">The player who wants to make a trade.</param>
public
void
Update
(
PlayerViewModel
player
)
{
TradeData
.
Dict
.
Clear
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment