Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to use grid for global layout #2516

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e6b6053
Disable tab key to avoid moving the window accidentally
liu-ziyang Oct 26, 2023
d42efa0
Add configuration for isolated tab
liu-ziyang Oct 26, 2023
76bcd4e
remove accidental commit
liu-ziyang Oct 26, 2023
a0f8a69
Merge branch 'poooi:master' into enable-isolated-plugin-tab
liu-ziyang Oct 28, 2023
ac9cde2
moved grid layout config to panel section
liu-ziyang Nov 11, 2023
0cc52c9
Merge branch 'enable-isolated-plugin-tab' of github.com:liu-ziyang/po…
liu-ziyang Nov 11, 2023
3398e27
revert accidental changes
liu-ziyang Nov 11, 2023
1e14cb3
Merge branch 'poooi:master' into enable-isolated-plugin-tab
liu-ziyang Nov 11, 2023
3d432c5
deactivate tab if grid panel
liu-ziyang Nov 11, 2023
9d72b79
wrap poi with grid
liu-ziyang Nov 18, 2023
8d8abe9
grid layout iteration 1
liu-ziyang Dec 12, 2023
549ce77
undo unnecessary file change
liu-ziyang Dec 12, 2023
41135d6
adjust layout config
liu-ziyang Dec 12, 2023
022ae37
wrap the poi app in the grid
liu-ziyang Jan 4, 2024
14fdca9
update arrangement for the layout
liu-ziyang Jan 6, 2024
e9388d2
Merge branch 'master' of github.com:liu-ziyang/poi into enable-isolat…
liu-ziyang Jan 18, 2024
45f92f3
undo change that attempts to hide main page to debug
liu-ziyang Feb 24, 2024
44a8577
add configuration
liu-ziyang Feb 24, 2024
d589a81
clean ups
liu-ziyang Mar 11, 2024
78e4c93
clean ups
liu-ziyang Mar 11, 2024
f406ed8
add game draggable
liu-ziyang Mar 11, 2024
674d209
Merge branch 'master' of github.com:liu-ziyang/poi into enable-isolat…
liu-ziyang Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
52 changes: 30 additions & 22 deletions lib/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,31 +227,39 @@ const defaultConfig = {
],
lg: [
{
w: 12,
h: 3,
w: 27,
h: 58,
x: 0,
y: 0,
static: true,
i: 'poi-main',
},
{
w: 10,
h: 3,
x: 0,
y: 58,
minW: 3,
minH: 2,
maxW: 20,
maxH: 50,
i: 'teitoku-panel',
},
{
w: 6,
h: 8,
w: 5,
h: 9,
x: 0,
y: 3,
y: 61,
minW: 1,
minH: 3,
maxW: 20,
maxH: 50,
i: 'resource-panel',
},
{
w: 8,
h: 25,
x: 12,
w: 12,
h: 40,
x: 27,
y: 0,
minW: 3,
minH: 9,
Expand All @@ -260,43 +268,43 @@ const defaultConfig = {
i: 'miniship',
},
{
w: 6,
h: 7,
x: 6,
y: 11,
w: 5,
h: 12,
x: 0,
y: 70,
minW: 2,
minH: 6,
maxW: 10,
maxH: 50,
i: 'repair-panel',
},
{
w: 6,
h: 7,
w: 5,
h: 12,
x: 6,
y: 18,
y: 70,
minW: 2,
minH: 6,
maxW: 10,
maxH: 50,
i: 'construction-panel',
},
{
w: 6,
h: 8,
w: 5,
h: 9,
x: 6,
y: 3,
y: 61,
minW: 3,
minH: 5,
maxW: 20,
maxH: 50,
i: 'expedition-panel',
},
{
w: 6,
h: 14,
x: 0,
y: 11,
w: 8,
h: 24,
x: 11,
y: 58,
minW: 3,
minH: 5,
maxW: 20,
Expand Down
143 changes: 141 additions & 2 deletions views/app.es
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import ReactDOM from 'react-dom'
import { connect, Provider } from 'react-redux'
import { webFrame } from 'electron'
import * as remote from '@electron/remote'
import { get } from 'lodash'
import { get, pick, isEqual, entries, fromPairs, map } from 'lodash'
import { I18nextProvider } from 'react-i18next'
import { ThemeProvider } from 'styled-components'
import { ResizeSensor, Popover } from '@blueprintjs/core'
import { Responsive as ResponsiveReactGridLayout } from 'react-grid-layout'

import '../assets/css/app.css'
import '../assets/css/global.css'
Expand All @@ -25,6 +26,14 @@ import i18next from './env-parts/i18next'
import { darkTheme, lightTheme } from './theme'
import { POPOVER_MODIFIERS } from './utils/tools'

import { ExpeditionPanel } from './components/main/parts/expedition-panel'
import { TaskPanel } from './components/main/parts/task-panel'
import { MiniShip } from './components/main/parts/mini-ship'
import { ResourcePanel } from './components/main/parts/resource-panel'
import { AdmiralPanel } from './components/main/parts/admiral-panel'
import { RepairPanel } from './components/main/parts/repair-panel'
import { ConstructionPanel } from './components/main/parts/construction-panel'

const config = remote.require('./lib/config')

// Disable OSX zoom
Expand All @@ -41,10 +50,70 @@ require('./services/alert')
Popover.defaultProps.modifiers = POPOVER_MODIFIERS
Popover.defaultProps.boundary = 'viewport'

// Override maxsize
const defaultLayout = config.getDefault('poi.mainpanel.layout')
const configLayout = config.get('poi.mainpanel.layout')
const keys = ['minW', 'maxW', 'minH', 'maxH']
const newLayout = fromPairs(
map(entries(defaultLayout), ([bp, conf]) => [
bp,
map(conf, (panelConf, i) => ({
...get(configLayout, [bp, i], panelConf),
...pick(panelConf, keys),
})),
]),
)

if (!isEqual(newLayout, configLayout)) {
config.set('poi.mainpanel.layout', newLayout)
}

// polyfill for old layouts
function layoutConfigOutdated(layoutConfig) {
return (
!layoutConfig.sm.find((a) => a.i === 'repair-panel') ||
!layoutConfig.lg.find((a) => a.i === 'repair-panel')
)
}

function layoutConfigFix(layoutConfig) {
if (layoutConfigOutdated(layoutConfig)) {
return defaultLayout
}
return defaultLayout
}

if (layoutConfigOutdated(config.get('poi.mainpanel.layout', defaultLayout))) {
config.set('poi.mainpanel.layout', defaultLayout)
}

const configKey = ['x', 'y', 'h', 'w', 'i', 'minW', 'maxW', 'minH', 'maxH']

function isPositionEqual(pos1, pos2) {
return isEqual(pick(pos1, configKey), pick(pos2, configKey))
}

function isLayoutEqual(layout1, layout2) {
return Object.keys(layout1)
.map((i) => isPositionEqual(layout1[i], layout2[i]))
.reduce((a, b) => a && b)
}

function isLayoutsEqual(layouts1, layouts2) {
if (layouts1 == undefined || layouts2 == undefined) {
return false
}
return Object.keys(layouts1)
.map((layoutName) => isLayoutEqual(layouts1[layoutName], layouts2[layoutName]))
.reduce((a, b) => a && b)
}

@connect((state) => ({
isHorizontal: get(state, 'config.poi.layout.mode', 'horizontal') === 'horizontal',
reversed: get(state, 'config.poi.layout.reverse', false),
isolateGameWindow: get(state, 'config.poi.layout.isolate', false),
grid: get(state, 'config.poi.layout.grid', false),
layouts: layoutConfigFix(get(state, 'config.poi.mainpanel.layout', defaultLayout)),
theme: get(state, 'config.poi.appearance.theme', 'dark'),
}))
class Poi extends Component {
Expand All @@ -69,8 +138,78 @@ class Poi extends Component {
})
}

onLayoutChange = (layout, layouts) => {
if (!isLayoutsEqual(layouts, config.get('poi.mainpanel.layout'))) {
config.set('poi.mainpanel.layout', layouts)
}
}

render() {
const { isHorizontal, reversed, theme } = this.props
const { isHorizontal, reversed, isolateGameWindow, grid, theme } = this.props
if (grid) {
return (
<ThemeProvider theme={theme === 'dark' ? darkTheme : lightTheme}>
<>
{config.get(
'poi.appearance.customtitlebar',
process.platform === 'win32' || process.platform === 'linux',
) && (
<title-bar>
<TitleBarWrapper />
</title-bar>
)}
<ResizeSensor onResize={this.handleResize}>
<poi-main
style={{
flexFlow: `${isHorizontal ? 'row' : 'column'}${
reversed ? '-reverse' : ''
} nowrap`,
...(!isHorizontal && { overflow: 'hidden' }),
}}
>
<ResponsiveReactGridLayout
layouts={this.props.layouts}
// onLayoutChange={this.onLayoutChange}
rowHeight={10}
margin={[3, 3]}
cols={{ lg: 40, sm: 10 }}
breakpoints={{ lg: 750, sm: 0 }}
width={1800}
isResizable={true}
isDraggable={true}
compactType="horizontal"
>
<div className="teitoku-panel" key="teitoku-panel">
<AdmiralPanel editable={this.props.editable} />
</div>
<div className="resource-panel" key="resource-panel">
<ResourcePanel editable={this.props.editable} />
</div>
<div className="repair-panel panel-col" key="repair-panel">
<RepairPanel editable={this.props.editable} />
</div>
<div className="construction-panel panel-col" key="construction-panel">
<ConstructionPanel editable={this.props.editable} />
</div>
<div className="expedition-panel" key="expedition-panel">
<ExpeditionPanel editable={this.props.editable} />
</div>
<div className="task-panel" key="task-panel">
<TaskPanel editable={this.props.editable} />
</div>
<div className="kan-game-wrapper" key="poi-main">
<KanGameWrapper key="frame" />
</div>
</ResponsiveReactGridLayout>
<PoiApp />
Copy link
Contributor Author

@liu-ziyang liu-ziyang Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KochiyaOcean There are 2 approach I am trying, the first one is leaving the poi app outside the grid, which resulted in the control panel taking over the whole screen and I can't figure out how to resize it.

The other approach is put this as a div like other components, I personally prefer doing so because it would then allow moving the control panel around. but if I do that, somehow the control will completely disappear even though the grid item is there and draggable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-01-03 at 9 23 52 PM

when the poi app is wrapped in the grid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may caused by PoiApp component is actually a fragment and some event bundling failed to work. Maybe you can check the console to find if there is any js wise errors. In the other way, if the DOM compoents are mounted correctly, it would be more likely to be a css issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to get devtools to show up again but couldn't figure out what event bundling is broken, there are many error messages and don't seem to be relevant to my untrained eye. any theory based on file change in this PR?

</poi-main>
</ResizeSensor>
<ModalTrigger />
<BasicAuth />
</>
</ThemeProvider>
)
}
return (
<ThemeProvider theme={theme === 'dark' ? darkTheme : lightTheme}>
<>
Expand Down
Loading
Loading