示例#1
0
文件: main.go 项目: walesey/go-engine
func createWindow(controllerManager *glfwController.ControllerManager) (window *ui.Window, content *ui.Container) {
	// Create window with size
	window = ui.NewWindow()
	window.SetScale(mgl32.Vec2{300, 0}.Vec3(0))

	// create a click and drag tab
	tab := ui.NewContainer()
	tab.SetBackgroundColor(70, 70, 170, 255)
	tab.SetHeight(40)

	// create a content container
	content = ui.NewContainer()
	content.SetBackgroundColor(200, 200, 200, 255)
	content.SetPadding(ui.NewMargin(10))

	// Add all the containers to the window
	mainContainer := ui.NewContainer()
	mainContainer.AddChildren(tab, content)
	window.SetElement(mainContainer)

	// create uiController
	uiController := ui.NewUiController(window)
	controllerManager.AddController(uiController.(glfwController.Controller))
	ui.ClickAndDragWindow(window, tab.Hitbox, uiController)

	return
}
示例#2
0
func (e *Editor) openFileBrowser(heading string, callback func(filePath string), filters ...string) {
	if e.fileBrowserOpen {
		return
	}
	if e.fileBrowser == nil {

		e.uiAssets.AddCallback("fileBrowserOpen", func(element ui.Element, args ...interface{}) {
			if len(args) >= 2 && !args[1].(bool) { // not on release
				e.fileBrowser.callback(e.fileBrowser.GetFileTextField())
			}
		})

		e.uiAssets.AddCallback("fileBrowserCancel", func(element ui.Element, args ...interface{}) {
			e.closeFileBrowser()
		})

		e.uiAssets.AddCallback("fileBrowserScrollup", func(element ui.Element, args ...interface{}) {
			if len(args) >= 2 && !args[1].(bool) { // not on release
				if e.fileBrowser.scrollOffset > 0 {
					e.fileBrowser.scrollOffset = e.fileBrowser.scrollOffset - 1
					e.fileBrowser.UpdateFileSystem()
				}
			}
		})

		e.uiAssets.AddCallback("fileBrowserScrollDown", func(element ui.Element, args ...interface{}) {
			if len(args) >= 2 && !args[1].(bool) { // not on release
				e.fileBrowser.scrollOffset = e.fileBrowser.scrollOffset + 1
				e.fileBrowser.UpdateFileSystem()
			}
		})

		window, container, _ := e.defaultWindow()
		window.SetTranslation(mgl32.Vec3{100, 100, 1})
		window.SetScale(mgl32.Vec3{800, 0, 1})

		e.fileBrowserController = ui.NewUiController(window).(glfwController.Controller)
		window.Tabs, _ = ui.LoadHTML(container, strings.NewReader(fileBrowserHtml), strings.NewReader(globalCss), e.uiAssets)

		e.fileBrowser = &FileBrowser{
			window:       window,
			assets:       e.uiAssets,
			callback:     callback,
			root:         ".",
			scrollOffset: 0,
			openFolders:  make(map[string]bool),
		}
	}
	e.fileBrowser.callback = callback
	e.fileBrowser.SetHeading(heading)
	e.fileBrowser.SetFileTextField("")
	e.fileBrowser.extensionFilter = filters
	e.gameEngine.AddOrtho(e.fileBrowser.window)
	e.controllerManager.AddController(e.fileBrowserController)
	e.fileBrowserOpen = true
	e.fileBrowser.UpdateFileSystem()
}
示例#3
0
func (e *Editor) openProgressBar() {
	if e.progressBar == nil {
		window := ui.NewWindow()
		window.SetTranslation(mgl32.Vec3{500, 0, 0})
		window.SetScale(mgl32.Vec3{330, 0, 1})

		container := ui.NewContainer()
		container.SetBackgroundColor(200, 200, 200, 255)
		window.SetElement(container)

		e.controllerManager.AddController(ui.NewUiController(window).(glfwController.Controller))
		ui.LoadHTML(container, strings.NewReader(progressBarHtml), strings.NewReader(globalCss), e.uiAssets)
		window.Render()

		e.progressBar = window
	}
	e.gameEngine.AddOrtho(e.progressBar)
}
示例#4
0
func (e *Editor) openNodeEditor(node *editorModels.NodeModel, callback func()) {
	window, container, _ := e.defaultWindow()
	window.SetTranslation(mgl32.Vec3{100, 100, 1})
	window.SetScale(mgl32.Vec3{500, 0, 1})
	uiController := ui.NewUiController(window).(glfwController.Controller)

	e.uiAssets.AddCallback("nodeEditorOk", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			node.Id = window.TextElementById("name").GetText()
			node.Classes = []string{}
			for i := 1; i <= 3; i++ {
				className := window.TextElementById(fmt.Sprintf("class%v", i)).GetText()
				if len(className) > 0 {
					node.Classes = append(node.Classes, className)
				}
			}
			e.gameEngine.RemoveSpatial(window, true)
			e.controllerManager.RemoveController(uiController)
			callback()
		}
	})

	e.uiAssets.AddCallback("nodeEditorCancel", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			e.gameEngine.RemoveSpatial(window, true)
			e.controllerManager.RemoveController(uiController)
		}
	})

	e.controllerManager.AddController(uiController)
	window.Tabs, _ = ui.LoadHTML(container, strings.NewReader(nodeEditMenuHtml), strings.NewReader(globalCss), e.uiAssets)

	e.gameEngine.AddOrtho(window)

	window.TextElementById("name").SetText(node.Id)
	for i, class := range node.Classes {
		if i < 3 {
			window.TextElementById(fmt.Sprintf("class%v", i+1)).SetText(class)
		}
	}
	window.Render()
}
示例#5
0
文件: ui.go 项目: walesey/go-engine
func (e *Editor) openMainMenu() {
	if e.mainMenu == nil {

		e.uiAssets.AddCallback("open", func(element ui.Element, args ...interface{}) {
			if len(args) >= 2 && !args[1].(bool) { // not on release
				e.openFileBrowser("Open", func(filePath string) {
					e.loadMap(filePath)
					e.closeFileBrowser()
				}, ".json")
			}
		})
		e.uiAssets.AddCallback("save", func(element ui.Element, args ...interface{}) {
			if len(args) >= 2 && !args[1].(bool) { // not on release
				e.openFileBrowser("Save", func(filePath string) {
					e.saveMap(filePath)
					e.closeFileBrowser()
				}, ".json")
			}
		})
		e.uiAssets.AddCallback("exit", func(element ui.Element, args ...interface{}) {
			os.Exit(0)
		})

		window, container, _ := e.defaultWindow()
		window.SetTranslation(mgl32.Vec3{200, 200, 1})
		window.SetScale(mgl32.Vec3{400, 0, 1})

		ui.LoadHTML(container, strings.NewReader(mainMenuHtml), strings.NewReader(globalCss), e.uiAssets)
		window.Render()

		e.mainMenuController = ui.NewUiController(window).(glfwController.Controller)
		e.mainMenu = window
	}
	e.gameEngine.AddOrtho(e.mainMenu)
	e.controllerManager.AddController(e.mainMenuController)
}
示例#6
0
func (e *Editor) initOverviewMenu() {

	e.uiAssets.AddCallback("import", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			e.openFileBrowser("import", func(filePath string) {
				e.setGeametry(filePath)
				e.overviewMenu.updateTree(e.currentMap)
				e.closeFileBrowser()
			}, ".obj")
		}
	})

	e.uiAssets.AddCallback("newGroup", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			uniqueIdCounter++
			e.createNewGroup(fmt.Sprintf("group_%v", uniqueIdCounter))
			e.overviewMenu.updateTree(e.currentMap)
			e.refreshMap()
		}
	})

	e.uiAssets.AddCallback("copyGroup", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			e.copyNewGroup()
			e.overviewMenu.updateTree(e.currentMap)
			e.refreshMap()
		}
	})

	e.uiAssets.AddCallback("referenceGroup", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			e.referenceGroup()
			e.overviewMenu.updateTree(e.currentMap)
			e.refreshMap()
		}
	})

	e.uiAssets.AddCallback("deleteGroup", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			e.deleteGroup()
			e.overviewMenu.updateTree(e.currentMap)
			e.refreshMap()
		}
	})

	e.uiAssets.AddCallback("editGroup", func(element ui.Element, args ...interface{}) {
		if len(args) >= 2 && !args[1].(bool) { // not on release
			e.editGroup(func() {
				e.overviewMenu.updateTree(e.currentMap)
			})
		}
	})

	e.uiAssets.AddCallback("scale", func(element ui.Element, args ...interface{}) {
		e.mouseMode = "scale"
	})

	e.uiAssets.AddCallback("translate", func(element ui.Element, args ...interface{}) {
		e.mouseMode = "translate"
	})

	e.uiAssets.AddCallback("rotate", func(element ui.Element, args ...interface{}) {
		e.mouseMode = "rotate"
	})

	e.uiAssets.AddCallback("reset", func(element ui.Element, args ...interface{}) {
		e.resetGroup()
	})

	window, container, _ := e.defaultWindow()
	window.SetTranslation(mgl32.Vec3{10, 10, 1})
	window.SetScale(mgl32.Vec3{500, 0, 1})

	e.controllerManager.AddController(ui.NewUiController(window).(glfwController.Controller))
	ui.LoadHTML(container, strings.NewReader(overviewMenuHtml), strings.NewReader(globalCss), e.uiAssets)

	e.gameEngine.AddOrtho(window)
	e.overviewMenu = &Overview{
		window:    window,
		assets:    e.uiAssets,
		openNodes: make(map[string]bool),
	}
	e.overviewMenu.updateTree(e.currentMap)
}