mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Made the center gui look better
This commit is contained in:
@@ -30,7 +30,7 @@ function center.clear(player)
|
||||
end
|
||||
|
||||
function center._center.open(event)
|
||||
local player = Game.get_player(player)
|
||||
local player = Game.get_player(event)
|
||||
local _center = Gui._get_data('center')[event.element.name]
|
||||
local center_flow = center.get_flow(player)
|
||||
if center_flow[_center.name] then center.clear(player) return end
|
||||
@@ -46,38 +46,45 @@ function center._center.open(event)
|
||||
if not success then error(err) end
|
||||
else error('No Callback on center frame '.._center.name)
|
||||
end
|
||||
player.opened=center_frame
|
||||
end
|
||||
|
||||
function center._center:callback(frame)
|
||||
frame.focus()
|
||||
local tabs = self.tabs
|
||||
local tab_bar_scroll = frame.add{
|
||||
type='scroll-pane',
|
||||
name='tab_bar_scroll',
|
||||
vertical_scroll_policy='never',
|
||||
horizontal_scroll_policy='always'
|
||||
}
|
||||
local tab_bar = tab_bar_scroll.add{
|
||||
type='flow',
|
||||
direction='horizontal',
|
||||
local tab_bar = frame.add{
|
||||
type='frame',
|
||||
name='tab_bar'
|
||||
}
|
||||
local tab_bar_scroll = tab_bar.add{
|
||||
type='scroll-pane',
|
||||
name='tab_bar_scroll',
|
||||
can_scroll_horizontally=true,
|
||||
direction='horizontal'
|
||||
}
|
||||
local tab_bar_scroll_flow = tab_bar_scroll.add{
|
||||
type='flow',
|
||||
name='tab_bar_scroll_flow',
|
||||
direction='horizontal'
|
||||
}
|
||||
local tab = frame.add{
|
||||
type ='frame',
|
||||
name='tab',
|
||||
direction='vertical'
|
||||
}
|
||||
local tab_scroll = tab.add{
|
||||
type ='scroll-pane',
|
||||
name='tab',
|
||||
vertical_scroll_policy='auto',
|
||||
horizontal_scroll_policy='never'
|
||||
name='tab_scroll',
|
||||
can_scroll_horizontally=false
|
||||
}
|
||||
local first_tab = nil
|
||||
for name,button in pairs(tabs) do
|
||||
local first_tab = first_tab or name
|
||||
button:draw(tab_bar)
|
||||
for name,button in pairs(self.tabs) do
|
||||
first_tab = first_tab or name
|
||||
button:draw(tab_bar_scroll_flow)
|
||||
end
|
||||
self.tabs[first_tab](tab)
|
||||
tab.style.minimal_height = 300; tab.style.maximal_height = 300
|
||||
tab.style.minimal_width = 500; tab.style.maximal_width = 500
|
||||
tab_bar_scroll.style.minimal_height = 60; tab_bar_scroll.style.maximal_height = 60
|
||||
tab_bar_scroll.style.minimal_width = 500; tab_bar_scroll.style.maximal_width = 500
|
||||
self._tabs[self.name..'_'..first_tab](tab_scroll)
|
||||
tab_scroll.style.height = 300
|
||||
tab_scroll.style.width = 500
|
||||
tab_bar_scroll.style.height = 80
|
||||
tab_bar_scroll.style.width = 500
|
||||
frame.parent.add{type='frame',name='temp'}.destroy()--recenter the GUI
|
||||
end
|
||||
|
||||
@@ -88,10 +95,10 @@ function center._center:add_tab(name,caption,tooltip,callback)
|
||||
name=self.name..'_'..name,
|
||||
caption=caption,
|
||||
tooltip=tooltip
|
||||
}.on_event('click',function(event)
|
||||
local tab = event.element.parent.parent.parent.tab
|
||||
}:on_event('click',function(event)
|
||||
local tab = event.element.parent.parent.parent.parent.tab.tab_scroll
|
||||
tab.clear()
|
||||
local frame_name = tab.parent.name
|
||||
local frame_name = tab.parent.parent.name
|
||||
local _center = Gui._get_data('center')[frame_name]
|
||||
local _tab = _center._tabs[event.element.name]
|
||||
if is_type(_tab,'function') then
|
||||
@@ -102,4 +109,8 @@ function center._center:add_tab(name,caption,tooltip,callback)
|
||||
return self
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_gui_closed,function(event)
|
||||
if event.element and event.element.valid then event.element.destroy() end
|
||||
end)
|
||||
|
||||
return center
|
||||
@@ -318,13 +318,12 @@ function inputs.add_slider(name,orientation,min,max,start_callback,callback)
|
||||
}
|
||||
slider.data._start = start_callback
|
||||
slider.data._callback = callback
|
||||
slider.data.max = max
|
||||
slider:on_event('slider',function(event)
|
||||
local slider = Gui._get_data('inputs_'..event.element.type)[event.element.name]
|
||||
local player = Game.get_player(event)
|
||||
local value = event.element.slider_value
|
||||
local data = slider.data
|
||||
local percent = value/data.max
|
||||
local percent = value/event.element.get_slider_maximum()
|
||||
if is_type(data._callback,'function') then
|
||||
local success, err = pcall(data._callback,player,value,percent,event.element)
|
||||
if not success then error(err) end
|
||||
|
||||
@@ -49,7 +49,9 @@ center.add{
|
||||
caption='Gui Center',
|
||||
tooltip='Just a gui test'
|
||||
}:add_tab('tab-1','Tab 1','Just a tab',function(frame)
|
||||
frame.add{type='lable',caption='Test'}
|
||||
frame.add{type='label',caption='Test'}
|
||||
end):add_tab('tab-2','Tab 2','Just a tab',function(frame)
|
||||
frame.add{type='lable',caption='Test 2'}
|
||||
for i = 1,100 do
|
||||
frame.add{type='label',caption='Test 2'}
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user