Skip to content

Commit

Permalink
Make chat panel float
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Jan 23, 2024
1 parent 482e7af commit 19420fd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions srcjs/stendhal.css
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ div.logcolR {
flex: 1;
height: auto;
overflow: hidden;
position: absolute;
}

#equipmentborder {
Expand Down
35 changes: 35 additions & 0 deletions srcjs/stendhal/ui/ChatPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/***************************************************************************
* Copyright © 2024 - Faiumoni e. V. *
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/

import { Panel } from "./toolkit/Panel";
import { singletons } from "../SingletonRepo";


export class ChatPanel extends Panel {

constructor() {
super("bottomPanel");
// hide until display is ready
this.setVisible(false);
}

/**
* Updates element using viewport attributes.
*/
public override refresh() {
const rect = singletons.getViewPort().getElement().getBoundingClientRect();
const halfHeight = Math.abs(rect.height / 2);
this.componentElement.style["width"] = rect.width + "px";
this.componentElement.style["height"] = halfHeight + "px";
this.componentElement.style["left"] = rect.left + "px";
this.componentElement.style["top"] = (rect.top + halfHeight) + "px";
}
}
5 changes: 5 additions & 0 deletions srcjs/stendhal/ui/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class UI {
return;
}
this.displayReady = true;

const chatPanel = this.get(UIComponentEnum.BottomPanel)!;
chatPanel.refresh();
chatPanel.setVisible(stendhal.config.getBoolean("client.chat.visible"));
// initialize on-screen joystick
stendhal.ui.gamewindow.updateJoystick();
QuickMenu.init();
Expand All @@ -87,6 +91,7 @@ class UI {
console.debug("display not in \"ready\" state");
return;
}
this.get(UIComponentEnum.BottomPanel)!.refresh();
QuickMenu.refresh();
}
}
Expand Down
5 changes: 2 additions & 3 deletions srcjs/stendhal/ui/factory/DesktopUserInterfaceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* *
***************************************************************************/

import { ChatPanel } from "../ChatPanel";
import { UIComponentEnum } from "../UIComponentEnum";
import { ui } from "../UI";

Expand Down Expand Up @@ -66,9 +67,7 @@ export class DesktopUserInterfaceFactory {

// hide pouch by default

// emoji button causes spacing between elements so apply theme to container panel
const bottomPanel = new Panel("bottomPanel", true);
bottomPanel.setVisible(singletons.getConfigManager().getBoolean("client.chat.visible"));
const bottomPanel = new ChatPanel();
ui.registerComponent(UIComponentEnum.BottomPanel, bottomPanel);

this.add(bottomPanel, UIComponentEnum.ChatInput, new ChatInputComponent());
Expand Down

0 comments on commit 19420fd

Please sign in to comment.