extensions/__menu: Figuring out how this thing should work

This commit is contained in:
Perttu Ahola 2014-09-26 12:23:53 +03:00
parent 865e71ec38
commit f11bd3ed25
3 changed files with 427 additions and 32 deletions

View File

@ -7,45 +7,98 @@ local dump = buildat.dump
local M = {safe = nil}
log:info("extension/__menu/init.lua: Loading")
local ui_stack_name_i = 1 -- For generating a unique name for each stack
local function UIStack(root)
local self = {}
self.root = root
self.stack_name = "ui_stack_"..ui_stack_name_i
ui_stack_name_i = ui_stack_name_i + 1
self.element_name_i = 1
self.stack = {}
function self:push()
if #self.stack >= 1 then
local top = self.stack[#self.stack]
top:SetVisible(false)
end
local element_name = self.stack_name.."_"..self.element_name_i
local element = self.root:CreateChild("UIElement")
element:SetName(element_name)
element:SetStyleAuto()
element:SetLayout(LM_HORIZONTAL, 0, IntRect(0, 0, 0, 0))
element:SetAlignment(HA_CENTER, VA_CENTER)
self.element_name_i = self.element_name_i + 1
table.insert(self.stack, element)
return element
end
function self:pop()
local top = table.remove(self.stack)
self.root:RemoveChild(top)
if #self.stack >= 1 then
local top = self.stack[#self.stack]
top:SetVisible(true)
end
end
return self
end
local ui_stack = UIStack(ui.root)
local function launch_connect_to_server()
end
function M.boot()
local style = cache:GetResource("XMLFile", "UI/DefaultStyle.xml")
local style = cache:GetResource("XMLFile", "__menu/res/boot_style.xml")
ui.root.defaultStyle = style
window = Window:new()
window:SetStyleAuto()
ui.root:AddChild(window)
window:SetMinSize(384, 192)
window:SetLayout(LM_HORIZONTAL, 6, IntRect(6, 6, 6, 6))
window:SetAlignment(HA_CENTER, VA_CENTER)
window:SetName("Window")
local checkBox = CheckBox:new()
checkBox:SetName("CheckBox")
checkBox:SetStyleAuto()
window:AddChild(checkBox)
local root = ui_stack:push()
local button = Button:new()
local test_element = root:CreateChild("Sprite")
test_element:SetTexture(
cache:GetResource("Texture2D", "__menu/res/icon_network.png"))
test_element.color = Color(.2, .2, .2)
test_element:SetFixedSize(400, 400)
local root = ui_stack:push()
local layout = root:CreateChild("Window")
layout:SetStyleAuto()
layout:SetName("Layout")
layout:SetLayout(LM_HORIZONTAL, 20, IntRect(0, 0, 0, 0))
layout:SetAlignment(HA_CENTER, VA_CENTER)
local button = layout:CreateChild("Button")
button:SetStyleAuto()
button:SetName("Button")
button.Height = 200
button.Width = 200
window:AddChild(button)
--[[local font = cache:GetResource("Font", "Fonts/Anonymous Pro.ttf")
local buttonText = button:CreateChild("Text")
buttonText:SetAlignment(magic.HA_CENTER, magic.HA_CENTER)
buttonText.text = "Button Text"
buttonText:SetFont(font)]]
local buttonImage = button:CreateChild("Sprite")
--buttonImage:SetTexture(cache:GetResource("Texture2D", "Textures/LogoLarge.png"))
buttonImage:SetTexture(cache:GetResource("Texture2D", "__menu/res/icon_network.png"))
buttonImage:SetAlignment(magic.HA_CENTER, magic.HA_CENTER)
buttonImage:SetSize(200, 200)
button:SetLayout(LM_VERTICAL, 10, IntRect(0, 0, 0, 0))
local button_image = button:CreateChild("Sprite")
button_image:SetName("ButtonImage")
button_image:SetTexture(
cache:GetResource("Texture2D", "__menu/res/icon_network.png"))
button_image.color = Color(.3, .3, .3)
button_image:SetFixedSize(200, 200)
local button_text = button:CreateChild("Text")
button_text:SetName("ButtonText")
button_text:SetStyleAuto()
button_text.text = "Connect to server"
button_text.color = Color(.3, .3, .3)
button_text:SetAlignment(HA_CENTER, VA_CENTER)
button_text:SetTextAlignment(HA_CENTER)
local lineEdit = LineEdit:new()
lineEdit:SetStyleAuto()
lineEdit:SetName("LineEdit")
lineEdit.minHeight = 24
window:AddChild(lineEdit)
magic.SubscribeToEvent(button, "HoverBegin",
function(self, event_type, event_data)
self:GetChild("ButtonImage").color = Color(1, 1, 1)
self:GetChild("ButtonText").color = Color(1, 1, 1)
end)
magic.SubscribeToEvent(button, "HoverEnd",
function(self, event_type, event_data)
self:GetChild("ButtonImage").color = Color(.3, .3, .3)
self:GetChild("ButtonText").color = Color(.3, .3, .3)
end)
magic.SubscribeToEvent(button, "Released",
function(self, event_type, event_data)
log:info("Button clicked: \"Connect to server\"")
launch_connect_to_server()
end)
magic.SubscribeToEvent("KeyDown", function(event_type, event_data)
local key = event_data:GetInt("Key")

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -0,0 +1,342 @@
<elements>
<element type="BorderImage" >
<attribute name="Texture" value="Texture2D;__menu/res/boot_style.png" />
</element>
<element type="Button" style="BorderImage">
<attribute name="Size" value="16 16" />
<attribute name="Image Rect" value="16 0 32 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Pressed Image Offset" value="16 0" />
<attribute name="Hover Image Offset" value="0 16" />
<attribute name="Pressed Child Offset" value="0 0" />
</element>
<element type="CheckBox" style="BorderImage">
<attribute name="Min Size" value="16 16" />
<attribute name="Max Size" value="16 16" />
<attribute name="Image Rect" value="80 0 96 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Checked Image Offset" value="16 0" />
<attribute name="Hover Image Offset" value="0 16" />
</element>
<element type="CloseButton" style="Button" auto="false"> <!-- non-auto style is shown explicitly in the Editor's style drop down list for user selection -->
<attribute name="Min Size" value="16 16" />
<attribute name="Max Size" value="16 16" />
<attribute name="Image Rect" value="144 0 160 16" />
<attribute name="Focus Mode" value="NotFocusable" />
</element>
<element type="Cursor">
<attribute name="Shapes">
<variant type="Int" value="8" />
<variant type="String" value="Normal" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="0 0 12 24" />
<variant type="IntVector2" value="0 0" />
<variant type="String" value="ResizeVertical" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="0 64 20 84" />
<variant type="IntVector2" value="9 9" />
<variant type="String" value="ResizeDiagonalTopRight" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="20 64 40 84" />
<variant type="IntVector2" value="9 9" />
<variant type="String" value="ResizeHorizontal" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="40 64 60 84" />
<variant type="IntVector2" value="9 9" />
<variant type="String" value="ResizeDiagonalTopLeft" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="60 64 80 84" />
<variant type="IntVector2" value="9 9" />
<variant type="String" value="RejectDrop" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="80 64 100 84" />
<variant type="IntVector2" value="9 9" />
<variant type="String" value="AcceptDrop" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="100 64 128 90" />
<variant type="IntVector2" value="0 0" />
<variant type="String" value="Busy" />
<variant type="ResourceRef" value="Image;Textures/UI.png" />
<variant type="IntRect" value="128 64 148 85" />
<variant type="IntVector2" value="9 9" />
</attribute>
</element>
<element type="DropDownList" style="BorderImage">
<attribute name="Image Rect" value="16 0 32 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Pressed Image Offset" value="16 0" />
<attribute name="Hover Image Offset" value="0 16" />
<attribute name="Pressed Child Offset" value="-1 1" />
<attribute name="Layout Mode" value="Horizontal" />
<attribute name="Layout Border" value="4 1 4 1" />
<element internal="true">
<element type="Text" internal="true" />
</element>
<element type="Window" internal="true" popup="true">
<attribute name="Layout Border" value="2 4 2 4" />
<element type="ListView" internal="true">
<attribute name="Highlight Mode" value="Always" />
<element type="BorderImage" internal="true"> <!-- Override scroll panel attributes from default ListView -->
<attribute name="Opacity" value="0" />
<attribute name="Clip Border" value="2 0 2 0" />
</element>
</element>
</element>
</element>
<element type="LineEdit" style="BorderImage">
<attribute name="Border" value="4 4 4 4" />
<attribute name="Image Rect" value="64 0 80 16" />
<attribute name="Hover Image Offset" value="0 16" /> <!-- Background color of the hover image IS the hover color of LineEdit -->
<element type="Text" internal="true">
<attribute name="Color" value="0.9 1 0.9 1" />
<attribute name="Selection Color" value="0.3 0.4 0.7 1" />
</element>
<element type="BorderImage" internal="true">
<attribute name="Size" value="4 16" />
<attribute name="Priority" value="1" />
<attribute name="Image Rect" value="12 0 16 16" />
</element>
</element>
<element type="ListView" style="ScrollView"> <!-- Shortcut to copy all the styles from ScrollView -->
<element type="BorderImage" internal="true">
<element internal="true">
<attribute name="Layout Mode" value="Vertical" />
</element>
</element>
</element>
<element type="HierarchyListView" style="ListView" auto="false">
<attribute name="Hierarchy Mode" value="true" />
<attribute name="Base Indent" value="1" /> <!-- Allocate space for overlay icon at the first level -->
<element type="BorderImage" internal="true">
<element type="HierarchyContainer" internal="true">
<attribute name="Layout Mode" value="Vertical" />
</element>
</element>
</element>
<element type="HierarchyListViewOverlay" style="BorderImage">
<attribute name="Min Size" value="16 16" />
<attribute name="Max Size" value="16 16" />
<attribute name="Image Rect" value="176 0 192 16" />
<attribute name="Checked Image Offset" value="16 0" />
<attribute name="Hover Image Offset" value="0 16" />
</element>
<element type="Menu" style="BorderImage">
<attribute name="Image Rect" value="112 0 128 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Pressed Image Offset" value="16 0" />
<attribute name="Hover Image Offset" value="0 16" />
</element>
<element type="ScrollBar">
<attribute name="Min Size" value="16 16" />
<attribute name="Left Image Rect" value="32 32 48 48" />
<attribute name="Up Image Rect" value="0 32 16 48" />
<attribute name="Right Image Rect" value="48 32 64 48" />
<attribute name="Down Image Rect" value="16 32 32 48" />
<element type="Button" internal="true">
<attribute name="Size" value="16 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Pressed Image Offset" value="64 0" />
<attribute name="Hover Image Offset" value="0 16" />
</element>
<element type="Slider" internal="true">
<attribute name="Size" value="16 16" />
</element>
<element type="Button" internal="true">
<attribute name="Size" value="16 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Pressed Image Offset" value="64 0" />
<attribute name="Hover Image Offset" value="0 16" />
</element>
</element>
<element type="ScrollView">
<element type="ScrollBar" internal="true">
<attribute name="Size" value="0 16" />
</element>
<element type="ScrollBar" internal="true">
<attribute name="Size" value="16 0" />
</element>
<element type="BorderImage" internal="true">
<attribute name="Image Rect" value="48 0 64 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Hover Image Offset" value="16 16" />
<attribute name="Clip Border" value="2 2 2 2" />
</element>
</element>
<element type="Slider" style="BorderImage">
<attribute name="Size" value="16 16" />
<attribute name="Image Rect" value="48 0 64 16" />
<attribute name="Border" value="4 4 4 4" />
<element type="BorderImage" internal="true">
<attribute name="Image Rect" value="16 0 32 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Hover Image Offset" value="0 16" />
</element>
</element>
<element type="Window" style="BorderImage">
<attribute name="Image Rect" value="48 0 64 16" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Resize Border" value="8 8 8 8" />
</element>
<element type="DialogWindow" style="Window" auto="false">
<attribute name="Is Movable" value="true" />
<attribute name="Modal Shade Color" value="0.3 0.4 0.7 0.4" />
<attribute name="Modal Frame Color" value="0.3 0.4 0.7" />
<attribute name="Modal Frame Size" value="2 2" />
</element>
<element type="ListRow">
<attribute name="Min Size" value="0 17" />
<attribute name="Max Size" value="2147483647 17" />
<attribute name="Layout Mode" value="Horizontal" />
</element>
<element type="PanelView" style="ListView" auto="false"> <!-- todo: rename this to PanelListView -->
<element type="BorderImage" internal="true">
<attribute name="Image Rect" value="48 16 64 32" />
<attribute name="Hover Image Offset" value="80 32" />
<element internal="true">
<attribute name="Layout Spacing" value="4" />
<attribute name="Layout Border" value="4 4 4 4" />
</element>
</element>
</element>
<element type="Panel" auto="false">
<attribute name="Layout Mode" value="Vertical" />
<attribute name="Layout Spacing" value="4" />
</element>
<element type="HorizontalPanel" auto="false">
<attribute name="Layout Mode" value="Horizontal" />
<attribute name="Layout Spacing" value="4" />
</element>
<element type="Text">
<attribute name="Font" value="Font;Fonts/Anonymous Pro.ttf" />
<attribute name="Font Size" value="11" />
<attribute name="Color" value="0.85 0.85 0.85" />
</element>
<element type="DebugHudText" style="Text" auto="false">
<attribute name="Text Effect" value="Shadow" />
</element>
<element type="ConsoleBackground" auto="false">
<attribute name="Color" value="0.15 0.15 0.15 0.8" />
<attribute name="Layout Border" value="4 4 4 4" />
</element>
<element type="ConsoleText" style="Text" auto="false">
<attribute name="Hover Color" value="0.3 0.4 0.7 1" />
<attribute name="Selection Color" value="0.2 0.225 0.35 1" />
</element>
<element type="ConsoleHighlightedText" style="ConsoleText" auto="false">
<attribute name="Color" value="1 0 0 1" />
</element>
<element type="ConsoleLineEdit" style="LineEdit" auto="false">
<attribute name="Min Size" value="0 17" />
<attribute name="Max Size" value="2147483647 17" />
<element type="Text" internal="true">
<attribute name="Selection Color" value="0.3 0.4 0.7 0.75" />
</element>
</element>
<element type="FileSelector" style="DialogWindow" auto="false">
<attribute name="Size" value="400 300" />
<attribute name="Is Resizable" value="true" />
<attribute name="Resize Border" value="6 6 6 6" />
<attribute name="Layout Mode" value="vertical" />
<attribute name="Layout Spacing" value="4" />
<attribute name="Layout Border" value="6 6 6 6" />
</element>
<element type="FileSelectorButton" style="Button" auto="false">
<attribute name="Min Size" value="80 17" />
<attribute name="Max Size" value="80 17" />
</element>
<element type="FileSelectorButtonText" style="Text" auto="false" />
<element type="FileSelectorListView" style="ListView" auto="false">
<attribute name="Highlight Mode" value="Always" />
</element>
<element type="FileSelectorLineEdit" style="LineEdit" auto="false">
<attribute name="Min Size" value="0 17" />
<attribute name="Max Size" value="2147483647 17" />
</element>
<element type="FileSelectorFilterList" style="DropDownList" auto="false">
<attribute name="Min Size" value="64 17" />
<attribute name="Max Size" value="64 17" />
<attribute name="Resize Popup" value="true" />
</element>
<element type="FileSelectorFilterText" style="Text" auto="false">
<attribute name="Is Enabled" value="true" />
<attribute name="Selection Color" value="0.2 0.225 0.35 1" />
<attribute name="Hover Color" value="0.3 0.4 0.7 1" />
</element>
<element type="FileSelectorLayout" auto="false">
<attribute name="Min Size" value="0 17" />
<attribute name="Max Size" value="2147483647 17" />
<attribute name="Layout Spacing" value="4" />
</element>
<element type="FileSelectorListText" style="Text" auto="false">
<attribute name="Hover Color" value="0.3 0.4 0.7 1" />
<attribute name="Selection Color" value="0.2 0.225 0.35 1" />
</element>
<element type="FileSelectorTitleText" style="Text" auto="false" />
<element type="EditorDivider" style="BorderImage" auto="false">
<attribute name="Image Rect" value="144 32 160 43" />
<attribute name="Border" value="4 4 4 4" />
<attribute name="Min Size" value="0 11" />
<attribute name="Max Size" value="2147483647 11" />
</element>
<element type="EditorSeparator" auto="false">
<attribute name="Min Size" value="0 2" />
<attribute name="Max Size" value="2147483647 2" />
</element>
<element type="EditorMenuBar" style="BorderImage" auto="false">
<attribute name="Image Rect" value="112 0 128 16" />
<attribute name="Border" value="4 4 4 4" />
</element>
<element type="EditorMenuText" style="Text" auto="false" />
<element type="EditorAttributeText" auto="false">
<attribute name="Font" value="Font;Fonts/BlueHighway.ttf" />
<attribute name="Font Size" value="9" />
</element>
<element type="EditorEnumAttributeText" style="EditorAttributeText" auto="false">
<attribute name="Is Enabled" value="true" />
<attribute name="Selection Color" value="0.2 0.225 0.35 1" />
<attribute name="Hover Color" value="0.3 0.4 0.7 1" />
</element>
<element type="EditorToolBar" style="BorderImage">
<attribute name="Image Rect" value="48 0 64 16" />
<attribute name="Border" value="4 4 4 4" />
</element>
<element type="ToolBarButton" style="Button">
<attribute name="Min Size" value="34 34" />
<attribute name="Max Size" value="34 34" />
<attribute name="Layout Mode" value="Horizontal" />
<attribute name="Layout Border" value="2 2 2 2" />
<attribute name="Focus Mode" value="NotFocusable" />
</element>
<element type="ToolBarToggle" style="CheckBox">
<attribute name="Min Size" value="34 34" />
<attribute name="Max Size" value="34 34" />
<attribute name="Image Rect" value="208 0 224 16" />
<attribute name="Layout Mode" value="Horizontal" />
<attribute name="Layout Border" value="2 2 2 2" />
<attribute name="Focus Mode" value="NotFocusable" />
</element>
<element type="ToolBarToggleGroupLeft" style="ToolBarToggle">
<attribute name="Image Rect" value="160 32 176 48" />
</element>
<element type="ToolBarToggleGroupMiddle" style="ToolBarToggle">
<attribute name="Image Rect" value="192 32 208 48" />
</element>
<element type="ToolBarToggleGroupRight" style="ToolBarToggle">
<attribute name="Image Rect" value="224 32 240 48" />
</element>
<element type="EditorAttributeEdit" style="LineEdit" auto="false" />
<element type="ToolTipBorderImage" style="BorderImage">
<attribute name="Layout Mode" value="Horizontal" />
<attribute name="Layout Border" value="6 2 6 2" />
<attribute name="Image Rect" value="48 0 64 16" />
<attribute name="Border" value="6 2 2 2" />
</element>
<element type="ToolTipText" style="Text">
<attribute name="Font" value="Font;Fonts/BlueHighway.ttf" />
<attribute name="Font Size" value="9" />
</element>
<element type="ViewportBorder" style="BorderImage">
<attribute name="Image Rect" value="50 5 51 6" />
<attribute name="Border" value="0 0 0 0" />
</element>
</elements>