hadean-old/src/qt/GameView.ts

117 lines
3.0 KiB
TypeScript
Raw Normal View History

2021-07-23 00:12:02 -04:00
import { Game } from '@game';
2021-07-25 13:57:47 -04:00
import {
QLabel,
QTabWidget,
QWidget,
2021-07-26 14:23:41 -04:00
QIcon,
FlexLayout,
QGridLayout,
FocusPolicy,
WidgetEventTypes,
2021-07-26 23:15:05 -04:00
AlignmentFlag,
QListView,
QListWidget,
QListWidgetItem
2021-07-25 13:57:47 -04:00
} from '@nodegui/nodegui';
2021-07-26 14:23:41 -04:00
import { Pawn } from '../Pawn.js';
2021-07-23 00:12:02 -04:00
import { View } from './View.js';
export class GameView extends View {
game: Game;
title: QLabel;
2021-07-26 23:15:05 -04:00
timeLabel: QLabel;
2021-07-23 00:12:02 -04:00
left: QWidget;
2021-07-25 13:57:47 -04:00
right: QTabWidget;
2021-07-23 00:12:02 -04:00
addComponents(): void {
this.addLayout();
this.title = new QLabel();
this.left = new QWidget();
2021-07-25 13:57:47 -04:00
this.right = new QTabWidget();
2021-07-26 23:15:05 -04:00
this.timeLabel = new TimeWidget();
2021-07-23 00:12:02 -04:00
this.title.setText(this.game.name);
this.left.setInlineStyle('border: 1px solid white;')
this.right.setInlineStyle('border: 1px solid white;')
2021-07-26 23:15:05 -04:00
this.layout.addWidget(this.title, 0, 0);
this.layout.addWidget(this.timeLabel, 0, 1);
this.layout.addWidget(this.left, 1, 0);
this.layout.addWidget(this.right, 1, 1);
this.layout.setRowStretch(0, 0);
this.layout.setRowStretch(1, 1);
this.layout.setColumnStretch(0, 3);
this.layout.setColumnStretch(1, 2);
2021-07-25 13:57:47 -04:00
2021-07-26 14:23:41 -04:00
this.right.addTab(new PawnPageWidget(), new QIcon(), 'Pawns');
2021-07-26 23:15:05 -04:00
this.right.addTab(new InventoryWidget(), new QIcon(), 'Inventory')
2021-07-23 00:12:02 -04:00
}
constructor(game: Game) {
super();
this.game = game;
}
2021-07-25 13:57:47 -04:00
}
2021-07-26 14:23:41 -04:00
class PawnWidget extends QWidget {
constructor(pawn: Pawn) {
super();
2021-07-26 23:15:05 -04:00
let layout: QGridLayout;
this.setLayout(layout = new QGridLayout());
// this.setInlineStyle(`
// margin-bottom: 4px;
// `);
2021-07-26 14:23:41 -04:00
const nameLabel = new QLabel();
nameLabel.setText(pawn.name.first + ' ' + pawn.name.last);
nameLabel.setAlignment(AlignmentFlag.AlignLeft | AlignmentFlag.AlignTop);
2021-07-26 23:15:05 -04:00
2021-07-26 14:23:41 -04:00
const activityLabel = new QLabel();
activityLabel.setText(pawn.status);
activityLabel.setAlignment(AlignmentFlag.AlignRight | AlignmentFlag.AlignTop);
2021-07-26 23:15:05 -04:00
2021-07-26 14:23:41 -04:00
this.layout.addWidget(nameLabel, 0, 0, 1, 1);
this.layout.addWidget(activityLabel, 0, 1, 1, 1);
2021-07-26 23:15:05 -04:00
layout.setColumnStretch(0, 1);
layout.setColumnStretch(1, 1);
layout.setRowStretch(0, 1);
// this.setFocusPolicy(FocusPolicy.ClickFocus);
2021-07-26 14:23:41 -04:00
}
}
2021-07-26 23:15:05 -04:00
class PawnPageWidget extends QListWidget {
2021-07-26 14:23:41 -04:00
constructor() {
super();
2021-07-26 23:15:05 -04:00
// this.setLayout(new FlexLayout());
this.setInlineStyle('background: purple;');
// this.layout.addWidget(new PawnWidget(Game.current.pawns[0]));
2021-07-26 14:23:41 -04:00
for(const pawn of Game.current.pawns) {
// const label = new QLabel();
// label.setText(pawn.name.first);
// this.layout.addWidget(label);
2021-07-26 23:15:05 -04:00
// this.layout.addWidget(new PawnWidget(pawn));
const item = new QListWidgetItem();
this.addItem(item);
this.setItemWidget(item, new PawnWidget(pawn));
2021-07-26 14:23:41 -04:00
}
}
2021-07-26 23:15:05 -04:00
}
class TimeWidget extends QLabel {
constructor() {
super();
this.setAlignment(AlignmentFlag.AlignRight | AlignmentFlag.AlignVCenter);
setInterval(() => {
this.setText(Game.current.clock.toString());
}, 100)
}
}
class InventoryWidget extends QWidget {
2021-07-26 14:23:41 -04:00
}