Add mobile touch UI and AVA2 biology system with server tools
This commit is contained in:
@@ -0,0 +1,457 @@
|
||||
// PORT: AVA2 biology (bio.*), with native touch-sized controls and original command vocabulary.
|
||||
static const char c_szBiologScript[] = R"PY(# -*- coding: utf-8 -*-
|
||||
import app
|
||||
import chat
|
||||
import game
|
||||
import grp
|
||||
import item
|
||||
import net
|
||||
import player
|
||||
import ui
|
||||
import uiToolTip
|
||||
import wndMgr
|
||||
import weakref
|
||||
import os
|
||||
import sys
|
||||
L = player.AutoHuntLocalize
|
||||
g_window = None
|
||||
g_entry = None
|
||||
CATALOG = {1: {'index': 1, 'level': 30, 'material': 30006, 'count': 10, 'cooldown': 600, 'chance': 60, 'stone': 30220, 'bonuses': [{'point': 'POINT_DEF_GRADE_BONUS', 'label': '防御力', 'value': 30}], 'choose': False, 'enhancer': 71035, 'skip': 30250}, 2: {'index': 2, 'level': 40, 'material': 30047, 'count': 15, 'cooldown': 600, 'chance': 60, 'stone': 30221, 'bonuses': [{'point': 'POINT_ATT_GRADE_BONUS', 'label': '攻击力', 'value': 40}], 'choose': False, 'enhancer': 71035, 'skip': 30250}, 3: {'index': 3, 'level': 50, 'material': 30015, 'count': 15, 'cooldown': 900, 'chance': 60, 'stone': 30222, 'bonuses': [{'point': 'POINT_ATTBONUS_MONSTER', 'label': '对怪物伤害 %', 'value': 5}], 'choose': False, 'enhancer': 71035, 'skip': 30250}, 4: {'index': 4, 'level': 60, 'material': 30050, 'count': 20, 'cooldown': 900, 'chance': 60, 'stone': 30223, 'bonuses': [{'point': 'POINT_ATTBONUS_STONE', 'label': '对陨石伤害 %', 'value': 4}, {'point': 'POINT_ATTBONUS_BOSS', 'label': '对 Boss 伤害 %', 'value': 4}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 5: {'index': 5, 'level': 70, 'material': 300004, 'count': 25, 'cooldown': 1800, 'chance': 60, 'stone': 30224, 'bonuses': [{'point': 'POINT_ATTBONUS_BOSS', 'label': '对 Boss 伤害 %', 'value': 6}, {'point': 'POINT_ATTBONUS_STONE', 'label': '对陨石伤害 %', 'value': 6}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 6: {'index': 6, 'level': 80, 'material': 300005, 'count': 30, 'cooldown': 1800, 'chance': 60, 'stone': 30225, 'bonuses': [{'point': 'POINT_MAX_HP', 'label': '生命值', 'value': 1000}, {'point': 'POINT_CASTING_SPEED', 'label': '施法速度', 'value': 10}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 7: {'index': 7, 'level': 85, 'material': 300006, 'count': 40, 'cooldown': 2700, 'chance': 60, 'stone': 30226, 'bonuses': [{'point': 'POINT_RESIST_WARRIOR', 'label': '战士抗性 %', 'value': 10}, {'point': 'POINT_RESIST_ASSASSIN', 'label': '忍者抗性 %', 'value': 10}, {'point': 'POINT_RESIST_SURA', 'label': '修罗抗性 %', 'value': 10}, {'point': 'POINT_RESIST_SHAMAN', 'label': '萨满抗性 %', 'value': 10}], 'choose': False, 'enhancer': 71035, 'skip': 30250}, 8: {'index': 8, 'level': 90, 'material': 300007, 'count': 50, 'cooldown': 3600, 'chance': 60, 'stone': 30227, 'bonuses': [{'point': 'POINT_ATTBONUS_WARRIOR', 'label': '对战士伤害 %', 'value': 10}, {'point': 'POINT_ATTBONUS_ASSASSIN', 'label': '对忍者伤害 %', 'value': 10}, {'point': 'POINT_ATTBONUS_SURA', 'label': '对修罗伤害 %', 'value': 10}, {'point': 'POINT_ATTBONUS_SHAMAN', 'label': '对萨满伤害 %', 'value': 10}], 'choose': False, 'enhancer': 71035, 'skip': 30250}, 9: {'index': 9, 'level': 92, 'material': 300008, 'count': 10, 'cooldown': 7200, 'chance': 60, 'stone': 30228, 'bonuses': [{'point': 'POINT_MAX_HP', 'label': '生命值', 'value': 1200}, {'point': 'POINT_DEF_GRADE_BONUS', 'label': '防御力', 'value': 120}, {'point': 'POINT_ATT_GRADE_BONUS', 'label': '攻击力', 'value': 50}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 10: {'index': 10, 'level': 94, 'material': 300009, 'count': 20, 'cooldown': 7200, 'chance': 60, 'stone': 30229, 'bonuses': [{'point': 'POINT_MAX_HP', 'label': '生命值', 'value': 1500}, {'point': 'POINT_DEF_GRADE_BONUS', 'label': '防御力', 'value': 140}, {'point': 'POINT_ATT_GRADE_BONUS', 'label': '攻击力', 'value': 60}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 11: {'index': 11, 'level': 98, 'material': 300010, 'count': 35, 'cooldown': 10800, 'chance': 60, 'stone': 30230, 'bonuses': [{'point': 'POINT_ATTBONUS_MONSTER', 'label': '对怪物伤害 %', 'value': 10}, {'point': 'POINT_RESIST_HUMAN', 'label': '半人抗性 %', 'value': 10}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 12: {'index': 12, 'level': 100, 'material': 300011, 'count': 35, 'cooldown': 10800, 'chance': 60, 'stone': 30231, 'bonuses': [{'point': 'POINT_ATTBONUS_STONE', 'label': '对陨石伤害 %', 'value': 10}, {'point': 'POINT_MELEE_MAGIC_ATT_BONUS_PER', 'label': '近战及魔法攻击 %', 'value': 10}], 'choose': True, 'enhancer': 71035, 'skip': 30250}, 13: {'index': 13, 'level': 105, 'material': 300012, 'count': 35, 'cooldown': 10800, 'chance': 60, 'stone': 30232, 'bonuses': [{'point': 'POINT_ATTBONUS_BOSS', 'label': '对 Boss 伤害 %', 'value': 10}, {'point': 'POINT_ATTBONUS_HUMAN', 'label': '对半人伤害 %', 'value': 10}], 'choose': True, 'enhancer': 71035, 'skip': 30250}}
|
||||
SHOP = [{'vnum': 30220, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 5000000}, {'vnum': 30221, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 7000000}, {'vnum': 30222, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 10000000}, {'vnum': 30223, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 13000000}, {'vnum': 30224, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 20000000}, {'vnum': 30225, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 25000000}, {'vnum': 30226, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 50000000}, {'vnum': 30227, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 100000000}, {'vnum': 30228, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 200000000}, {'vnum': 30229, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 200000000}, {'vnum': 30230, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 500000000}, {'vnum': 30231, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 500000000}, {'vnum': 30232, 'count': 1, 'cost': 0, 'amount': 0, 'gold': 500000000}, {'vnum': 300004, 'count': 1, 'cost': 30091, 'amount': 5, 'gold': 0}, {'vnum': 300005, 'count': 1, 'cost': 30197, 'amount': 3, 'gold': 0}, {'vnum': 300006, 'count': 1, 'cost': 30198, 'amount': 2, 'gold': 0}, {'vnum': 300007, 'count': 1, 'cost': 30196, 'amount': 2, 'gold': 0}, {'vnum': 300008, 'count': 1, 'cost': 70031, 'amount': 3, 'gold': 0}, {'vnum': 300009, 'count': 1, 'cost': 70031, 'amount': 5, 'gold': 0}, {'vnum': 300010, 'count': 1, 'cost': 30520, 'amount': 7, 'gold': 0}, {'vnum': 300011, 'count': 1, 'cost': 30521, 'amount': 7, 'gold': 0}, {'vnum': 300012, 'count': 1, 'cost': 30518, 'amount': 7, 'gold': 0}]
|
||||
|
||||
def BonusText(bonus):
|
||||
return bonus['label'].replace(" %", "")+" +%d"%bonus['value']+("%" if bonus['label'].endswith("%") else "")
|
||||
|
||||
|
||||
def Text(parent, x, y, text="", color=0xffe8dec8):
|
||||
line = ui.TextLine()
|
||||
line.SetParent(parent)
|
||||
line.AddFlag("not_pick")
|
||||
line.SetPosition(x, y)
|
||||
line.SetText(L(text))
|
||||
line.SetPackedFontColor(color)
|
||||
line.Show()
|
||||
return line
|
||||
|
||||
|
||||
class Action(ui.Window):
|
||||
def __init__(self, parent, x, y, width, text, event):
|
||||
ui.Window.__init__(self)
|
||||
if parent:
|
||||
self.SetParent(parent)
|
||||
self.SetPosition(x, y)
|
||||
self.SetSize(width, 48)
|
||||
self.event = event
|
||||
self.enabled = True
|
||||
self.down = False
|
||||
self.label = Text(self, width/2, 24, text)
|
||||
self.label.SetHorizontalAlignCenter()
|
||||
self.label.SetVerticalAlignCenter()
|
||||
self.Show()
|
||||
|
||||
def SetText(self, text):
|
||||
self.label.SetText(L(text))
|
||||
|
||||
def SetEnabled(self, enabled):
|
||||
self.enabled = bool(enabled)
|
||||
self.label.SetPackedFontColor(0xffefdbac if enabled else 0xff817c70)
|
||||
|
||||
def OnRender(self):
|
||||
x, y = self.GetGlobalPosition()
|
||||
grp.SetColor(0xdd684f2f if self.down else 0xdd2d261d)
|
||||
grp.RenderBar(x, y, self.GetWidth(), self.GetHeight())
|
||||
grp.SetColor(0xffb99a66 if self.enabled else 0xff57534b)
|
||||
grp.RenderBox(x, y, self.GetWidth(), self.GetHeight())
|
||||
|
||||
def OnMouseLeftButtonDown(self):
|
||||
self.down = self.enabled
|
||||
return True
|
||||
|
||||
def OnMouseLeftButtonUp(self):
|
||||
invoke = self.down and self.enabled and self.IsIn()
|
||||
self.down = False
|
||||
if invoke:
|
||||
self.event()
|
||||
return True
|
||||
|
||||
def OnMouseOverOut(self):
|
||||
self.down = False
|
||||
|
||||
|
||||
class BiologWindow(ui.Window):
|
||||
def __init__(self):
|
||||
ui.Window.__init__(self)
|
||||
self.SetWindowName("BiologWindow")
|
||||
self.AddFlag("float")
|
||||
self.AddFlag("movable")
|
||||
self.SetSize(540, 400)
|
||||
self.heading = Text(self, 22, 18, "生物学家研究", 0xffffd68b)
|
||||
self.closeButton = Action(self, 470, 6, 48, "关闭", self.Hide)
|
||||
self.title = Text(self, 22, 48)
|
||||
self.phase = Text(self, 22, 68)
|
||||
self.material = Text(self, 104, 92)
|
||||
self.progress = Text(self, 104, 114)
|
||||
self.owned = Text(self, 104, 136)
|
||||
self.cooldown = Text(self, 22, 160)
|
||||
self.reward = [Text(self, 22+(i%2)*260, 188+(i/2)*22) for i in range(4)]
|
||||
self.message = Text(self, 22, 378, "正在同步研究进度", 0xffb3aa98)
|
||||
self.icon = ui.ExpandedImageBox()
|
||||
self.icon.SetParent(self)
|
||||
self.icon.SetPosition(26, 92)
|
||||
self.icon.AddFlag("not_pick")
|
||||
self.tooltip = uiToolTip.ItemToolTip()
|
||||
self.tooltip.Hide()
|
||||
self.enhance = Action(self, 22, 288, 158, "精华:开启", lambda:self.Option(0))
|
||||
self.skip = Action(self, 190, 288, 158, "跳过冷却:开启", lambda:self.Option(1))
|
||||
self.reminder = Action(self, 358, 288, 160, "到期提醒:开启", lambda:self.Option(2))
|
||||
self.submit = Action(self, 22, 344, 158, "提交材料", self.Act)
|
||||
self.shopButton = Action(self, 190, 344, 158, "研究商店", self.Shop)
|
||||
self.resetButton = Action(self, 358, 344, 160, "重选奖励", self.Reset)
|
||||
self.choices = [Action(self, 22+(i%2)*260, 188+(i/2)*54, 238, "", lambda i=i:self.Gift(i)) for i in range(4)]
|
||||
self.prev = Action(self, 22, 288, 158, "上一项", lambda:self.Browse(-1))
|
||||
self.next = Action(self, 358, 288, 160, "下一项", lambda:self.Browse(1))
|
||||
self.options = [True, True, True] # AVA2 defaults: enhancer, time skip, reminder.
|
||||
self.index = 0
|
||||
self.count = 0
|
||||
self.deadline = 0
|
||||
self.serverTime = 0
|
||||
self.receivedAt = 0
|
||||
self.pendingUntil = 0
|
||||
self.nextQuery = app.GetTime()+1
|
||||
self.queryStarted = 0
|
||||
self.mode = "research"
|
||||
self.bonuses = [0]*13
|
||||
self.browse = 0
|
||||
self.hasState = False
|
||||
self.iconVnum = 0
|
||||
self.iconHover = False
|
||||
self.lastRemaining = 0
|
||||
self.dimensions = None
|
||||
self.LoadOptions()
|
||||
self.Hide()
|
||||
self.Refresh()
|
||||
|
||||
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 PreferencePath(self):
|
||||
# Keep preferences outside a signed macOS app; Android falls back to its writable client dir.
|
||||
base = os.environ.get("HOME", ".")
|
||||
if sys.platform.startswith("linux"):
|
||||
base = "."
|
||||
folder = os.path.join(base, ".metin2", "biolog")
|
||||
name = player.GetName()
|
||||
return folder, os.path.join(folder, name.encode("hex")+".cfg")
|
||||
|
||||
def LoadOptions(self):
|
||||
try:
|
||||
folder,path = self.PreferencePath()
|
||||
values = [int(x) for x in open(path,"r").read().strip().split("#")]
|
||||
if len(values)==3 and all(type(x) in (bool,int) and x in (0,1) for x in values):
|
||||
self.options = map(bool, values)
|
||||
except (IOError, OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
def Option(self, index):
|
||||
self.options[index] = not self.options[index]
|
||||
try:
|
||||
folder,path = self.PreferencePath()
|
||||
if not os.path.isdir(folder): os.makedirs(folder)
|
||||
with open(path,"w") as stream: stream.write("#".join(str(int(x)) for x in self.options))
|
||||
except (IOError,OSError):
|
||||
pass
|
||||
self.Refresh()
|
||||
|
||||
def Toggle(self):
|
||||
if self.IsShow(): self.Hide()
|
||||
else:
|
||||
self.mode = "research"
|
||||
self.SetCenterPosition()
|
||||
self.Show()
|
||||
self.SetTop()
|
||||
self.Query()
|
||||
|
||||
def Query(self):
|
||||
now = app.GetTime()
|
||||
self.nextQuery = now+3
|
||||
if not self.queryStarted:self.queryStarted=now
|
||||
net.SendChatPacket("/bio status")
|
||||
|
||||
def SetData(self, words):
|
||||
if len(words)!=3:return False
|
||||
try:index,count,deadline=map(int,words)
|
||||
except (ValueError,TypeError):return False
|
||||
if index not in CATALOG or count<0 or count>CATALOG[index]['count']+1 or deadline<0:return False
|
||||
self.index,self.count,self.deadline=index,count,deadline
|
||||
self.receivedAt=app.GetTime()
|
||||
self.hasState=True
|
||||
self.pendingUntil=0
|
||||
self.Refresh()
|
||||
return True
|
||||
|
||||
def SetPhase(self, index, stone):
|
||||
try:index=int(index)
|
||||
except (ValueError,TypeError):return
|
||||
if index not in CATALOG:return
|
||||
self.index=index
|
||||
self.count=CATALOG[index]['count']+(0 if stone else 1)
|
||||
self.hasState=True
|
||||
self.pendingUntil=0
|
||||
self.Refresh()
|
||||
|
||||
def Phase(self):
|
||||
if not self.hasState:return "loading"
|
||||
if self.index>=14:return "complete"
|
||||
row=CATALOG[self.index]
|
||||
if self.count<row['count']:return "collect"
|
||||
if row['stone'] and self.count==row['count']:return "stone"
|
||||
return "gift"
|
||||
|
||||
def Remaining(self):
|
||||
if not self.deadline:return 0
|
||||
reference=self.serverTime if self.serverTime else app.GetGlobalTimeStamp()
|
||||
return max(0,int(self.deadline-reference-(app.GetTime()-self.receivedAt)+0.999))
|
||||
|
||||
def ItemCount(self,vnum):
|
||||
return player.GetItemCountByVnum(vnum) if vnum else 0
|
||||
|
||||
def CanAct(self):
|
||||
if not self.hasState or app.GetTime()<self.pendingUntil:return False
|
||||
if self.mode=="shop":
|
||||
offer=SHOP[self.browse]
|
||||
return self.ItemCount(offer['cost'])>=offer['amount'] if offer['cost'] else player.GetElk()>=offer['gold']
|
||||
if self.mode=="reset" or self.index not in CATALOG:return False
|
||||
row=CATALOG[self.index]
|
||||
if player.GetStatus(player.LEVEL)<row['level']:return False
|
||||
phase=self.Phase()
|
||||
if phase=="collect":
|
||||
return self.ItemCount(row['material'])>0 and (self.Remaining()==0 or (self.options[1] and self.ItemCount(row['skip'])>0))
|
||||
return phase=="stone" and self.ItemCount(row['stone'])>0
|
||||
|
||||
def Act(self):
|
||||
if not self.CanAct():return
|
||||
self.pendingUntil=app.GetTime()+5
|
||||
if self.mode=="shop":net.SendChatPacket("/bio buy %d"%self.browse)
|
||||
else:net.SendChatPacket("/bio mission %d %d"%(int(self.options[0]),int(self.options[1])))
|
||||
self.nextQuery=app.GetTime()+1
|
||||
self.Refresh()
|
||||
|
||||
def Gift(self, choice):
|
||||
if app.GetTime()<self.pendingUntil:return
|
||||
index=self.ResetIndex() if self.mode=="reset" else self.index
|
||||
if index not in CATALOG or choice>=len(CATALOG[index]['bonuses']):return
|
||||
if self.mode=="reset":
|
||||
if self.ItemCount(70028)<1 or self.bonuses[index-1]==choice+1:return
|
||||
command="/bio reset %d %d"%(index,choice)
|
||||
else:
|
||||
if self.Phase()!="gift":return
|
||||
command="/bio gift %d"%choice
|
||||
self.pendingUntil=app.GetTime()+5
|
||||
net.SendChatPacket(command)
|
||||
self.nextQuery=app.GetTime()+1
|
||||
self.Refresh()
|
||||
|
||||
def Shop(self):
|
||||
self.mode="research" if self.mode=="shop" else "shop"
|
||||
self.browse=0
|
||||
self.Refresh()
|
||||
|
||||
def ResetEntries(self):
|
||||
return [i+1 for i,value in enumerate(self.bonuses) if value and i+1<self.index and CATALOG[i+1]['choose']]
|
||||
|
||||
def ResetIndex(self):
|
||||
entries=self.ResetEntries()
|
||||
return entries[self.browse%len(entries)] if entries else 0
|
||||
|
||||
def Reset(self):
|
||||
self.mode="research" if self.mode=="reset" else "reset"
|
||||
self.browse=0
|
||||
self.Refresh()
|
||||
|
||||
def Browse(self, delta):
|
||||
count=len(SHOP) if self.mode=="shop" else len(self.ResetEntries())
|
||||
if count:self.browse=(self.browse+delta)%count
|
||||
self.Refresh()
|
||||
|
||||
def ItemName(self,vnum):
|
||||
item.SelectItem(vnum)
|
||||
return item.GetItemName()
|
||||
|
||||
def Refresh(self):
|
||||
for button in self.choices+[self.prev,self.next]:button.Hide()
|
||||
for line in self.reward:line.SetText("")
|
||||
for button in (self.enhance,self.skip,self.reminder):button.Show()
|
||||
self.submit.SetEnabled(self.CanAct())
|
||||
for i,button in enumerate((self.enhance,self.skip,self.reminder)):
|
||||
button.SetText(("精华:","跳过冷却:","到期提醒:")[i]+("开启" if self.options[i] else "关闭"))
|
||||
button.SetEnabled(app.GetTime()>=self.pendingUntil)
|
||||
self.shopButton.SetText("返回研究" if self.mode=="shop" else "研究商店")
|
||||
self.resetButton.SetText("返回研究" if self.mode=="reset" else "重选奖励")
|
||||
self.message.SetText(L("请求处理中……" if app.GetTime()<self.pendingUntil else ""))
|
||||
if not self.hasState:
|
||||
self.title.SetText(L("正在同步研究进度……"))
|
||||
return
|
||||
if self.index>=14 and self.mode=="research":
|
||||
self.title.SetText(L("全部研究已完成"))
|
||||
self.phase.SetText(L("30~105 级研究奖励已领取。"))
|
||||
self.icon.Hide()
|
||||
for line in (self.material,self.progress,self.owned,self.cooldown):line.SetText("")
|
||||
self.submit.SetText("已完成")
|
||||
return
|
||||
if self.mode=="shop":
|
||||
offer=SHOP[self.browse];vnum=offer['vnum']
|
||||
self.title.SetText(L("研究商店 %d / %d")%(self.browse+1,len(SHOP)))
|
||||
self.phase.SetText(L("与 AVA2 生物学家商店相同的物品与兑换条件。"))
|
||||
self.progress.SetText(L("购买数量:%d")%offer['count'])
|
||||
cost=(self.ItemName(offer['cost'])+L(" × %d")%offer['amount']) if offer['cost'] else L("金币 %d")%offer['gold']
|
||||
self.cooldown.SetText(L("价格:")+cost)
|
||||
self.submit.SetText("购买")
|
||||
for b in (self.enhance,self.skip,self.reminder):b.Hide()
|
||||
self.prev.Show();self.next.Show()
|
||||
else:
|
||||
index=self.ResetIndex() if self.mode=="reset" else self.index
|
||||
if not index:
|
||||
self.title.SetText(L("暂无可重选的奖励"))
|
||||
self.phase.SetText(L("完成有奖励选项的研究后,可消耗重选道具。"))
|
||||
self.icon.Hide()
|
||||
for line in (self.material,self.progress,self.owned,self.cooldown):line.SetText("")
|
||||
self.submit.SetEnabled(False)
|
||||
return
|
||||
row=CATALOG[index]
|
||||
phase="gift" if self.mode=="reset" else self.Phase()
|
||||
vnum=row['stone'] if phase=="stone" else row['material']
|
||||
self.title.SetText(L("%d 级研究 · %d / 13")%(row['level'],index))
|
||||
text={"collect":"收集材料", "stone":"提交任务石", "gift":"选择研究奖励"}.get(phase,"")
|
||||
self.phase.SetText(L(text))
|
||||
self.progress.SetText(L("进度:%d / %d")%(min(self.count,row['count']) if self.mode!="reset" else row['count'],row['count']))
|
||||
remaining=self.Remaining() if phase=="collect" else 0
|
||||
self.cooldown.SetText(L("冷却 %02d:%02d:%02d · 基础成功率 %d%%")%(remaining/3600,(remaining/60)%60,remaining%60,row['chance']))
|
||||
self.submit.SetText("提交任务石" if phase=="stone" else "提交材料")
|
||||
if phase=="gift":
|
||||
for b in (self.enhance,self.skip,self.reminder):b.Hide()
|
||||
for i,bonus in enumerate(row['bonuses']):
|
||||
b=self.choices[i];b.SetText(BonusText(bonus));b.Show()
|
||||
b.SetEnabled(app.GetTime()>=self.pendingUntil and (self.mode!="reset" or (self.ItemCount(70028)>0 and self.bonuses[index-1]!=i+1)))
|
||||
else:
|
||||
for line,bonus in zip(self.reward,row['bonuses']):line.SetText(L(BonusText(bonus)))
|
||||
if self.mode=="reset":
|
||||
for b in (self.enhance,self.skip,self.reminder):b.Hide()
|
||||
self.prev.Show();self.next.Show()
|
||||
self.message.SetText(L("消耗重选道具 ×1,当前选择:%d")%self.bonuses[index-1])
|
||||
elif player.GetStatus(player.LEVEL)<row['level']:
|
||||
self.message.SetText(L("需要角色等级 %d")%row['level'])
|
||||
self.material.SetText(self.ItemName(vnum))
|
||||
self.owned.SetText(L("背包持有:%d")%self.ItemCount(vnum))
|
||||
if vnum!=self.iconVnum:
|
||||
self.iconVnum=vnum
|
||||
self.icon.LoadImage(item.GetIconImageFileName())
|
||||
self.icon.SetScale(1.6,1.6)
|
||||
self.icon.Show()
|
||||
|
||||
def OnUpdate(self):
|
||||
now=app.GetTime()
|
||||
# Keep the expiry reminder alive while the panel is closed, like AVA2's loop callback.
|
||||
if now>=self.nextQuery and (self.IsShow() or not self.hasState):self.Query()
|
||||
remaining=self.Remaining()
|
||||
if self.options[2] and self.lastRemaining>0 and remaining==0 and self.Phase()=="collect":
|
||||
chat.AppendChat(chat.CHAT_TYPE_NOTICE,L("[生物学家] 可以再次提交研究材料了。"))
|
||||
self.lastRemaining=remaining
|
||||
if not self.IsShow():return
|
||||
dimensions=(wndMgr.GetScreenWidth(),wndMgr.GetScreenHeight())
|
||||
if dimensions!=self.dimensions:
|
||||
self.dimensions=dimensions
|
||||
height=min(400,dimensions[1]-12)
|
||||
self.SetSize(540,height)
|
||||
self.message.SetPosition(22,height-20)
|
||||
for b in (self.submit,self.shopButton,self.resetButton):b.SetPosition(b.GetLocalPosition()[0],height-56)
|
||||
for b in (self.enhance,self.skip,self.reminder,self.prev,self.next):b.SetPosition(b.GetLocalPosition()[0],height-112)
|
||||
self.SetCenterPosition()
|
||||
self.Refresh()
|
||||
x,y=self.GetGlobalPosition();mx,my=wndMgr.GetMousePosition()
|
||||
hover=self.iconVnum and x+24<=mx<x+86 and y+92<=my<y+154
|
||||
if hover and not self.iconHover:self.tooltip.SetItemToolTip(self.iconVnum)
|
||||
elif not hover and self.iconHover:self.tooltip.Hide()
|
||||
self.iconHover=hover
|
||||
|
||||
def Hide(self):
|
||||
ui.Window.Hide(self)
|
||||
if hasattr(self,"tooltip"):self.tooltip.Hide()
|
||||
self.iconHover=False
|
||||
|
||||
def OnPressEscapeKey(self):
|
||||
self.Hide()
|
||||
return True
|
||||
|
||||
def Destroy(self):
|
||||
self.Hide()
|
||||
for b in self.choices+[self.submit,self.shopButton,self.resetButton,self.enhance,self.skip,self.reminder,self.closeButton,self.prev,self.next]:b.event=None
|
||||
self.hasState=False
|
||||
|
||||
|
||||
class Entry(Action):
|
||||
def __init__(self, window):
|
||||
Action.__init__(self, None, 0, 0, 64, "研究", Toggle)
|
||||
self.minimap = weakref.proxy(window.interface.wndMiniMap)
|
||||
self.SetWindowName("BiologEntry")
|
||||
self.OnUpdate()
|
||||
|
||||
def OnUpdate(self):
|
||||
x, y = self.minimap.GetGlobalPosition()
|
||||
self.SetPosition(max(4, x - 68), y + 44)
|
||||
if g_window and not g_window.IsShow():g_window.OnUpdate()
|
||||
|
||||
|
||||
def Toggle():
|
||||
if g_window:g_window.Toggle()
|
||||
|
||||
_open=game.GameWindow.Open
|
||||
_close=game.GameWindow.Close
|
||||
_command=game.GameWindow.BINARY_ServerCommand_Run
|
||||
|
||||
def Open(self):
|
||||
global g_window,g_entry
|
||||
_open(self)
|
||||
g_window=BiologWindow()
|
||||
g_entry=Entry(self)
|
||||
g_entry.nextTick=0
|
||||
|
||||
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)
|
||||
|
||||
def Command(self,line):
|
||||
words=line.split()
|
||||
if not words:return _command(self,line)
|
||||
name=words[0]
|
||||
if name in ("biodata","biostone","bioodul","bioempty","biotime","biobonuses","bioreselect","BioNotice"):
|
||||
if not g_window:return 1
|
||||
try:
|
||||
if name=="biodata":g_window.SetData(words[1:])
|
||||
elif name=="biostone" and len(words)==2:g_window.SetPhase(words[1],True)
|
||||
elif name=="bioodul" and len(words)==2:g_window.SetPhase(words[1],False)
|
||||
elif name=="bioempty":g_window.index=14;g_window.hasState=True;g_window.pendingUntil=0;g_window.Refresh()
|
||||
elif name=="biotime" and len(words)==2:g_window.serverTime=int(words[1]);g_window.receivedAt=app.GetTime()
|
||||
elif name=="biobonuses" and len(words)==14:
|
||||
values=map(int,words[1:])
|
||||
if all(0<=v<=4 for v in values):g_window.bonuses=values
|
||||
elif name=="bioreselect":
|
||||
if not g_window.IsShow():g_window.Toggle()
|
||||
g_window.mode="reset";g_window.browse=0;g_window.Refresh()
|
||||
elif name=="BioNotice" and len(words)>=2:
|
||||
text={"level":"等级不足,暂时无法继续研究。","material":"研究材料不足。","cooldown":"冷却中,需要冷却药剂才能立即提交。","success":"研究成功,进度增加。","failure":"研究失败,材料已消耗。","stone":"请先准备所需任务石。","complete":"所有生物学家研究已完成。","busy":"请先关闭交易、商店或任务对话。","bought":"购买成功。","cost":"金币或兑换材料不足。","reset":"研究奖励已重新选择。","reset_item":"需要重选道具。"}.get(words[1],"")
|
||||
if text:chat.AppendChat(chat.CHAT_TYPE_INFO,L(text))
|
||||
g_window.pendingUntil=0
|
||||
except (ValueError,TypeError,IndexError):pass
|
||||
return 1
|
||||
return _command(self,line)
|
||||
|
||||
game.GameWindow.Open=Open
|
||||
game.GameWindow.Close=Close
|
||||
game.GameWindow.BINARY_ServerCommand_Run=Command
|
||||
)PY";
|
||||
@@ -0,0 +1,280 @@
|
||||
// PORT: mobile presentation; menu actions and player data use the existing client APIs.
|
||||
static const char c_szMobileHUDScript[] = R"PY(# -*- coding: utf-8 -*-
|
||||
import app
|
||||
import game
|
||||
import grp
|
||||
import math
|
||||
import net
|
||||
import player
|
||||
import ui
|
||||
import uiCharacter
|
||||
import weakref
|
||||
import wndMgr
|
||||
import mt_mobile_inventory
|
||||
|
||||
L = player.AutoHuntLocalize
|
||||
g_hud = None
|
||||
|
||||
|
||||
def _Text(parent, text):
|
||||
line = ui.TextLine()
|
||||
line.SetParent(parent)
|
||||
line.AddFlag("not_pick")
|
||||
line.SetText(L(text))
|
||||
line.SetOutline()
|
||||
line.Show()
|
||||
return line
|
||||
|
||||
|
||||
class RoundAction(ui.Window):
|
||||
def __init__(self, parent, text, action, icon=None):
|
||||
ui.Window.__init__(self)
|
||||
self.SetParent(parent)
|
||||
self.action = action
|
||||
self.down = False
|
||||
self.label = _Text(self, text)
|
||||
self.label.SetHorizontalAlignCenter()
|
||||
self.label.SetVerticalAlignCenter()
|
||||
self.icon = None
|
||||
if icon:
|
||||
self.icon = ui.ExpandedImageBox()
|
||||
self.icon.SetParent(self)
|
||||
self.icon.AddFlag("not_pick")
|
||||
self.icon.LoadImage(icon)
|
||||
self.iconSize = (self.icon.GetWidth(), self.icon.GetHeight())
|
||||
self.icon.Show()
|
||||
self.Show()
|
||||
|
||||
def Place(self, x, y, size):
|
||||
self.SetPosition(int(x), int(y))
|
||||
self.SetSize(int(size), int(size))
|
||||
self.label.SetPosition(int(size/2), int(size/2))
|
||||
if self.icon:
|
||||
edge = size * .62
|
||||
self.icon.SetScale(edge / max(1, self.iconSize[0]), edge / max(1, self.iconSize[1]))
|
||||
self.icon.SetPosition(int((size-edge)/2), int((size-edge)/2))
|
||||
|
||||
def OnRender(self):
|
||||
x, y = self.GetGlobalPosition()
|
||||
r = self.GetWidth()/2.0
|
||||
grp.SetColor(0xE0664B2D if self.down else 0xBB281A16)
|
||||
# Horizontal strips fill a round button without requiring extra image assets.
|
||||
for row in xrange(0, self.GetHeight(), 3):
|
||||
dy = min(r, row + 1.5 - r)
|
||||
half = math.sqrt(max(0, r*r - dy*dy))
|
||||
grp.RenderBar(x+r-half, y+row, half*2, min(3, self.GetHeight()-row))
|
||||
grp.SetColor(0xFFE6CB8D if self.down else 0xCCB99A66)
|
||||
for i in xrange(32):
|
||||
a = i * math.pi / 16
|
||||
b = (i+1) * math.pi / 16
|
||||
xx, yy = x+r+math.cos(a)*(r-1), y+r+math.sin(a)*(r-1)
|
||||
grp.RenderLine(xx, yy, (math.cos(b)-math.cos(a))*(r-1), (math.sin(b)-math.sin(a))*(r-1))
|
||||
|
||||
def OnMouseLeftButtonDown(self):
|
||||
self.down = True
|
||||
return True
|
||||
|
||||
def OnMouseLeftButtonUp(self):
|
||||
held = self.down
|
||||
self.down = False
|
||||
if held and self.IsIn():
|
||||
self.action()
|
||||
return True
|
||||
|
||||
def OnMouseOverOut(self):
|
||||
self.down = False
|
||||
|
||||
|
||||
class Status(ui.Window):
|
||||
def __init__(self, parent, taskbar, action):
|
||||
ui.Window.__init__(self)
|
||||
self.SetParent(parent)
|
||||
self.AddFlag("not_pick")
|
||||
self.taskbar = weakref.proxy(taskbar)
|
||||
self.frame = ui.ExpandedImageBox()
|
||||
self.frame.SetParent(self)
|
||||
self.frame.AddFlag("not_pick")
|
||||
self.frame.LoadImage("d:/ymir work/ui/game/taskbar/gauge.sub")
|
||||
# Keep the original bar frame, cropping away the large legacy orb on its left.
|
||||
self.frame.SetRenderingRect(-56.0/self.frame.GetWidth(), -12.0/self.frame.GetHeight(),
|
||||
0, (46.0-self.frame.GetHeight())/self.frame.GetHeight())
|
||||
self.frame.Show()
|
||||
self.gauge = taskbar.GetChild("Gauge_Board")
|
||||
self.gaugePosition = self.gauge.GetLocalPosition()
|
||||
self.gauge.SetParent(self)
|
||||
self.gauge.AddFlag("not_pick")
|
||||
self.gauge.SetAlpha(0)
|
||||
self.gauge.Show()
|
||||
for name in ("RampageGauge", "RampageGauge2"):
|
||||
if taskbar.IsChild(name):
|
||||
taskbar.GetChild(name).Hide()
|
||||
self.face = RoundAction(self, "", action, uiCharacter.FACE_IMAGE_DICT.get(net.GetMainActorRace()))
|
||||
self.name = _Text(self, "")
|
||||
self.hp = _Text(self, "")
|
||||
self.sp = _Text(self, "")
|
||||
self.energy = _Text(self, "")
|
||||
self.hp.SetHorizontalAlignCenter()
|
||||
self.sp.SetHorizontalAlignCenter()
|
||||
self.values = (0, 1, 0, 1, 0, 1)
|
||||
self.lastStatus = None
|
||||
self.Show()
|
||||
|
||||
def Place(self, scale):
|
||||
self.scale = scale
|
||||
self.SetPosition(int(12*scale), int(10*scale))
|
||||
self.SetSize(int(290*scale), int(88*scale))
|
||||
# The original three bars are native-size: their outer frame is 34 pixels tall.
|
||||
self.face.Place(18*scale, 14*scale+12, 34)
|
||||
self.name.SetPosition(int(66*scale), 0)
|
||||
# The original frame, animated HP/SP textures, recovery overlays and ST strip stay intact.
|
||||
bar_x = int(18*scale) + 34 - 56
|
||||
self.gauge.SetPosition(bar_x, int(14*scale))
|
||||
self.frame.SetPosition(bar_x, int(14*scale))
|
||||
self.hp.SetHorizontalAlignLeft()
|
||||
self.sp.SetHorizontalAlignLeft()
|
||||
self.hp.SetPosition(bar_x+166, int(24*scale))
|
||||
self.sp.SetPosition(bar_x+166, int(42*scale))
|
||||
self.energy.SetPosition(int(66*scale), int(68*scale))
|
||||
|
||||
def Refresh(self):
|
||||
hp, mh = player.GetStatus(player.HP), player.GetStatus(player.MAX_HP)
|
||||
sp, ms = player.GetStatus(player.SP), player.GetStatus(player.MAX_SP)
|
||||
exp, me = player.GetStatus(player.EXP), player.GetStatus(player.NEXT_EXP)
|
||||
self.values = (hp, mh, sp, ms, exp, me)
|
||||
status = self.values + (player.GetStatus(player.STAMINA), player.GetStatus(player.MAX_STAMINA),
|
||||
player.GetStatus(player.HP_RECOVERY), player.GetStatus(player.SP_RECOVERY))
|
||||
if status != self.lastStatus:
|
||||
self.taskbar.RefreshStatus()
|
||||
self.lastStatus = status
|
||||
self.name.SetText("%s Lv.%d" % (player.GetName(), player.GetStatus(player.LEVEL)))
|
||||
self.hp.SetText("%d / %d" % (hp, mh) if mh > 0 else "--")
|
||||
self.sp.SetText("%d / %d" % (sp, ms) if ms > 0 else "--")
|
||||
energy = player.GetStatus(player.ENERGY)
|
||||
remaining = player.GetStatus(player.ENERGY_END_TIME) - app.GetGlobalTimeStamp()
|
||||
if energy > 0 and remaining > 0:
|
||||
self.energy.SetText(L("能量 +%d %d分钟") % (energy, (remaining+59)/60))
|
||||
self.energy.Show()
|
||||
else:
|
||||
self.energy.Hide()
|
||||
|
||||
def Restore(self):
|
||||
self.gauge.Hide()
|
||||
self.gauge.SetAlpha(1)
|
||||
self.gauge.SetParent(self.taskbar)
|
||||
self.gauge.SetPosition(*self.gaugePosition)
|
||||
self.face.action = None
|
||||
|
||||
|
||||
class HUD(ui.Window):
|
||||
def __init__(self, window):
|
||||
ui.Window.__init__(self)
|
||||
self.SetWindowName("MobileHUD")
|
||||
self.AddFlag("not_pick")
|
||||
self.window = weakref.proxy(window)
|
||||
interface = window.interface
|
||||
self.taskbar = weakref.proxy(interface.wndTaskBar)
|
||||
self.original = (self.taskbar.Show, self.taskbar.Hide, self.taskbar.IsShow)
|
||||
self.original[1]()
|
||||
self.taskbar.Show = self.Show
|
||||
self.taskbar.Hide = self.Hide
|
||||
self.taskbar.IsShow = self.IsShow
|
||||
self.chat = weakref.proxy(interface.wndChat)
|
||||
self.chatColors = (self.chat.BOARD_START_COLOR, self.chat.BOARD_END_COLOR, self.chat.BOARD_MIDDLE_COLOR)
|
||||
self.chat.BOARD_START_COLOR = self.chat.BOARD_END_COLOR = self.chat.BOARD_MIDDLE_COLOR = 0
|
||||
self.status = Status(self, interface.wndTaskBar, interface.ToggleCharacterWindowStatusPage)
|
||||
self.experience = self.taskbar.expGaugeBoard
|
||||
self.experiencePosition = self.experience.GetLocalPosition()
|
||||
self.experience.SetParent(self)
|
||||
self.experience.AddFlag("not_pick")
|
||||
self.experience.Show()
|
||||
for point in self.taskbar.expGauge:
|
||||
point.AddFlag("not_pick")
|
||||
self.experienceText = _Text(self.experience, "")
|
||||
self.top = []
|
||||
for text, index, action in (("", 0, interface.ToggleCharacterWindowStatusPage),
|
||||
("", 1, interface.ToggleInventoryWindow),
|
||||
("", 2, interface.ToggleMessenger),
|
||||
("", 3, interface.ToggleSystemDialog)):
|
||||
self.top.append(RoundAction(self, text, action, self.taskbar.toggleButtonDict[index].GetUpVisualFileName()))
|
||||
self.side = [RoundAction(self, "任务", lambda: interface.ToggleCharacterWindow("QUEST")),
|
||||
RoundAction(self, "帮助", interface.OpenHelpWindow),
|
||||
RoundAction(self, "聊天", interface.ToggleChat)]
|
||||
self.dimensions = None
|
||||
self.OnUpdate()
|
||||
self.Show()
|
||||
|
||||
def Show(self):
|
||||
ui.Window.Show(self)
|
||||
self.SetTop()
|
||||
|
||||
def OnUpdate(self):
|
||||
w, h = wndMgr.GetScreenWidth(), wndMgr.GetScreenHeight()
|
||||
target = max(48, mt_mobile_inventory.touch_target)
|
||||
dimensions = (w, h, target)
|
||||
if dimensions != self.dimensions:
|
||||
self.dimensions = dimensions
|
||||
s = max(target/52.0, min(1.35, max(.65, min(h/600.0, w/800.0))))
|
||||
self.SetSize(w, h)
|
||||
self.status.Place(s)
|
||||
self.experience.SetPosition(int(12*s), int(h-self.experience.GetHeight()-6*s))
|
||||
self.experienceText.SetPosition(self.experience.GetWidth()+6, 10)
|
||||
size, gap = max(target, 48*s), 8*s
|
||||
for i, button in enumerate(self.top):
|
||||
button.Place(w-12*s-(4-i)*(size+gap), 10*s, size)
|
||||
for i, button in enumerate(self.side):
|
||||
if h < 520 or s > 1.25:
|
||||
button.Place(12*s+i*(size+gap), 140*s, size)
|
||||
else:
|
||||
button.Place(12*s, 140*s+i*(size+gap), size)
|
||||
self.window.affectShower.SetPosition(int(18*s), int(104*s))
|
||||
minimap = self.window.interface.wndMiniMap
|
||||
minimap.SetWindowHorizontalAlignLeft()
|
||||
minimap.SetWindowVerticalAlignTop()
|
||||
minimap.SetPosition(int(w-minimap.GetWidth()-12*s), int(72*s))
|
||||
chat = self.window.interface.wndChat
|
||||
chat.SetPosition(int(180*s), int(h-86*s))
|
||||
chat.Refresh()
|
||||
# The original help prompt would duplicate the touch-sized left-side entry.
|
||||
self.window.interface.wndGameButton.gameButtonDict["HELP"].Hide()
|
||||
energy = self.window.interface.wndEnergyBar
|
||||
if energy:
|
||||
energy.Hide()
|
||||
self.status.Refresh()
|
||||
# Match TaskBar.SetExperience's unsigned 32-bit experience counters.
|
||||
exp, total = (value & 0xffffffff for value in self.status.values[4:6])
|
||||
self.experienceText.SetText((L("经验 %.2f%%") % (100.0*exp/total)) if total > 0 else L("经验 --"))
|
||||
|
||||
def Destroy(self):
|
||||
self.Hide()
|
||||
self.chat.BOARD_START_COLOR, self.chat.BOARD_END_COLOR, self.chat.BOARD_MIDDLE_COLOR = self.chatColors
|
||||
self.taskbar.Show, self.taskbar.Hide, self.taskbar.IsShow = self.original
|
||||
self.status.Restore()
|
||||
self.experience.Hide()
|
||||
self.experience.SetParent(self.taskbar)
|
||||
self.experience.SetPosition(*self.experiencePosition)
|
||||
for button in self.top + self.side:
|
||||
button.action = None
|
||||
self.window = None
|
||||
|
||||
|
||||
_open = game.GameWindow.Open
|
||||
_close = game.GameWindow.Close
|
||||
|
||||
|
||||
def Open(self):
|
||||
global g_hud
|
||||
_open(self)
|
||||
g_hud = HUD(self)
|
||||
|
||||
|
||||
def Close(self):
|
||||
global g_hud
|
||||
if g_hud:
|
||||
g_hud.Destroy()
|
||||
g_hud = None
|
||||
_close(self)
|
||||
|
||||
|
||||
game.GameWindow.Open = Open
|
||||
game.GameWindow.Close = Close
|
||||
)PY";
|
||||
@@ -0,0 +1,125 @@
|
||||
// PORT: touch inventory gestures; original methods own use, move and sale requests.
|
||||
static const char c_szMobileInventoryScript[] = R"PY(# -*- coding: utf-8 -*-
|
||||
import app
|
||||
import constInfo
|
||||
import game
|
||||
import mouseModule
|
||||
import player
|
||||
import shop
|
||||
import uiInventory
|
||||
import uiShop
|
||||
|
||||
# These flags are scoped by the native touch controller, never by desktop mouse input.
|
||||
tap = False
|
||||
double_tap = False
|
||||
dragging = False
|
||||
touch_target = 48
|
||||
_last = None
|
||||
_last_time = -1
|
||||
_drag = None
|
||||
_OriginalSelect = uiInventory.InventoryWindow.SelectItemSlot
|
||||
_OriginalUse = uiInventory.InventoryWindow.UseItemSlot
|
||||
_OriginalShopLoad = uiShop.ShopDialog.LoadDialog
|
||||
|
||||
|
||||
def _ShopLoad(self):
|
||||
result = _OriginalShopLoad(self)
|
||||
# The original loader names child windows but leaves this root unnamed.
|
||||
self.SetWindowName("ShopDialog")
|
||||
return result
|
||||
|
||||
|
||||
def _Snapshot(owner, slot):
|
||||
import weakref
|
||||
cell = owner._InventoryWindow__InventoryLocalSlotPosToGlobalSlotPos(slot)
|
||||
return (owner if isinstance(owner, weakref.ProxyTypes) else weakref.proxy(owner), owner.inventoryPageIndex, cell,
|
||||
player.GetItemIndex(cell), player.GetItemCount(cell))
|
||||
|
||||
|
||||
def _Valid(snapshot):
|
||||
if not snapshot:
|
||||
return False
|
||||
try:
|
||||
owner, page, cell, vnum, count = snapshot
|
||||
return (owner.IsShow() and owner.inventoryPageIndex == page and vnum != 0 and
|
||||
player.GetItemIndex(cell) == vnum and player.GetItemCount(cell) == count and
|
||||
not constInfo.GET_ITEM_QUESTION_DIALOG_STATUS())
|
||||
except ReferenceError:
|
||||
return False
|
||||
|
||||
|
||||
def _Select(self, slot):
|
||||
global _last, _last_time, _drag
|
||||
mouse = mouseModule.mouseController
|
||||
if tap and not mouse.isAttached() and not constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() and app.GetCursor() not in (app.SELL, app.BUY):
|
||||
_last = _Snapshot(self, slot)
|
||||
_last_time = app.GetTime()
|
||||
if _last[3]:
|
||||
self.ShowToolTip(_last[2])
|
||||
return
|
||||
snapshot = _Snapshot(self, slot) if dragging and not mouse.isAttached() else None
|
||||
result = _OriginalSelect(self, slot)
|
||||
if snapshot and mouse.isAttached() and mouse.GetAttachedType() == player.SLOT_TYPE_INVENTORY:
|
||||
_drag = snapshot
|
||||
return result
|
||||
|
||||
|
||||
def _Use(self, slot):
|
||||
global _last
|
||||
if double_tap:
|
||||
snapshot = _last
|
||||
_last = None
|
||||
if (not _Valid(snapshot) or not 0 <= app.GetTime()-_last_time <= .5 or
|
||||
snapshot != _Snapshot(self, slot)):
|
||||
return
|
||||
return _OriginalUse(self, slot)
|
||||
|
||||
|
||||
def SetDrag(active):
|
||||
global dragging, _drag, _last
|
||||
dragging = active
|
||||
_drag = None
|
||||
_last = None
|
||||
|
||||
|
||||
def Drop(shop_target):
|
||||
"""Consume stale inventory drags and NPC-shop drops; other targets use the normal UI path."""
|
||||
global _drag
|
||||
mouse = mouseModule.mouseController
|
||||
if not _drag or not mouse.isAttached():
|
||||
return False
|
||||
snapshot = _drag
|
||||
if (not _Valid(snapshot) or mouse.GetAttachedType() != player.SLOT_TYPE_INVENTORY or
|
||||
mouse.GetAttachedSlotNumber() != snapshot[2] or mouse.GetAttachedItemIndex() != snapshot[3] or
|
||||
mouse.GetAttachedItemCount() != snapshot[4]):
|
||||
mouse.DeattachObject()
|
||||
_drag = None
|
||||
return True
|
||||
if not shop_target or not shop.IsOpen() or shop.IsPrivateShop():
|
||||
return False
|
||||
# Always use the original inventory sale dialog, including anti-sell checks and identity recheck.
|
||||
owner, page, cell, vnum, count = snapshot
|
||||
mouse.DeattachObject()
|
||||
_drag = None
|
||||
owner._InventoryWindow__SellItem(cell)
|
||||
return True
|
||||
|
||||
|
||||
def Reset():
|
||||
global tap, double_tap, dragging, _last, _drag
|
||||
tap = double_tap = dragging = False
|
||||
_last = _drag = None
|
||||
|
||||
|
||||
_Close = game.GameWindow.Close
|
||||
|
||||
def Close(self):
|
||||
Reset()
|
||||
_Close(self)
|
||||
|
||||
|
||||
uiInventory.InventoryWindow.SelectItemSlot = _Select
|
||||
uiInventory.InventoryWindow.UseItemSlot = _Use
|
||||
uiShop.ShopDialog.LoadDialog = _ShopLoad
|
||||
game.GameWindow.Close = Close
|
||||
)PY";
|
||||
@@ -161,6 +161,7 @@ struct GameSingletons
|
||||
std::unique_ptr<GameSingletons> g_game_singletons;
|
||||
bool g_host_hardware_cursor_enabled = false;
|
||||
bool g_touch_input = false;
|
||||
int g_inventory_touch_target = 0;
|
||||
|
||||
bool fail(std::string* error, const std::string& text)
|
||||
{
|
||||
@@ -526,6 +527,76 @@ bool quick_slot_image_uv(CGraphicImage* image, std::string* texture, float uv[4]
|
||||
}
|
||||
}
|
||||
|
||||
// PORT: presentation only; skill validation remains in RequestUseLocalQuickSlot.
|
||||
QuickSlotState LocalQuickSlotState(int localSlotIndex)
|
||||
{
|
||||
QuickSlotState state;
|
||||
if (!g_game_singletons || localSlotIndex < 0 || localSlotIndex >= 8) return state;
|
||||
DWORD type = SLOT_TYPE_NONE, position = 0;
|
||||
auto& player = CPythonPlayer::Instance();
|
||||
player.GetLocalQuickSlotData(static_cast<DWORD>(localSlotIndex), &type, &position);
|
||||
if (type == SLOT_TYPE_SKILL) {
|
||||
state.learned = player.GetSkillLevel(position) > 0;
|
||||
state.active = player.IsSkillActive(position);
|
||||
if (player.IsSkillCoolTime(position))
|
||||
state.remaining = std::max(0.0f, player.GetSkillCoolTime(position) - player.GetSkillElapsedCoolTime(position));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
void SetInventoryTouchTarget(float logicalSize)
|
||||
{
|
||||
if (!g_touch_input || !g_launcher) return;
|
||||
const int size = std::max(48, int(std::ceil(logicalSize)));
|
||||
if (size == g_inventory_touch_target) return;
|
||||
std::string error;
|
||||
if (RunLine(("__import__('mt_mobile_inventory').touch_target = " + std::to_string(size)).c_str(), &error))
|
||||
g_inventory_touch_target = size;
|
||||
}
|
||||
|
||||
void SetInventoryTap(bool tap)
|
||||
{
|
||||
if (!g_touch_input) return;
|
||||
std::string error;
|
||||
RunLine(tap ? "__import__('mt_mobile_inventory').tap = True" :
|
||||
"__import__('mt_mobile_inventory').tap = False", &error);
|
||||
}
|
||||
|
||||
void SetInventoryDoubleTap(bool tap)
|
||||
{
|
||||
if (!g_touch_input) return;
|
||||
std::string error;
|
||||
RunLine(tap ? "__import__('mt_mobile_inventory').double_tap = True" :
|
||||
"__import__('mt_mobile_inventory').double_tap = False", &error);
|
||||
}
|
||||
|
||||
void SetInventoryDrag(bool dragging)
|
||||
{
|
||||
if (!g_touch_input) return;
|
||||
std::string error;
|
||||
RunLine(dragging ? "__import__('mt_mobile_inventory').SetDrag(True)" :
|
||||
"__import__('mt_mobile_inventory').SetDrag(False)", &error);
|
||||
}
|
||||
|
||||
bool FinishInventoryDrag(int x, int y)
|
||||
{
|
||||
if (!g_touch_input || !g_window_manager) return false;
|
||||
UIMouseMove(x, y);
|
||||
bool shop_target = false;
|
||||
for (auto* picked = g_window_manager->GetPointWindow(); picked; picked = picked->GetParent())
|
||||
if (std::string(picked->GetName()) == "ShopDialog") {
|
||||
shop_target = true;
|
||||
break;
|
||||
}
|
||||
std::string result, error;
|
||||
if (!Evaluate(shop_target ? "__import__('mt_mobile_inventory').Drop(True)" :
|
||||
"__import__('mt_mobile_inventory').Drop(False)", &result, &error)) {
|
||||
UIDeattachObject();
|
||||
return true; // Never fall back to a direct shop sale after a failed confirmation handler.
|
||||
}
|
||||
return result == "True" || result == "1";
|
||||
}
|
||||
|
||||
bool LocalQuickSlotIcon(int localSlotIndex, std::string* texture, float uv[4], int* count)
|
||||
{
|
||||
if (!g_game_singletons || localSlotIndex < 0 || localSlotIndex >= 8) return false;
|
||||
@@ -915,8 +986,11 @@ namespace PythonBoot
|
||||
#include "FrameRateOptionScript.inc"
|
||||
#include "UIScaleOptionScript.inc"
|
||||
#include "InventoryPagesScript.inc"
|
||||
#include "MobileInventoryScript.inc"
|
||||
#include "MallHintScript.inc"
|
||||
#include "ServerBonusScript.inc"
|
||||
#include "MobileHUDScript.inc"
|
||||
#include "BiologScript.inc"
|
||||
|
||||
static void install_script_module(const char* c_szModule, const char* c_szScript)
|
||||
{
|
||||
@@ -975,8 +1049,15 @@ bool RunMainScript(const char* lpCmdLine, std::string* error)
|
||||
install_script_module("mt_framerate", c_szFrameRateOptionScript);
|
||||
install_script_module("mt_uiscale", c_szUIScaleOptionScript);
|
||||
install_script_module("mt_inventory", c_szInventoryPagesScript);
|
||||
if (g_touch_input) {
|
||||
g_inventory_touch_target = 0;
|
||||
install_script_module("mt_mobile_inventory", c_szMobileInventoryScript);
|
||||
}
|
||||
install_script_module("mt_mallhint", c_szMallHintScript);
|
||||
install_script_module("mt_bonuses", c_szServerBonusScript);
|
||||
install_script_module("mt_biolog", c_szBiologScript);
|
||||
if (g_touch_input)
|
||||
install_script_module("mt_mobile_hud", c_szMobileHUDScript);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,13 @@ bool AutoHuntIsEnabled();
|
||||
bool AutoHuntAvailable();
|
||||
// The skill or inventory item in the local quick slot: its UI texture name, the icon's (su, sv, eu, ev)
|
||||
// inside it and the item count (0 for a skill).
|
||||
struct QuickSlotState { float remaining = 0; bool learned = true; bool active = false; };
|
||||
QuickSlotState LocalQuickSlotState(int localSlotIndex);
|
||||
void SetInventoryTap(bool tap);
|
||||
void SetInventoryDoubleTap(bool tap);
|
||||
void SetInventoryDrag(bool dragging);
|
||||
bool FinishInventoryDrag(int x, int y);
|
||||
void SetInventoryTouchTarget(float logicalSize);
|
||||
bool LocalQuickSlotIcon(int localSlotIndex, std::string* texture, float uv[4], int* count);
|
||||
// Touch gestures: a Win32 WM_LBUTTONDBLCLK (40250 CPythonApplication::OnMouseLeftButtonDoubleClick),
|
||||
// whether an icon hangs on the cursor (CWindowManager::IsAttaching) and mouseController.DeattachObject().
|
||||
|
||||
Reference in New Issue
Block a user