forked from akrasuski1/akrOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_menu.ks
141 lines (120 loc) · 2.91 KB
/
job_menu.ks
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
136
137
138
139
140
141
@lazyglobal off.
function run_menu{
parameter
os_data,
window_index,
title,
list_of_names,
return_index. // if true, returns index, otherwise value in list
local current_option is 0.
local len is list_of_names:length().
local process is list(
make_process_system_struct(
os_data,"update_menu",window_index,"Menu"
),
current_option,"ag7","ag8","ag9",list_of_names,title,
return_index
).
return process.
}
function draw_menu_status{
parameter process.
if not has_focus(process){
return 0.
}
local status is get_status_window(get_process_os_data(process)).
local x is status[0].
local y is status[1].
print "AG7 - up" at (x+2,y+1).
print "AG8 - down" at (x+2,y+2).
print "AG9 - select" at (x+2,y+3).
validate_process_status(process).
}
function draw_menu{
parameter process.
if not is_process_gui(process){
return 0.
}
local window is get_process_window(process).
local x is window[0].
local y is window[1].
local list_of_names is process[5].
local len is process[5]:length().
local title is process[6].
local current_option is process[1].
print title at(x+2,y+2).
local i is 0.
until i=len{
print "[ ] "+list_of_names[i] at(x+2,y+i+4).
set i to i+1.
}
//TODO: what if options dont fit on window? "[ ] Next page"
print "*" at(x+3,y+4+current_option).
validate_process_window(process).
}
function update_menu{
parameter process.
// restore state:
local window is 0.
local x is 0.
local y is 0.
if is_process_gui(process){
set window to get_process_window(process).
set x to window[0].
set y to window[1].
}
local current_option is process[1].
local list_of_names is process[5].
local len is list_of_names:length().
local return_index is process[7].
// input:
local old_ag7 is process[2].
set process[2] to ag7.
local changed_ag7 is old_ag7<>process[2].
local old_ag8 is process[3].
set process[3] to ag8.
local changed_ag8 is old_ag8<>process[3].
local old_ag9 is process[4].
set process[4] to ag9.
local changed_ag9 is old_ag9<>process[4].
if old_ag7="ag7" or not has_focus(process){
set changed_ag7 to false.
set changed_ag8 to false.
set changed_ag9 to false.
}
if process_needs_redraw(process){
draw_menu(process).
}
if process_status_needs_redraw(process){
draw_menu_status(process).
}
if changed_ag7{
if is_process_gui(process){
print " " at(x+3,y+4+current_option).
}
set current_option to mod(current_option-1+len,len).
if is_process_gui(process){
print "*" at(x+3,y+4+current_option).
}
}
else if changed_ag8{
if is_process_gui(process){
print " " at(x+3,y+4+current_option).
}
set current_option to mod(current_option+1,len).
if is_process_gui(process){
print "*" at(x+3,y+4+current_option).
}
}
else if changed_ag9{
kill_process(process). // suicide
if return_index{
return current_option.
}
else{
return list_of_names[current_option].
}
}
// save:
set process[1] to current_option.
}