複雑な動きのVSの7セグメントをpng画像で再現。
ポイントは50行目から56行目までのdatarefの数値を取り出す作業。桁ごとに数値を取得して表示する。
複雑な動きのVSの7セグメントをpng画像で再現。 -- 画像県警の初期設定 ---- -- E_Camera Move ---- local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png") local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png") local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png") local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png") local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png") local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png") local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png") local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png") local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png") local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png") local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png") local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png") local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png") local image_7seg_space = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_space.png") local VS_7seg_number_A = { " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" } --11 local VS_7seg_image_A = { image_7seg_space, image_7seg_space, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5, image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 } local VS_7seg_number_B = { "1", "2", "3", "4", "5", "6", "7", "8", "9" } --9 local VS_7seg_image_B = { image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5, image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 } local VS_7seg_number_C = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" } --10 local VS_7seg_image_C = { image_7seg_0, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5, image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 } local VS_7seg_number_D = { "-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" } -- 11 local VS_7seg_image_D = { image_7seg_space, image_7seg_0, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5, image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 } DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot") DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach") DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial") DataRef("mcp_ALT_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial") DataRef("ap_VVI_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos") --------------------------------------------------------------------------------- view_selector_wnd = float_wnd_create(300, 250, 1, true) float_wnd_set_position(view_selector_wnd, 300, 100) float_wnd_set_title(view_selector_wnd, "7segment Test") float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd") float_wnd_set_onclose(view_selector_wnd, "on_close") --------------------------------------------------------------------------------- function view_selector_build_wnd(view_selector_wnd, x, y) --ALTITUDE 7セグメント表示 VVI_pos_7seg = string.format("%05d", ap_VVI_pos_7segment) --マイナスが5桁になるので "%05d" になる --桁毎に数値を取り出す --上で変換した数字を取り指す作業、最初の「1,1」と最後の「6,6」もマイナス等が関係しているが実際は使わないので削除している。 ap_VVI_pos_4_digit = string.sub(VVI_pos_7seg, 2, 2) --4 ap_VVI_pos_3_digit = string.sub(VVI_pos_7seg, 3, 3) --3 ap_VVI_pos_2_digit = string.sub(VVI_pos_7seg, 4, 4) --2 ap_VVI_pos_1_digit = string.sub(VVI_pos_7seg, 5, 5) --1 --データがどのようになっているかを見るために表示している。"ap_VVI_pos_1_digit :"と合わせると良い。 imgui.TextUnformatted("ap_VVI_pos_4_digit : " .. ap_VVI_pos_4_digit) --4 imgui.TextUnformatted("ap_VVI_pos_3_digit : " .. ap_VVI_pos_3_digit) --3 imgui.TextUnformatted("ap_VVI_pos_2_digit : " .. ap_VVI_pos_2_digit) --2 imgui.TextUnformatted("ap_VVI_pos_1_digit : " .. ap_VVI_pos_1_digit) --1桁目を表示 imgui.TextUnformatted("dataref : " .. ap_VVI_pos_7segment) --datare値を表示 --プラスとマイナスの記号を表示するたものもの imgui.SetCursorPosX(130) imgui.SetCursorPosY(120) if ap_VVI_pos_7segment > 0 then imgui.Image(image_7seg_plus, 17, 29) end if ap_VVI_pos_7segment < 0 then imgui.Image(image_7seg_minus, 17, 29) end imgui.SetCursorPosX(155) --3桁 imgui.SetCursorPosY(120) if ap_VVI_pos_4_digit == "0" then --一応0を入れているがこれは実際は使わないはずである。 imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_4_digit == "1" then imgui.Image(image_7seg_1, 17, 29) elseif ap_VVI_pos_4_digit == "2" then imgui.Image(image_7seg_2, 17, 29) elseif ap_VVI_pos_4_digit == "3" then imgui.Image(image_7seg_3, 17, 29) elseif ap_VVI_pos_4_digit == "4" then imgui.Image(image_7seg_4, 17, 29) elseif ap_VVI_pos_4_digit == "5" then imgui.Image(image_7seg_5, 17, 29) elseif ap_VVI_pos_4_digit == "6" then imgui.Image(image_7seg_6, 17, 29) elseif ap_VVI_pos_4_digit == "7" then imgui.Image(image_7seg_7, 17, 29) elseif ap_VVI_pos_4_digit == "8" then imgui.Image(image_7seg_8, 17, 29) elseif ap_VVI_pos_4_digit == "9" then imgui.Image(image_7seg_9, 17, 29) end imgui.SameLine() if ap_VVI_pos_7segment == 50 or ap_VVI_pos_7segment == -50 or ap_VVI_pos_7segment == 0000 then imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_3_digit == "0" then imgui.Image(image_7seg_0, 17, 29) elseif ap_VVI_pos_3_digit == "1" then imgui.Image(image_7seg_1, 17, 29) elseif ap_VVI_pos_3_digit == "2" then imgui.Image(image_7seg_2, 17, 29) elseif ap_VVI_pos_3_digit == "3" then imgui.Image(image_7seg_3, 17, 29) elseif ap_VVI_pos_3_digit == "4" then imgui.Image(image_7seg_4, 17, 29) elseif ap_VVI_pos_3_digit == "5" then imgui.Image(image_7seg_5, 17, 29) elseif ap_VVI_pos_3_digit == "6" then imgui.Image(image_7seg_6, 17, 29) elseif ap_VVI_pos_3_digit == "7" then imgui.Image(image_7seg_7, 17, 29) elseif ap_VVI_pos_3_digit == "8" then imgui.Image(image_7seg_8, 17, 29) elseif ap_VVI_pos_3_digit == "9" then imgui.Image(image_7seg_9, 17, 29) end imgui.SameLine() if ap_VVI_pos_7segment == 0000 then imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_2_digit == "0" then imgui.Image(image_7seg_0, 17, 29) elseif ap_VVI_pos_2_digit == "1" then imgui.Image(image_7seg_1, 17, 29) elseif ap_VVI_pos_2_digit == "2" then imgui.Image(image_7seg_2, 17, 29) elseif ap_VVI_pos_2_digit == "3" then imgui.Image(image_7seg_3, 17, 29) elseif ap_VVI_pos_2_digit == "4" then imgui.Image(image_7seg_4, 17, 29) elseif ap_VVI_pos_2_digit == "5" then imgui.Image(image_7seg_5, 17, 29) elseif ap_VVI_pos_2_digit == "6" then imgui.Image(image_7seg_6, 17, 29) elseif ap_VVI_pos_2_digit == "7" then imgui.Image(image_7seg_7, 17, 29) elseif ap_VVI_pos_2_digit == "8" then imgui.Image(image_7seg_8, 17, 29) elseif ap_VVI_pos_2_digit == "9" then imgui.Image(image_7seg_9, 17, 29) end imgui.SameLine() if ap_VVI_pos_7segment == 0000 then imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_1_digit == "0" then imgui.Image(image_7seg_0, 17, 29) elseif ap_VVI_pos_1_digit == "1" then imgui.Image(image_7seg_1, 17, 29) elseif ap_VVI_pos_1_digit == "2" then imgui.Image(image_7seg_2, 17, 29) elseif ap_VVI_pos_1_digit == "3" then imgui.Image(image_7seg_3, 17, 29) elseif ap_VVI_pos_1_digit == "4" then imgui.Image(image_7seg_4, 17, 29) elseif ap_VVI_pos_1_digit == "5" then imgui.Image(image_7seg_5, 17, 29) elseif ap_VVI_pos_1_digit == "6" then imgui.Image(image_7seg_6, 17, 29) elseif ap_VVI_pos_1_digit == "7" then imgui.Image(image_7seg_7, 17, 29) elseif ap_VVI_pos_1_digit == "8" then imgui.Image(image_7seg_8, 17, 29) elseif ap_VVI_pos_1_digit == "9" then imgui.Image(image_7seg_9, 17, 29) end end function on_close(view_selector_wnd) end
for文でまとめたもの
-- 画像県警の初期設定 ---- -- E_Camera Move ---- local image_7seg_0 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_0.png") local image_7seg_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_1.png") local image_7seg_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_2.png") local image_7seg_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_3.png") local image_7seg_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_4.png") local image_7seg_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_5.png") local image_7seg_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_6.png") local image_7seg_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_7.png") local image_7seg_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_8.png") local image_7seg_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_9.png") local image_7seg_point = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_point.png") local image_7seg_plus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_plus.png") local image_7seg_minus = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_minus.png") local image_7seg_space = float_wnd_load_image(SCRIPT_DIRECTORY .. "/img/7seg_w_space.png") local VS_7seg_number_pattern_A = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" } --10 local VS_7seg_image_pattern_A = { image_7seg_space, image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5, image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 } local VS_7seg_number_pattern_B = { "1", "2", "3", "4", "5", "6", "7", "8", "9" } --9 local VS_7seg_image_pattern_B = { image_7seg_1, image_7seg_2, image_7seg_3, image_7seg_4, image_7seg_5, image_7seg_6, image_7seg_7, image_7seg_8, image_7seg_9 } DataRef("COURSE_7segment", "laminar/B738/autopilot/course_pilot") DataRef("IAS_MACH_7segment", "laminar/B738/autopilot/mcp_speed_dial_kts_mach") DataRef("mcp_hdg_dial_7segment", "laminar/B738/autopilot/mcp_hdg_dial") DataRef("mcp_ALT_dial_7segment", "laminar/B738/autopilot/mcp_alt_dial") DataRef("ap_VVI_pos_7segment", "laminar/B738/autopilot/ap_vvi_pos") --------------------------------------------------------------------------------- view_selector_wnd = float_wnd_create(300, 250, 1, true) float_wnd_set_position(view_selector_wnd, 300, 100) float_wnd_set_title(view_selector_wnd, "7segment Test") float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd") float_wnd_set_onclose(view_selector_wnd, "on_close") --------------------------------------------------------------------------------- function view_selector_build_wnd(view_selector_wnd, x, y) --ALTITUDE 7セグメント表示 VVI_pos_7seg = string.format("%05d", ap_VVI_pos_7segment) --マイナスが5桁になるので "%05d" になる --桁毎に数値を取り出す --上で変換した数字を取り指す作業、最初の「1,1」と最後の「6,6」もマイナス等が関係しているが実際は使わないので削除している。 ap_VVI_pos_4_digit = string.sub(VVI_pos_7seg, 2, 2) --4 ap_VVI_pos_3_digit = string.sub(VVI_pos_7seg, 3, 3) --3 ap_VVI_pos_2_digit = string.sub(VVI_pos_7seg, 4, 4) --2 ap_VVI_pos_1_digit = string.sub(VVI_pos_7seg, 5, 5) --1 --データがどのようになっているかを見るために表示している。"ap_VVI_pos_1_digit :"と合わせると良い。 imgui.TextUnformatted("ap_VVI_pos_4_digit : " .. ap_VVI_pos_4_digit) --4 imgui.TextUnformatted("ap_VVI_pos_3_digit : " .. ap_VVI_pos_3_digit) --3 imgui.TextUnformatted("ap_VVI_pos_2_digit : " .. ap_VVI_pos_2_digit) --2 imgui.TextUnformatted("ap_VVI_pos_1_digit : " .. ap_VVI_pos_1_digit) --1桁目を表示 imgui.TextUnformatted("dataref : " .. ap_VVI_pos_7segment) --datare値を表示 --プラスとマイナスの記号を表示するたものもの imgui.SetCursorPosX(130) imgui.SetCursorPosY(120) if ap_VVI_pos_7segment > 0 then imgui.Image(image_7seg_plus, 17, 29) end if ap_VVI_pos_7segment < 0 then imgui.Image(image_7seg_minus, 17, 29) end imgui.SetCursorPosX(155) --4桁以降のポジション imgui.SetCursorPosY(120) for i = 1, 10 do if ap_VVI_pos_4_digit == VS_7seg_number_pattern_A[i] then --一応0を入れているがこれは実際は使わないはずである。 imgui.Image(VS_7seg_image_pattern_A[i], 17, 29) end end imgui.SameLine() --ここで50と-50と1000になったとき頭に0が付くので空白にするためのもの if ap_VVI_pos_7segment == 50 or ap_VVI_pos_7segment == -50 or ap_VVI_pos_7segment == 0000 then imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_3_digit == "0" then --上以外の場合は空白ではなく"0"にする。 imgui.Image(image_7seg_0, 17, 29) end for i = 1, 9 do if ap_VVI_pos_3_digit == VS_7seg_number_pattern_B[i] then imgui.Image(VS_7seg_image_pattern_B[i], 17, 29) end end imgui.SameLine() --ここで0000になったとき「2桁目」の数字を何も表示しないようにするためのもの if ap_VVI_pos_7segment == 0000 then imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_2_digit == "0" then --上以外の場合は空白ではなく"0"にする。 imgui.Image(image_7seg_0, 17, 29) end for i = 1, 9 do if ap_VVI_pos_2_digit == VS_7seg_number_pattern_B[i] then imgui.Image(VS_7seg_image_pattern_B[i], 17, 29) end end imgui.SameLine() --ここで0000になったとき「1桁目」の数字を何も表示しないようにするためのもの if ap_VVI_pos_7segment == 0000 then imgui.Image(image_7seg_space, 17, 29) elseif ap_VVI_pos_1_digit == "0" then --上以外の場合は空白ではなく"0"にする。 imgui.Image(image_7seg_0, 17, 29) end for i = 1, 9 do if ap_VVI_pos_1_digit == VS_7seg_number_pattern_B[i] then imgui.Image(VS_7seg_image_pattern_B[i], 17, 29) end end end function on_close(view_selector_wnd) end