--***************************************************************************** --* File: lua/modules/ui/game/rename.lua --* Author: Chris Blackwell --* Summary: Rename dialog --* --* Copyright © 2005 Gas Powered Games, Inc. All rights reserved. --***************************************************************************** local UIUtil = import('/lua/modules/ui/uiutil.lua') local LayoutHelpers = import('/lua/modules/maui/layouthelpers.lua') local Group = import('/lua/modules/maui/group.lua').Group local Text = import('/lua/modules/maui/text.lua').Text local Button = import('/lua/modules/maui/button.lua').Button local Bitmap = import('/lua/modules/maui/bitmap.lua').Bitmap local Edit = import('/lua/modules/maui/edit.lua').Edit local dialog = false function ShowRenameDialog(currentName) -- Dialog already showing? Don't show another one if dialog then return end local mapGroup = import('/lua/modules/ui/game/borders.lua').GetMapGroup() dialog = Bitmap(mapGroup, UIUtil.SkinnableFile('/dialogs/unit-naming/unit-name_bmp.dds'), "Rename Dialog") LayoutHelpers.AtCenterIn(dialog, mapGroup) local label = UIUtil.CreateText(dialog, "Enter New Name", 9, UIUtil.buttonFont) LayoutHelpers.RelativeTo(label, dialog, UIUtil.SkinnableFile('/dialogs/unit-naming/unit-naming_layout.lua'), 'l_text-etc', 'unit-name_bmp') local cancelButton = UIUtil.CreateButtonStd(dialog, '/dialogs/standard-small_btn/standard-small', "", 10) LayoutHelpers.RelativeTo(cancelButton, dialog, UIUtil.SkinnableFile('/dialogs/unit-naming/unit-naming_layout.lua'), 'l_cancel_btn copy 2', 'unit-name_bmp') cancelButton.OnClick = function(self, modifiers) dialog:Destroy() dialog = false end --TODO this should be in layout local nameEdit = Edit(dialog) LayoutHelpers.AtLeftTopIn(nameEdit, dialog, 24, 28) nameEdit.Width:Set(283) nameEdit.Height:Set(nameEdit:GetFontHeight()) nameEdit:SetFont(UIUtil.bodyFont, 12) nameEdit:SetForegroundColor(UIUtil.fontColor) nameEdit:ShowBackground(false) nameEdit:AcquireFocus() local firstTime = true nameEdit.OnEnterPressed = function(self, text) local newName = nameEdit:GetText() if (newName != nil) and (newName != "") then ConExecute('RenameUnit ' .. newName) end dialog:Destroy() dialog = false return true end dialog:SetNeedsFrameUpdate(true) dialog.OnFrame = function(self, elapsedTime) -- this works around the fact that wxWindows processes keys and then generates a wmChar message -- so if you don't set the text you'll see the hotkey that made this dialog if firstTime then nameEdit:SetText(currentName) firstTime = false end end local okButton = UIUtil.CreateButtonStd(dialog, '/dialogs/standard-small_btn/standard-small', "OK", 10) LayoutHelpers.RelativeTo(okButton, dialog, UIUtil.SkinnableFile('/dialogs/unit-naming/unit-naming_layout.lua'), 'l_standard_btn_up copy 2', 'unit-name_bmp') okButton.OnClick = function(self, modifiers) local newName = nameEdit:GetText() if (newName != nil) and (newName != "") then ConExecute('RenameUnit ' .. newName) end dialog:Destroy() dialog = false end end