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.

User:Daedalusai

From Dwarf Fortress Wiki
Revision as of 03:04, 8 January 2009 by Daedalusai (talk | contribs) (combined 2 functions used to check key state,replace if-else statement&braces with more concise bitwise operation,)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Some interface utilities[edit]

Tile Counter or Scrolling Accelerator[edit]

Lack of reference make me feel really stupid while planning digging area,so i tried to make a utility that shows coordinate.

This utility intercept arrow key strokes,then send keystrokes to game according to which key being pressed down(physiaclly),while counting how many keystrokes have been sent. As a side effect of sending keystrokes directly to the game,keystrokes can be sent much faster,result in much faster scrolling speed.

Note: This utility can't see where the cursor is in game,so if you move cursor over edge of map,the counter will not stop. If you want to measure how many tiles between edge of map and a giving spot,start measuring from edge of map. Otherwise,the counter is quite accurate as long as you don't touch the border.

Hotkey[edit]

Shift+r: Reset counter


;init config
SetTitleMatchMode, 3
#InstallKeybdHook
SendMode, Play

;Create Gui
Gui, Add, Text, x6 y10 w100 h20 vTXvalue, X: 0
Gui, Add, Text, x6 y30 w100 h20 vTYvalue, Y: 0
Gui, Add, Button, x106 y0 w40 h50 vBReset gReset, Reset
; Generated using SmartGUI Creator 4.0
Gui, Show, x554 y336 h53 w149, ShowXY

;var
x := 0
y := 0
keystateflags := 0x0
	
;timer
SetTimer, supplementchk, 20
SetTimer, supplementchk, Off
SetTimer, supplementchkswitch, -90
SetTimer, supplementchkswitch, Off

;init routine
ownPID := DllCall("GetCurrentProcessId")
WinSet, AlwaysOnTop, On, ahk_pid %ownPID%
Return

;Hotkeys

Left::
Right::
Up::
Down::
+Left::
+Right::
+Up::
+Down::
SetTimer, supplementchkswitch, Off
SetTimer, supplementchk, Off
keystateflags := Chkkey(x, y)
if keystateflags & 0x3 != 0
GuiControl, Text, TXvalue, % "X: " x
if keystateflags & 0xc != 0
GuiControl, Text, TYvalue, % "Y: " y
SetTimer, supplementchkswitch, On
Return

~+r::
;Button
Reset:
x := 0
y := 0
GuiControl, Text, TXvalue, % "X: " x
GuiControl, Text, TYvalue, % "Y: " y
Return

;timer routine
supplementchk:
if ( Chkkey(x, y) = 0x0 )
{
	SetTimer, supplementchk, Off
	Return
}
GuiControl, Text, TXvalue, % "X: " x
GuiControl, Text, TYvalue, % "Y: " y
Return

supplementchkswitch:
SetTimer, supplementchk, On
Return


;Functions

Chkkey(ByRef x, ByRef y)
{
keyflag := 0x0
chkstateLR := 0x0
chkstateUD := 0x0
chkstateall := 0x0
steps := 1
prefix := ""
GetKeyState, state, Left, P
if state = D
keyflag += 0x1
GetKeyState, state, Right, P
if state = D
keyflag += 0x2
GetKeyState, state, Up, P
if state = D
keyflag += 0x4
GetKeyState, state, Down, P
if state = D
keyflag += 0x8

if ( keyflag = 0x0 or keyflag = 0xf )
{
Return keyflag
}
chkstateLR := keyflag & 0x3
chkstateUD := keyflag & 0xc

GetKeyState, state, Shift, P
if state = D
{
	prefix := prefix "+"
	steps := 10
}
GetKeyState, state,Ctrl,
if state = D
{
	prefix := prefix "^"
	steps := 0
}
GetKeyState, state, Alt,
if state = D
{
	prefix := prefix "!"
	steps := 0
}

if ( chkstateLR != 0x3 and chkstateLR != 0x0 )
{
		if chkstateLR = 0x1
	{
		Send %prefix%{Left}
		x -= %steps%
	}
	if chkstateLR = 0x2
	{
		Send %prefix%{Right}
		x += %steps%
	}
}

if ( chkstateUD != 0xc and chkstateUD != 0x0 )
	{
		if chkstateUD = 0x4
	{
		Send %prefix%{Up}
		y += %steps%
	}
	if chkstateUD = 0x8
	{
		Send %prefix%{Down}
		y -= %steps%
	}
}

fexit:
Return keyflag
}

;build-in function
GuiClose:
ExitApp