def attachHostNameToSign(self, locator): if self.hostName == '': return nameText = TextNode('nameText') nameText.setCardAsMargin(0.1, 0.1, 0.1, 0.1) nameText.setCardDecal(True) nameText.setCardColor(1.0, 1.0, 1.0, 0.0) r = 232.0 / 255.0 g = 169.0 / 255.0 b = 23.0 / 255.0 nameText.setTextColor(r, g, b, 1) nameText.setAlign(nameText.ACenter) nameText.setFont(ToontownGlobals.getBuildingNametagFont()) nameText.setShadowColor(0, 0, 0, 1) nameText.setBin('fixed') if TTLocalizer.BuildingNametagShadow: nameText.setShadow(*TTLocalizer.BuildingNametagShadow) nameWordWrap = 11.0 nameText.setWordwrap(nameWordWrap) scaleMult = 0.48 houseName = self.hostName nameText.setText(houseName) textWidth = nameText.getWidth() xScale = 1.0 * scaleMult if textWidth > nameWordWrap: xScale = nameWordWrap / textWidth * scaleMult sign_origin = locator namePlate = sign_origin.attachNewNode(nameText) namePlate.setDepthWrite(0) namePlate.setPos(0, 0, 0) namePlate.setScale(xScale)
def attachHostNameToSign(self, locator): if self.hostName == "": return nameText = TextNode("nameText") nameText.setCardAsMargin(0.1, 0.1, 0.1, 0.1) nameText.setCardDecal(True) nameText.setCardColor(1.0, 1.0, 1.0, 0.0) r = 232.0 / 255.0 g = 169.0 / 255.0 b = 23.0 / 255.0 nameText.setTextColor(r, g, b, 1) nameText.setAlign(nameText.ACenter) nameText.setFont(ToontownGlobals.getBuildingNametagFont()) nameText.setShadowColor(0, 0, 0, 1) nameText.setBin("fixed") if TTLocalizer.BuildingNametagShadow: nameText.setShadow(*TTLocalizer.BuildingNametagShadow) nameWordWrap = 11.0 nameText.setWordwrap(nameWordWrap) scaleMult = 0.48 houseName = self.hostName nameText.setText(houseName) textWidth = nameText.getWidth() xScale = 1.0 * scaleMult if textWidth > nameWordWrap: xScale = nameWordWrap / textWidth * scaleMult sign_origin = locator namePlate = sign_origin.attachNewNode(nameText) namePlate.setDepthWrite(0) namePlate.setPos(0, 0, 0) namePlate.setScale(xScale)
def attachHostNameToSign(self, locator): if (self.hostName == ""): # don't bother putting an empty string up return nameText = TextNode('nameText') nameText.setCardAsMargin(0.1, 0.1, 0.1, 0.1) nameText.setCardDecal(True) nameText.setCardColor(1.0, 1.0, 1.0, 0.0) r = 232.0 /255.0 #self.randomGenerator.random() g = 169.0 / 255.0 #self.randomGenerator.random() b = 23.0 / 255.0 #self.randomGenerator.random() nameText.setTextColor(r,g,b,1) nameText.setAlign(nameText.ACenter) nameText.setFont(ToontownGlobals.getBuildingNametagFont()) nameText.setShadowColor(0, 0, 0, 1) nameText.setBin('fixed') if TTLocalizer.BuildingNametagShadow: nameText.setShadow(*TTLocalizer.BuildingNametagShadow) nameWordWrap = 11.0 nameText.setWordwrap(nameWordWrap) scaleMult = 0.48 #xScale = 1.0 * scaleMult #numLines = 0 houseName = self.hostName nameText.setText(houseName) #self.nameText = nameText # Since the text is wordwrapped, it may flow over more # than one line. Try to adjust the scale and position of # the sign accordingly. #textHeight = nameText.getHeight() - 2 textWidth = nameText.getWidth() xScale = 1.0 * scaleMult if textWidth > nameWordWrap: xScale = nameWordWrap / textWidth * scaleMult sign_origin = locator # self.house.find("**/sign_origin") #pos = sign_origin.getPos() #sign_origin.setPosHpr(pos[0],pos[1],pos[2]+.15*textHeight,90,0,0) namePlate = sign_origin.attachNewNode(nameText) namePlate.setDepthWrite(0) namePlate.setPos(0,0,0) namePlate.setScale(xScale)
class TextBoard(): def __init__(self, text_color=(1, 1, 1), max_nr_rows=3, nr_char_per_row=20, frame_color=(0, 0, 0), frame_padding=0.4, frame_line_width=2, background_color=(1, 1, 0), background_padding=0.8): #print "TextBoard::init" # everything that belongs to this TextBoard will be stored under the root node self.root_node_path = render.attachNewNode(PandaNode('')) # create the text node that will be the TextBoard self.text_node = TextNode('') self.text_node_path = self.root_node_path.attachNewNode(self.text_node) self.set_max_nr_rows(max_nr_rows) r, g, b = text_color self.set_text_color(r, g, b) self.text_node.setAlign( TextNode.ALeft) # TextNode.ALeft, TextNode.ACenterba letter_width, letter_height = self._compute_letter_size() self.max_row_length = nr_char_per_row * letter_width self.text_node.setWordwrap(self.max_row_length) width, height = self._compute_max_text_size() self.text_node_path.setPos(0.5 * background_padding, -0.01, -letter_height) self.background_node_path = self.root_node_path.attachNewNode( PandaNode('background_node')) self._create_background(self.background_node_path, width + background_padding, height + background_padding + letter_height) self.frame_node_path = self.root_node_path.attachNewNode( PandaNode('frame_node')) self._create_frame(self.frame_node_path, width + background_padding, height + background_padding + letter_height) r, g, b = frame_color self.set_frame_color(r, g, b) self.set_frame_line_width(frame_line_width) r, g, b = background_color self.set_background_color(r, g, b) def _compute_max_text_size(self): self.text_node.setText(' ') width = 0 while (not self.text_node.getWidth() == width) and self.text_node.getWidth() < self.max_row_length: width = self.text_node.getWidth() self.text_node.appendText(' ') while self.text_node.getNumRows() < self.text_node.getMaxRows(): self.text_node.appendText('\n') return self.text_node.getWidth(), self.text_node.getHeight() def _compute_letter_size(self): self.text_node.setText('W') return self.text_node.getWidth(), self.text_node.getHeight() def _create_background(self, root_node_path, width, height): node, _vdata = create_side((0, 0), (width, -height)) root_node_path.attachNewNode(node) def _create_frame(self, root_node_path, width, height): # top node, _vdata = create_line(0, 0, width, 0) root_node_path.attachNewNode(node) # right side node, _vdata = create_line(width, 0, width, -height) root_node_path.attachNewNode(node) # bottom side node, _vdata = create_line(width, -height, 0, -height) root_node_path.attachNewNode(node) # right side node, _vdata = create_line(0, -height, 0, 0) root_node_path.attachNewNode(node) def get_node_path(self): return self.root_node_path def set_scale(self, scale): self.root_node_path.setScale(scale) def set_center_pos_xz(self, x, z): self.set_center_pos(x, 0, z) def set_center_pos(self, x, y, z): width, height = get_bounding_width_height(self.get_node_path()) self.get_node_path().setPos(x - width / 2.0, y, z + height / 2.0) def set_text(self, text=''): self.text_node.clearText() self.text_node.setText(text) def set_text_color(self, r, g, b, alpha=1): self.text_node.setTextColor(r, g, b, alpha) def set_max_nr_rows(self, n): self.text_node.setMaxRows(n) def set_frame_visible(self, visible): rgba = self.frame_node_path.getColor() r = rgba[0] g = rgba[1] b = rgba[2] if visible: alpha = 1 else: alpha = 0 self.frame_node_path.setColor(r, g, b, alpha) def set_frame_color(self, r, g, b, alpha=1): self.frame_node_path.setColor(r, g, b, alpha) def set_frame_line_width(self, width): self.frame_node_path.setRenderModeThickness(width) def set_background_visible(self, visible): rgba = self.background_node_path.getColor() r = rgba[0] g = rgba[1] b = rgba[2] if visible: alpha = 1 else: alpha = 0 self.background_node_path.setColor(r, g, b, alpha) def set_background_color(self, r, g, b, alpha=1): self.background_node_path.setColor(r, g, b, alpha)
class TextBoard(): def __init__(self, text_color=(1,1,1), max_nr_rows=3, nr_char_per_row=20, frame_color=(0,0,0), frame_padding=0.4, frame_line_width=2, background_color=(1,1,0), background_padding=0.8): #print "TextBoard::init" # everything that belongs to this TextBoard will be stored under the root node self.root_node_path = render.attachNewNode(PandaNode('')) # create the text node that will be the TextBoard self.text_node = TextNode('') self.text_node_path = self.root_node_path.attachNewNode(self.text_node) self.set_max_nr_rows(max_nr_rows) r,g,b = text_color self.set_text_color(r, g, b) self.text_node.setAlign(TextNode.ALeft) # TextNode.ALeft, TextNode.ACenterba letter_width, letter_height = self._compute_letter_size() self.max_row_length = nr_char_per_row * letter_width self.text_node.setWordwrap(self.max_row_length) width, height = self._compute_max_text_size() self.text_node_path.setPos(0.5*background_padding,-0.01,-letter_height) self.background_node_path = self.root_node_path.attachNewNode(PandaNode('background_node')) self._create_background(self.background_node_path, width+background_padding, height+background_padding+letter_height) self.frame_node_path = self.root_node_path.attachNewNode(PandaNode('frame_node')) self._create_frame(self.frame_node_path, width+background_padding, height+background_padding+letter_height) r,g,b = frame_color self.set_frame_color(r, g, b) self.set_frame_line_width(frame_line_width) r,g,b = background_color self.set_background_color(r, g, b) def _compute_max_text_size(self): self.text_node.setText(' ') width = 0 while (not self.text_node.getWidth() == width) and self.text_node.getWidth() < self.max_row_length: width = self.text_node.getWidth() self.text_node.appendText(' ') while self.text_node.getNumRows() < self.text_node.getMaxRows(): self.text_node.appendText('\n') return self.text_node.getWidth(), self.text_node.getHeight() def _compute_letter_size(self): self.text_node.setText('W') return self.text_node.getWidth(), self.text_node.getHeight() def _create_background(self, root_node_path, width, height): node, _vdata = create_side((0,0), (width, -height)) root_node_path.attachNewNode(node) def _create_frame(self, root_node_path, width, height): # top node, _vdata = create_line(0, 0, width, 0) root_node_path.attachNewNode(node) # right side node, _vdata = create_line(width, 0, width, -height) root_node_path.attachNewNode(node) # bottom side node, _vdata = create_line(width, -height, 0, -height) root_node_path.attachNewNode(node) # right side node, _vdata = create_line(0, -height, 0, 0) root_node_path.attachNewNode(node) def get_node_path(self): return self.root_node_path def set_scale(self, scale): self.root_node_path.setScale(scale) def set_center_pos_xz(self, x, z): self.set_center_pos(x, 0, z) def set_center_pos(self, x, y, z): width, height = get_bounding_width_height(self.get_node_path()) self.get_node_path().setPos(x-width/2.0, y, z+height/2.0) def set_text(self, text=''): self.text_node.clearText() self.text_node.setText(text) def set_text_color(self, r, g, b, alpha=1): self.text_node.setTextColor(r,g,b,alpha) def set_max_nr_rows(self, n): self.text_node.setMaxRows(n) def set_frame_visible(self, visible): rgba = self.frame_node_path.getColor() r = rgba[0] g = rgba[1] b = rgba[2] if visible: alpha = 1 else: alpha = 0 self.frame_node_path.setColor(r, g, b, alpha) def set_frame_color(self, r, g, b, alpha=1): self.frame_node_path.setColor(r, g, b, alpha) def set_frame_line_width(self, width): self.frame_node_path.setRenderModeThickness(width) def set_background_visible(self, visible): rgba = self.background_node_path.getColor() r = rgba[0] g = rgba[1] b = rgba[2] if visible: alpha = 1 else: alpha = 0 self.background_node_path.setColor(r, g, b, alpha) def set_background_color(self, r, g, b, alpha=1): self.background_node_path.setColor(r,g,b,alpha)