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 all 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
169 changes: 169 additions & 0 deletions lib/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,175 @@ const defaultConfig = {
],
},
},
grid: {
layout: {
sm: [
{
w: 10,
h: 3,
x: 0,
y: 0,
minW: 3,
minH: 2,
maxW: 10,
maxH: 50,
i: 'teitoku-panel',
},
{
w: 5,
h: 8,
x: 0,
y: 3,
minW: 1,
minH: 3,
maxW: 10,
maxH: 50,
i: 'resource-panel',
},
{
w: 5,
h: 36,
x: 0,
y: 11,
minW: 3,
minH: 9,
maxW: 10,
maxH: 50,
i: 'miniship',
},
{
w: 5,
h: 6,
x: 5,
y: 3,
minW: 2,
minH: 6,
maxW: 10,
maxH: 50,
i: 'repair-panel',
},
{
w: 5,
h: 6,
x: 5,
y: 9,
minW: 2,
minH: 6,
maxW: 10,
maxH: 50,
i: 'construction-panel',
},
{
w: 5,
h: 7,
x: 5,
y: 15,
minW: 3,
minH: 5,
maxW: 10,
maxH: 50,
i: 'expedition-panel',
},
{
w: 5,
h: 13,
x: 5,
y: 23,
minW: 3,
minH: 5,
maxW: 10,
maxH: 50,
i: 'task-panel',
},
],
lg: [
{
w: 27,
h: 58,
x: 0,
y: 0,
i: 'kan-game-wrapper',
},
{
w: 10,
h: 3,
x: 0,
y: 58,
minW: 3,
minH: 2,
maxW: 20,
maxH: 50,
i: 'teitoku-panel',
},
{
w: 5,
h: 9,
x: 0,
y: 61,
minW: 1,
minH: 3,
maxW: 20,
maxH: 50,
i: 'resource-panel',
},
{
w: 12,
h: 60,
x: 27,
y: 0,
minW: 3,
minH: 9,
maxW: 40,
maxH: 120,
i: 'poi-main',
},
{
w: 5,
h: 12,
x: 0,
y: 70,
minW: 2,
minH: 6,
maxW: 10,
maxH: 50,
i: 'repair-panel',
},
{
w: 5,
h: 12,
x: 6,
y: 70,
minW: 2,
minH: 6,
maxW: 10,
maxH: 50,
i: 'construction-panel',
},
{
w: 5,
h: 9,
x: 6,
y: 61,
minW: 3,
minH: 5,
maxW: 20,
maxH: 50,
i: 'expedition-panel',
},
{
w: 8,
h: 24,
x: 11,
y: 58,
minW: 3,
minH: 5,
maxW: 20,
maxH: 50,
i: 'task-panel',
},
],
},
},
},
proxy: {
socks5: {
Expand Down
106 changes: 104 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 } 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,13 @@ 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 { 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 +49,28 @@ require('./services/alert')
Popover.defaultProps.modifiers = POPOVER_MODIFIERS
Popover.defaultProps.boundary = 'viewport'

// Override maxsize
const defaultGridLayout = config.getDefault('poi.grid.layout')

function isPositionEqual(pos1, pos2) {
const configKey = ['x', 'y', 'h', 'w', 'i', 'minW', 'maxW', 'minH', 'maxH']

return isEqual(pick(pos1, configKey), pick(pos2, configKey))
}

function isLayoutsEqual(layout1, layout2) {
return Object.keys(layout1)
.map((i) => isPositionEqual(layout1[i], layout2[i]))
.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),
gridLayouts: get(state, 'config.poi.grid.layout', defaultGridLayout),
editable: get(state, 'config.poi.layout.editable', false),
theme: get(state, 'config.poi.appearance.theme', 'dark'),
}))
class Poi extends Component {
Expand All @@ -69,8 +95,84 @@ class Poi extends Component {
})
}

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

render() {
const { isHorizontal, reversed, theme } = this.props
const { isHorizontal, reversed, theme, grid } = 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>
)}
<ResponsiveReactGridLayout
layouts={this.props.gridLayouts}
onLayoutChange={this.onGridLayoutChange}
rowHeight={10}
margin={[3, 3]}
cols={{ lg: 40, sm: 10 }}
breakpoints={{ lg: 750, sm: 0 }}
width={1800}
compactType="horizontal"
isResizable={this.props.editable}
isDraggable={this.props.editable}
>
<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="kan-game-wrapper"
isResizable={false}
isDraggable={this.props.editable}
>
<KanGameWrapper key="frame" />
</div>
<div className="poi-main" key="poi-main">
<poi-main
style={{
flexFlow: `${isHorizontal ? 'row' : 'column'}${
reversed ? '-reverse' : ''
} nowrap`,
height: `100%`,
...(!isHorizontal && { overflow: 'hidden' }),
}}
>
<PoiApp />
</poi-main>
</div>
</ResponsiveReactGridLayout>
<ModalTrigger />
<BasicAuth />
</>
</ThemeProvider>
)
}
return (
<ThemeProvider theme={theme === 'dark' ? darkTheme : lightTheme}>
<>
Expand Down
Loading
Loading