def init_label(self): cvsmr.image_init(self.name + "-n") self.temp = cvsmr.sprite_object(self.name + "-n", [0, 0], 0) self.raw_length = self.temp.sprite.width self.raw_height = self.temp.sprite.height self.temp = None
def __init__(self): cvsmgmt.scene_object.__init__(self, 0) self.handlers[0] = True self.handlers[5] = True self.handlers[3] = True self.render_objects = [[cvsmr.sprite_object("ocean", [0, 0], 0)]] self.render_objects[0][0].scale(100, 100) self.checkbox.set_source(self.render_objects[0][0])
def __init__(self, anchor, group_num = config.num_scene_groups, sprite_name = None): self.anchor = anchor self.group_num = group_num if(sprite_name != None): self.sprite = cvsmr.sprite_object(sprite_name, anchor, group_num) else: self.sprite = None self.elements = None
def __init__(self, anchor, sprite_name, clicked_sprite_name, group_num = config.num_scene_groups+1): cvsmgmt.scene_object.__init__(self,group_num) self.sprite_name = sprite_name self.click_sprite_name = clicked_sprite_name self.render_objects.append([cvsmr.sprite_object(sprite_name, anchor, group_num)]) self.click_state = False self.checkbox.set_source(self.render_objects[0][0]) self.handlers[0] = True self.handlers[4] = True
def __init__(self, scroll_menu, group_num, sprite_name, anchor, height): cvsmgmt.scene_object.__init__(self,group_num) self.anchor = anchor self.render_objects.append([cvsmr.sprite_object(sprite_name, anchor, group_num)]) self.checkbox.set_source(self.render_objects[0][0]) self.anchor_original = anchor[1] - self.render_objects[0][0].sprite.height/2 self.height = height self.scroll_menu = scroll_menu self.handlers[0] = True self.handlers[5] = True
def __init__(self, anchor, group_num, char_width, sprite_name): cvsmgmt.scene_object.__init__(self,group_num) self.anchor = anchor self.width = char_width * 20 #pixel width, experiment with the constant self.broad_checkbox(self.anchor[0],self.anchor[1], self.anchor[0] + self.width, self.anchor[1] + 60) self.char_width = char_width self.string = "" self.render_objects = [[ cvsmr.label_object("", anchor, group_num+1), cvsmr.sprite_object(sprite_name, anchor, group_num) ]] self.render_objects[0][0].set_style(20,color = (255,255,255,255)) self.handlers[0] = True self.handlers[7] = True self.handlers[8] = True self.handlers[9] = True self.flash_state = False self.flash_update_entry = cvsmgmt.persistent_update_entry(30, self.flash)
def init_provinces(group): mysize = 10 fileone = open("resources/map/num.txt", "r") file = fileone.read() fileone.close() config.num_provinces = int(file) config.provinces = [None] * config.num_provinces # polygon fileone = open("resources/map/mapt.txt", "r") file = fileone.read() fileone.close() map = file.split("\n") for i in range(0, int(len(map) / 2)): file = map[i * 2 + 1].split("\t") temp_poly = cvsmr.polygon_object(group_num=group) temp_poly.vertices = [None] * ((len(file) - 1) * 2) for j in range(0, len(file) - 1): if (file[j] != ''): temp = file[j].split(",") temp_poly.vertices[j * 2] = (float(temp[0]) / 10.0 + 820.0) * mysize temp_poly.vertices[j * 2 + 1] = ((11000 - float(temp[1])) / 10.0) * mysize temp_poly.solid_color_coords(255, 255, 255) config.provinces[i] = province() config.provinces[i].render_objects[0][0] = temp_poly config.provinces[i].checkbox.set_source(temp_poly) config.provinces[i].set_id(int(map[i * 2].split("]")[0][1:])) config.provinces[i].index = i config.provinces[i].inside_coord = [(int(map[i * 2].split("\t")[2].split(",")[0]) + 820) * mysize, (11000 - int(map[i * 2].split("\t")[2].split(",")[1]) * 10) * mysize / 10] # province borders config.province_borders = cvsmgmt.scene_object() config.province_borders.render_objects = [[cvsmr.line_object(config.line_groups["1/" + str(group + 1)])]] fileone = open("resources/map/mapl.txt", "r") file = fileone.read() fileone.close() map = file.split("\n") for i in range(0, int(len(map) / 2)): # int(len(map)/2) file = map[i * 2 + 1].split("\t") temp_poly = cvsmr.line_object(config.line_groups["3/" + str(group + 3)]) temp_poly.vertices_loop = [0] * (len(file) - 1) * 2 for j in range(0, len(file)): if (file[j] != ''): temp = file[j].split(",") temp_poly.vertices_loop[j * 2] = (((float(temp[0]))) / 10 + 820) * mysize temp_poly.vertices_loop[j * 2 + 1] = ((11000 - float(temp[1])) / 10) * mysize temp_poly.convert_loop() temp_poly.solid_color_coords(70,70,70) config.provinces[i].border = temp_poly config.provinces[i].name = map[i * 2].split("\t")[1] #add the completed province border loop to the uniform thing for i in range(0,len(temp_poly.vertices)): config.province_borders.render_objects[0][0].vertices.append(temp_poly.vertices[i]) config.province_borders.render_objects[0][0].solid_color_coords(70,70,70) # setting adjacents fileone = open("resources/map/mapa.txt", "r") file = fileone.read() fileone.close() adj = file.split("\n") for i in range(0, int(len(map) / 2)): tempc = adj[i * 2].split('\t') temp1 = adj[1 + i * 2].split('\t') config.provinces[i].centroid = [((float(tempc[2].split(',')[0])) / 10 + 820) * mysize, ((11000 - (float(tempc[2].split(',')[1]))) / 10) * mysize] config.provinces[i].centroid_score = int(tempc[3]) for p in range(0, len(temp1) - 1): config.provinces[i].adjacents_border.append([]) temp = temp1[p].split(',') for j in range(0, len(temp)): if (temp[j] != '' and temp[j] != 'False'): config.provinces[i].adjacents_border[p].append(int(temp[j])) if (int(temp[j]) not in config.provinces[i].adjacents): config.provinces[i].adjacents.append(config.provinces[int(temp[j])]) elif (temp[j] == 'False'): config.provinces[i].adjacents_border[p].append(-1) # labels fileone = open("resources/map/map_label.txt", "r") file = fileone.read().split("\n") fileone.close() for i in range(0, len(config.provinces)): me = config.provinces[i] temp = file[i].split("\t") cvsmr.image_init(me.name) temp_sprite = cvsmr.sprite_object(me.name, [((float(temp[1].split(",")[0])) / 10.0 + 820.0) * mysize, ((11000 - (float(temp[1].split(",")[1]))) / 10.0) * mysize], group + 4) #temp_sprite.sprite.update(scale_x=0.8, scale_y=0.8) temp_sprite.sprite.update(rotation=math.degrees(float(temp[2]))) me.label = temp_sprite
def __init__(self): cvsmgmt.scene_object.__init__(self, 5) self.render_objects = [[cvsmr.sprite_object("terrain_map", [0, 0], 4)]] self.render_objects[0][0].scale(3.33, 3.33) self.render_objects[0][0].coords(8200,0)
def draw_label(self): self.body_labels = [] # Make a label for each body for r in range(0, len(self.bodies)): # Make a new label for this body self.body_labels.append([cvsmr.sprite_object(self.name + "-n", [0, 0], 5), None]) # Find bounds for the body self.maxx = 0 self.minx = 99999999 self.maxy = 0 self.miny = 99999999 for i in range(1, len(self.bodies[r])): if (self.bodies[r][i] != None): if (self.maxx < self.bodies[r][i].centroid[0]): self.maxx = self.bodies[r][i].centroid[0] elif (self.minx > self.bodies[r][i].centroid[0]): self.minx = self.bodies[r][i].centroid[0] if (self.maxy < self.bodies[r][i].centroid[1]): self.maxy = self.bodies[r][i].centroid[1] elif (self.miny > self.bodies[r][i].centroid[1]): self.miny = self.bodies[r][i].centroid[1] self.sumx = 0 self.sumy = 0 self.scoresum = 0 self.body_num = 0 for i in range(0, len(self.bodies[r])): if (self.bodies[r][i] != None): self.sumx += self.bodies[r][i].centroid[0] * self.bodies[r][i].centroid_score self.sumy += self.bodies[r][i].centroid[1] * self.bodies[r][i].centroid_score self.scoresum += self.bodies[r][i].centroid_score self.avgx = self.sumx / (self.scoresum) self.avgy = self.sumy / (self.scoresum) if (self.maxx - self.minx > (self.maxy - self.miny) * 0.8): self.leftxsum = 0 self.rightxsum = 0 self.leftysum = 0 self.rightysum = 0 self.leftxscore = 0 self.rightxscore = 0 self.leftyscore = 0 self.rightyscore = 0 for i in range(0, len(self.bodies[r])): if (self.bodies[r][i] != None): if (self.bodies[r][i].centroid[0] <= self.avgx): self.leftxsum += self.bodies[r][i].centroid[0] * self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.leftxscore += self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.leftysum += self.bodies[r][i].centroid[1] * self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) self.leftyscore += self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) else: self.rightxsum += self.bodies[r][i].centroid[0] * self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.rightxscore += self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.rightysum += self.bodies[r][i].centroid[1] * self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) self.rightyscore += self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) self.point1 = [self.leftxsum / self.leftxscore, self.leftysum / self.leftyscore] self.point2 = [self.rightxsum / self.rightxscore, self.rightysum / self.rightyscore] else: self.topxsum = 0 self.topysum = 0 self.bottomxsum = 0 self.bottomysum = 0 self.topxscore = 0 self.topyscore = 0 self.bottomxscore = 0 self.bottomyscore = 0 for i in range(0, len(self.bodies[r])): if (self.bodies[r][i] != None): if (self.bodies[r][i].centroid[1] <= self.avgy): self.bottomxsum += self.bodies[r][i].centroid[0] * self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.bottomxscore += self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.bottomysum += self.bodies[r][i].centroid[1] * self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) self.bottomyscore += self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) else: self.topxsum += self.bodies[r][i].centroid[0] * self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.topxscore += self.bodies[r][i].centroid_score * abs( self.avgx - self.bodies[r][i].centroid[0]) self.topysum += self.bodies[r][i].centroid[1] * self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) self.topyscore += self.bodies[r][i].centroid_score * abs( self.avgy - self.bodies[r][i].centroid[1]) self.point1 = [self.topxsum / self.topxscore, self.topysum / self.topyscore] self.point2 = [self.bottomxsum / self.bottomxscore, self.bottomysum / self.bottomyscore] if (self.point1[0] > self.point2[0]): self.temp = self.point1 self.point1 = self.point2 self.point2 = self.temp self.length = ((self.point2[0] - self.point1[0]) ** 2 + (self.point2[1] - self.point1[1]) ** 2) ** 0.5 self.line_vec = [(self.point2[0] - self.point1[0]) / self.length, (self.point2[1] - self.point1[1]) / self.length] self.angle = math.degrees(math.asin(self.line_vec[1])) self.length_scale = self.length / self.raw_length self.final_scale = self.length_scale self.perp = [self.line_vec[1] * self.raw_height * self.final_scale / 2, -1 * self.line_vec[0] * self.raw_height * self.final_scale / 2] # make_label self.length_progress = 0 self.body_labels[r][0].sprite.update(x=self.point1[0] + self.perp[0], y=self.point1[1] + self.perp[1], scale_x=self.final_scale, scale_y=self.final_scale, rotation=-1 * self.angle) self.body_labels[r][1] = self.final_scale '''