-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathautofish.lua
More file actions
135 lines (117 loc) · 3.71 KB
/
Copy pathautofish.lua
File metadata and controls
135 lines (117 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
-- config ui for autofish
local gui = require("gui")
local widgets = require("gui.widgets")
local autofish = reqscript("autofish")
local REFRESH_MS = 10000
---
-- Autofish
---
Autofish = defclass(Autofish, widgets.Window)
Autofish.ATTRS{
frame_title = "Autofish",
frame = {w=35, h=11},
}
function Autofish:init()
self:addviews{
widgets.ToggleHotkeyLabel{
view_id="enable_toggle",
frame={t=0, l=0, w=31},
label="Autofish is",
key="CUSTOM_CTRL_E",
options={{value=true, label="Enabled", pen=COLOR_GREEN},
{value=false, label="Disabled", pen=COLOR_RED}},
on_change=function(val) dfhack.run_command{val and "enable" or "disable", "autofish"} end
},
widgets.EditField{
view_id="maximum",
frame={t=2,l=0},
label_text="Maximum fish target: ",
key="CUSTOM_M",
on_char=function(ch) return ch:match("%d") end,
on_submit=function(text)
autofish.set_maxFish(tonumber(text))
autofish.set_minFish(math.floor(tonumber(text)*0.75))
self:refresh_data()
end
},
widgets.ToggleHotkeyLabel{
view_id="useRawFish",
frame={t=3, l=0, w=31},
label="Counting raw fish:",
key="CUSTOM_ALT_R",
options={{value=true, label="Yes", pen=COLOR_GREEN},
{value=false, label="No", pen=COLOR_RED}},
on_change=function(val)
autofish.set_useRaw(val)
end
},
widgets.Label{
view_id="fish_count",
frame={t=5, l=0, h=1},
auto_height=false
},
widgets.Label{
view_id="current_mode",
frame={t=6, l=0, h=1},
auto_height=false,
visible=autofish.isEnabled
}
}
self:refresh_data()
end
function get_count_pen(val, min, max)
if val <= min then return COLOR_RED end
if val <= max then return COLOR_YELLOW end
return COLOR_GREEN
end
function get_count_text(val, min, max)
return {text=tostring(val), pen=get_count_pen(val, min, max)}
end
function get_fishing_text(val)
if not val then return {text="not ", pen=COLOR_RED} end
return ""
end
function Autofish:refresh_data()
self.subviews.enable_toggle:setOption(autofish.isEnabled())
--self.subviews.minimum:setText(tostring(autofish.set_minFish))
self.subviews.maximum:setText(tostring(autofish.s_maxFish))
self.subviews.useRawFish:setOption(autofish.s_useRaw)
local prep, raw = autofish.count_fish()
local total = prep+raw
local counts_text = {
"Fish: ",
get_count_text(total, autofish.s_minFish, autofish.s_maxFish),
" (",
{text=tostring(prep), pen=COLOR_GREY}, " prepared, ",
{text=tostring(raw), pen=COLOR_GREY}, " raw)"
}
self.subviews.fish_count:setText(counts_text)
local fishingText = {
"Currently ",
get_fishing_text(autofish.isFishing),
"fishing."
}
self.subviews.current_mode:setText(fishingText)
self.next_refresh_ms = dfhack.getTickCount() + REFRESH_MS
end
function Autofish:render(dc)
if self.next_refresh_ms <= dfhack.getTickCount() then
self:refresh_data()
end
Autofish.super.render(self, dc)
end
---
-- AutofishScreen
---
AutofishScreen = defclass(AutofishScreen, gui.ZScreen)
AutofishScreen.ATTRS{focus_path = "autofish"}
function AutofishScreen:init()
self:addviews{Autofish{}}
end
function AutofishScreen:onDismiss()
view = nil
end
if not dfhack.isMapLoaded then
qerror("autofish requires a map to be loaded")
end
view = view and view:raise() or AutofishScreen{}:show()