Files
m2dev-client/assets/root/uiBiolog.py
2026-04-16 17:27:05 +02:00

143 lines
3.8 KiB
Python

import time
import net
import player
import quest
import ui
class BiologWindow(ui.BoardWithTitleBar):
TITLE_PREFIX = "Biolog Stage "
STAGE_TARGETS = {
1 : 10,
2 : 15,
3 : 20,
4 : 20,
5 : 25,
6 : 30,
7 : 30,
8 : 40,
9 : 40,
}
def __init__(self):
ui.BoardWithTitleBar.__init__(self)
self.lastRefreshTime = 0.0
self.AddFlag("float")
self.AddFlag("movable")
self.SetSize(230, 165)
self.SetTitleName("Biolog")
self.SetCloseEvent(self.Hide)
self.__CreateChildren()
self.Hide()
def __del__(self):
ui.BoardWithTitleBar.__del__(self)
def __CreateChildren(self):
self.statusLine = self.__CreateValueLine(15, 36)
self.stageLine = self.__CreateValueLine(15, 58)
self.itemLine = self.__CreateValueLine(15, 80)
self.progressLine = self.__CreateValueLine(15, 102)
self.cooldownLine = self.__CreateValueLine(15, 124)
submitButton = ui.Button()
submitButton.SetParent(self)
submitButton.SetPosition(134, 132)
submitButton.SetUpVisual("d:/ymir work/ui/public/small_thin_button_01.sub")
submitButton.SetOverVisual("d:/ymir work/ui/public/small_thin_button_02.sub")
submitButton.SetDownVisual("d:/ymir work/ui/public/small_thin_button_03.sub")
submitButton.SetText("Submit")
submitButton.SetEvent(self.__OnSubmit)
submitButton.Show()
self.submitButton = submitButton
def __CreateValueLine(self, x, y):
textLine = ui.TextLine()
textLine.SetParent(self)
textLine.SetPosition(x, y)
textLine.SetOutline()
textLine.Show()
return textLine
def __GetBiologData(self):
questCount = min(quest.GetQuestCount(), quest.QUEST_MAX_NUM)
for questIndex in range(questCount):
(questName, questIcon, questCounterName, questCounterValue) = quest.GetQuestData(questIndex)
if not questName.startswith(self.TITLE_PREFIX):
continue
try:
stageIndex = int(questName[len(self.TITLE_PREFIX):])
except:
continue
totalRequired = self.STAGE_TARGETS.get(stageIndex, questCounterValue)
(clockName, clockValue) = quest.GetQuestLastTime(questIndex)
return {
"stage" : stageIndex,
"itemName" : questCounterName,
"remaining" : max(questCounterValue, 0),
"required" : max(totalRequired, 0),
"clockName" : clockName,
"clockValue" : max(clockValue, 0),
}
return None
def __FormatCooldown(self, seconds):
hours = seconds // 3600
minutes = (seconds // 60) % 60
return "%02d:%02d:%02d" % (hours, minutes, seconds % 60)
def __RefreshLockedState(self):
if player.GetStatus(player.LEVEL) < 30:
self.statusLine.SetText("Status: Unlocks at level 30")
else:
self.statusLine.SetText("Status: No active biolog stage")
self.stageLine.SetText("Stage: -")
self.itemLine.SetText("Item: -")
self.progressLine.SetText("Progress: -")
self.cooldownLine.SetText("Cooldown: -")
self.submitButton.Hide()
def Refresh(self):
biologData = self.__GetBiologData()
if not biologData:
self.__RefreshLockedState()
return
submitted = max(biologData["required"] - biologData["remaining"], 0)
self.statusLine.SetText("Status: %s" % ("Ready" if biologData["clockValue"] <= 0 else "Cooldown"))
self.stageLine.SetText("Stage: %d / 9" % biologData["stage"])
self.itemLine.SetText("Item: %s" % biologData["itemName"])
self.progressLine.SetText("Progress: %d / %d" % (submitted, biologData["required"]))
if biologData["clockValue"] > 0 and len(biologData["clockName"]) > 0:
self.cooldownLine.SetText("Cooldown: %s" % self.__FormatCooldown(biologData["clockValue"]))
else:
self.cooldownLine.SetText("Cooldown: Ready")
self.submitButton.Show()
def Show(self):
self.Refresh()
ui.BoardWithTitleBar.Show(self)
def OnUpdate(self):
currentTime = time.time()
if currentTime - self.lastRefreshTime < 0.2:
return
self.lastRefreshTime = currentTime
self.Refresh()
def __OnSubmit(self):
net.SendBiologSubmit()
self.lastRefreshTime = 0.0
self.Refresh()