def show_result(self, target, value): textnode = p3d.TextNode('effect result') textnode.set_align(p3d.TextNode.ACenter) textnode.set_text(value) textnp = self.rendernp.attach_new_node(textnode) textnp.set_billboard_point_eye() textnp.set_bin("fixed", 0) textnp.set_depth_test(False) textnp.set_depth_write(False) textnp.set_shader_auto(True) textnp.set_color_scale((0, 0, 0, 1)) textnp.set_light_off() textnp.hide() def func(): textnp.set_pos(target.as_nodepath, 0, 0, 2) intervals.Sequence( intervals.Func(textnp.show), intervals.LerpPosInterval( textnp, 1.0, textnp.get_pos() + p3d.LVector3(0, 0, 0.5)), intervals.Func(textnp.remove_node), ).start() return intervals.Func(func)
def update_move_debug(self, start_position: core.Point3, new_position: core.Point3): self.clear_debug() self._debug = self._scene.attach_new_node("debug") self._debug.set_depth_write(False) self._debug.set_depth_test(False) self._debug.set_bin("fixed", constants.FRONT_MOST) direction = new_position - start_position half_direction = direction / 2 self._debug.set_pos(start_position + half_direction) debug_segments = core.LineSegs("debug_line") debug_segments.set_thickness(4) debug_segments.set_color(0, 1, 1, 0.85) debug_segments.draw_to(-half_direction) debug_segments.draw_to(half_direction) self._debug.attach_new_node(debug_segments.create()) debug_text_node = core.TextNode("debug_text") theta = math.atan2(direction.y, direction.x) theta = math.degrees(theta) text = f"Angle: {theta}\n" text += f"Delta: {direction}" debug_text_node.set_text(text) debug_text_node.set_align(core.TextNode.A_center) debug_text: core.NodePath = self._debug.attach_new_node(debug_text_node) debug_text.set_billboard_axis() debug_text.set_scale(-96)
def __init__(self, pos, world): self.id = next(Dorf.idgen) self.world = world self.node = loader.loadModel('media/models/dorfPH.egg') self.text = core.TextNode('dorf') self.text.setText('Dorf {}'.format(self.id)) self.text.setAlign(core.TextNode.ACenter) self.text.setTextColor(1, 1, 0.5, 1) self.text.setShadow(0.1, 0.1) self.text.setShadowColor(0, 0, 0, 0.8) self.textnode = self.node.attachNewNode(self.text) self.textnode.setBillboardPointEye() self.textnode.setPos(0, 0, 1.1) self.textnode.setScale(0.4) self.textnode.setDepthWrite(False) self.textnode.setDepthTest(False) self.textnode.setShaderOff() self.x = int(pos.x) self.y = int(pos.y) self.z = 0 self.next = None self.dir = (1, 0) taskMgr.doMethodLater(0.5, self.move, 'Move dorf') self.set_z(int(pos.z)) self.node.setPos(pos.x, pos.y, 0) self.particles = ParticleEffect() self.particles.loadConfig('media/sparks.ptf') self.particles.reparentTo(self.node)
def __add_number_node(self, row=None, col=None): base_aspect = common.SCR_RES[0] / common.SCR_RES[1] aspect = self.win.get_x_size() / self.win.get_y_size() aspect = 1 / base_aspect * aspect if row is not None and col is None: a = self.__h_txt_grid ai = row nm = 'row' i = len(a[ai]) v = self.__h_txt_values[ai][i] x = (common.NG_TXT_XX + i * common.NG_TXT_XXO) * aspect y = (common.NG_TXT_XY + row * common.NG_TXT_XYO) * aspect elif col is not None and row is None: a = self.__v_txt_grid ai = col nm = 'col' i = len(a[ai]) v = self.__v_txt_values[ai][i] x = (common.NG_TXT_YX + col * common.NG_TXT_YXO) * aspect y = (common.NG_TXT_YY + i * common.NG_TXT_YYO) * aspect else: raise ValueError('expected either row or col') tn = core.TextNode(f'nonogramm_{nm}{ai}/{i}') tnp = self.__text.attach_new_node(tn) tn.set_text(v) tnp.set_scale(0.05) tnp.set_pos( x, 0, y ) a[ai].append(tnp)
def __update_hint(self, ft): if self.__text_node is None: self.__text_node = core.TextNode('hint') tnp = self.__hints.attach_new_node(self.__text_node) tnp.set_scale(0.05) tnp.set_pos(-0.4, 0, 0.5) msg, duration = self.__hint_queue.pop(0) self.__text_node.set_text(msg) self.__next_txt_change = ft + duration
def __init__(self, text="", font=None, color=None): self.node = core.TextNode("") self.node.text = text self.node.align = core.TextNode.A_center if font is not None: self.node.font = font if color is not None: self.node.text_color = color
def _make_debug_text(self, message: str, position: core.Point3, colour: core.Vec4, theta: float): node_name = str(uuid.uuid4()) text_node = core.TextNode(node_name) text_node.set_text(message) text_node.set_align(core.TextNode.A_center) text: core.NodePath = self._debug_geometry.attach_new_node(text_node) text.set_color(colour) text.set_pos(position) text.set_h(theta) text.set_scale(-192)
def test_textnode_flatten_color(): text = core.TextNode("test") text.text_color = (0, 0, 0, 1) path = core.NodePath(text) color = core.LColor(1, 0, 0, 1) path.set_color(color) path.flatten_strong() assert text.text_color.almost_equal(color) assert text.shadow_color.almost_equal(color) assert text.frame_color.almost_equal(color) assert text.card_color.almost_equal(color)
def test_textnode_frame_actual(): text = core.TextNode("test") text.text = "Test" l, r, b, t = 0.1, 0.2, 0.3, 0.4 text.set_frame_actual(l, r, b, t) assert text.has_frame() assert not text.is_frame_as_margin() assert text.get_frame_as_set() == (l, r, b, t) frame_actual = text.get_frame_actual() frame_expect = core.LVecBase4(l, r, b, t) assert frame_actual == frame_expect
def test_textnode_card_actual(): text = core.TextNode("test") text.text = "Test" l, r, b, t = 0.1, 0.2, 0.3, 0.4 text.set_card_actual(l, r, b, t) assert text.has_card() assert not text.is_card_as_margin() assert text.get_card_as_set() == (l, r, b, t) card_actual = text.get_card_actual() card_expect = core.LVecBase4(l, r, b, t) assert card_actual == card_expect
def test_textnode_frame_as_margin(): text = core.TextNode("test") text.text = "Test" l, r, b, t = 0.1, 0.2, 0.3, 0.4 text.set_frame_as_margin(l, r, b, t) assert text.has_frame() assert text.is_frame_as_margin() assert text.get_frame_as_set() == (l, r, b, t) frame_actual = text.get_frame_actual() frame_expect = core.LVecBase4(text.get_left() - l, text.get_right() + r, text.get_bottom() - b, text.get_top() + t) assert frame_actual == frame_expect
def load_monster_models(self, forms=None, weapons=None): for monact in self.monster_actors: monact.cleanup() monact.remove_node() self.monster_actors = [] labels = [] if forms is None: forms = [i.form for i in self.player.monsters] labels = [i.name for i in self.player.monsters] weapons = [i.weapon for i in self.player.monsters] if not labels: labels = itertools.repeat('') if weapons is None: weapons = itertools.repeat(None) stride = 2 offset = 0 for form, weapon, labelstr in zip(forms, weapons, labels): actor = MonsterActor(form, self.monsters_root, weapon) actor.set_h(45) actor.set_pos(self.monsters_root, p3d.LVector3(offset, 0, 0)) self.monster_actors.append(actor) label = p3d.TextNode('monster label') label.set_align(p3d.TextNode.ACenter) label.set_text(labelstr) labelnp = actor.attach_new_node(label) labelnp.set_pos(0, 0, 2.3) labelnp.set_scale(0.2) labelnp.set_billboard_point_eye() labelnp.set_bin("fixed", 0) labelnp.set_depth_test(False) labelnp.set_depth_write(False) labelnp.set_shader_auto(True) labelnp.set_color_scale((0, 0, 0, 1)) labelnp.set_light_off() offset += stride if self.monster_actors: self.lighting.recalc_bounds(self.monsters_root)
def printText(self, name, message, color): text = pcore.TextNode( name ) # create a TextNode. Note that 'name' is not the text, rather it is a name that identifies the object. text.setText(message) # Here we set the text of the TextNode x, y, z = color # break apart the color tuple text.setTextColor(x, y, z, 1) # Set the text color from the color tuple text3d = pcore.NodePath( text ) # Here we create a NodePath from the TextNode, so that we can manipulate it 'in world' text3d.reparentTo( self.cosy ) # This is important. We reparent the text NodePath to the 'render' tree. text3d.setTwoSided(True) # The render tree contains what is going to be rendered into the 3D WORLD. # If we reparented it to 'render2d' instead, it would appear in the 2D WORLD. # The 2D WORLD, from the documentation, is as if someone had written on your computer screen. return text3d # return the NodePath for further use
def test_textnode_write(): out = core.StringStream() text = core.TextNode("test") text.write(out, 0) assert out.data.startswith(b"TextNode test")
def setup_geometry(self, all_geometry: sector_geometry.SectorGeometry): self._parts = {} debug_display_node = core.TextNode("debug") text = f"Angle: {self.get_direction_theta()}\n" text += f"Direction: {self.get_direction()}\n" text += f"Length: {self.get_direction().length()}" debug_display_node.set_text(text) debug_display_node.set_align(core.TextNode.A_center) self._debug_display = all_geometry.scene.attach_new_node( debug_display_node) self._debug_display.set_pos(self.get_centre()) self._debug_display.set_billboard_axis() self._debug_display.set_scale(-96) self._debug_display.hide() all_geometry.add_vertex_highlight_geometry( self.point_1, self._sector.floor_z_at_point(self.point_1), self._sector.ceiling_z_at_point(self.point_1), self.vertex_part_name, ) thickness = 4 if self._wall.wall.stat.poly_blue: colour = core.Vec4(0, 0, 1, 1) elif self._wall.wall.stat.poly_green: colour = core.Vec4(0, 1, 0, 1) elif self._other_side_wall is None: colour = core.Vec4(1, 1, 1, 1) elif self._wall.wall.stat.blocking2: thickness = 16 colour = core.Vec4(1, 0, 1, 1) elif self._wall.wall.stat.blocking: colour = core.Vec4(1, 0, 1, 1) else: colour = core.Vec4(1, 0, 0, 1) all_geometry.add_2d_geometry(self.point_1, self.point_2, colour, thickness) all_geometry.add_2d_highlight_geometry(self.default_part, self.point_1, self.point_2) if self._other_side_wall is None: if self._wall.wall.stat.align: peg = self._sector.floor_z else: peg = self._sector.ceiling_z self._parts["full"] = sector_geometry.GeometryPart( self._wall.wall.picnum, self._wall.wall.palette, self._wall.data.pan_always, "full", ) self._make_wall_part( all_geometry, peg, lambda point: self._sector.floor_z_at_point(point), lambda point: self._sector.ceiling_z_at_point(point), self._parts["full"], ) else: if not self.other_side_sector.sector.sector.floor_stat.parallax: if self._wall.wall.stat.bottom_swap: lower_picnum = self._other_side_wall._wall.wall.picnum lower_stat = self._other_side_wall._wall.wall.stat else: lower_picnum = self._wall.wall.picnum lower_stat = self._wall.wall.stat if lower_stat.align: peg = self._sector.ceiling_z else: peg = self.other_side_sector.floor_z self._parts["lower"] = sector_geometry.GeometryPart( lower_picnum, self._wall.wall.palette, self._wall.data.pan_always, "lower", ) self._make_wall_part( all_geometry, peg, lambda point: self._sector.floor_z_at_point(point), lambda point: self.other_side_sector.floor_z_at_point(point ), self._parts["lower"], stat=lower_stat, ) if not self.other_side_sector.sector.sector.ceiling_stat.parallax: if self._wall.wall.stat.align: peg = self._sector.ceiling_z else: peg = self.other_side_sector.ceiling_z self._parts["upper"] = sector_geometry.GeometryPart( self._wall.wall.picnum, self._wall.wall.palette, self._wall.data.pan_always, "upper", ) self._make_wall_part( all_geometry, peg, lambda point: self.other_side_sector.ceiling_z_at_point( point), lambda point: self._sector.ceiling_z_at_point(point), self._parts["upper"], ) if self._has_wall_mask: if self._wall.wall.stat.align: peg = min(self._sector.floor_z, self.other_side_sector.floor_z) else: peg = max(self._sector.ceiling_z, self.other_side_sector.ceiling_z) self._parts["middle"] = sector_geometry.GeometryPart( self._wall.wall.over_picnum, self._wall.wall.palette, self._wall.data.pan_always, "middle", ) self._make_wall_part( all_geometry, peg, lambda point: self.other_side_sector.floor_z_at_point(point ), lambda point: self.other_side_sector.ceiling_z_at_point( point), self._parts["middle"], ) self._needs_geometry_reset = False