mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Merge branch 'react-transition-test' into v2
This commit is contained in:
@@ -55,7 +55,7 @@ export function UnitControlMenu() {
|
||||
updateData();
|
||||
})
|
||||
|
||||
/* When all units are selected clean the view */
|
||||
/* When all units are deselected clean the view */
|
||||
document.addEventListener("clearSelection", () => {
|
||||
setOpen(false);
|
||||
setSelectedUnits([])
|
||||
|
||||
55
frontend/react/src/ui/panels/unitmousecontrolbar.tsx
Normal file
55
frontend/react/src/ui/panels/unitmousecontrolbar.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Unit } from '../../unit/unit';
|
||||
import { ContextActionSet } from '../../unit/contextactionset';
|
||||
import { OlStateButton } from '../components/olstatebutton';
|
||||
import { faAccessibleIcon } from '@fortawesome/free-brands-svg-icons';
|
||||
import { faCamera } from '@fortawesome/free-solid-svg-icons';
|
||||
import { getApp } from '../../olympusapp';
|
||||
|
||||
export function UnitMouseControlBar(props: {
|
||||
|
||||
}) {
|
||||
var [open, setOpen] = useState(false);
|
||||
var [selectedUnits, setSelectedUnits] = useState([] as Unit[]);
|
||||
var [contextActionsSet, setContextActionsSet] = useState(new ContextActionSet());
|
||||
|
||||
/* When a unit is selected, open the menu */
|
||||
document.addEventListener("unitsSelection", (ev: CustomEventInit) => {
|
||||
setOpen(true);
|
||||
setSelectedUnits(ev.detail as Unit[]);
|
||||
|
||||
updateData();
|
||||
})
|
||||
|
||||
/* When a unit is deselected, refresh the view */
|
||||
document.addEventListener("unitDeselection", (ev: CustomEventInit) => {
|
||||
/* TODO add delay to avoid doing it too many times */
|
||||
updateData();
|
||||
})
|
||||
|
||||
/* When all units are deselected clean the view */
|
||||
document.addEventListener("clearSelection", () => {
|
||||
setOpen(false);
|
||||
setSelectedUnits([]);
|
||||
updateData();
|
||||
})
|
||||
|
||||
/* Update the current values of the shown data */
|
||||
function updateData() {
|
||||
var newContextActionSet = new ContextActionSet();
|
||||
|
||||
getApp().getUnitsManager().getSelectedUnits().forEach((unit: Unit) => {
|
||||
unit.appendContextActions(newContextActionSet);
|
||||
})
|
||||
|
||||
setContextActionsSet(newContextActionSet);
|
||||
}
|
||||
|
||||
return <div className='flex gap-2 rounded-md absolute top-20 left-[50%] translate-x-[-50%] bg-gray-200 dark:bg-olympus-900 z-ui-1 p-2'>
|
||||
{
|
||||
Object.values(contextActionsSet.getContextActions()).map((contextAction) => {
|
||||
return <OlStateButton checked={false} icon={contextAction.getIcon()} onClick={() => {}} />
|
||||
})
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import './ui.css'
|
||||
|
||||
import { EventsProvider } from '../eventscontext'
|
||||
@@ -16,6 +16,7 @@ import { getApp, setupApp } from '../olympusapp'
|
||||
import { LoginModal } from './modals/login'
|
||||
import { sha256 } from 'js-sha256'
|
||||
import { MiniMapPanel } from './panels/minimappanel'
|
||||
import { UnitMouseControlBar } from './panels/unitmousecontrolbar'
|
||||
|
||||
export type OlympusState = {
|
||||
mainMenuVisible: boolean,
|
||||
@@ -29,7 +30,7 @@ export type OlympusState = {
|
||||
}
|
||||
|
||||
export function UI() {
|
||||
var [loginModalVisible, setLoginModalVisible] = useState(true);
|
||||
var [loginModalVisible, setLoginModalVisible] = useState(false /* Temporary during devel */);
|
||||
var [mainMenuVisible, setMainMenuVisible] = useState(false);
|
||||
var [spawnMenuVisible, setSpawnMenuVisible] = useState(false);
|
||||
var [unitControlMenuVisible, setUnitControlMenuVisible] = useState(false);
|
||||
@@ -91,6 +92,15 @@ export function UI() {
|
||||
setLoginModalVisible(false);
|
||||
}
|
||||
|
||||
/* Temporary during devel */
|
||||
useEffect(() => {
|
||||
window.setTimeout(() => {
|
||||
checkPassword("admin");
|
||||
connect("devel");
|
||||
}, 1000)
|
||||
}, [])
|
||||
|
||||
|
||||
return (
|
||||
<div className="absolute top-0 left-0 h-screen w-screen font-sans overflow-hidden" onLoad={setupApp}>
|
||||
<StateProvider value={{
|
||||
@@ -151,6 +161,7 @@ export function UI() {
|
||||
<MiniMapPanel />
|
||||
<UnitControlMenu />
|
||||
<div id='map-container' className='h-full w-screen' />
|
||||
<UnitMouseControlBar />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user