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 "User:Daedalusai"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(now response to shift+arrow keys,shift+r retain original function)
(combined 2 functions used to check key state,replace if-else statement&braces with more concise bitwise operation,)
 
Line 32: Line 32:
 
x := 0
 
x := 0
 
y := 0
 
y := 0
 +
keystateflags := 0x0
 
 
 
;timer
 
;timer
Line 56: Line 57:
 
SetTimer, supplementchkswitch, Off
 
SetTimer, supplementchkswitch, Off
 
SetTimer, supplementchk, Off
 
SetTimer, supplementchk, Off
if ChkaxisX(x) != 0
+
keystateflags := Chkkey(x, y)
 +
if keystateflags & 0x3 != 0
 
GuiControl, Text, TXvalue, % "X: " x
 
GuiControl, Text, TXvalue, % "X: " x
if ChkaxisY(y) != 0
+
if keystateflags & 0xc != 0
 
GuiControl, Text, TYvalue, % "Y: " y
 
GuiControl, Text, TYvalue, % "Y: " y
 
SetTimer, supplementchkswitch, On
 
SetTimer, supplementchkswitch, On
Line 74: Line 76:
 
;timer routine
 
;timer routine
 
supplementchk:
 
supplementchk:
if (ChkaxisX(x)+ChkaxisY(y) = 0)
+
if ( Chkkey(x, y) = 0x0 )
 
{
 
{
 
SetTimer, supplementchk, Off
 
SetTimer, supplementchk, Off
Line 90: Line 92:
 
;Functions
 
;Functions
  
ChkaxisX(ByRef x)
+
Chkkey(ByRef x, ByRef y)
 
{
 
{
xmove := 0
+
keyflag := 0x0
 +
chkstateLR := 0x0
 +
chkstateUD := 0x0
 +
chkstateall := 0x0
 
steps := 1
 
steps := 1
 
prefix := ""
 
prefix := ""
 
GetKeyState, state, Left, P
 
GetKeyState, state, Left, P
 
if state = D
 
if state = D
xmove += 1
+
keyflag += 0x1
 
GetKeyState, state, Right, P
 
GetKeyState, state, Right, P
 
if state = D
 
if state = D
xmove += 3
+
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
 
GetKeyState, state, Shift, P
 
if state = D
 
if state = D
Line 119: Line 138:
 
steps := 0
 
steps := 0
 
}
 
}
if xmove != 4
+
 
 +
if ( chkstateLR != 0x3 and chkstateLR != 0x0 )
 
{
 
{
if xmove != 0
+
if chkstateLR = 0x1
 
{
 
{
if xmove = 1
+
Send %prefix%{Left}
{
+
x -= %steps%
Send %prefix%{Left}
 
x -= %steps%
 
Return 1
 
}
 
else
 
{
 
Send %prefix%{Right}
 
x += %steps%
 
Return 3
 
}
 
 
}
 
}
else
+
if chkstateLR = 0x2
 
{
 
{
Return 0
+
Send %prefix%{Right}
 +
x += %steps%
 
}
 
}
}
 
else
 
{
 
Return 4
 
}
 
Return
 
 
}
 
}
  
ChkaxisY(ByRef y)
+
if ( chkstateUD != 0xc and chkstateUD != 0x0 )
{
+
{
ymove := 0
+
if chkstateUD = 0x4
steps := 1
 
prefix := ""
 
GetKeyState, state, Up, P
 
if state = D
 
ymove += 1
 
GetKeyState, state, Down, P
 
if state = D
 
ymove += 3
 
GetKeyState, state, Shift,
 
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 ymove != 4
 
{
 
if ymove != 0
 
 
{
 
{
if ymove = 1
+
Send %prefix%{Up}
{
+
y += %steps%
Send %prefix%{Up}
 
y += %steps%
 
Return 1
 
}
 
else
 
{
 
Send %prefix%{Down}
 
y -= %steps%
 
Return 3
 
}
 
 
}
 
}
else
+
if chkstateUD = 0x8
 
{
 
{
Return 0
+
Send %prefix%{Down}
 +
y -= %steps%
 
}
 
}
 
}
 
}
else
+
 
{
+
fexit:
Return 4
+
Return keyflag
}
 
Return
 
 
}
 
}
  

Latest revision as of 03:04, 8 January 2009

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