inventory-items-2 #44
@ -32,7 +32,7 @@
|
||||
<app-script-account-overview *ngIf="openContent == ModelComponentType.SCRIPTACCOUNT" #scriptAccountOverview [gameModel]="gameModel" (onOpenScriptAccount)="openModelComponent($event)"></app-script-account-overview>
|
||||
<app-gamescript-overview *ngIf="openContent == ModelComponentType.GAMESYTEM" #gamesystemOverview [gameModel]="gameModel" (openGamesystemEditor)="openModelComponent($event)"></app-gamescript-overview>
|
||||
<app-character-overview *ngIf="openContent == ModelComponentType.CHARACTER" #characterOverview [gameModel]="gameModel" (onOpenCharacterEditor)="openModelComponent($event)"></app-character-overview>
|
||||
<app-item-overview *ngIf="openContent == ModelComponentType.ITEMGROUP || openContent == ModelComponentType.ITEM" #itemOverview [gameModel]="gameModel"></app-item-overview>
|
||||
<app-item-overview *ngIf="openContent == ModelComponentType.ITEMGROUP || openContent == ModelComponentType.ITEM" #itemOverview [gameModel]="gameModel" (openItemgroupEmitter)="openModelComponent($event)"></app-item-overview>
|
||||
</mat-drawer>
|
||||
|
||||
<div class="example-sidenav-content">
|
||||
|
@ -83,6 +83,7 @@ import {
|
||||
StateInitialCellComponent
|
||||
} from "./editor/gamesystem-editor/state-editor/simple-state-editor/state-initial-cell/state-initial-cell.component";
|
||||
import {ItemOverviewComponent} from "./side-overviews/item-overview/item-overview.component";
|
||||
import {ItemGroupEditorComponent} from "./editor/items/item-group-editor/item-group-editor.component";
|
||||
|
||||
// AoT requires an exported function for factories
|
||||
const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json');
|
||||
@ -172,7 +173,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
|
||||
MatExpansionPanel,
|
||||
MatExpansionPanelTitle,
|
||||
MatCardTitle,
|
||||
MatExpansionPanelHeader
|
||||
MatExpansionPanelHeader,
|
||||
ItemGroupEditorComponent
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
|
@ -20,5 +20,6 @@
|
||||
>
|
||||
|
||||
</app-character-editor>
|
||||
<app-item-group-editor *ngIf="modelComponent.type === ModelComponentType.ITEMGROUP"></app-item-group-editor>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
|
@ -0,0 +1 @@
|
||||
<p>item-group-editor works!</p>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ItemGroupEditorComponent } from './item-group-editor.component';
|
||||
|
||||
describe('ItemGroupEditorComponent', () => {
|
||||
let component: ItemGroupEditorComponent;
|
||||
let fixture: ComponentFixture<ItemGroupEditorComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ItemGroupEditorComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ItemGroupEditorComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,12 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-item-group-editor',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './item-group-editor.component.html',
|
||||
styleUrl: './item-group-editor.component.scss'
|
||||
})
|
||||
export class ItemGroupEditorComponent {
|
||||
|
||||
}
|
@ -69,7 +69,7 @@ export class GameModel {
|
||||
}
|
||||
}
|
||||
|
||||
private static findItemgroupByName(name: string, itemgroups: ItemGroup[]) {
|
||||
public static findItemgroupByName(name: string, itemgroups: ItemGroup[]) {
|
||||
const itemgroupQueue: ItemGroup[] = itemgroups.concat();
|
||||
while(itemgroupQueue.length > 0 ) {
|
||||
const currentItemgroup = itemgroupQueue.shift()!;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
|
||||
<!-- This is the tree node template for leaf nodes -->
|
||||
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding matTreeNodePaddingIndent="10">
|
||||
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding matTreeNodePaddingIndent="10" (click)="onSelectItem(node)" (contextmenu)="onSelectItem(node)" (dblclick)="openItemEditor(node)">
|
||||
<!-- use a disabled button to provide padding for tree leaf -->
|
||||
<button class="small-icon-button" mat-icon-button disabled></button>
|
||||
<mat-icon class="small-icon-button" *ngIf="node.type == ModelComponentType.ITEMGROUP">folder</mat-icon>
|
||||
@ -8,7 +8,7 @@
|
||||
{{node.name}}
|
||||
</mat-tree-node>
|
||||
<!-- This is the tree node template for expandable nodes -->
|
||||
<mat-tree-node *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding matTreeNodePaddingIndent="10">
|
||||
<mat-tree-node *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding matTreeNodePaddingIndent="10" (click)="onSelectItem(node)" (contextmenu)="onSelectItem(node)" (dblclick)="openItemEditor(node)">
|
||||
<button class="small-icon-button" mat-icon-button matTreeNodeToggle
|
||||
[attr.aria-label]="'Toggle ' + node.name">
|
||||
<mat-icon class="mat-icon-rtl-mirror">
|
||||
|
@ -1,13 +1,12 @@
|
||||
import {Component, Input, OnInit} from '@angular/core';
|
||||
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
||||
import {GameModel} from "../../project/game-model/GameModel";
|
||||
import {FlatTreeControl} from "@angular/cdk/tree";
|
||||
import {MatTreeFlatDataSource, MatTreeFlattener} from "@angular/material/tree";
|
||||
import {ItemGroup} from "../../project/game-model/inventory/ItemGroup";
|
||||
import {AbstractItemGroup} from "../../project/game-model/inventory/AbstractItemGroup";
|
||||
import {ConcreteItemGroup} from "../../project/game-model/inventory/ConcreteItemGroup";
|
||||
import {ModelComponent} from "../../project/game-model/ModelComponent";
|
||||
import {Item} from "../../project/game-model/inventory/Item";
|
||||
import {ModelComponentType} from "../../project/game-model/ModelComponentType";
|
||||
import {ItemGroup} from "../../project/game-model/inventory/ItemGroup";
|
||||
|
||||
interface FlatNode {
|
||||
expandable: boolean,
|
||||
@ -24,6 +23,7 @@ interface FlatNode {
|
||||
export class ItemOverviewComponent implements OnInit{
|
||||
|
||||
@Input() gameModel: GameModel | undefined
|
||||
@Output() openItemgroupEmitter: EventEmitter<ItemGroup> = new EventEmitter();
|
||||
|
||||
private _transformer = (node: ModelComponent, level: number) => {
|
||||
if(node instanceof AbstractItemGroup) {
|
||||
@ -64,6 +64,7 @@ export class ItemOverviewComponent implements OnInit{
|
||||
);
|
||||
|
||||
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
|
||||
selectedItem: FlatNode | undefined
|
||||
|
||||
hasChild = (_: number, node: FlatNode) => node.expandable;
|
||||
|
||||
@ -82,4 +83,17 @@ export class ItemOverviewComponent implements OnInit{
|
||||
}
|
||||
|
||||
protected readonly ModelComponentType = ModelComponentType;
|
||||
|
||||
onSelectItem(node: FlatNode) {
|
||||
this.selectedItem = node;
|
||||
}
|
||||
|
||||
openItemEditor(node: FlatNode) {
|
||||
if(node.type == ModelComponentType.ITEMGROUP) {
|
||||
const itemGroup = GameModel.findItemgroupByName(node.name, this.gameModel!.itemgroups);
|
||||
if(itemGroup) {
|
||||
this.openItemgroupEmitter.emit(itemGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user