Add AVA2-style display options (effect level, trees, clouds)

Client-only port of ENABLE_GRAPHIC_ON_OFF / HIDE_OBJECTS: five effect
levels toggle attached actor effects via Active/Deactive, tree and cloud
parts use background.SetVisiblePart, plus shortcuts for the original
name and damage options. mt_display window, mt_display.cfg, port.display
test, docs/AVA2-DISPLAY.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-15 21:11:25 +09:00
co-authored by Claude Opus 5.5
parent e22d7ba6fd
commit e546f91e03
15 changed files with 376 additions and 0 deletions
+141
View File
@@ -0,0 +1,141 @@
// PORT: AVA2-style display options (ENABLE_GRAPHIC_ON_OFF effect level, HIDE_OBJECTS tree/cloud parts),
// client-only. The effect level is systemSetting.SetEffectLevel (CInstanceBase::__UpdateEffectShown deactivates
// attached effects); trees and clouds use the original background.SetVisiblePart; names and damage numbers
// are shortcuts to the original game options. See docs/AVA2-DISPLAY.md.
static const char c_szDisplayScript[] = R"PY(# -*- coding: utf-8 -*-
import background
import game
import grp
import systemSetting
import ui
import weakref
from mt_biolog import Action, Text, L
from mt_wiki import B
g_window=None
g_entry=None
CONFIG='mt_display.cfg'
LEVELS=(u'全部特效',u'只看怪物特效',u'只看玩家特效',u'只看自己特效',u'关闭全部特效')
LEVEL_HINTS=('显示所有角色的特效','隐藏其他玩家和NPC的特效,保留自己和怪物的','隐藏怪物和NPC的特效,保留玩家的',
'只保留自己的特效','连自己的特效也隐藏')
class Options(object):
def __init__(self):self.effect=0;self.tree=True;self.cloud=True
def Load(self,text):
words=text.split()
if len(words)!=3 or not all(w.isdigit() and len(w)==1 for w in words):return
effect,tree,cloud=[int(w) for w in words]
if effect<len(LEVELS) and tree in (0,1) and cloud in (0,1):self.effect=effect;self.tree=tree==1;self.cloud=cloud==1
def Dump(self):return '%d %d %d'%(self.effect,int(self.tree),int(self.cloud))
def Apply(self):
systemSetting.SetEffectLevel(self.effect)
background.SetVisiblePart(background.PART_TREE,int(self.tree))
background.SetVisiblePart(background.PART_CLOUD,int(self.cloud))
def LoadConfig(options):
try:
f=open(CONFIG,'r');text=f.read();f.close();options.Load(text)
except (IOError,OSError):pass
def SaveConfig(options):
try:
f=open(CONFIG,'w');f.write(options.Dump());f.close()
except (IOError,OSError):pass
def Mark(text,on):return L(B(u'【%s】'%text if on else text))
class DisplayWindow(ui.Window):
def __init__(self,options):
ui.Window.__init__(self);self.SetWindowName('DisplayWindow');self.AddFlag('float');self.AddFlag('movable')
self.options=options;self.SetSize(332,404)
self.heading=Text(self,18,18,'显示设置',0xffffd68b)
self.closeButton=Action(self,256,6,60,'关闭',self.Hide)
self.effectText=Text(self,18,54,'特效',0xffc3b7a1)
self.levelButtons=[Action(self,18+(i%2)*152,76+(i//2)*52,144,'',lambda level=i:self.SetLevel(level)) for i in range(len(LEVELS))]
self.sceneText=Text(self,18,238,'场景和文字',0xffc3b7a1)
self.treeButton=Action(self,18,260,144,'',self.ToggleTree)
self.cloudButton=Action(self,170,260,144,'',self.ToggleCloud)
self.nameButton=Action(self,18,312,144,'',self.ToggleName)
self.damageButton=Action(self,170,312,144,'',self.ToggleDamage)
self.status=Text(self,18,376,'',0xffc3b7a1)
self.Refresh();self.Hide()
def Buttons(self):return [self.closeButton,self.treeButton,self.cloudButton,self.nameButton,self.damageButton]+self.levelButtons
def Open(self):self.Refresh();self.SetCenterPosition();self.Show();self.SetTop()
def Changed(self):self.options.Apply();SaveConfig(self.options);self.Refresh()
def SetLevel(self,level):self.options.effect=level;self.Changed()
def ToggleTree(self):self.options.tree=not self.options.tree;self.Changed()
def ToggleCloud(self):self.options.cloud=not self.options.cloud;self.Changed()
# Names and damage numbers are the original game options (saved by the client config on exit).
def ToggleName(self):systemSetting.SetAlwaysShowNameFlag(not systemSetting.IsAlwaysShowName());self.Refresh()
def ToggleDamage(self):systemSetting.SetShowDamageFlag(not systemSetting.IsShowDamage());self.Refresh()
def Refresh(self):
o=self.options
for i,button in enumerate(self.levelButtons):button.SetText(Mark(LEVELS[i],i==o.effect))
self.treeButton.SetText(Mark(u'显示树木',o.tree));self.cloudButton.SetText(Mark(u'显示云',o.cloud))
self.nameButton.SetText(Mark(u'总是显示名字',systemSetting.IsAlwaysShowName()))
self.damageButton.SetText(Mark(u'显示伤害数字',systemSetting.IsShowDamage()))
self.status.SetText(L(LEVEL_HINTS[o.effect]))
def OnRender(self):
x,y=self.GetGlobalPosition();grp.SetColor(0xf51b1916);grp.RenderBar(x,y,self.GetWidth(),self.GetHeight());grp.SetColor(0xff9b7b48);grp.RenderBox(x,y,self.GetWidth(),self.GetHeight())
def OnPressEscapeKey(self):self.Hide();return True
def Destroy(self):
self.Hide()
for b in self.Buttons():b.event=None
class Entry(Action):
def __init__(self,window):
Action.__init__(self,None,0,0,64,'显示',Toggle)
self.minimap=weakref.proxy(window.interface.wndMiniMap);self.SetWindowName('DisplayEntry');self.OnUpdate()
def OnUpdate(self):
x,y=self.minimap.GetGlobalPosition();self.SetPosition(max(4,x-68),y+252)
g_options=Options()
LoadConfig(g_options)
systemSetting.SetEffectLevel(g_options.effect)
def Toggle():
if g_window:
if g_window.IsShow():g_window.Hide()
else:g_window.Open()
_open=game.GameWindow.Open
_close=game.GameWindow.Close
def Open(self):
global g_window,g_entry
_open(self);g_options.Apply();g_window=DisplayWindow(g_options);g_entry=Entry(self)
def Close(self):
global g_window,g_entry
if g_entry:g_entry.Hide();g_entry.event=None;g_entry=None
if g_window:g_window.Destroy();g_window=None
_close(self)
game.GameWindow.Open=Open
game.GameWindow.Close=Close
)PY";
+2
View File
@@ -1001,6 +1001,7 @@ namespace PythonBoot
#include "WikiEntryScript.inc"
#include "SwitchbotScript.inc"
#include "PickupScript.inc"
#include "DisplayScript.inc"
static void install_script_module(const char* c_szModule, const char* c_szScript)
{
@@ -1076,6 +1077,7 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
install_script_module("mt_wiki_entries", c_szWikiEntryScript);
install_script_module("mt_switchbot", c_szSwitchbotScript);
install_script_module("mt_pickup", c_szPickupScript);
install_script_module("mt_display", c_szDisplayScript);
if (g_touch_input)
install_script_module("mt_mobile_hud", c_szMobileHUDScript);
}
+2
View File
@@ -320,6 +320,8 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
COMMAND ${MT_WIKI_PYTHON3} ${PROJECT_SOURCE_DIR}/tests/wiki/test_switchbot.py)
add_test(NAME port.pickup
COMMAND ${MT_WIKI_PYTHON3} ${PROJECT_SOURCE_DIR}/tests/wiki/test_pickup.py)
add_test(NAME port.display
COMMAND ${MT_WIKI_PYTHON3} ${PROJECT_SOURCE_DIR}/tests/wiki/test_display.py)
endif()
# Offline locale data builder: retains 40250 proto layout and gameplay fields.
add_executable(locale_proto_patch ${PROJECT_SOURCE_DIR}/tests/port/locale_proto_patch.cpp)
+11
View File
@@ -252,6 +252,17 @@ void CEffectManager::DeactiveEffectInstance(DWORD dwInstanceIndex)
pEffectInstance->SetDeactive();
}
// PORT: AVA2 ENABLE_GRAPHIC_ON_OFF (display options effect level).
void CEffectManager::ActiveEffectInstance(DWORD dwInstanceIndex)
{
TEffectInstanceMap::iterator itor = m_kEftInstMap.find(dwInstanceIndex);
if (itor == m_kEftInstMap.end())
return;
itor->second->SetActive();
}
void CEffectManager::CreateUnsafeEffectInstance(DWORD dwEffectDataID, CEffectInstance ** ppEffectInstance)
{
CEffectData * pEffect;
+1
View File
@@ -47,6 +47,7 @@ class CEffectManager : public CScreen, public CSingleton<CEffectManager>
BOOL SelectEffectInstance(DWORD dwInstanceIndex);
bool DestroyEffectInstance(DWORD dwInstanceIndex);
void DeactiveEffectInstance(DWORD dwInstanceIndex);
void ActiveEffectInstance(DWORD dwInstanceIndex); // PORT: AVA2 ENABLE_GRAPHIC_ON_OFF
void SetEffectTextures(DWORD dwID, std::vector<std::string> textures);
void SetEffectInstancePosition(const D3DXVECTOR3 & c_rv3Position);
+4
View File
@@ -496,6 +496,9 @@ class CActorInstance : public IActorInstance, public IFlyTargetableObject
float GetHeight();
void ShowAllAttachingEffect();
void HideAllAttachingEffect();
// PORT: AVA2 ENABLE_GRAPHIC_ON_OFF. Deactivates (not hides) attached effects, so it does not fight
// the assassin invisibility Show/Hide; effects attached while off start deactivated.
void SetAttachingEffectShown(bool bShown);
void ClearAttachingEffect();
// Fishing
@@ -793,6 +796,7 @@ class CActorInstance : public IActorInstance, public IFlyTargetableObject
// Attached Effect
std::list<TAttachingEffect> m_AttachingEffectList;
bool m_bEffectInitialized;
bool m_bAttachingEffectShown = true;
// material color
DWORD m_dwMtrlColor;
+20
View File
@@ -294,6 +294,8 @@ DWORD CActorInstance::AttachEffectByID(DWORD dwParentPartIndex, const char * c_p
ae.iBoneIndex = -1;
}
if (!m_bAttachingEffectShown)
rkEftMgr.DeactiveEffectInstance(ae.dwEffectIndex);
m_AttachingEffectList.push_back(ae);
return ae.dwEffectIndex;
@@ -472,6 +474,8 @@ void CActorInstance::RefreshActorInstance()
ae.iBoneIndex = iBoneIndex;
if (!m_bAttachingEffectShown)
CEffectManager::Instance().DeactiveEffectInstance(ae.dwEffectIndex);
m_AttachingEffectList.push_back(ae);
}
break;
@@ -593,6 +597,22 @@ void CActorInstance::HideAllAttachingEffect()
}
}
void CActorInstance::SetAttachingEffectShown(bool bShown)
{
if (m_bAttachingEffectShown == bShown)
return;
m_bAttachingEffectShown = bShown;
CEffectManager& rkEftMgr = CEffectManager::Instance();
for (const TAttachingEffect& ae : m_AttachingEffectList)
{
if (bShown)
rkEftMgr.ActiveEffectInstance(ae.dwEffectIndex);
else
rkEftMgr.DeactiveEffectInstance(ae.dwEffectIndex);
}
}
void CActorInstance::__ClearAttachingEffect()
{
m_bEffectInitialized = false;
+21
View File
@@ -4,6 +4,7 @@
#include "PythonNonPlayer.h"
#include "PythonPlayer.h"
#include "PythonCharacterManager.h"
#include "PythonSystem.h"
#include "AbstractPlayer.h"
#include "AbstractApplication.h"
#include "Packet.h"
@@ -1868,6 +1869,7 @@ void CInstanceBase::Update()
{
++ms_dwUpdateCounter;
__UpdateEffectShown();
StateProcess();
m_GraphicThingInstance.PhysicsProcess();
m_GraphicThingInstance.RotationProcess();
@@ -2454,6 +2456,25 @@ bool CInstanceBase::__IsInViewFrustum()
return m_GraphicThingInstance.isShow();
}
// PORT: AVA2 ENABLE_GRAPHIC_ON_OFF effect level, applied to attached effects (skills, buffs, refine glow).
void CInstanceBase::__UpdateEffectShown()
{
const int iLevel = CPythonSystem::Instance().GetEffectLevel();
bool isShown = true;
if (iLevel == 4)
isShown = false;
else if (iLevel != 0 && !__IsMainInstance())
{
if (iLevel == 1)
isShown = IsEnemy() || IsStone();
else if (iLevel == 2)
isShown = IsPC();
else
isShown = false;
}
m_GraphicThingInstance.SetAttachingEffectShown(isShown);
}
bool CInstanceBase::__CanRender()
{
if (!__IsInViewFrustum())
+1
View File
@@ -407,6 +407,7 @@ class CInstanceBase
protected:
bool __IsExistMainInstance();
bool __IsMainInstance();
void __UpdateEffectShown();
bool __MainCanSeeHiddenThing();
float __GetBowRange();
+4
View File
@@ -110,6 +110,9 @@ class CPythonSystem : public CSingleton<CPythonSystem>
bool IsAlwaysShowName();
bool IsShowDamage();
bool IsShowSalesText();
// PORT: AVA2 effect_level (0 all, 1 hide players/NPCs, 2 hide monsters/NPCs, 3 hide others, 4 hide all).
int GetEffectLevel() { return m_iPortEffectLevel; }
void SetEffectLevel(int iLevel) { m_iPortEffectLevel = iLevel < 0 || iLevel > 4 ? 0 : iLevel; }
bool IsUseDefaultIME();
bool IsNoSoundCard();
bool IsAutoTiling();
@@ -159,4 +162,5 @@ class CPythonSystem : public CSingleton<CPythonSystem>
bool m_isInterfaceConfig;
PyObject * m_poInterfaceHandler;
TWindowStatus m_WindowStatus[WINDOW_MAX_NUM];
int m_iPortEffectLevel = 0;
};
@@ -211,6 +211,22 @@ PyObject * systemSetShowSalesTextFlag(PyObject * poSelf, PyObject * poArgs)
return Py_BuildNone();
}
PyObject * systemSetEffectLevel(PyObject * poSelf, PyObject * poArgs)
{
int iLevel;
if (!PyTuple_GetInteger(poArgs, 0, &iLevel))
return Py_BuildException();
CPythonSystem::Instance().SetEffectLevel(iLevel);
return Py_BuildNone();
}
PyObject * systemGetEffectLevel(PyObject * poSelf, PyObject * poArgs)
{
return Py_BuildValue("i", CPythonSystem::Instance().GetEffectLevel());
}
PyObject * systemIsAlwaysShowName(PyObject * poSelf, PyObject * poArgs)
{
return Py_BuildValue("i", CPythonSystem::Instance().IsAlwaysShowName());
@@ -422,6 +438,8 @@ void initsystem()
{ "SetShowSalesTextFlag", systemSetShowSalesTextFlag, METH_VARARGS },
{ "IsShowSalesText", systemIsShowSalesText, METH_VARARGS },
{ "SetEffectLevel", systemSetEffectLevel, METH_VARARGS }, // PORT: AVA2
{ "GetEffectLevel", systemGetEffectLevel, METH_VARARGS },
{ "GetShadowLevel", systemGetShadowLevel, METH_VARARGS },
{ "SetShadowLevel", systemSetShadowLevel, METH_VARARGS },