diff --git a/srcjs/stendhal/ui/component/GroupMemberComponent.ts b/srcjs/stendhal/ui/component/GroupMemberComponent.ts index 8855e86001..34ddf362a8 100644 --- a/srcjs/stendhal/ui/component/GroupMemberComponent.ts +++ b/srcjs/stendhal/ui/component/GroupMemberComponent.ts @@ -9,18 +9,83 @@ * * ***************************************************************************/ +import { ui } from "../UI"; +import { UIComponentEnum } from "../UIComponentEnum"; + import { Component } from "../toolkit/Component"; +import { ActionContextMenu } from "../dialog/ActionContextMenu"; +import { ChatInputComponent } from "./ChatInputComponent"; + +declare let marauroa: any; +declare let stendhal: any; /** * a group member */ export class GroupMemberComponent extends Component { - constructor(name: string) { + constructor(private memberName: string, private isUserLeader: boolean) { super("group-member-template"); - this.child(".group-member-name")!.innerText = name; + this.child(".group-member-name")!.innerText = memberName; + this.componentElement.addEventListener("mouseup", (event) => { + this.onMouseUp(event); + }); } + buildActions(actions: any) { + let playerName = this.memberName; + actions.push({ + title: "Talk", + action: function(_groupMemberComponent: GroupMemberComponent) { + (ui.get(UIComponentEnum.ChatInput) as ChatInputComponent).setText("/msg " + + playerName + + " "); + } + }); + actions.push({ + title: "Where", + action: function(_groupMemberComponent: GroupMemberComponent) { + let action = { + "type": "where", + "target": playerName, + "zone": marauroa.currentZoneName + }; + marauroa.clientFramework.sendAction(action); + } + }); + if (this.isUserLeader && (!marauroa.me || this.memberName != marauroa.me["_name"])) { + actions.push({ + title: "Kick", + action: function(_groupMemberComponent: GroupMemberComponent) { + let action = { + "type": "group_management", + "action": "kick", + "params": playerName, + "zone": marauroa.currentZoneName + }; + marauroa.clientFramework.sendAction(action); + } + }); + actions.push({ + title: "Make leader", + action: function(_groupMemberComponent: GroupMemberComponent) { + let action = { + "type": "group_management", + "action": "leader", + "params": playerName, + "zone": marauroa.currentZoneName + }; + marauroa.clientFramework.sendAction(action); + } + }); + } + + } + + onMouseUp(event: MouseEvent) { + stendhal.ui.actionContextMenu.set(ui.createSingletonFloatingWindow("Action", + new ActionContextMenu(this), Math.max(10, event.pageX - 50), event.pageY - 5)); + } } diff --git a/srcjs/stendhal/ui/component/GroupPanelComponent.ts b/srcjs/stendhal/ui/component/GroupPanelComponent.ts index 4937642843..aff7f54738 100644 --- a/srcjs/stendhal/ui/component/GroupPanelComponent.ts +++ b/srcjs/stendhal/ui/component/GroupPanelComponent.ts @@ -105,7 +105,7 @@ export class GroupPanelComponent extends Panel { renderGroupMembers() { this.clear(); for (let member of Object.keys(stendhal.data.group.members)) { - this.add(new GroupMemberComponent(member)); + this.add(new GroupMemberComponent(member, stendhal.data.group.leader === marauroa.me["_name"])); } }