Skip to content

Commit

Permalink
Fix modded race rendering, new way to make item descs
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzomafizzo committed Apr 20, 2014
1 parent 85e8880 commit 3ce862d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 60 deletions.
12 changes: 6 additions & 6 deletions starcheat/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def get_item_image(self, name):
icon_file = item[0]["image"]
icon = icon_file.split(':')
icon = icon[0]
except KeyError:
except (KeyError, TypeError):
logging.warning("No image key for "+name)
return None

Expand Down Expand Up @@ -888,15 +888,16 @@ def get_preview_image(self, name, gender):
def render_player(self, player):
name = player.get_race()
gender = player.get_gender()
asset_loc = self.get_species(name)[0][1]

body_sprites = self.assets.read("/humanoid/%s/%sbody.png" % (name, gender),
self.assets.vanilla_assets, True)
asset_loc, True)
frontarm_sprites = self.assets.read("/humanoid/%s/frontarm.png" % name,
self.assets.vanilla_assets, True)
asset_loc, True)
backarm_sprites = self.assets.read("/humanoid/%s/backarm.png" % name,
self.assets.vanilla_assets, True)
asset_loc, True)
head_sprites = self.assets.read("/humanoid/%s/%shead.png" % (name, gender),
self.assets.vanilla_assets, True)
asset_loc, True)

body_img = Image.open(BytesIO(body_sprites)).crop((43, 0, 86, 43))
frontarm_img = Image.open(BytesIO(frontarm_sprites)).crop((43, 0, 86, 43))
Expand All @@ -920,7 +921,6 @@ def render_player(self, player):
base.paste(body_img, mask=body_img)
base.paste(frontarm_img, mask=frontarm_img)


return base

def get_hair_image(self, name, hair_type, hair_group, gender):
Expand Down
11 changes: 9 additions & 2 deletions starcheat/gui/appearance.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,16 @@ def write_appearance_values(self):
self.player.set_facial_hair_directives(self.colors["facial_hair"])
self.player.set_facial_mask_directives(self.colors["facial_mask"])

image = self.assets.species().render_player(self.player)
pixmap = QPixmap.fromImage(ImageQt(image)).scaled(86, 86)
# render player preview
try:
image = self.assets.species().render_player(self.player)
pixmap = QPixmap.fromImage(ImageQt(image)).scaled(86, 86)
except (OSError, TypeError, AttributeError):
logging.exception("Couldn't load species images")
pixmap = QPixmap()

self.ui.player_preview.setPixmap(pixmap)

self.main_window.window.setWindowModified(True)

def new_color_edit(self, type):
Expand Down
67 changes: 56 additions & 11 deletions starcheat/gui/itembrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,66 @@
import assets, qt_itembrowser
from config import Config

def format_status_effects(data):
info = "<b>Status Effects:</b><br>"
for status in data:
if "amount" in status:
info += "%s (%s)<br>" % (status["kind"], str(status["amount"]))
else:
info += "%s<br>" % status["kind"]
return info

def format_effects(data):
info = "<b>Effects:</b><br>"
for status in data[0]:
if "amount" in status:
info += "%s (%s)<br>" % (status["kind"], str(status["amount"]))
else:
info += "%s<br>" % status["kind"]
return info

data_format = (
# (key name, format/func)
# key name is name of the key in item data it corresponds to
# format/func is either a format string with 1 %s replacement that the
# key gets passed to or a function that outputs a string using the option
# as input
# order matters
("shortdescription", "<b>%s</b> "),
("itemName", "(%s)<br>"),
("objectName", "(%s)<br>"),
("description", "%s<br><br>"),
("inspectionKind", "<b>Type:</b> %s<br>"),
("rarity", "<b>Rarity:</b> %s<br><br>"),
("statusEffects", format_status_effects),
("effects", format_effects),
("blockRadius", "<b>Mining Radius:</b> %s blocks")
)

def generate_item_info(item_data):
"""Takes inventory item data and makes a detailed description (HTML)."""
info = ""

if item_data == None:
return ""

for fmt in data_format:
if fmt[0] in item_data:
if type(fmt[1]) is str:
info += fmt[1] % str(item_data[fmt[0]])
else:
info += fmt[1](item_data[fmt[0]])

return info


class BrowserItem(QListWidgetItem):
def __init__(self, name, desc):
if desc == "":
display = name
else:
display = "%s (%s)" % (desc, name)
#display = "%s (%s)" % (desc, name)
display = desc
QListWidgetItem.__init__(self, display)
self.name = name

Expand Down Expand Up @@ -87,16 +141,7 @@ def update_item_view(self):
logging.warning("Unable to load item image: "+selected)
self.ui.item_icon.setPixmap(QPixmap())

# TODO: update qt objectnames, already not making sense
try:
self.ui.item_name.setText(item[0]["shortdescription"])
except KeyError:
self.ui.item_name.setText("Missing short description")

try:
self.ui.short_desc.setText(item[0]["description"])
except KeyError:
self.ui.short_desc.setText("Missing description")
self.ui.short_desc.setText(generate_item_info(item[0]))

# populate default variant table
row = 0
Expand Down
21 changes: 9 additions & 12 deletions starcheat/gui/itemedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import assets, qt_itemedit, qt_itemeditoptions, saves
from gui.common import inv_icon, ItemWidget, empty_slot
from gui.itembrowser import ItemBrowser
from gui.itembrowser import ItemBrowser, generate_item_info
from config import Config

class ItemEditOptions():
Expand Down Expand Up @@ -112,18 +112,15 @@ def __init__(self, parent, item, player, browser_category="<all>"):
def update_item_info(self, name, data):
item_info = "<html><body>"

try:
item_info += "<strong>" + data["shortdescription"] + "</strong>"
except KeyError:
try:
item_info += "<strong>" + self.assets.items().get_item(name)[0]["shortdescription"] + "</strong>"
except:
pass
#try:
# item_info += "<strong>" + data["shortdescription"] + "</strong><br>"
#except KeyError:
# try:
# item_info += "<strong>" + self.assets.items().get_item(name)[0]["shortdescription"] + "</strong><br>"
# except:
# pass

try:
item_info += "<p>" + data["description"] + "</p>"
except KeyError:
pass
item_info += generate_item_info(data)

item_info += "</body></html>"
self.ui.desc.setText(item_info)
Expand Down
11 changes: 9 additions & 2 deletions starcheat/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,15 @@ def update_bag(self, bag_name):
column = 0

def update_player_preview(self):
image = self.assets.species().render_player(self.player)
pixmap = QPixmap.fromImage(ImageQt(image)).scaled(86, 86)
try:
image = self.assets.species().render_player(self.player)
pixmap = QPixmap.fromImage(ImageQt(image)).scaled(86, 86)
except (OSError, TypeError, AttributeError):
# TODO: more specific error handling. may as well except all errors
# at this point jeez
logging.exception("Couldn't load species images")
pixmap = QPixmap()

self.ui.player_preview.setPixmap(pixmap)
self.window.setWindowModified(True)

Expand Down
43 changes: 16 additions & 27 deletions starcheat/templates/ItemBrowser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>616</width>
<height>386</height>
<width>600</width>
<height>350</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -87,30 +87,6 @@
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="item_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>15</height>
</size>
</property>
<property name="font">
<font>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>item_name</string>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="2">
<widget class="QLabel" name="item_icon">
<property name="minimumSize">
<size>
Expand Down Expand Up @@ -138,7 +114,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="0" column="1" rowspan="2">
<widget class="QLabel" name="short_desc">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
Expand All @@ -162,6 +138,19 @@
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QTableWidget" name="info">
<property name="minimumSize">
Expand Down

0 comments on commit 3ce862d

Please sign in to comment.