respect scaling in char.ini and default for smooth scaling for big sprites

This commit is contained in:
cidoku 2025-02-19 18:20:03 -03:00
parent f73b3422d1
commit 3f44b65c60
2 changed files with 50 additions and 26 deletions

View File

@ -65,6 +65,10 @@ C_GRAY = 8
C_RAINBOW = 9
C_BLACK = 10
SCALING_AUTO = 0
SCALING_PIXEL = 1
SCALING_SMOOTH = 2
DOWNLOAD_BLACKLIST = []
VIEWPORT_W = 256*2
@ -83,12 +87,6 @@ def encode_ao_str(text):
def get_char_ini(char, section, value, default=""):
tempini = ConfigParser()
# with open(AOpath + 'characters/' + char.lower() + '/char.ini', 'r') as file:
# for line in file:
# try:
# tempini.readfp(file)
# except:
# pass
return ini.read_ini(AOpath + 'characters/' + char.lower() + '/char.ini', section, value, default)
def get_option(section, value, default=""):
@ -237,6 +235,7 @@ class AOCharMovie(QtGui.QLabel):
self.time_mod = 62
self.play_once = True
self.m_flipped = False
self.scaling = SCALING_AUTO
self.m_movie = QtGui.QMovie()
@ -260,7 +259,7 @@ class AOCharMovie(QtGui.QLabel):
def set_flipped(self, flip):
self.m_flipped = flip
def play(self, p_char, p_emote, emote_prefix):
def play(self, p_char, p_emote, emote_prefix, scaling = SCALING_AUTO):
if p_emote[0] == "/" or p_emote[0] == "/":
p_emote = p_emote[1:]
elif "../../characters" in p_emote:
@ -274,6 +273,8 @@ class AOCharMovie(QtGui.QLabel):
self.pillow_frames = []
self.pillow_frame = 0
self.scaling = scaling
p_char = p_char.lower().decode('utf-8')
original_path = AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".gif"
@ -347,7 +348,7 @@ class AOCharMovie(QtGui.QLabel):
self.show()
def play_pre(self, p_char, p_emote, duration):
def play_pre(self, p_char, p_emote, duration, scaling = SCALING_AUTO):
p_char = p_char.lower()
gif_path = AOpath+"characters/"+p_char+"/"+p_emote+".gif"
apng_path = AOpath+"characters/"+p_char+"/"+p_emote+".apng"
@ -392,9 +393,9 @@ class AOCharMovie(QtGui.QLabel):
self.m_movie.setSpeed(int(percentage_modifier))
self.pillow_speed = percentage_modifier / 100.
self.play(p_char, p_emote, "")
self.play(p_char, p_emote, "", scaling)
def play_talking(self, p_char, p_emote):
def play_talking(self, p_char, p_emote, scaling = SCALING_AUTO):
p_char = p_char.lower()
gif_path = AOpath + 'characters/' + p_char + '/(b)' + p_emote + '.gif'
@ -406,9 +407,9 @@ class AOCharMovie(QtGui.QLabel):
self.play_once = False
self.m_movie.setSpeed(100)
self.pillow_speed = 1
self.play(p_char, p_emote, '(b)')
self.play(p_char, p_emote, '(b)', scaling)
def play_idle(self, p_char, p_emote):
def play_idle(self, p_char, p_emote, scaling = SCALING_AUTO):
p_char = p_char.lower()
gif_path = AOpath + 'characters/' + p_char + '/(a)' + p_emote + '.gif'
@ -420,18 +421,28 @@ class AOCharMovie(QtGui.QLabel):
self.play_once = False
self.m_movie.setSpeed(100)
self.pillow_speed = 1
self.play(p_char, p_emote, '(a)')
self.play(p_char, p_emote, '(a)', scaling)
def stop(self):
self.m_movie.stop()
self.preanim_timer.stop()
self.hide()
def get_transform(self, smooth_condition=True):
if self.scaling == SCALING_PIXEL:
return QtCore.Qt.FastTransformation
elif self.scaling == SCALING_SMOOTH:
return QtCore.Qt.SmoothTransformation
elif smooth_condition:
return QtCore.Qt.SmoothTransformation
else:
return QtCore.Qt.FastTransformation
@QtCore.pyqtSlot(int)
def frame_change(self, n_frame):
f_img = self.m_movie.currentImage().mirrored(self.m_flipped, False)
if not f_img.isNull() and (f_img.size().width() != VIEWPORT_W or f_img.size().height() != VIEWPORT_H):
f_img = f_img.scaled(VIEWPORT_W, VIEWPORT_H, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.FastTransformation)
if not f_img.isNull():
f_img = f_img.scaled(VIEWPORT_W, VIEWPORT_H, QtCore.Qt.KeepAspectRatioByExpanding, self.get_transform(f_img.size().height() > VIEWPORT_H))
f_pixmap = QtGui.QPixmap.fromImage(f_img)
self.setPixmap(f_pixmap)
@ -457,8 +468,8 @@ class AOCharMovie(QtGui.QLabel):
def set_pillow_frame(self):
f_img = self.pillow_frames[self.pillow_frame][0].mirrored(self.m_flipped, False)
if not f_img.isNull() and (f_img.size().width() != VIEWPORT_W or f_img.size().height() != VIEWPORT_H):
f_img = f_img.scaled(VIEWPORT_W, VIEWPORT_H, QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.FastTransformation)
if not f_img.isNull():
f_img = f_img.scaled(VIEWPORT_W, VIEWPORT_H, QtCore.Qt.KeepAspectRatioByExpanding, self.get_transform(f_img.size().height() > VIEWPORT_H))
f_pixmap = QtGui.QPixmap.fromImage(f_img)
self.setPixmap(f_pixmap)
@ -689,6 +700,7 @@ class gui(QtGui.QWidget):
charid = -1
login = False
privateinv = False
scaling = [SCALING_AUTO, SCALING_AUTO]
#ICchat = QtCore.pyqtSignal(str, str, str, str, str, str, int, int, int, int, int, int, int, int)
#ICchat = QtCore.pyqtSignal(list)
@ -2339,13 +2351,17 @@ class gui(QtGui.QWidget):
self.objectionview.raise_()
self.whiteflashlab.raise_()
self.scaling[1] = self.get_scaling(ini.read_ini(AOpath + 'characters/' + self.m_chatmessage[OTHER_NAME] + '/char.ini', "options", "scaling").lower())
self.sidechar.set_flipped(self.m_chatmessage[OTHER_FLIP] == "1")
self.sidechar.play_idle(self.m_chatmessage[OTHER_NAME], self.m_chatmessage[OTHER_EMOTE])
self.sidechar.play_idle(self.m_chatmessage[OTHER_NAME], self.m_chatmessage[OTHER_EMOTE], self.scaling[1])
else:
self.sidechar.hide()
self.sidechar.move(0, 0)
self.scaling[0] = self.get_scaling(ini.read_ini(AOpath + 'characters/' + self.m_chatmessage[CHARNAME] + '/char.ini', "options", "scaling").lower())
if (emote_mod == 1 or emote_mod == 2 or emote_mod == 6) and self.m_chatmessage[PREANIM] != "-":
# sfx_delay = int(self.m_chatmessage[SFX_DELAY]) * 60
# if sfx_delay > 0:
@ -2359,6 +2375,14 @@ class gui(QtGui.QWidget):
else:
self.play_preanim(True)
def get_scaling(self, scaling_str):
if scaling_str == "pixel" or scaling_str == "fast":
return SCALING_PIXEL
elif scaling_str == "smooth":
return SCALING_SMOOTH
else:
return SCALING_AUTO
def play_preanim(self, noninterrupting):
f_char = self.m_chatmessage[CHARNAME]
f_preanim = self.m_chatmessage[PREANIM]
@ -2383,7 +2407,7 @@ class gui(QtGui.QWidget):
self.anim_state = 1
self.preanim_done()
self.char.play_pre(f_char, f_preanim, preanim_duration)
self.char.play_pre(f_char, f_preanim, preanim_duration, self.scaling[0])
if noninterrupting:
self.anim_state = 4
else:
@ -2456,10 +2480,10 @@ class gui(QtGui.QWidget):
f_emote = self.m_chatmessage[ANIM]
if f_anim_state == 2:
self.char.play_talking(f_char, f_emote)
self.char.play_talking(f_char, f_emote, self.scaling[0])
self.anim_state = 2
else:
self.char.play_idle(f_char, f_emote)
self.char.play_idle(f_char, f_emote, self.scaling[0])
self.anim_state = 3
if exists(AOpath+"callwords.ini"):
@ -2564,7 +2588,7 @@ class gui(QtGui.QWidget):
self.text_state = 2
if self.anim_state != 4:
self.anim_state = 3
self.char.play_idle(self.m_chatmessage[CHARNAME], self.m_chatmessage[ANIM])
self.char.play_idle(self.m_chatmessage[CHARNAME], self.m_chatmessage[ANIM], self.scaling[0])
else:
f_character2 = f_message[self.tick_pos]
f_character = QtCore.QString(f_character2)
@ -2609,7 +2633,7 @@ class gui(QtGui.QWidget):
if not self.entire_message_is_blue and self.anim_state != 4:
f_char = self.m_chatmessage[CHARNAME]
f_emote = self.m_chatmessage[ANIM]
self.char.play_idle(f_char, f_emote)
self.char.play_idle(f_char, f_emote, self.scaling[0])
elif f_character == ")" and not self.next_character_is_not_special and self.inline_color_stack:
if self.inline_color_stack[-1] == INLINE_BLUE:
@ -2625,7 +2649,7 @@ class gui(QtGui.QWidget):
if self.inline_blue_depth == 0 and self.anim_state != 4 and not (self.tick_pos+1 >= len(f_message)):
f_char = self.m_chatmessage[CHARNAME]
f_emote = self.m_chatmessage[ANIM]
self.char.play_talking(f_char, f_emote)
self.char.play_talking(f_char, f_emote, self.scaling[0])
else:
self.next_character_is_not_special = True
self.tick_pos -= 1

View File

@ -626,7 +626,7 @@ class AOServerInfo(QtCore.QThread):
type = int(network[0])
areas[type] = [network[i] for i in range(1, len(network))]
areas_len = len(areas[type])
print '[client]', 'the server has %d areas' % areas_len
print '[client]', 'The server has %d areas' % areas_len
for i in range(areas_len):
areas[4].append(musiclist[0])
del musiclist[0]