本帖最后由 武安apk43 于 2023-7-16 23:17 编辑
考虑到百科界面的中文人名地名不是按照拼音排序,这个是硬编码不可改变的。有时候要查找相关信息时非常不方便。我借助WSE实现了这个功能:输入关键字可搜索人名、地名,点击搜索结果可跳转菜单继续操作,比如查看人物日志,镜头定位地点等。
秉承无私分享精神,现在分享给modders参考使用,无需许可,只要credit即可。
效果图(搜索“夫人”):
代码:
界面编辑主要涉及容器页面滚动,鼠标选中、鼠标点击、slot巧妙传参等。匹配字符串用到WSE的操作符str_contains。有个被注释掉的显示鼠标坐标的功能是R大的代码。
##Wuan
("search_npcs_and_settlements", 0, mesh_load_window, [
(ti_on_presentation_load,
[
(set_fixed_point_multiplier, 1000),
#Troops
(str_store_string, s0, "@Troops"),
(call_script, "script_gpu_create_text_overlay", "str_s0", 200, 600, 1000, 500, 50, tf_center_justify),
(str_store_string, s0, "str_empty_string"),
(call_script, "script_gpu_create_text_box_overlay", "str_empty_string", 100, 550),
(assign, "$g_presentation_obj_1", reg1),
(str_store_string, s0, "@Search"),
(call_script, "script_gpu_create_game_button_overlay", "str_s0", 400, 550),
(assign, "$g_presentation_obj_2", reg1),
#Settlements
(str_store_string, s0, "@Settlements"),
(call_script, "script_gpu_create_text_overlay", "str_s0", 200, 300, 1000, 500, 50, tf_center_justify),
(str_store_string, s0, "str_empty_string"),
(call_script, "script_gpu_create_text_box_overlay", "str_empty_string", 100, 250),
(assign, "$g_presentation_obj_4", reg1),
(str_store_string, s0, "@Search"),
(call_script, "script_gpu_create_game_button_overlay", "str_s0", 400, 250),
(assign, "$g_presentation_obj_5", reg1),
#Back
(str_store_string, s0, "@Back"),
(call_script, "script_gpu_create_game_button_overlay", "str_s0", 900, 20),
(assign, "$g_presentation_obj_6", reg1),
(str_clear, s0),
# Scrollable area (all the next overlay will be contained in this, s0 sets the scrollbar)
(create_text_overlay, reg1, s0, tf_scrollable_style_2), # Optional: tf_scrollable_style
(position_set_x, pos1, 600),
(position_set_y, pos1, 100),
(overlay_set_position, reg1, pos1),
(position_set_x, pos1, 300),
(position_set_y, pos1, 530),
(overlay_set_area_size, reg1, pos1),
(set_container_overlay, reg1),
# set base position
(assign, ":y_pos", 0),
(try_begin),
(eq, "$display_troops_or_settlements", 1),#Search Troops
(try_for_range_backwards, ":troop_id", original_kingdom_heroes_begin, heroes_end),
(troop_slot_eq, ":troop_id", slot_troop_matched_search, 1),
(str_store_troop_name, s0, ":troop_id"),
(val_add, ":y_pos", 30),
(call_script, "script_gpu_create_text_overlay", "str_s0", 150, ":y_pos", 1000, 250, 50, tf_center_justify),
(troop_set_slot, "trp_temp_array_a", reg1, ":troop_id"), # Use different overlay id as different slots to store the corresponding troop id
(try_end),
(else_try),
(eq, "$display_troops_or_settlements", 2),#Search Settlements
(try_for_range_backwards, ":party_id", centers_begin, centers_end),
(party_slot_eq, ":party_id", slot_party_matched_search, 1),
(str_store_party_name, s0, ":party_id"),
(val_add, ":y_pos", 30),
(call_script, "script_gpu_create_text_overlay", "str_s0", 150, ":y_pos", 1000, 250, 50, tf_center_justify),
(troop_set_slot, "trp_temp_array_a", reg1, ":party_id"), # Use different overlay id as different slots to store the corresponding party id
(try_end),
(try_end),
(set_container_overlay, -1),
# ##CC
# ###### mouse fix pos system #######
# (create_text_overlay, "$g_presentation_obj_39", "@ ", tf_center_justify|tf_vertical_align_center),
# (create_mesh_overlay, "$g_presentation_obj_38", "mesh_white_plane"),
# (position_set_x, pos1, 50),
# (position_set_y, pos1, 37500),
# (overlay_set_size, "$g_presentation_obj_38", pos1),
# (create_mesh_overlay, "$g_presentation_obj_37", "mesh_white_plane"),
# (position_set_x, pos1, 50000),
# (position_set_y, pos1, 50),
# (overlay_set_size, "$g_presentation_obj_37", pos1),
# ###### mouse fix pos system #######
# ##CC
(presentation_set_duration, 999999),
]),
(ti_on_presentation_event_state_change,
[
(store_trigger_param_1, ":object"),
(try_begin),
(eq, ":object", "$g_presentation_obj_1"),
(call_script, "script_cf_remove_space_characters_begin_end"), # Remove space characters at the beginning and end of the string, store in s7
(else_try),
(eq, ":object", "$g_presentation_obj_2"),
(neg|str_is_empty, s7),
(assign, ":num_matched", 0),
(try_for_range, ":troop_id", original_kingdom_heroes_begin, heroes_end),
(str_store_troop_name, s10, ":troop_id"),
(try_begin),
(str_contains, s10, s7), ## WSE
(val_add, ":num_matched", 1),
(troop_set_slot, ":troop_id", slot_troop_matched_search, 1),
(else_try),
(troop_set_slot, ":troop_id", slot_troop_matched_search, 0),
(try_end),
(try_end),
(try_begin),
(eq, ":num_matched", 0),
(display_message, "@No Matched Troops!"),
(else_try),
(assign, "$display_troops_or_settlements", 1),
(start_presentation, "prsnt_search_npcs_and_settlements"),
(try_end),
(else_try),
(eq, ":object", "$g_presentation_obj_4"),
(call_script, "script_cf_remove_space_characters_begin_end"),# Remove space characters at the beginning and end of the string, store in s7
(else_try),
(eq, ":object", "$g_presentation_obj_5"),
(neg|str_is_empty, s7),
(assign, ":num_matched", 0),
(try_for_range, ":party_id", centers_begin, centers_end),
(str_store_party_name, s10, ":party_id"),
(try_begin),
(str_contains, s10, s7), ## WSE
(val_add, ":num_matched", 1),
(party_set_slot, ":party_id", slot_party_matched_search, 1),
(else_try),
(party_set_slot, ":party_id", slot_party_matched_search, 0),
(try_end),
(try_end),
(try_begin),
(eq, ":num_matched", 0),
(display_message, "@No Matched Settlements!"),
(else_try),
(assign, "$display_troops_or_settlements", 2),
(start_presentation, "prsnt_search_npcs_and_settlements"),
(try_end),
(else_try),
(eq, ":object", "$g_presentation_obj_6"),
(assign, "$display_troops_or_settlements", 0),
(presentation_set_duration, 0),
(jump_to_menu, "mnu_reports"),
(try_end),
]),
(ti_on_presentation_mouse_press,
[
(store_trigger_param_1, ":object"),
(store_trigger_param_2, ":mouse_state"),
(try_begin),
(ge, ":object", 8),
(eq, ":mouse_state", 0),
(try_begin),
(neq, "$display_troops_or_settlements", 0),
(troop_set_slot, "trp_temp_troop", slot_selected_object, ":object"), # Store the current overlay id to the slot to pass the parameter to the menu
(presentation_set_duration, 0),
(try_begin),
(eq, "$display_troops_or_settlements", 1), # Searched Troops
(jump_to_menu, "mnu_change_screen_to_troop_notes"),
(else_try),
(eq, "$display_troops_or_settlements", 2), # Searched Settlements
(jump_to_menu, "mnu_display_settlement_on_the_map"),
(try_end),
(try_end),
(try_end),
]),
(ti_on_presentation_mouse_enter_leave,
[
(store_trigger_param_1, ":object"),
(store_trigger_param_2, ":enter_leave"),
(ge, ":object", 8),
(try_begin),
(eq, ":enter_leave", 0),
(overlay_set_color, ":object", 0xFF00FF00), # Green
(else_try),
(eq, ":enter_leave", 1),
(overlay_set_color, ":object", gpu_black),
(try_end),
]),
# ##CC
# (ti_on_presentation_run,
# [
# ###### mouse fix pos system #######
# (mouse_get_position, pos1),
# (position_get_x, reg50, pos1),
# (position_get_y, reg51, pos1),
# (position_set_x, pos1, reg50),
# (position_set_y, pos1, 0),
# (overlay_set_position, "$g_presentation_obj_38", pos1),
# (position_set_x, pos1, 0),
# (position_set_y, pos1, reg51),
# (overlay_set_position, "$g_presentation_obj_37", pos1),
# (try_begin),
# (le, reg50, 500),
# (assign, ":x_offset", 70),
# (else_try),
# (assign, ":x_offset", -70),
# (try_end),
# (try_begin),
# (le, reg51, 375),
# (assign, ":y_offset", 20),
# (else_try),
# (assign, ":y_offset", -20),
# (try_end),
# (store_add, ":pos_x", reg50, ":x_offset"),
# (store_add, ":pos_y", reg51, ":y_offset"),
# (position_set_x, pos1, ":pos_x"),
# (position_set_y, pos1, ":pos_y"),
# (overlay_set_position, "$g_presentation_obj_39", pos1),
# (overlay_set_text, "$g_presentation_obj_39", "@({reg50},{reg51})"),
# ###### mouse fix pos system #######
# ]),
# ##CC
]),
##Wuan
|
由于中文一些问题,需要对输入字符串的前后空格去除处理。主要涉及WSE的一些操作符str_length,str_starts_with,str_ends_with,str_store_substring 等。
##Wuan
##script_cf_remove_space_characters_begin_end
#input: s0, output: s7
("cf_remove_space_characters_begin_end",
[
# Remove space characters at the beginning and end of the string
(str_store_string, s7, s0),
(str_store_string, s1, "str_empty_string"), # Space string
(neg|str_is_empty, s7),
(str_length, ":str_length", s7), ## WSE
(val_add, ":str_length", 1), # "try_for_range" does not include the upper limit value of the range
(try_for_range, ":r", 0, ":str_length"), # Traverse each character of the string from index 0 to str_length
(try_begin),
(neg|str_is_empty, s7),
(str_length, ":str_length", s7), ## WSE # Retrieve the string length as it may have changed
(gt, ":str_length", 1), # More than one character
(try_begin),
(str_starts_with, s7, s1), ## WSE # Start with space
(str_store_substring, s7, s7, 1), ## WSE # Store a substring starting from index 1 to the end in its own string register
(else_try),
(str_ends_with, s7, s1), ## WSE # End with space
(val_sub, ":str_length", 1),# Remove space character
(str_store_substring, s7, s7, 0, ":str_length"), #WSE # Store a substring of length "str_length" starting from index 0 in its own string register
(try_end),
(else_try),
(break_loop), ## WSE
(try_end),
(try_end),
]),
##Wuan
用到的银色雄鹿mod的部分scripts:
##Windyplains
# script_gpu_create_text_overlay
("gpu_create_text_overlay",
[
(store_script_param, ":string", 1),
(store_script_param, ":pos_x", 2),
(store_script_param, ":pos_y", 3),
(store_script_param, ":text_size", 4),
(store_script_param, ":size_x", 5),
(store_script_param, ":size_y", 6),
(store_script_param, ":flags", 7),
(set_fixed_point_multiplier, 1000),
(create_text_overlay, reg1, ":string", ":flags"),
(position_set_x, pos1, ":pos_x"),
(position_set_y, pos1, ":pos_y"),
(overlay_set_position, reg1, pos1),
(position_set_x, pos1, ":text_size"),
(position_set_y, pos1, ":text_size"),
(overlay_set_size, reg1, pos1),
(position_set_x, pos1, ":size_x"),
(position_set_y, pos1, ":size_y"),
(overlay_set_area_size, reg1, pos1),
(overlay_set_text, reg1, ":string"),
#(assign, reg0, ":pos_y"),
#(display_message, "@{s0}: {reg0}"),
]),
# script_gpu_create_text_box_overlay
("gpu_create_text_box_overlay",
[
(store_script_param, ":string", 1),
(store_script_param, ":pos_x", 2),
(store_script_param, ":pos_y", 3),
(set_fixed_point_multiplier, 1000),
(create_simple_text_box_overlay, reg1, ":string"),
(position_set_x, pos1, ":pos_x"),
(position_set_y, pos1, ":pos_y"),
(overlay_set_position, reg1, pos1),
(overlay_set_text, reg1, ":string"),
]),
# script_gpu_create_game_button_overlay
("gpu_create_game_button_overlay",
[
(store_script_param, ":string", 1),
(store_script_param, ":pos_x", 2),
(store_script_param, ":pos_y", 3),
(set_fixed_point_multiplier, 1000),
(create_game_button_overlay, reg1, ":string"),
(position_set_x, pos1, ":pos_x"),
(position_set_y, pos1, ":pos_y"),
(overlay_set_position, reg1, pos1),
(overlay_set_text, reg1, ":string"),
]),
##Windyplains
|
下面这个子菜单加到喜欢的地方即可,比如报告菜单里
##wuan
("action_search_npcs_and_settlements",[],"Search npcs and settlements.",
[
(assign, "$display_troops_or_settlements", 0),
(start_presentation, "prsnt_search_npcs_and_settlements"),
]
),
##wuan
跳转菜单。实际定位到人物、地点后可更多操作,比如改人名地名等。
##Wuan
(
"change_screen_to_troop_notes",mnf_disable_all_keys,
"Change screen to troop notes",
"none",
[ (troop_get_slot, ":object_slot", "trp_temp_troop", slot_selected_object), # Get current overlay id as slot
(troop_get_slot, reg0, "trp_temp_array_a", ":object_slot"), # To get the troop id
(str_store_troop_name, s0, reg0),],
[
("change_screen_to_troop_notes",
[],
"Check the note of {s0}.",
[
(change_screen_notes, 1, reg0),
]),
("return",[],"Return.",
[
(start_presentation, "prsnt_search_npcs_and_settlements"),
]),
]
),
(
"display_settlement_on_the_map",mnf_disable_all_keys,
"Display the settlement on the map",
"none",
[ (troop_get_slot, ":object_slot", "trp_temp_troop", slot_selected_object), # Get current overlay id as slot
(troop_get_slot, reg0, "trp_temp_array_a", ":object_slot"), # To get the party id
(str_store_party_name, s0, reg0),],
[
("display_on_the_map",
[
],
"Display {s0} on the map.",
[
(change_screen_map),
(set_camera_follow_party, reg0),
]),
("return",[],"Return.",
[
(start_presentation, "prsnt_search_npcs_and_settlements"),
]),
]
),
##Wuan
|
涉及到一些slot就自行添加并设置合适的数值了
|