Commit 7193a725 authored by Romain DELEAU's avatar Romain DELEAU

add prerequires on repeat-tasks

parent d77be140
......@@ -35,18 +35,83 @@
</div>
</div>
<div class="piece-prerequires" [class]="pieceDetailsService.piece == task ? displayPrequires : 'hide'">
<div class="piece-prerequires-prerequires">
<label class="piece-prerequires-title">{{'task_prerequire_antecedents_title' | translate}}</label>
<div class="piece-prerequires-form">
<ng-container *ngIf="hasPossibleAntecedents()">
<ng-container *ngFor="let inlineTask of role.tasks">
<ng-container *ngFor="let element of inlineTask; let index = index">
<div class="piece-prerequires-prerequires-element" *ngIf="element?.identifier && (task.identifier != element?.identifier) && element?.type != 'annexe'">
<input name="antecedent" type="checkbox" [checked]="isCheckedTask(element)" (change)="checkboxChangedTask($event, element)"/>
<label for="antecedent">{{element?.identifier}}</label>
</div>
</ng-container>
</ng-container>
</ng-container>
<div style="text-align: center;" *ngIf="!hasPossibleAntecedents()">{{'task_prerequire_antecedents_err2' | translate}}</div>
</div>
</div>
<div class="piece-prerequires-ressources">
<label class="piece-prerequires-title">{{'task_prerequire_ressource_title' | translate}}</label>
<div class="piece-prerequires-form">
<ng-container *ngFor="let ressource of scenario.ressources">
<div class="piece-prerequires-ressources-element" *ngIf="ressource.name">
<div class="piece-prerequires-ressources-element-checkbox">
<input name="ressource" type="checkbox" (change)="checkboxChangedRessource($event, ressource)" [checked]="isCheckedRessource(ressource)"/>
<label for="ressource" [title]="ressource.name">{{ressource.name}}</label>
</div>
<div class="piece-prerequires-ressources-element-quantity" *ngIf="isCheckedRessource(ressource)">
<select name="ressource" [(ngModel)]="getAssociatePrerequireRessource(ressource).operator">
<option><</option>
<option><=</option>
<option>=</option>
<option>>=</option>
<option>></option>
</select>
<input type="text" value="1" [(ngModel)]="getAssociatePrerequireRessource(ressource).quantity"/>
</div>
</div>
</ng-container>
<ng-container *ngFor="let ressource of role.ressources">
<div class="piece-prerequires-ressources-element" *ngIf="ressource.name">
<div class="piece-prerequires-ressources-element-checkbox">
<input name="ressource" type="checkbox" (change)="checkboxChangedRessource($event, ressource)" [checked]="isCheckedRessource(ressource)"/>
<label for="ressource" [title]="ressource.name">{{ressource.name}}</label>
</div>
<div class="piece-prerequires-ressources-element-quantity" *ngIf="isCheckedRessource(ressource)">
<select name="ressource" [(ngModel)]="getAssociatePrerequireRessource(ressource).operator">
<option><</option>
<option><=</option>
<option>=</option>
<option>>=</option>
<option>></option>
</select>
<input type="text" value="1" [(ngModel)]="getAssociatePrerequireRessource(ressource).quantity"/>
</div>
</div>
</ng-container>
</div>
</div>
</div>
<div class="piece-form">
<label>{{'repeatTask_title' | translate}}<br>{{'repeatTask_while' | translate}}</label>
<textarea [(ngModel)]="task.objective" [(ngModel)]="task.objective" (change)="editTrace($event,'Task_action')" [style.background-image]="(i == findFirstIndexOfTaskType('repeat')[0] && j == findFirstIndexOfTaskType('repeat')[1]) ? urlIcon : ''"
[placeholder]="translate.instant('repeatTask_action_placeholder')"
[matTooltip]="translate.instant('task_action_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></textarea>
<mat-icon class="piece-form-comment" fontIcon="comment" *ngIf="task.comments.length > 0"></mat-icon>
<mat-icon class="piece-form-repeat" fontIcon="refresh" *ngIf="(task.repeat.iteration > 0 || task.repeat.while != '') && !unityService.unity_isActive"></mat-icon>
<span class="piece-form-repeat-off" *ngIf="(task.repeat.iteration > 0 || task.repeat.while != '') && !unityService.unity_isActive && task.repeat.limitMissionRepeat == 1"></span>
<mat-icon class="piece-form-character" fontIcon="person" *ngIf="task.characters.length > 0 && !unityService.unity_isActive"
[style.color]="task.characters.length == 1 ? task.characters[0].color : 'black'"
[style.background]="task.characters.length > 1 ? 'linear-gradient('+ task.characters[0].color +','+ task.characters[task.characters.length-1].color +')' : 'white'"></mat-icon>
<mat-icon class="piece-form-interrupt" fontIcon="front_hand" *ngIf="task.interrupt != '' && !unityService.unity_isActive"></mat-icon>
<button mat-button class="piece-form-prerequires" (click)="changeDisplayPrerequires()"
[matTooltip]="translate.instant('task_prerequire_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips">
{{'task_prerequire_label' | translate}}
</button>
</div>
<mat-icon class="piece-form-comment" fontIcon="comment" *ngIf="task.comments.length > 0"></mat-icon>
<mat-icon class="piece-form-repeat" fontIcon="refresh" *ngIf="(task.repeat.iteration > 0 || task.repeat.while != '') && !unityService.unity_isActive"></mat-icon>
<span class="piece-form-repeat-off" *ngIf="(task.repeat.iteration > 0 || task.repeat.while != '') && !unityService.unity_isActive && task.repeat.limitMissionRepeat == 1"></span>
<mat-icon class="piece-form-character" fontIcon="person" *ngIf="task.characters.length > 0 && !unityService.unity_isActive"
[style.color]="task.characters.length == 1 ? task.characters[0].color : 'black'"
[style.background]="task.characters.length > 1 ? 'linear-gradient('+ task.characters[0].color +','+ task.characters[task.characters.length-1].color +')' : 'white'"></mat-icon>
<mat-icon class="piece-form-interrupt" fontIcon="front_hand" *ngIf="task.interrupt != '' && !unityService.unity_isActive"></mat-icon>
</div>
......@@ -31,7 +31,7 @@
}
mat-icon:hover {
opacity: 0.75;
opacity: 0.65;
}
&-directioncross {
......@@ -77,7 +77,6 @@
}
&-form {
height: 100%;
padding: 0px 10px 0px 35px;
position: relative;
display: flex;
......@@ -99,7 +98,7 @@
border: none;
border-radius: 20px;
resize: none;
height: 50%;
height: 155px;
padding: 10px;
background-position: center;
background-repeat: no-repeat;
......@@ -109,7 +108,7 @@
&-comment {
transform: scale(1.2);
position: absolute;
bottom: 35px;
bottom: 65px;
left: 50px;
background-color: white;
padding: 4px;
......@@ -119,7 +118,7 @@
&-repeat {
transform: scale(1.2);
position: absolute;
bottom: 35px;
bottom: 65px;
left: 100px;
background-color: white;
padding: 4px;
......@@ -129,7 +128,7 @@
height: 3px;
width: 35px;
background-color: black;
bottom: 50px;
bottom: 80px;
left: 99px;
position: absolute;
transform: rotateZ(45deg);
......@@ -139,7 +138,7 @@
&-character {
transform: scale(1.2);
position: absolute;
bottom: 35px;
bottom: 65px;
left: 150px;
padding: 4px;
border-radius: 50%;
......@@ -148,12 +147,121 @@
&-interrupt {
transform: scale(1.2);
position: absolute;
bottom: 35px;
bottom: 65px;
left: 200px;
background-color: white;
padding: 4px;
border-radius: 50%;
}
&-prerequires {
width: 100px;
height: 50px;
background-color: white;
border-radius: 10px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
margin-top: 62px;
}
}
&-prerequires {
position: absolute;
width: 375px;
height: 150px;
background-color: #f7f7f7;
z-index: -1;
bottom: 120px;
right: 20px;
border: solid black 1px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
transition: transform 0.5s ease;
border-left: none;
display: flex;
flex-direction: row;
padding-left: 2px;
&-title {
margin-left: auto;
margin-right: auto;
font-family: 'Glacial Indifference Bold';
font-size: 13px;
}
&-form {
display: flex;
flex-direction: column;
overflow-x: hidden;
overflow-y: auto;
}
&-prerequires {
position: relative;
border-right: solid #a3a3a3 1px;
top: 50%;
transform: translateY(-50%);
width: 50%;
height: 90%;
display: flex;
flex-direction: column;
}
&-ressources {
width: 50%;
height: 90%;
border-bottom-right-radius: 10px;
position: relative;
top: 50%;
transform: translateY(-50%);
border-bottom-left-radius: 10px;
display: flex;
flex-direction: column;
&-element {
display: flex;
flex-direction: row;
margin-top: 5px;
&-checkbox {
position: relative;
width: 50%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
&-quantity {
position: relative;
width: 50%;
display: flex;
margin-right: 10px;
justify-content: flex-end;
input {
width: 20px;
border: none;
border-radius: 10px;
text-align: center;
}
select {
width: 40px;
background-color: white;
border: none;
border-radius: 10px;
margin-right: 5px;
}
}
}
}
}
&-prerequires.show {
transform: translateX(100%);
padding-left: 27px;
}
}
......
......@@ -12,6 +12,10 @@ import { Trace } from 'src/app/class/trace/trace';
import { MinimapService } from 'src/app/services/minimap/minimap.service';
import { TranslateService } from '@ngx-translate/core';
import { UnityService } from 'src/app/services/unity/unity.service';
import { PrerequireTask } from 'src/app/class/prerequires/prerequire-task/prerequire-task';
import { TutorialService } from 'src/app/services/tutorial/tutorial.service';
import { Ressource } from 'src/app/class/ressource/ressource';
import { PrerequireRessource } from 'src/app/class/prerequires/prerequire-ressource/prerequire-ressource';
@Component({
selector: 'app-repeat-task',
......@@ -21,6 +25,7 @@ import { UnityService } from 'src/app/services/unity/unity.service';
export class RepeatTaskComponent implements OnInit {
displayMenu: string = 'hide';
displayPrequires: string = 'hide';
@Input() scenario: Scenario = new Scenario();
@Input() task: Task = new Task('normal');
......@@ -35,7 +40,7 @@ export class RepeatTaskComponent implements OnInit {
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog, private minimapService: MinimapService, protected translate: TranslateService,
protected unityService: UnityService) { }
protected unityService: UnityService, private tutorialService: TutorialService) { }
ngOnInit(): void {
this.mission.equalizeLengths();
......@@ -152,4 +157,96 @@ export class RepeatTaskComponent implements OnInit {
editMoveTrace(event: any, source: string): void {
this.scenario.traces.push(new Trace(this.scenario.traces.length,'move',this.missionIndex,this.roleIndex,source,'Repeat_task_['+this.i+';'+this.j+']', '#B9DFE3'));
}
changeDisplayPrerequires(): void {
if(this.displayPrequires == 'show') {
this.displayPrequires = 'hide';
this.scenario.traces.push(new Trace(this.scenario.traces.length,'hide',this.missionIndex,this.roleIndex,'prerequires','Task_['+this.i+';'+this.j+']', '#B9DFE3'));
} else {
this.displayPrequires = 'show';
this.scenario.traces.push(new Trace(this.scenario.traces.length,'show',this.missionIndex,this.roleIndex,'prerequires','Task_['+this.i+';'+this.j+']', '#B9DFE3'));
}
}
checkboxChangedTask(event: any, task:(Task|null)): void {
if (task instanceof Task) {
if (event.target.checked) {
this.onCheckTask(task);
} else {
this.onUncheckTask(task);
}
}
}
isCheckedTask(task: (Task|null)): boolean {
if (task instanceof Task) {
return this.task.prerequireTasks.some(element => element.identifier == task.identifier);
}
return false;
}
onCheckTask(task: Task): void {
this.task.prerequireTasks.push(new PrerequireTask(task.identifier));
this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.roleIndex,'prerequire_task','Task_['+this.i+';'+this.j+']', '#B9DFE3'));
this.validTutorialPhase7();
}
onUncheckTask(task: Task): void {
let i: number = this.task.prerequireTasks.findIndex(element => element.identifier == task.identifier);
this.task.prerequireTasks.splice(i,1);
this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.roleIndex,'prerequire_task','Task_['+this.i+';'+this.j+']', '#B9DFE3'));
}
checkboxChangedRessource(event: any, ressource: Ressource): void {
if (event.target.checked) {
this.onCheckRessource(ressource);
} else {
this.onUncheckRessource(ressource);
}
}
isCheckedRessource(ressource: Ressource): boolean {
return this.task.prerequireRessources.some(element => element.ressource == ressource);
}
onCheckRessource(ressource: Ressource): void {
this.task.prerequireRessources.push(new PrerequireRessource(ressource));
this.scenario.traces.push(new Trace(this.scenario.traces.length,'new',this.missionIndex,this.roleIndex,'prerequire_ressource','Task_['+this.i+';'+this.j+']', '#B9DFE3'));
this.validTutorialPhase7();
}
onUncheckRessource(ressource: Ressource): void {
let i: number = this.task.prerequireRessources.findIndex(element => ressource == element.ressource);
this.task.prerequireRessources.splice(i, 1);
this.scenario.traces.push(new Trace(this.scenario.traces.length,'delete',this.missionIndex,this.roleIndex,'prerequire_ressource','Task_['+this.i+';'+this.j+']', '#B9DFE3'));
}
getAssociatePrerequireRessource(ressource: Ressource): PrerequireRessource {
let i: number = this.task.prerequireRessources.findIndex(element => ressource == element.ressource);
return this.task.prerequireRessources[i];
}
hasPossibleAntecedents(): boolean {
let res = false;
this.role.tasks.forEach(inlineTask => {
for(let i = 0; i < inlineTask.length; i++) {
if (inlineTask[i]?.identifier && (this.task.identifier != inlineTask[i]?.identifier)) {
res = true;
}
}
});
return res;
}
validTutorialPhase7(): void {
if (!this.tutorialService.optionnalPhase && !this.tutorialService.phaseDone[this.tutorialService.phase-1] && this.tutorialService.isActive && this.tutorialService.phase == 7
&& this.task.symbol.symbol && (this.task.prerequireTasks.length > 0 || this.task.prerequireRessources.length > 0)
&& this.scenario.missions[0].roles[0].tasks[0].some(task => task?.symbol.symbol && (task.prerequireTasks.length > 0 || task.prerequireRessources.length > 0))
&& this.scenario.missions[0].roles[1].tasks[0].some(task => task?.symbol.symbol && (task.prerequireTasks.length > 0 || task.prerequireRessources.length > 0))) {
this.scenario.traces.push(new Trace(this.scenario.traces.length, 'valid_phase', undefined, undefined, 'phase_'+this.tutorialService.phase, 'Tutorial'));
this.tutorialService.validPhase();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment