v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "Architect.ahk"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
m (link to main ahk page)
m (unversioned)
 
Line 193: Line 193:
 
  return
 
  return
 
[[Category:ahk scripts]]
 
[[Category:ahk scripts]]
 +
{{unversioned}}

Latest revision as of 17:20, 21 July 2019

Used to automate designation of areas. See Macros and Keymaps for more scripts.

#EscapeChar \
; Example: Simple text editor with menu bar.

Gui, Font,, Courier new
; Create the sub-menus for the menu bar:
Menu, FileMenu, Add, &New, FileNew
Menu, FileMenu, Add, &Open, FileOpen
Menu, FileMenu, Add, &Save, FileSave
Menu, FileMenu, Add, Save &As, FileSaveAs
Menu, FileMenu, Add  ; Separator line.
Menu, FileMenu, Add, Run, FileRun
Menu, FileMenu, Add  ; Separator line.
Menu, FileMenu, Add, E&xit, FileExit
Menu, HelpMenu, Add, &About, HelpAbout

; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu

; Attach the menu bar to the window:
Gui, Menu, MyMenuBar

; Create the main Edit control and display the window:
Gui, +Resize  ; Make the window resizable.
Gui, Add, Checkbox, vConstruction, Construction?
Gui, Add, Edit, vDesignations W600 R19
Gui, Show,, YAMS
CurrentFileName =  ; Indicate that there is no current file.
return

FileNew:
GuiControl,, Designations  ; Clear the Edit control.
return

FileOpen:
Gui +OwnDialogs  ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open File, Text Documents (*.txt)
if SelectedFileName =  ; No file selected.
    return
Gosub FileRead
return

FileRead:  ; Caller has set the variable SelectedFileName for us.
FileRead, Designations, %SelectedFileName%  ; Read the file's contents into the variable.
if ErrorLevel
{
    MsgBox Could not open "%SelectedFileName%".
    return
}
GuiControl,, Designations, %Designations%  ; Put the text into the control.
CurrentFileName = %SelectedFileName%
Gui, Show,, %CurrentFileName%   ; Show file name in title bar.
return

FileSave:
if CurrentFileName =   ; No filename selected yet, so do Save-As instead.
    Goto FileSaveAs
Gosub SaveCurrentFile
return

FileSaveAs:
Gui +OwnDialogs  ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, S16,, Save File, Text Documents (*.txt)
if SelectedFileName =  ; No file selected.
    return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return

SaveCurrentFile:  ; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
    FileDelete %CurrentFileName%
    if ErrorLevel
    {
        MsgBox The attempt to overwrite "%CurrentFileName%" failed.
        return
    }
}
GuiControlGet, Designations  ; Retrieve the contents of the Edit control.
FileAppend, %Designations%, %CurrentFileName%  ; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):
Gui, Show,, %CurrentFileName%
return

HelpAbout:
Gui, 2:+owner1  ; Make the main window (Gui #1) the owner of the "about box" (Gui #2).
Gui +Disabled  ; Disable main window.
Gui, 2:Add, Text,, Text for about box.
Gui, 2:Add, Button, Default, OK
Gui, 2:Show
return

2ButtonOK:  ; This section is used by the "about box" above.
2GuiClose:
2GuiEscape:
Gui, 1:-Disabled  ; Re-enable the main window (must be done prior to the next step).
Gui Destroy  ; Destroy the about box.
return

GuiDropFiles:  ; Support drag & drop.
Loop, parse, A_GuiEvent, `n
{
    SelectedFileName = %A_LoopField%  ; Get the first file only (in case there's more than one).
    break
}
Gosub FileRead
return

GuiSize:
if ErrorLevel = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
NewWidth := A_GuiWidth - 20
NewHeight := A_GuiHeight - 40
GuiControl, Move, Designations, W%NewWidth% H%NewHeight%
return

FileExit:     ; User chose "Exit" from the File menu.
GuiClose:  ; User closed the window.
ExitApp


FileRun: 
  arp := ""
	ctr :=0 
  Gui, Submit , NoHide
	if (construction) {
	  preCommand   := "{RIGHT}"
	  apresCommand := "{ENTER}{ENTER}"
		spacer :="{RIGHT}"
	} else {
	  apresCommand := "{ENTER}{ENTER}{RIGHT}"
		spacer := "x"
	}
 	IfWinExist, Dwarf Fortress ; make sure df is running 
 		WinActivate
		
 		sleep, 3000
  
	chars = 0
	StringReplace, arp, Designations, %A_Space%  , %spacer%,1	
	Stringsplit, lines, arp
	
	Loop,
	{
	  ctr := a_index
    thisLine  := lines%a_index%
		if (thisLine ="") {
			break
		}
		if (thisLine = "\r") { 
			continue
		}
			if (thisLine = "\n") {
				
				if (!Construction){
					Send, {DOWN}
					loop, %chars% {
						Send, {LEFT}
					}
				} else {
				  send, w		
					Send, {DOWN}
					loop, %chars% {
						Send, {LEFT}
					}
					send, %a_space%
				}
					chars = 0
				continue
		} else { 
		}
		
    send, %thisLine%
		sleep, 20
		send, %apresCommand%
		chars ++
	  if (construction) {
		  send, w		
			send, {RIGHT}
			send, %a_space%
		}		
		if (chars >100) {
		  break
		}
		;
		;  clear out the lines "array"
		;
		lines%a_index% := ""
	}
	return